Skip to content

Commit

Permalink
Fix location for typescript type assertions in AST (#9284)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Jan 7, 2019
1 parent efc60a1 commit e43777b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/babel-parser/src/plugins/typescript.js
Expand Up @@ -896,6 +896,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

tsParseTypeAssertion(): N.TsTypeAssertion {
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,
// but need `tsInType` to satisfy the assertion in `tsParseType`.
node.typeAnnotation = this.tsInType(() => this.tsParseType());
Expand Down Expand Up @@ -2001,7 +2002,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

// Handle type assertions
parseMaybeUnary(refShorthandDefaultPos?: ?Pos): N.Expression {
if (!this.hasPlugin("jsx") && this.eatRelational("<")) {
if (!this.hasPlugin("jsx") && this.isRelational("<")) {
return this.tsParseTypeAssertion();
} else {
return super.parseMaybeUnary(refShorthandDefaultPos);
Expand Down
Expand Up @@ -59,12 +59,12 @@
},
"object": {
"type": "TSTypeAssertion",
"start": 2,
"start": 1,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 2
"column": 1
},
"end": {
"line": 1,
Expand Down
Expand Up @@ -80,12 +80,12 @@
"operator": "+",
"right": {
"type": "TSTypeAssertion",
"start": 5,
"start": 4,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 5
"column": 4
},
"end": {
"line": 1,
Expand Down
Expand Up @@ -60,12 +60,12 @@
"operator": "+=",
"left": {
"type": "TSTypeAssertion",
"start": 2,
"start": 1,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 2
"column": 1
},
"end": {
"line": 1,
Expand Down
Expand Up @@ -59,12 +59,12 @@
},
"left": {
"type": "TSTypeAssertion",
"start": 1,
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
"column": 0
},
"end": {
"line": 1,
Expand Down
Expand Up @@ -45,12 +45,12 @@
},
"expression": {
"type": "TSTypeAssertion",
"start": 1,
"start": 0,
"end": 10,
"loc": {
"start": {
"line": 1,
"column": 1
"column": 0
},
"end": {
"line": 1,
Expand Down

0 comments on commit e43777b

Please sign in to comment.