ladybird/Libraries/LibJS/Tests/automatic-semicolon-insertion.js
Matthew Olsson d52ea37717 LibJS: Integrate labels into the Interpreter
The interpreter now considers a statement or block's label when
considering whether or not to break. All statements can be labelled.
2020-05-29 16:20:32 +02:00

72 lines
1.3 KiB
JavaScript

load("test-common.js");
/**
* This file tests automatic semicolon insertion rules.
* If this file produces syntax errors, something is wrong.
*/
function bar() {
// https://github.com/SerenityOS/serenity/issues/1829
if (1)
return 1;
else
return 0;
if (1)
return 1
else
return 0
if (1)
return 1
else
return 0;
}
function foo() {
label:
for (var i = 0; i < 4; i++) {
break // semicolon inserted here
continue // semicolon inserted here
break label // semicolon inserted here
continue label // semicolon inserted here
}
var j // semicolon inserted here
do {
} while (1 === 2) // semicolon inserted here
return // semicolon inserted here
1;
var curly/* semicolon inserted here */}
function baz() {
let counter = 0;
let outer;
outer:
for (let i = 0; i < 5; ++i) {
for (let j = 0; j < 5; ++j) {
continue // semicolon inserted here
outer // semicolon inserted here
}
counter++;
}
return counter;
}
try {
assert(foo() === undefined);
assert(baz() === 5);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}
// This vardecl must appear exactly at the end of the file (no newline or whitespace after it)
var eof