Skip to content

Commit 3bf5615

Browse files
committed
use return 0,<exp> to try to deal with comments.
The problem is JavaScript's idiotic automatic semicolon insertion. If you have an expression like ```js return 2 ``` That's just returns undefined. So, if the user enters ``` // hello t ``` That gets converted to ```js return // hello t ``` We used to try to strip linefeeds and comments and it mostly worked but the comment stripper was simple because who the F wants to write a whole effing parser just to strip comments. As a try, if we change the generated code to ```js return 0,// hello t ``` The automatic semicolon insertion doesn't happen and it correctly returns t.
1 parent d99fde3 commit 3bf5615

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/ByteBeatCompiler.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export default class ByteBeatCompiler {
88

99
static removeCommentsAndLineBreaks(x) {
1010
// remove comments (hacky)
11-
x = x.replace(/\/\/.*/g, ' ');
12-
x = x.replace(/\n/g, ' ');
13-
x = x.replace(/\/\*.*?\*\//g, ' ');
11+
//x = x.replace(/\/\/.*/g, ' ');
12+
//x = x.replace(/\n/g, ' ');
13+
//x = x.replace(/\/\*.*?\*\//g, ' ');
1414
return x;
1515
}
1616

@@ -326,7 +326,7 @@ export default class ByteBeatCompiler {
326326
} else { // infix
327327
x = `
328328
return function(t, i, stack, window, extra) {
329-
return ${ByteBeatCompiler.strip(x)};
329+
return 0,${ByteBeatCompiler.strip(x)};
330330
}`;
331331
}
332332
}

0 commit comments

Comments
 (0)