Skip to content

Commit

Permalink
fix: ensure comment stack is correctly handled
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 2, 2021
1 parent 96712cd commit 2f02b9a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -1876,13 +1876,13 @@ export default class ExpressionParser extends LValParser {
};
elem.tail = isTail;
this.next();
const result = this.finishNodeAt(
this.finishNode(elem, "TemplateElement");
this.resetEndLocation(
elem,
"TemplateElement",
elemEnd,
createPositionFromPosition(this.state.lastTokEndLoc, endOffset),
);
return result;
return elem;
}

// https://tc39.es/ecma262/#prod-TemplateLiteral
Expand Down
@@ -0,0 +1 @@
`${a}` // comment
@@ -0,0 +1,62 @@
{
"type": "File",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
"program": {
"type": "Program",
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
"expression": {
"type": "TemplateLiteral",
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}},
"expressions": [
{
"type": "Identifier",
"start":3,"end":4,"loc":{"start":{"line":1,"column":3},"end":{"line":1,"column":4},"identifierName":"a"},
"name": "a"
}
],
"quasis": [
{
"type": "TemplateElement",
"start":1,"end":1,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":1}},
"value": {
"raw": "",
"cooked": ""
},
"tail": false
},
{
"type": "TemplateElement",
"start":5,"end":5,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":5}},
"value": {
"raw": "",
"cooked": ""
},
"tail": true
}
]
},
"trailingComments": [
{
"type": "CommentLine",
"value": " comment",
"start":7,"end":17,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":17}}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " comment",
"start":7,"end":17,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":17}}
}
]
}

0 comments on commit 2f02b9a

Please sign in to comment.