diff --git a/packages/babel-parser/src/plugins/typescript.js b/packages/babel-parser/src/plugins/typescript.js index 0d5d380c307c..1a0c8c7a652d 100644 --- a/packages/babel-parser/src/plugins/typescript.js +++ b/packages/babel-parser/src/plugins/typescript.js @@ -896,6 +896,7 @@ export default (superClass: Class): Class => 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()); @@ -2001,7 +2002,7 @@ export default (superClass: Class): Class => // 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); diff --git a/packages/babel-parser/test/fixtures/typescript/cast/need-parentheses/output.json b/packages/babel-parser/test/fixtures/typescript/cast/need-parentheses/output.json index 8895830ae739..bb02e0d6956a 100644 --- a/packages/babel-parser/test/fixtures/typescript/cast/need-parentheses/output.json +++ b/packages/babel-parser/test/fixtures/typescript/cast/need-parentheses/output.json @@ -59,12 +59,12 @@ }, "object": { "type": "TSTypeAssertion", - "start": 2, + "start": 1, "end": 6, "loc": { "start": { "line": 1, - "column": 2 + "column": 1 }, "end": { "line": 1, diff --git a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-after-operator/output.json b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-after-operator/output.json index 8f2d74a4e5fa..f8020782bcc6 100644 --- a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-after-operator/output.json +++ b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-after-operator/output.json @@ -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, diff --git a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-and-assign/output.json b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-and-assign/output.json index 84ad7e4d64d0..964e552cfc5f 100644 --- a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-and-assign/output.json +++ b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-and-assign/output.json @@ -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, diff --git a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-before-operator/output.json b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-before-operator/output.json index 1599d9ec1425..34f750336a37 100644 --- a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-before-operator/output.json +++ b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion-before-operator/output.json @@ -59,12 +59,12 @@ }, "left": { "type": "TSTypeAssertion", - "start": 1, + "start": 0, "end": 10, "loc": { "start": { "line": 1, - "column": 1 + "column": 0 }, "end": { "line": 1, diff --git a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion/output.json b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion/output.json index 5d5a05d21acf..0da048e7ef02 100644 --- a/packages/babel-parser/test/fixtures/typescript/cast/type-assertion/output.json +++ b/packages/babel-parser/test/fixtures/typescript/cast/type-assertion/output.json @@ -45,12 +45,12 @@ }, "expression": { "type": "TSTypeAssertion", - "start": 1, + "start": 0, "end": 10, "loc": { "start": { "line": 1, - "column": 1 + "column": 0 }, "end": { "line": 1,