From 828169e6117a6f913f3d7c067fb3790a478cb839 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Mon, 28 Jan 2019 13:35:35 -0800 Subject: [PATCH] Fix line continuation with Unicode line terminators (#9403) --- packages/babel-parser/src/tokenizer/index.js | 3 +++ .../fixtures/es2015/uncategorised/22/input.js | 2 +- .../es2015/uncategorised/22/output.json | 24 +++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 270614a16e..f576698130 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -1213,6 +1213,8 @@ export default class Tokenizer extends LocationParser { case charCodes.lineFeed: this.state.lineStart = this.state.pos; ++this.state.curLine; + case charCodes.lineSeparator: + case charCodes.paragraphSeparator: return ""; default: if (ch >= charCodes.digit0 && ch <= charCodes.digit7) { @@ -1242,6 +1244,7 @@ export default class Tokenizer extends LocationParser { this.state.pos += octalStr.length - 1; return String.fromCharCode(octal); } + return String.fromCharCode(ch); } } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js index 7db23de554..4fa5abf7ff 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/input.js @@ -1,3 +1,3 @@ `\n\r\b\v\t\f\ \ -` \ No newline at end of file +\
\
` \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json index 7152cd61de..0dff1ff533 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/22/output.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -9,13 +9,13 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "program": { "type": "Program", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -23,7 +23,7 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "sourceType": "script", @@ -32,7 +32,7 @@ { "type": "ExpressionStatement", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -40,13 +40,13 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "expression": { "type": "TemplateLiteral", "start": 0, - "end": 18, + "end": 22, "loc": { "start": { "line": 1, @@ -54,7 +54,7 @@ }, "end": { "line": 3, - "column": 1 + "column": 5 } }, "expressions": [], @@ -62,7 +62,7 @@ { "type": "TemplateElement", "start": 1, - "end": 17, + "end": 21, "loc": { "start": { "line": 1, @@ -70,11 +70,11 @@ }, "end": { "line": 3, - "column": 0 + "column": 4 } }, "value": { - "raw": "\\n\\r\\b\\v\\t\\f\\\n\\\n", + "raw": "\\n\\r\\b\\v\\t\\f\\\n\\\n\\\u2028\\\u2029", "cooked": "\n\r\b\u000b\t\f" }, "tail": true @@ -85,4 +85,4 @@ ], "directives": [] } -} \ No newline at end of file +}