mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibJS: Always insert semicolon after do-while statement if missing
https://tc39.es/ecma262/#sec-additions-and-changes-that-introduce-incompatibilities-with-prior-editions 11.9.1: In ECMAScript 2015, Automatic Semicolon Insertion adds a semicolon at the end of a do-while statement if the semicolon is missing. This change aligns the specification with the actual behaviour of most existing implementations.
This commit is contained in:
parent
d278f61f4c
commit
b4e51249e9
Notes:
sideshowbarker
2024-07-19 01:41:00 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b4e51249e95 Pull-request: https://github.com/SerenityOS/serenity/pull/3863 Reviewed-by: https://github.com/awesomekling
2 changed files with 8 additions and 1 deletions
|
@ -1524,7 +1524,10 @@ NonnullRefPtr<DoWhileStatement> Parser::parse_do_while_statement()
|
|||
auto test = parse_expression(0);
|
||||
|
||||
consume(TokenType::ParenClose);
|
||||
consume_or_insert_semicolon();
|
||||
|
||||
// Since ES 2015 a missing semicolon is inserted here, despite the regular ASI rules not applying
|
||||
if (match(TokenType::Semicolon))
|
||||
consume();
|
||||
|
||||
return create_ast_node<DoWhileStatement>(move(test), move(body));
|
||||
}
|
||||
|
|
|
@ -18,3 +18,7 @@ test("exception in test expression", () => {
|
|||
do {} while (foo);
|
||||
}).toThrow(ReferenceError);
|
||||
});
|
||||
|
||||
test("automatic semicolon insertion", () => {
|
||||
expect("do {} while (false) foo").toEval();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue