Skip to content

Commit

Permalink
fix: check preceding line break before exclamation (#14049)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 16, 2021
1 parent 7178fbb commit ad17fe1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -2832,7 +2832,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
kind: "var" | "let" | "const",
): void {
super.parseVarId(decl, kind);
if (decl.id.type === "Identifier" && this.eat(tt.bang)) {
if (
decl.id.type === "Identifier" &&
!this.hasPrecedingLineBreak() &&
this.eat(tt.bang)
) {
decl.definite = true;
}

Expand Down
@@ -0,0 +1,2 @@
let x
!function() {};
@@ -0,0 +1,54 @@
{
"type": "File",
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":15}},
"program": {
"type": "Program",
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":15}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
"declarations": [
{
"type": "VariableDeclarator",
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}},
"id": {
"type": "Identifier",
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"x"},
"name": "x"
},
"init": null
}
],
"kind": "let"
},
{
"type": "ExpressionStatement",
"start":6,"end":21,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":15}},
"expression": {
"type": "UnaryExpression",
"start":6,"end":20,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":14}},
"operator": "!",
"prefix": true,
"argument": {
"type": "FunctionExpression",
"start":7,"end":20,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":14}},
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":18,"end":20,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":14}},
"body": [],
"directives": []
}
}
}
}
],
"directives": []
}
}

0 comments on commit ad17fe1

Please sign in to comment.