Skip to content

Commit a1416da

Browse files
committed
Unbreak HATs
1 parent e19c766 commit a1416da

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/jsgen.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,10 @@ class JSGenerator {
762762
// If you don't do this, the loop effectively yields twice per iteration and will run at half-speed.
763763
const isLastInLoop = this.isLastBlockInLoop();
764764

765-
if (node.blockType === BlockType.COMMAND) {
765+
const blockType = node.blockType;
766+
if (blockType === BlockType.COMMAND || blockType === BlockType.HAT) {
766767
this.source += `${this.generateCompatibilityLayerCall(node, isLastInLoop)};\n`;
767-
} else if (node.blockType === BlockType.CONDITIONAL) {
768+
} else if (blockType === BlockType.CONDITIONAL) {
768769
this.source += `switch (Math.round(${this.generateCompatibilityLayerCall(node, isLastInLoop)})) {\n`;
769770
for (let i = 0; i < node.substacks.length; i++) {
770771
this.source += `case ${i + 1}: {\n`;
@@ -773,12 +774,14 @@ class JSGenerator {
773774
this.source += `}\n`;
774775
}
775776
this.source += `}\n`;
776-
} else if (node.blockType === BlockType.LOOP) {
777+
} else if (blockType === BlockType.LOOP) {
777778
const stackFrameName = this.localVariables.next();
778779
this.source += `const ${stackFrameName} = persistentStackFrame();\n`;
779780
this.source += `while (toBoolean(${this.generateCompatibilityLayerCall(node, isLastInLoop, stackFrameName)})) {\n`;
780781
this.descendStack(node.substacks[0], new Frame(true));
781782
this.source += '}\n';
783+
} else {
784+
throw new Error(`Unknown block type: ${blockType}`);
782785
}
783786

784787
if (isLastInLoop) {

0 commit comments

Comments
 (0)