Skip to content

Commit 471f3f6

Browse files
committed
Fixed errors
1 parent 850eabc commit 471f3f6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cubestack/cubestack.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var lex = (code) => {
109109
tokens.push(new Token("error", "invalid move", move, `${move} is not a valid move on a 3x3 rubiks cube`));
110110
}
111111

112-
for (var move of (code ?? "").replace(/\n/g, " ").replace(/\s\s/g, " ").split(" ")) {
112+
for (var move of (code ?? "").replace(/\n/g, " ").replace(/\s\s/g, " ").split(" ").filter(move => !!move)) {
113113
if (state == "string") {
114114
if (base36map.includes(move)) {
115115
token.push(move);
@@ -348,16 +348,17 @@ var compile = (tokens, input = "", options = {}) => {
348348
compiled.push(`}`);
349349
}
350350
} else if (token.type == "error") {
351+
globalThis.errored = true;
351352
if (options.platform == "node") {
352-
compiled.push(`process.stdout.write("error:\\n ${token.name}\\n ${token.value}");`);
353+
compiled.push(`process.stdout.write("error:\\n ${token.name}\\n ${token.value}\\n");`);
353354
} else if (options.platform == "web") {
354-
compiled.push(`$("#output").innerText += "error:\\n ${token.name}\\n ${token.value}";`);
355+
compiled.push(`$("#output").innerText += "error:\\n ${token.name}\\n ${token.value}\\n";`);
355356
}
356357
break;
357358
}
358359
}
359360

360-
if (!printed && options.setup) {
361+
if (!printed && options.setup && !globalThis.errored) {
361362
compiled.push(
362363
`var toPrint = ${options.stackName}.pop() ?? "";`,
363364
`if (typeof toPrint != "string") toPrint = JSON.stringify(toPrint, null, 2);`,

0 commit comments

Comments
 (0)