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:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user