File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
- import type { ExpressionNode , TransformContext } from '../src'
1
+ import { babelParse , walkIdentifiers } from '@vue/compiler-sfc'
2
+ import {
3
+ type ExpressionNode ,
4
+ type TransformContext ,
5
+ isReferencedIdentifier ,
6
+ } from '../src'
2
7
import { type Position , createSimpleExpression } from '../src/ast'
3
8
import {
4
9
advancePositionWithClone ,
@@ -115,3 +120,18 @@ test('toValidAssetId', () => {
115
120
'_component_test_2797935797_1' ,
116
121
)
117
122
} )
123
+
124
+ describe ( 'isReferencedIdentifier' , ( ) => {
125
+ test ( 'identifiers in function parameters should not be inferred as references' , ( ) => {
126
+ expect . assertions ( 4 )
127
+ const ast = babelParse ( `(({ title }) => [])` )
128
+ walkIdentifiers (
129
+ ast . program . body [ 0 ] ,
130
+ ( node , parent , parentStack , isReference ) => {
131
+ expect ( isReference ) . toBe ( false )
132
+ expect ( isReferencedIdentifier ( node , parent , parentStack ) ) . toBe ( false )
133
+ } ,
134
+ true ,
135
+ )
136
+ } )
137
+ } )
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ export function isReferencedIdentifier(
122
122
return false
123
123
}
124
124
125
- if ( isReferenced ( id , parent ) ) {
125
+ if ( isReferenced ( id , parent , parentStack [ parentStack . length - 2 ] ) ) {
126
126
return true
127
127
}
128
128
@@ -132,7 +132,8 @@ export function isReferencedIdentifier(
132
132
case 'AssignmentExpression' :
133
133
case 'AssignmentPattern' :
134
134
return true
135
- case 'ObjectPattern' :
135
+ case 'ObjectProperty' :
136
+ return parent . key !== id && isInDestructureAssignment ( parent , parentStack )
136
137
case 'ArrayPattern' :
137
138
return isInDestructureAssignment ( parent , parentStack )
138
139
}
You can’t perform that action at this time.
0 commit comments