@@ -98,7 +98,11 @@ class ScriptTreeGenerator {
9898 }
9999 }
100100
101- this . oldCompilerStub = new oldCompilerCompatiblity . ScriptTreeGeneratorStub ( this ) ;
101+ this . oldCompilerStub = (
102+ oldCompilerCompatiblity . enabled ?
103+ new oldCompilerCompatiblity . ScriptTreeGeneratorStub ( this ) :
104+ null
105+ ) ;
102106 }
103107
104108 setProcedureVariant ( procedureVariant ) {
@@ -202,6 +206,13 @@ class ScriptTreeGenerator {
202206 * @returns {IntermediateInput } Compiled input node for this input.
203207 */
204208 descendInput ( block , preserveStrings = false ) {
209+ if ( this . oldCompilerStub ) {
210+ const oldCompilerResult = this . oldCompilerStub . descendInputFromNewCompiler ( block ) ;
211+ if ( oldCompilerResult ) {
212+ return oldCompilerResult ;
213+ }
214+ }
215+
205216 switch ( block . opcode ) {
206217 case 'colour_picker' :
207218 return this . createConstantInput ( block . fields . COLOUR . value , true ) ;
@@ -566,14 +577,7 @@ class ScriptTreeGenerator {
566577 if ( compatBlocks . inputs . includes ( block . opcode ) ) {
567578 return this . descendCompatLayerInput ( block ) ;
568579 }
569-
570- // It might be an extension block using patches for the old compiler.
571- const oldCompilerResult = this . oldCompilerStub . descendInputFromNewCompiler ( block ) ;
572- if ( oldCompilerResult ) {
573- return oldCompilerResult ;
574- }
575-
576- // It might be an extension block using the default compatibility layer.
580+ // It might be an extension block.
577581 const blockInfo = this . getBlockInfo ( block . opcode ) ;
578582 if ( blockInfo ) {
579583 const type = blockInfo . info . blockType ;
@@ -603,6 +607,13 @@ class ScriptTreeGenerator {
603607 * @returns {IntermediateStackBlock } Compiled node for this block.
604608 */
605609 descendStackedBlock ( block ) {
610+ if ( this . oldCompilerStub ) {
611+ const oldCompilerResult = this . oldCompilerStub . descendStackedBlockFromNewCompiler ( block ) ;
612+ if ( oldCompilerResult ) {
613+ return oldCompilerResult ;
614+ }
615+ }
616+
606617 switch ( block . opcode ) {
607618 case 'control_all_at_once' :
608619 // In Scratch 3, this block behaves like "if 1 = 1"
@@ -944,14 +955,7 @@ class ScriptTreeGenerator {
944955 if ( compatBlocks . stacked . includes ( block . opcode ) ) {
945956 return this . descendCompatLayerStack ( block ) ;
946957 }
947-
948- // It might be an extension block using patches for the old compiler.
949- const oldCompilerResult = this . oldCompilerStub . descendStackedBlockFromNewCompiler ( block ) ;
950- if ( oldCompilerResult ) {
951- return oldCompilerResult ;
952- }
953-
954- // It might be an extension block using the default compatibility layer.
958+ // It might be an extension block.
955959 const blockInfo = this . getBlockInfo ( block . opcode ) ;
956960 if ( blockInfo ) {
957961 const type = blockInfo . info . blockType ;
0 commit comments