From 63f9a3c94688ab6cb917770cf62831a729185c17 Mon Sep 17 00:00:00 2001 From: Georgii Dolzhykov Date: Tue, 29 Oct 2019 22:25:42 +0200 Subject: [PATCH] rename `assertsModifier` to `asserts` (#10613) see https://github.com/babel/babel/pull/10543#issuecomment-547571501 --- .../babel-generator/src/generators/typescript.js | 2 +- .../babel-parser/src/plugins/typescript/index.js | 12 ++++++------ .../assert-predicate/arrow-function/output.json | 6 +++--- .../assert-predicate/asserts-var/output.json | 4 ++-- .../asserts-with-predicate/output.json | 4 ++-- .../function-declaration/output.json | 6 +++--- packages/babel-types/src/definitions/typescript.js | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/babel-generator/src/generators/typescript.js b/packages/babel-generator/src/generators/typescript.js index aa5e4ce4cde6..a201a5d5d658 100644 --- a/packages/babel-generator/src/generators/typescript.js +++ b/packages/babel-generator/src/generators/typescript.js @@ -197,7 +197,7 @@ export function TSTypeReference(node) { } export function TSTypePredicate(node) { - if (node.assertsModifier) { + if (node.asserts) { this.word("asserts"); this.space(); } diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index a47dfac29ba6..26a6246d59e6 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -904,8 +904,8 @@ export default (superClass: Class): Class => const t: N.TsTypeAnnotation = this.startNode(); this.expect(returnToken); - const assertsModifier = this.tsTryParse( - this.tsParseTypePredicateAssertsModifier.bind(this), + const asserts = this.tsTryParse( + this.tsParseTypePredicateAsserts.bind(this), ); const typePredicateVariable = @@ -913,7 +913,7 @@ export default (superClass: Class): Class => this.tsTryParse(this.tsParseTypePredicatePrefix.bind(this)); if (!typePredicateVariable) { - if (!assertsModifier) { + if (!asserts) { // : type return this.tsParseTypeAnnotation(/* eatColon */ false, t); } @@ -921,7 +921,7 @@ export default (superClass: Class): Class => // : asserts foo const node = this.startNodeAtNode(t); node.parameterName = this.parseIdentifier(); - node.assertsModifier = assertsModifier; + node.asserts = asserts; t.typeAnnotation = this.finishNode(node, "TSTypePredicate"); return this.finishNode(t, "TSTypeAnnotation"); } @@ -931,7 +931,7 @@ export default (superClass: Class): Class => const node = this.startNodeAtNode(t); node.parameterName = typePredicateVariable; node.typeAnnotation = type; - node.assertsModifier = assertsModifier; + node.asserts = asserts; t.typeAnnotation = this.finishNode(node, "TSTypePredicate"); return this.finishNode(t, "TSTypeAnnotation"); }); @@ -959,7 +959,7 @@ export default (superClass: Class): Class => } } - tsParseTypePredicateAssertsModifier(): boolean { + tsParseTypePredicateAsserts(): boolean { if (!this.tsIsIdentifier()) { return false; } diff --git a/packages/babel-parser/test/fixtures/typescript/assert-predicate/arrow-function/output.json b/packages/babel-parser/test/fixtures/typescript/assert-predicate/arrow-function/output.json index e368637de0a9..f06258409292 100644 --- a/packages/babel-parser/test/fixtures/typescript/assert-predicate/arrow-function/output.json +++ b/packages/babel-parser/test/fixtures/typescript/assert-predicate/arrow-function/output.json @@ -164,7 +164,7 @@ } } }, - "assertsModifier": true + "asserts": true } }, "id": null, @@ -346,7 +346,7 @@ }, "name": "value" }, - "assertsModifier": true + "asserts": true } }, "id": null, @@ -607,4 +607,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-var/output.json b/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-var/output.json index a7b32e23d170..62c634c7dc8e 100644 --- a/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-var/output.json +++ b/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-var/output.json @@ -156,7 +156,7 @@ }, "name": "value" }, - "assertsModifier": true + "asserts": true } }, "declare": true @@ -164,4 +164,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-with-predicate/output.json b/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-with-predicate/output.json index ca83a725e2d5..82cdaebbcf79 100644 --- a/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-with-predicate/output.json +++ b/packages/babel-parser/test/fixtures/typescript/assert-predicate/asserts-with-predicate/output.json @@ -186,7 +186,7 @@ } } }, - "assertsModifier": true + "asserts": true } }, "declare": true @@ -194,4 +194,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-parser/test/fixtures/typescript/assert-predicate/function-declaration/output.json b/packages/babel-parser/test/fixtures/typescript/assert-predicate/function-declaration/output.json index 96aea85b2926..bea1caf3de2a 100644 --- a/packages/babel-parser/test/fixtures/typescript/assert-predicate/function-declaration/output.json +++ b/packages/babel-parser/test/fixtures/typescript/assert-predicate/function-declaration/output.json @@ -186,7 +186,7 @@ } } }, - "assertsModifier": true + "asserts": true } }, "body": { @@ -334,7 +334,7 @@ }, "name": "value" }, - "assertsModifier": true + "asserts": true } }, "body": { @@ -505,4 +505,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/packages/babel-types/src/definitions/typescript.js b/packages/babel-types/src/definitions/typescript.js index b20448af8d1e..bba8a5b73c8e 100644 --- a/packages/babel-types/src/definitions/typescript.js +++ b/packages/babel-types/src/definitions/typescript.js @@ -175,11 +175,11 @@ defineType("TSTypeReference", { defineType("TSTypePredicate", { aliases: ["TSType"], - visitor: ["parameterName", "typeAnnotation", "assertsModifier"], + visitor: ["parameterName", "typeAnnotation", "asserts"], fields: { parameterName: validateType(["Identifier", "TSThisType"]), typeAnnotation: validateOptionalType("TSTypeAnnotation"), - assertsModifier: validate(bool), + asserts: validate(bool), }, });