Recover from "missing semicolon" errors (#12437)

* Recover from "missing semicolon" errors

* Update other tests

* Fix flow

* Fix windows test

* Add back deleted test
This commit is contained in:
Nicolò Ribaudo
2021-02-01 10:08:43 +01:00
committed by GitHub
parent 2ea0a5d021
commit 8cf0a757d5
127 changed files with 2077 additions and 164 deletions

View File

@@ -99,6 +99,7 @@ export const ErrorMessages = Object.freeze({
MissingClassName: "A class name is required",
MissingEqInAssignment:
"Only '=' operator can be used for specifying default value.",
MissingSemicolon: "Missing semicolon",
MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX",
MixingCoalesceWithLogical:
"Nullish coalescing operator(??) requires parens when mixing with logical operators",

View File

@@ -915,9 +915,9 @@ export default class StatementParser extends ExpressionParser {
init: ?(N.VariableDeclaration | N.Expression),
): N.ForStatement {
node.init = init;
this.expect(tt.semi);
this.semicolon(/* allowAsi */ false);
node.test = this.match(tt.semi) ? null : this.parseExpression();
this.expect(tt.semi);
this.semicolon(/* allowAsi */ false);
node.update = this.match(tt.parenR) ? null : this.parseExpression();
this.expect(tt.parenR);

View File

@@ -105,8 +105,9 @@ export default class UtilParser extends Tokenizer {
// Consume a semicolon, or, failing that, see if we are allowed to
// pretend that there is a semicolon at this position.
semicolon(): void {
if (!this.isLineTerminator()) this.unexpected(null, tt.semi);
semicolon(allowAsi: boolean = true): void {
if (allowAsi ? this.isLineTerminator() : this.eat(tt.semi)) return;
this.raise(this.state.lastTokEnd, Errors.MissingSemicolon);
}
// Expect a token of a given type. If found, consume it, otherwise,