2020-07-03 21:39:25 +00:00
|
|
|
test("Issue #1829, if-else without braces or semicolons", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
const source = `if (1)
|
2020-11-11 22:16:37 +00:00
|
|
|
foo;
|
2020-07-03 21:39:25 +00:00
|
|
|
else
|
2020-11-11 22:16:37 +00:00
|
|
|
bar;
|
2020-04-17 13:52:38 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
if (1)
|
2020-11-11 22:16:37 +00:00
|
|
|
foo
|
2020-07-03 21:39:25 +00:00
|
|
|
else
|
2020-11-11 22:16:37 +00:00
|
|
|
bar
|
2020-04-17 13:52:38 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
if (1)
|
2020-11-11 22:16:37 +00:00
|
|
|
foo
|
2020-07-03 21:39:25 +00:00
|
|
|
else
|
2020-11-11 22:16:37 +00:00
|
|
|
bar;`;
|
2020-04-18 12:00:43 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
expect(source).toEval();
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
2020-04-18 12:00:43 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
test("break/continue, variable declaration, do-while, and return asi", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
const source = `function foo() {
|
2020-05-28 20:36:59 +00:00
|
|
|
label:
|
2020-04-17 13:52:38 +00:00
|
|
|
for (var i = 0; i < 4; i++) {
|
|
|
|
break // semicolon inserted here
|
|
|
|
continue // semicolon inserted here
|
2020-05-28 20:36:59 +00:00
|
|
|
|
|
|
|
break label // semicolon inserted here
|
|
|
|
continue label // semicolon inserted here
|
2020-04-17 13:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var j // semicolon inserted here
|
|
|
|
|
|
|
|
do {
|
|
|
|
} while (1 === 2) // semicolon inserted here
|
|
|
|
|
|
|
|
return // semicolon inserted here
|
|
|
|
1;
|
|
|
|
var curly/* semicolon inserted here */}
|
|
|
|
|
2021-06-18 18:09:17 +00:00
|
|
|
foo();`;
|
2020-05-28 20:36:59 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
expect(source).toEvalTo(undefined);
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("more break and continue asi", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
const source = `let counter = 0;
|
2020-07-03 21:39:25 +00:00
|
|
|
let outer;
|
2020-05-28 20:36:59 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
outer:
|
|
|
|
for (let i = 0; i < 5; ++i) {
|
|
|
|
for (let j = 0; j < 5; ++j) {
|
|
|
|
continue // semicolon inserted here
|
|
|
|
outer // semicolon inserted here
|
|
|
|
}
|
|
|
|
counter++;
|
2020-05-28 20:36:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-18 18:09:17 +00:00
|
|
|
counter;`;
|
2020-04-17 13:52:38 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
expect(source).toEvalTo(5);
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
2020-04-17 13:52:38 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
test("eof with no semicolon", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
expect("var eof").toEval();
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|