From 98b6effeefe177a539fb509a4efa2192a75496df Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 5 Jun 2015 09:36:37 +0100 Subject: [PATCH] update template literal parsing to properly handle newlines --- src/expression.js | 2 +- src/tokenize.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/expression.js b/src/expression.js index 7433cda730..3ab754733d 100755 --- a/src/expression.js +++ b/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/tokenize.js b/src/tokenize.js index fc9d706bb8..8d34c43a24 100755 --- a/src/tokenize.js +++ b/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