Fix location for typescript type assertions in AST (#9284)

This commit is contained in:
Daniel Tschinder 2019-01-06 16:39:14 -08:00 committed by GitHub
parent efc60a1703
commit e43777bb5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 11 deletions

View File

@ -896,6 +896,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
tsParseTypeAssertion(): N.TsTypeAssertion { tsParseTypeAssertion(): N.TsTypeAssertion {
const node: N.TsTypeAssertion = this.startNode(); const node: N.TsTypeAssertion = this.startNode();
this.next(); // <
// Not actually necessary to set state.inType because we never reach here if JSX plugin is enabled, // Not actually necessary to set state.inType because we never reach here if JSX plugin is enabled,
// but need `tsInType` to satisfy the assertion in `tsParseType`. // but need `tsInType` to satisfy the assertion in `tsParseType`.
node.typeAnnotation = this.tsInType(() => this.tsParseType()); node.typeAnnotation = this.tsInType(() => this.tsParseType());
@ -2001,7 +2002,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Handle type assertions // Handle type assertions
parseMaybeUnary(refShorthandDefaultPos?: ?Pos): N.Expression { parseMaybeUnary(refShorthandDefaultPos?: ?Pos): N.Expression {
if (!this.hasPlugin("jsx") && this.eatRelational("<")) { if (!this.hasPlugin("jsx") && this.isRelational("<")) {
return this.tsParseTypeAssertion(); return this.tsParseTypeAssertion();
} else { } else {
return super.parseMaybeUnary(refShorthandDefaultPos); return super.parseMaybeUnary(refShorthandDefaultPos);

View File

@ -59,12 +59,12 @@
}, },
"object": { "object": {
"type": "TSTypeAssertion", "type": "TSTypeAssertion",
"start": 2, "start": 1,
"end": 6, "end": 6,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 2 "column": 1
}, },
"end": { "end": {
"line": 1, "line": 1,

View File

@ -80,12 +80,12 @@
"operator": "+", "operator": "+",
"right": { "right": {
"type": "TSTypeAssertion", "type": "TSTypeAssertion",
"start": 5, "start": 4,
"end": 14, "end": 14,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 5 "column": 4
}, },
"end": { "end": {
"line": 1, "line": 1,

View File

@ -60,12 +60,12 @@
"operator": "+=", "operator": "+=",
"left": { "left": {
"type": "TSTypeAssertion", "type": "TSTypeAssertion",
"start": 2, "start": 1,
"end": 11, "end": 11,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 2 "column": 1
}, },
"end": { "end": {
"line": 1, "line": 1,

View File

@ -59,12 +59,12 @@
}, },
"left": { "left": {
"type": "TSTypeAssertion", "type": "TSTypeAssertion",
"start": 1, "start": 0,
"end": 10, "end": 10,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 1 "column": 0
}, },
"end": { "end": {
"line": 1, "line": 1,

View File

@ -45,12 +45,12 @@
}, },
"expression": { "expression": {
"type": "TSTypeAssertion", "type": "TSTypeAssertion",
"start": 1, "start": 0,
"end": 10, "end": 10,
"loc": { "loc": {
"start": { "start": {
"line": 1, "line": 1,
"column": 1 "column": 0
}, },
"end": { "end": {
"line": 1, "line": 1,