fix: check preceding line break before exclamation (#14049)

This commit is contained in:
Huáng Jùnliàng 2021-12-16 15:50:15 -05:00 committed by GitHub
parent 7178fbb008
commit ad17fe1cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 1 deletions

View File

@ -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;
}

View File

@ -0,0 +1,2 @@
let x
!function() {};

View 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": []
}
}