@@ -739,7 +739,7 @@ export function compileScript(
739
739
if ( enableRefSugar && Object . keys ( refBindings ) . length ) {
740
740
for ( const node of scriptSetupAst ) {
741
741
if ( node . type !== 'ImportDeclaration' ) {
742
- walkIdentifiers ( node , ( id , parent ) => {
742
+ walkIdentifiers ( node , ( id , parent , parentStack ) => {
743
743
if ( refBindings [ id . name ] && ! refIdentifiers . has ( id ) ) {
744
744
if ( isStaticProperty ( parent ) && parent . shorthand ) {
745
745
// let binding used in a property shorthand
@@ -1337,8 +1337,6 @@ function genRuntimeEmits(emits: Set<string>) {
1337
1337
: ``
1338
1338
}
1339
1339
1340
- const parentStack : Node [ ] = [ ]
1341
-
1342
1340
/**
1343
1341
* Walk an AST and find identifiers that are variable references.
1344
1342
* This is largely the same logic with `transformExpressions` in compiler-core
@@ -1347,15 +1345,19 @@ const parentStack: Node[] = []
1347
1345
*/
1348
1346
function walkIdentifiers (
1349
1347
root : Node ,
1350
- onIdentifier : ( node : Identifier , parent : Node ) => void
1348
+ onIdentifier : ( node : Identifier , parent : Node , parentStack : Node [ ] ) => void
1351
1349
) {
1350
+ const parentStack : Node [ ] = [ ]
1352
1351
const knownIds : Record < string , number > = Object . create ( null )
1353
1352
; ( walk as any ) ( root , {
1354
1353
enter ( node : Node & { scopeIds ?: Set < string > } , parent : Node | undefined ) {
1355
1354
parent && parentStack . push ( parent )
1356
1355
if ( node . type === 'Identifier' ) {
1357
- if ( ! knownIds [ node . name ] && isRefIdentifier ( node , parent ! ) ) {
1358
- onIdentifier ( node , parent ! )
1356
+ if (
1357
+ ! knownIds [ node . name ] &&
1358
+ isRefIdentifier ( node , parent ! , parentStack )
1359
+ ) {
1360
+ onIdentifier ( node , parent ! , parentStack )
1359
1361
}
1360
1362
} else if ( isFunction ( node ) ) {
1361
1363
// walk function expressions and add its arguments to known identifiers
@@ -1411,7 +1413,7 @@ function walkIdentifiers(
1411
1413
} )
1412
1414
}
1413
1415
1414
- function isRefIdentifier ( id : Identifier , parent : Node ) {
1416
+ function isRefIdentifier ( id : Identifier , parent : Node , parentStack : Node [ ] ) {
1415
1417
// declaration id
1416
1418
if (
1417
1419
( parent . type === 'VariableDeclarator' ||
0 commit comments