Skip to content

Commit c553490

Browse files
committed
Check old compiler stub after main switch statement
If extensions were overriding the default blocks, this is a breaking change, but they really shouldn't do that
1 parent fd70d15 commit c553490

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

src/compiler/irgen.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ class ScriptTreeGenerator {
9898
}
9999
}
100100

101-
this.oldCompilerStub = (
102-
oldCompilerCompatiblity.enabled ?
103-
new oldCompilerCompatiblity.ScriptTreeGeneratorStub(this) :
104-
null
105-
);
101+
this.oldCompilerStub = new oldCompilerCompatiblity.ScriptTreeGeneratorStub(this);
106102
}
107103

108104
setProcedureVariant (procedureVariant) {
@@ -206,13 +202,6 @@ class ScriptTreeGenerator {
206202
* @returns {IntermediateInput} Compiled input node for this input.
207203
*/
208204
descendInput (block, preserveStrings = false) {
209-
if (this.oldCompilerStub) {
210-
const oldCompilerResult = this.oldCompilerStub.descendInputFromNewCompiler(block);
211-
if (oldCompilerResult) {
212-
return oldCompilerResult;
213-
}
214-
}
215-
216205
switch (block.opcode) {
217206
case 'colour_picker':
218207
return this.createConstantInput(block.fields.COLOUR.value, true);
@@ -577,7 +566,14 @@ class ScriptTreeGenerator {
577566
if (compatBlocks.inputs.includes(block.opcode)) {
578567
return this.descendCompatLayerInput(block);
579568
}
580-
// It might be an extension block.
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.
581577
const blockInfo = this.getBlockInfo(block.opcode);
582578
if (blockInfo) {
583579
const type = blockInfo.info.blockType;
@@ -607,13 +603,6 @@ class ScriptTreeGenerator {
607603
* @returns {IntermediateStackBlock} Compiled node for this block.
608604
*/
609605
descendStackedBlock (block) {
610-
if (this.oldCompilerStub) {
611-
const oldCompilerResult = this.oldCompilerStub.descendStackedBlockFromNewCompiler(block);
612-
if (oldCompilerResult) {
613-
return oldCompilerResult;
614-
}
615-
}
616-
617606
switch (block.opcode) {
618607
case 'control_all_at_once':
619608
// In Scratch 3, this block behaves like "if 1 = 1"
@@ -955,7 +944,14 @@ class ScriptTreeGenerator {
955944
if (compatBlocks.stacked.includes(block.opcode)) {
956945
return this.descendCompatLayerStack(block);
957946
}
958-
// It might be an extension block.
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.
959955
const blockInfo = this.getBlockInfo(block.opcode);
960956
if (blockInfo) {
961957
const type = blockInfo.info.blockType;

src/compiler/old-compiler-compatibility.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* provided by the new compiler.
1414
* - Extensions treat IR nodes received from descendSubstack and similar as
1515
* opaque objects.
16+
* - Extensions are not trying to override the behavior of the native blocks.
1617
*/
1718

1819
const {InputOpcode, InputType} = require('./enums');
@@ -327,7 +328,6 @@ JSGeneratorStub.unstable_exports = {
327328
};
328329

329330
const oldCompilerCompatibility = {
330-
enabled: false,
331331
IRGeneratorStub,
332332
ScriptTreeGeneratorStub,
333333
TypedInput,

src/virtual-machine.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ class VirtualMachine extends EventEmitter {
244244

245245
i_will_not_ask_for_help_when_these_break: () => {
246246
this.emit('LEGACY_EXTENSION_API', 'i_will_not_ask_for_help_when_these_break');
247-
248247
const oldCompilerCompatibility = require('./compiler/old-compiler-compatibility.js');
249-
oldCompilerCompatibility.enabled = true;
250-
251248
return {
252249
IRGenerator: oldCompilerCompatibility.IRGeneratorStub,
253250
ScriptTreeGenerator: oldCompilerCompatibility.ScriptTreeGeneratorStub,

0 commit comments

Comments
 (0)