update template literal parsing to properly handle newlines

This commit is contained in:
Sebastian McKenzie 2015-06-05 09:36:37 +01:00
parent f268049fdc
commit 98b6effeef
2 changed files with 10 additions and 6 deletions

View File

@ -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()

View File

@ -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