For babylon typescript parser, fix false positive for ! after a line break (#6969)
Closes #6798
This commit is contained in:
parent
62bbee97d7
commit
aa38c47160
@ -1280,7 +1280,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
noCalls: ?boolean,
|
||||
state: { stop: boolean },
|
||||
): N.Expression {
|
||||
if (this.eat(tt.bang)) {
|
||||
if (!this.hasPrecedingLineBreak() && this.eat(tt.bang)) {
|
||||
const nonNullExpression: N.TsNonNullExpression = this.startNodeAt(
|
||||
startPos,
|
||||
startLoc,
|
||||
|
||||
2
packages/babylon/test/fixtures/typescript/cast/null-assertion-false-positive/actual.js
vendored
Normal file
2
packages/babylon/test/fixtures/typescript/cast/null-assertion-false-positive/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
a
|
||||
!b
|
||||
118
packages/babylon/test/fixtures/typescript/cast/null-assertion-false-positive/expected.json
vendored
Normal file
118
packages/babylon/test/fixtures/typescript/cast/null-assertion-false-positive/expected.json
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 1,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start": 0,
|
||||
"end": 1,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"identifierName": "a"
|
||||
},
|
||||
"name": "a"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 2,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "UnaryExpression",
|
||||
"start": 2,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"operator": "!",
|
||||
"prefix": true,
|
||||
"argument": {
|
||||
"type": "Identifier",
|
||||
"start": 3,
|
||||
"end": 4,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"identifierName": "b"
|
||||
},
|
||||
"name": "b"
|
||||
},
|
||||
"extra": {
|
||||
"parenthesizedArgument": false
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user