diff --git a/src/acorn/src/expression.js b/src/acorn/src/expression.js index 7433cda730..3ab754733d 100755 --- a/src/acorn/src/expression.js +++ b/src/acorn/src/expression.js @@ -513,7 +513,7 @@ pp.parseNew = function() { pp.parseTemplateElement = function() { let elem = this.startNode() elem.value = { - raw: this.input.slice(this.start, this.end), + raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'), cooked: this.value } this.next() diff --git a/src/acorn/src/tokenize.js b/src/acorn/src/tokenize.js index fc9d706bb8..8d34c43a24 100755 --- a/src/acorn/src/tokenize.js +++ b/src/acorn/src/tokenize.js @@ -577,11 +577,15 @@ pp.readTmplToken = function() { } else if (isNewLine(ch)) { out += this.input.slice(chunkStart, this.pos) ++this.pos - if (ch === 13 && this.input.charCodeAt(this.pos) === 10) { - ++this.pos - out += "\n" - } else { - out += String.fromCharCode(ch) + switch (ch) { + case 13: + if (this.input.charCodeAt(this.pos) === 10) ++this.pos; + case 10: + out += "\n"; + break; + default: + out += String.fromCharCode(ch); + break; } if (this.options.locations) { ++this.curLine diff --git a/test/acorn/tests-harmony.js b/test/acorn/tests-harmony.js index 01d6d596fb..d253ac2099 100755 --- a/test/acorn/tests-harmony.js +++ b/test/acorn/tests-harmony.js @@ -813,7 +813,7 @@ test("`\\n\\r\\b\\v\\t\\f\\\n\\\r\n`", { type: "TemplateLiteral", quasis: [{ type: "TemplateElement", - value: {raw: "\\n\\r\\b\\v\\t\\f\\\n\\\r\n", cooked: "\n\r\b\u000b\t\f"}, + value: {raw: "\\n\\r\\b\\v\\t\\f\\\n\\\n", cooked: "\n\r\b\u000b\t\f"}, tail: true, loc: { start: {line: 1, column: 1}, @@ -841,7 +841,7 @@ test("`\\n\\r\\b\\v\\t\\f\\\n\\\r\n`", { locations: true }); -test("`\n\r\n`", { +test("`\n\r\n\r`", { type: "Program", body: [{ type: "ExpressionStatement", @@ -849,27 +849,27 @@ test("`\n\r\n`", { type: "TemplateLiteral", quasis: [{ type: "TemplateElement", - value: {raw: "\n\r\n", cooked: "\n\n"}, + value: {raw: "\n\n\n", cooked: "\n\n\n"}, tail: true, loc: { start: {line: 1, column: 1}, - end: {line: 3, column: 0} + end: {line: 4, column: 0} } }], expressions: [], loc: { start: {line: 1, column: 0}, - end: {line: 3, column: 1} + end: {line: 4, column: 1} } }, loc: { start: {line: 1, column: 0}, - end: {line: 3, column: 1} + end: {line: 4, column: 1} } }], loc: { start: {line: 1, column: 0}, - end: {line: 3, column: 1} + end: {line: 4, column: 1} } }, { ecmaVersion: 6, @@ -14134,8 +14134,6 @@ test('function normal(x, y = 10) {}', { }] }, {ecmaVersion: 6}); -test("'use strict'; function f([x,,z]) {}", {}, {ecmaVersion: 6}); - // test preserveParens option with arrow functions test("() => 42", { type: "Program",