From b51e69c946dc2c9096c157fff4aac70dad65e400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 5 May 2021 09:23:24 -0400 Subject: [PATCH] fix: update chunkStart on missing unicode escape --- packages/babel-parser/src/tokenizer/index.js | 1 + .../fixtures/core/uncategorised/361/input.js | 1 - .../core/uncategorised/361/output.json | 25 ------------------- .../core/uncategorised/446/output.json | 4 +-- .../invalid-syntax/migrated_0032/output.json | 4 +-- .../migrated_0003/output.json | 4 +-- 6 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/core/uncategorised/361/input.js delete mode 100644 packages/babel-parser/test/fixtures/core/uncategorised/361/output.json diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 26dec238024f..cc3f13cef0cd 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -1462,6 +1462,7 @@ export default class Tokenizer extends ParserErrors { if (this.input.charCodeAt(++this.state.pos) !== charCodes.lowercaseU) { this.raise(this.state.pos, Errors.MissingUnicodeEscape); + chunkStart = this.state.pos - 1; continue; } diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/361/input.js b/packages/babel-parser/test/fixtures/core/uncategorised/361/input.js deleted file mode 100644 index 08eb2e095a9f..000000000000 --- a/packages/babel-parser/test/fixtures/core/uncategorised/361/input.js +++ /dev/null @@ -1 +0,0 @@ -x\ \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/361/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/361/output.json deleted file mode 100644 index 5a42dc401165..000000000000 --- a/packages/babel-parser/test/fixtures/core/uncategorised/361/output.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "type": "File", - "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, - "errors": [ - "SyntaxError: Expecting Unicode escape sequence \\uXXXX. (1:2)" - ], - "program": { - "type": "Program", - "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ExpressionStatement", - "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, - "expression": { - "type": "Identifier", - "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2},"identifierName":"xx\\"}, - "name": "xx\\" - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/core/uncategorised/446/output.json b/packages/babel-parser/test/fixtures/core/uncategorised/446/output.json index 9bdc5aca19d6..a0929f5950fc 100644 --- a/packages/babel-parser/test/fixtures/core/uncategorised/446/output.json +++ b/packages/babel-parser/test/fixtures/core/uncategorised/446/output.json @@ -16,8 +16,8 @@ "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, "expression": { "type": "Identifier", - "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2},"identifierName":"\\\\\\"}, - "name": "\\\\\\" + "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2},"identifierName":"\\\\"}, + "name": "\\\\" } } ], diff --git a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0032/output.json b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0032/output.json index 5a42dc401165..7fad8117d2b8 100644 --- a/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0032/output.json +++ b/packages/babel-parser/test/fixtures/esprima/invalid-syntax/migrated_0032/output.json @@ -15,8 +15,8 @@ "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2}}, "expression": { "type": "Identifier", - "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2},"identifierName":"xx\\"}, - "name": "xx\\" + "start":0,"end":2,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":2},"identifierName":"x\\"}, + "name": "x\\" } } ], diff --git a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json index 353591d6e66a..b1057bf575f9 100644 --- a/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json +++ b/packages/babel-parser/test/fixtures/esprima/statement-expression/migrated_0003/output.json @@ -15,8 +15,8 @@ "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, "expression": { "type": "Identifier", - "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8},"identifierName":"aa\\a"}, - "name": "aa\\a" + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8},"identifierName":"a\\a"}, + "name": "a\\a" } } ],