diff --git a/packages/babylon/src/tokenizer/index.js b/packages/babylon/src/tokenizer/index.js index 608a85bf79..b6b8fdc501 100644 --- a/packages/babylon/src/tokenizer/index.js +++ b/packages/babylon/src/tokenizer/index.js @@ -827,13 +827,22 @@ export default class Tokenizer extends LocationParser { } const content = this.input.slice(start, this.state.pos); ++this.state.pos; - // Need to use `readWord1` because '\uXXXX' sequences are allowed - // here (don't ask). - const mods = this.readWord1(); - if (mods) { - const validFlags = /^[gmsiyu]*$/; - if (!validFlags.test(mods)) { - this.raise(start, "Invalid regular expression flag"); + + const validFlags = /^[gmsiyu]$/; + let mods = ""; + while (this.state.pos < this.input.length) { + const char = this.input[this.state.pos]; + const charCode = this.fullCharCodeAtPos(); + if (validFlags.test(char)) { + ++this.state.pos; + mods += char; + } else if ( + isIdentifierChar(charCode) || + charCode === charCodes.backslash + ) { + this.raise(this.state.pos, "Invalid regular expression flag"); + } else { + break; } } diff --git a/packages/babylon/test/fixtures/core/uncategorised/108/options.json b/packages/babylon/test/fixtures/core/uncategorised/108/options.json new file mode 100644 index 0000000000..adf556b0a3 --- /dev/null +++ b/packages/babylon/test/fixtures/core/uncategorised/108/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Invalid regular expression flag (1:16)" +} diff --git a/packages/babylon/test/fixtures/core/uncategorised/108/output.json b/packages/babylon/test/fixtures/core/uncategorised/108/output.json deleted file mode 100644 index 83c8e811c9..0000000000 --- a/packages/babylon/test/fixtures/core/uncategorised/108/output.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "sourceType": "script", - "body": [ - { - "type": "VariableDeclaration", - "start": 0, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "declarations": [ - { - "type": "VariableDeclarator", - "start": 4, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "id": { - "type": "Identifier", - "start": 4, - "end": 5, - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 5 - }, - "identifierName": "x" - }, - "name": "x" - }, - "init": { - "type": "RegExpLiteral", - "start": 8, - "end": 22, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 1, - "column": 22 - } - }, - "extra": { - "raw": "/[P QR]/\\u0067" - }, - "pattern": "[P QR]", - "flags": "g" - } - } - ], - "kind": "var" - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babylon/test/fixtures/core/uncategorised/366/options.json b/packages/babylon/test/fixtures/core/uncategorised/366/options.json index cd4fc8b6bd..d67d8472c0 100644 --- a/packages/babylon/test/fixtures/core/uncategorised/366/options.json +++ b/packages/babylon/test/fixtures/core/uncategorised/366/options.json @@ -1,3 +1,3 @@ { - "throws": "Bad character escape sequence (1:17)" -} \ No newline at end of file + "throws": "Invalid regular expression flag (1:15)" +} diff --git a/scripts/tests/flow/flow_tests_whitelist.txt b/scripts/tests/flow/flow_tests_whitelist.txt index 3acff5ef56..77bc9b9cc2 100644 --- a/scripts/tests/flow/flow_tests_whitelist.txt +++ b/scripts/tests/flow/flow_tests_whitelist.txt @@ -33,7 +33,6 @@ invalid_syntax/migrated_0000.js invalid_syntax/migrated_0001.js invalid_syntax/migrated_0002.js invalid_syntax/migrated_0003.js -invalid_syntax/migrated_0010.js private_class_properties/valid.js types/annotations/migrated_0001.js types/annotations_in_comments_invalid/migrated_0003.js diff --git a/scripts/tests/test262/test262_whitelist.txt b/scripts/tests/test262/test262_whitelist.txt index a2a5fb7eee..2f6696503c 100644 --- a/scripts/tests/test262/test262_whitelist.txt +++ b/scripts/tests/test262/test262_whitelist.txt @@ -170,8 +170,6 @@ language/import/escaped-from.js(default) language/import/escaped-from.js(strict mode) language/literals/regexp/early-err-dup-flag.js(default) language/literals/regexp/early-err-dup-flag.js(strict mode) -language/literals/regexp/early-err-flags-unicode-escape.js(default) -language/literals/regexp/early-err-flags-unicode-escape.js(strict mode) language/literals/regexp/early-err-pattern.js(default) language/literals/regexp/early-err-pattern.js(strict mode) language/literals/regexp/invalid-braced-quantifier-exact.js(default)