@@ -155,11 +155,6 @@ export class ScriptLetContext {
155
155
for ( const callback of callbacks ) {
156
156
callback ( node as E , result ) ;
157
157
}
158
- ( node as any ) . parent = parent ;
159
-
160
- tokens . shift ( ) ; // (
161
- tokens . pop ( ) ; // )
162
- tokens . pop ( ) ; // ;
163
158
164
159
if ( isTS ) {
165
160
removeScope (
@@ -184,6 +179,12 @@ export class ScriptLetContext {
184
179
) ;
185
180
}
186
181
182
+ ( node as any ) . parent = parent ;
183
+
184
+ tokens . shift ( ) ; // (
185
+ tokens . pop ( ) ; // )
186
+ tokens . pop ( ) ; // ;
187
+
187
188
// Disconnect the tree structure.
188
189
exprSt . expression = null as never ;
189
190
}
@@ -242,7 +243,6 @@ export class ScriptLetContext {
242
243
for ( const callback of callbacks ) {
243
244
callback ( node , result ) ;
244
245
}
245
- ( node as any ) . parent = parent ;
246
246
247
247
const scope = result . getScope ( decl ) ;
248
248
for ( const variable of scope . variables ) {
@@ -253,6 +253,8 @@ export class ScriptLetContext {
253
253
}
254
254
}
255
255
256
+ ( node as any ) . parent = parent ;
257
+
256
258
tokens . shift ( ) ; // const
257
259
tokens . pop ( ) ; // ;
258
260
@@ -340,11 +342,6 @@ export class ScriptLetContext {
340
342
341
343
// Process for nodes
342
344
callback ( expr , ctx , idx ) ;
343
- ( expr as any ) . parent = eachBlock ;
344
- ( ctx as any ) . parent = eachBlock ;
345
- if ( idx ) {
346
- ( idx as any ) . parent = eachBlock ;
347
- }
348
345
349
346
// Process for scope
350
347
result . registerNodeToScope ( eachBlock , scope ) ;
@@ -365,6 +362,12 @@ export class ScriptLetContext {
365
362
removeReference ( ref , scope . upper ! ) ;
366
363
}
367
364
365
+ ( expr as any ) . parent = eachBlock ;
366
+ ( ctx as any ) . parent = eachBlock ;
367
+ if ( idx ) {
368
+ ( idx as any ) . parent = eachBlock ;
369
+ }
370
+
368
371
tokens . shift ( ) ; // Array
369
372
tokens . shift ( ) ; // .
370
373
tokens . shift ( ) ; // from
@@ -502,7 +505,7 @@ export class ScriptLetContext {
502
505
range,
503
506
} ) ;
504
507
if ( this . ctx . isTypeScript ( ) ) {
505
- source += ` : (${ arrayTypings [ index ] } )` ;
508
+ source += `: (${ arrayTypings [ index ] } )` ;
506
509
}
507
510
}
508
511
const restore = this . appendScript (
@@ -641,6 +644,7 @@ export class ScriptLetContext {
641
644
const comments = result . ast . comments ;
642
645
const processedComments = [ ] ;
643
646
const nodeToScope = getNodeToScope ( result . scopeManager ! ) ;
647
+ const postprocessList : ( ( ) => void ) [ ] = [ ] ;
644
648
645
649
let tok ;
646
650
while ( ( tok = tokens . shift ( ) ) ) {
@@ -749,6 +753,7 @@ export class ScriptLetContext {
749
753
750
754
result . ast . tokens = processedTokens ;
751
755
result . ast . comments = processedComments ;
756
+ postprocessList . forEach ( ( p ) => p ( ) ) ;
752
757
753
758
// Helpers
754
759
/** Get scope */
@@ -763,7 +768,12 @@ export class ScriptLetContext {
763
768
764
769
/** Register node to scope */
765
770
function registerNodeToScope ( node : any , scope : Scope ) : void {
766
- scope . block = node ;
771
+ // If we replace the `scope.block` at this time,
772
+ // the scope restore calculation will not work, so we will replace the `scope.block` later.
773
+ postprocessList . push ( ( ) => {
774
+ scope . block = node ;
775
+ } ) ;
776
+
767
777
const scopes = nodeToScope . get ( node ) ;
768
778
if ( scopes ) {
769
779
scopes . push ( scope ) ;
0 commit comments