For babylon typescript parser, fix false positive for ! after a line break (#6969)

Closes #6798
This commit is contained in:
Andy 2017-12-04 10:57:22 -08:00 committed by Nicolò Ribaudo
parent 62bbee97d7
commit aa38c47160
3 changed files with 121 additions and 1 deletions

View File

@ -1280,7 +1280,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
noCalls: ?boolean, noCalls: ?boolean,
state: { stop: boolean }, state: { stop: boolean },
): N.Expression { ): N.Expression {
if (this.eat(tt.bang)) { if (!this.hasPrecedingLineBreak() && this.eat(tt.bang)) {
const nonNullExpression: N.TsNonNullExpression = this.startNodeAt( const nonNullExpression: N.TsNonNullExpression = this.startNodeAt(
startPos, startPos,
startLoc, startLoc,

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