@@ -55,14 +55,24 @@ export function walkIdentifiers(
55
55
// mark property in destructure pattern
56
56
; ( node as any ) . inPattern = true
57
57
} else if ( isFunctionType ( node ) ) {
58
- // walk function expressions and add its arguments to known identifiers
59
- // so that we don't prefix them
60
- walkFunctionParams ( node , id => markScopeIdentifier ( node , id , knownIds ) )
58
+ if ( node . scopeIds ) {
59
+ node . scopeIds . forEach ( id => markKnownIds ( id , knownIds ) )
60
+ } else {
61
+ // walk function expressions and add its arguments to known identifiers
62
+ // so that we don't prefix them
63
+ walkFunctionParams ( node , id =>
64
+ markScopeIdentifier ( node , id , knownIds )
65
+ )
66
+ }
61
67
} else if ( node . type === 'BlockStatement' ) {
62
- // #3445 record block-level local variables
63
- walkBlockDeclarations ( node , id =>
64
- markScopeIdentifier ( node , id , knownIds )
65
- )
68
+ if ( node . scopeIds ) {
69
+ node . scopeIds . forEach ( id => markKnownIds ( id , knownIds ) )
70
+ } else {
71
+ // #3445 record block-level local variables
72
+ walkBlockDeclarations ( node , id =>
73
+ markScopeIdentifier ( node , id , knownIds )
74
+ )
75
+ }
66
76
}
67
77
} ,
68
78
leave ( node : Node & { scopeIds ?: Set < string > } , parent : Node | undefined ) {
@@ -227,6 +237,14 @@ export function extractIdentifiers(
227
237
return nodes
228
238
}
229
239
240
+ function markKnownIds ( name : string , knownIds : Record < string , number > ) {
241
+ if ( name in knownIds ) {
242
+ knownIds [ name ] ++
243
+ } else {
244
+ knownIds [ name ] = 1
245
+ }
246
+ }
247
+
230
248
function markScopeIdentifier (
231
249
node : Node & { scopeIds ?: Set < string > } ,
232
250
child : Identifier ,
@@ -236,11 +254,7 @@ function markScopeIdentifier(
236
254
if ( node . scopeIds && node . scopeIds . has ( name ) ) {
237
255
return
238
256
}
239
- if ( name in knownIds ) {
240
- knownIds [ name ] ++
241
- } else {
242
- knownIds [ name ] = 1
243
- }
257
+ markKnownIds ( name , knownIds )
244
258
; ( node . scopeIds || ( node . scopeIds = new Set ( ) ) ) . add ( name )
245
259
}
246
260
0 commit comments