diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index 1b9b7f1f3e83..79fa83a35446 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -1039,7 +1039,7 @@ export default (superClass: Class): Class => const t: N.TsTypeAnnotation = this.startNode(); this.expect(returnToken); - const asserts = this.tsTryParse( + const asserts = !!this.tsTryParse( this.tsParseTypePredicateAsserts.bind(this), ); diff --git a/packages/babel-parser/test/fixtures/typescript/arrow-function/predicate-types/output.json b/packages/babel-parser/test/fixtures/typescript/arrow-function/predicate-types/output.json index 4cc69d94f780..69135a95cab8 100644 --- a/packages/babel-parser/test/fixtures/typescript/arrow-function/predicate-types/output.json +++ b/packages/babel-parser/test/fixtures/typescript/arrow-function/predicate-types/output.json @@ -31,7 +31,8 @@ "type": "TSStringKeyword", "start":15,"end":21,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":21}} } - } + }, + "asserts": false } }, "id": null, diff --git a/packages/babel-parser/test/fixtures/typescript/function/predicate-types/output.json b/packages/babel-parser/test/fixtures/typescript/function/predicate-types/output.json index b834fb54ebb7..593fba67d38d 100644 --- a/packages/babel-parser/test/fixtures/typescript/function/predicate-types/output.json +++ b/packages/babel-parser/test/fixtures/typescript/function/predicate-types/output.json @@ -50,7 +50,8 @@ "type": "TSBooleanKeyword", "start":25,"end":32,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":32}} } - } + }, + "asserts": false } }, "body": { @@ -66,6 +67,10 @@ "expression": { "type": "FunctionExpression", "start":37,"end":70,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":34}}, + "extra": { + "parenthesized": true, + "parenStart": 36 + }, "id": null, "generator": false, "async": false, @@ -102,7 +107,8 @@ "type": "TSBooleanKeyword", "start":60,"end":67,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":31}} } - } + }, + "asserts": false } }, "body": { @@ -110,10 +116,6 @@ "start":68,"end":70,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":34}}, "body": [], "directives": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 36 } } }