@@ -188,6 +188,10 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
188
188
@ tmps ;
189
189
}
190
190
191
+ method cuid () {
192
+ $ ! qast ?? $ ! qast . cuid !! NQPMu;
193
+ }
194
+
191
195
method var_type ($ var ) { % ! var_types {$ var . name } }
192
196
method register_var_type ($ var , $ type ) { % ! var_types {$ var . name } := $ type }
193
197
@@ -860,15 +864,28 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
860
864
my $ cuid := self . mangled_cuid($ _ . key );
861
865
my $ reg := $ _ . value ;
862
866
867
+ my $ expected_outer := % * BLOCKS_INFO {$ _ . key }. outer;
868
+
869
+ if $ expected_outer . cuid ne $ * BLOCK . cuid {
870
+ @ capture_inners . push (" /*static block*/\n " );
871
+ @ capture_inners . push (" (function() \{\n " );
872
+ @ capture_inners . push (" var { $ expected_outer . ctx} = null;\n " );
873
+ }
874
+
863
875
if % * BLOCKS_AS_METHOD {$ _ . key } {
864
876
@ capture_inners . push (" $ reg = $ cuid .method" );
865
877
}
866
878
else {
867
879
@ capture_inners . push (" $ reg = $ cuid .capture" );
868
880
}
869
881
882
+
870
883
@ capture_inners . push (% * BLOCKS_DONE {$ _ . key });
871
884
@ capture_inners . push (" ;\n " );
885
+
886
+ if $ expected_outer . cuid ne $ * BLOCK . cuid {
887
+ @ capture_inners . push (" \} )();\n " );
888
+ }
872
889
}
873
890
Chunk. void (| @ capture_inners );
874
891
}
@@ -909,6 +926,8 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
909
926
my $ * CTX := self . unique_var(' ctx' );
910
927
$ * BLOCK . ctx($ * CTX );
911
928
929
+ % * BLOCKS_INFO {$ node . cuid} := $ * BLOCK ;
930
+
912
931
my $ body_want := $ node . blocktype eq ' immediate' ?? $ want !! $ T_OBJ ;
913
932
914
933
my $ as_method := self . looks_like_a_method($ node );
@@ -1238,6 +1257,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
1238
1257
1239
1258
# Blocks we've seen while compiling.
1240
1259
my % * BLOCKS_DONE ;
1260
+ my % * BLOCKS_INFO ;
1241
1261
my % * BLOCKS_AS_METHOD ;
1242
1262
my % * BLOCKS_DONE_CPS ;
1243
1263
0 commit comments