Skip to content

Commit

Permalink
Properly tack line numbers in readInvalidTemplateToken
Browse files Browse the repository at this point in the history
FIX: Fix a bug that broke line number accounting after a template literal
with invalid escape sequences.

Closes #1275
  • Loading branch information
marijnh committed Feb 7, 2024
1 parent 6770c2e commit 6c104c4
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions acorn/src/tokenize.js
Expand Up @@ -679,6 +679,11 @@ pp.readInvalidTemplateToken = function() {
case "`":
return this.finishToken(tt.invalidTemplate, this.input.slice(this.start, this.pos))

case "\r": case "\n": case "\u2028": case "\u2029":
++this.curLine
this.lineStart = this.pos + 1
break

// no default
}
}
Expand Down
94 changes: 94 additions & 0 deletions test/tests-harmony.js
Expand Up @@ -1093,6 +1093,100 @@ test("`outer${{x: {y: 10}}}bar${`nested${function(){return 1;}}endnest`}end`",{
ecmaVersion: 6
});

test("foo`\n\\x\n$\n`;", {
type: "Program",
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 4,
column: 2
}
},
body: [
{
type: "ExpressionStatement",
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 4,
column: 2
}
},
expression: {
type: "TaggedTemplateExpression",
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 4,
column: 1
}
},
tag: {
type: "Identifier",
loc: {
start: {
line: 1,
column: 0
},
end: {
line: 1,
column: 3
}
},
name: "foo"
},
quasi: {
type: "TemplateLiteral",
loc: {
start: {
line: 1,
column: 3
},
end: {
line: 4,
column: 1
}
},
expressions: [],
quasis: [
{
type: "TemplateElement",
loc: {
start: {
line: 1,
column: 4
},
end: {
line: 4,
column: 0
}
},
value: {
raw: "\n\\x\n$\n",
cooked: null
},
tail: true
}
]
}
}
}
],
sourceType: "script"
}, {
ecmaVersion: 10,
locations: true
});


// ES6: Switch Case Declaration

Expand Down

0 comments on commit 6c104c4

Please sign in to comment.