fix: check preceding line break before exclamation (#14049)
This commit is contained in:
parent
7178fbb008
commit
ad17fe1cce
@ -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;
|
||||
}
|
||||
|
||||
|
||||
2
packages/babel-parser/test/fixtures/typescript/variable-declarator/definite-asi/input.ts
vendored
Normal file
2
packages/babel-parser/test/fixtures/typescript/variable-declarator/definite-asi/input.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
let x
|
||||
!function() {};
|
||||
54
packages/babel-parser/test/fixtures/typescript/variable-declarator/definite-asi/output.json
vendored
Normal file
54
packages/babel-parser/test/fixtures/typescript/variable-declarator/definite-asi/output.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user