update template literal parsing to properly handle newlines
This commit is contained in:
parent
f268049fdc
commit
98b6effeef
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user