Skip to content

Commit ad17fe1

Browse files
authored
fix: check preceding line break before exclamation (#14049)
1 parent 7178fbb commit ad17fe1

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

packages/babel-parser/src/plugins/typescript/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2832,7 +2832,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
28322832
kind: "var" | "let" | "const",
28332833
): void {
28342834
super.parseVarId(decl, kind);
2835-
if (decl.id.type === "Identifier" && this.eat(tt.bang)) {
2835+
if (
2836+
decl.id.type === "Identifier" &&
2837+
!this.hasPrecedingLineBreak() &&
2838+
this.eat(tt.bang)
2839+
) {
28362840
decl.definite = true;
28372841
}
28382842

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let x
2+
!function() {};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":15}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":15}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "VariableDeclaration",
12+
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
13+
"declarations": [
14+
{
15+
"type": "VariableDeclarator",
16+
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5}},
17+
"id": {
18+
"type": "Identifier",
19+
"start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"x"},
20+
"name": "x"
21+
},
22+
"init": null
23+
}
24+
],
25+
"kind": "let"
26+
},
27+
{
28+
"type": "ExpressionStatement",
29+
"start":6,"end":21,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":15}},
30+
"expression": {
31+
"type": "UnaryExpression",
32+
"start":6,"end":20,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":14}},
33+
"operator": "!",
34+
"prefix": true,
35+
"argument": {
36+
"type": "FunctionExpression",
37+
"start":7,"end":20,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":14}},
38+
"id": null,
39+
"generator": false,
40+
"async": false,
41+
"params": [],
42+
"body": {
43+
"type": "BlockStatement",
44+
"start":18,"end":20,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":14}},
45+
"body": [],
46+
"directives": []
47+
}
48+
}
49+
}
50+
}
51+
],
52+
"directives": []
53+
}
54+
}

0 commit comments

Comments
 (0)