Espruino/tests/test_string_noparse.js
Gordon Williams 1f80e6e69b Fix if (0);"test"||fail() 2v19 regression - strings after if(0) didn't get interpreted
Ensure eval("1;;;")==1 - eval("1;")==1 before, but not eval("1;;")

We hit this with minification in the AT library... If there's a string right after an if(0) it
doesn't get parsed!

This happens because since 2v19ish we're no longer storing string contents in RAM if
we're not supposed to be executing. But we need to be sure we don't Lex too far ahead
with execute=false set
2023-09-13 16:39:08 +01:00

21 lines
672 B
JavaScript

function fail(n) {
throw new Error("FAILED at "+n);
}
/* We hit this with minification in the AT library... If there's a string right after an if(0) it
doesn't get parsed!
This happens because since 2v19ish we're no longer storing string contents in RAM if
we're not supposed to be executing. But we need to be sure we don't Lex too far ahead
with execute=false set
*/
while (0) 1;"test"||fail("while") // ok
for (;0;);"test"||fail("for") // ok
if (1) 1;"test"||fail("if(1)1;") // ok
if (0) 1;"test"||fail("if(0)1;") // failed
if (0);"test"||fail("if(0);") // failed
if (1);else;"test"||fail("if(1);else;") // failed
// if we got here we're ok
result=1