From 66b2c4bf5ebbae40c3815642168becd5f0c577cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 22 Jun 2021 10:25:12 -0400 Subject: [PATCH] refactor: move ES2022 AST nodes to core --- packages/babel-types/src/definitions/core.ts | 114 +++++++++++++++++ .../src/definitions/experimental.ts | 118 ------------------ 2 files changed, 114 insertions(+), 118 deletions(-) diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index c6ec727eb3bd..aa75643b2870 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -2050,3 +2050,117 @@ defineType("OptionalCallExpression", { }, }, }); + +// --- ES2022 --- +defineType("ClassProperty", { + visitor: ["key", "value", "typeAnnotation", "decorators"], + builder: [ + "key", + "value", + "typeAnnotation", + "decorators", + "computed", + "static", + ], + aliases: ["Property"], + fields: { + ...classMethodOrPropertyCommon, + value: { + validate: assertNodeType("Expression"), + optional: true, + }, + definite: { + validate: assertValueType("boolean"), + optional: true, + }, + typeAnnotation: { + validate: process.env.BABEL_8_BREAKING + ? assertNodeType("TypeAnnotation", "TSTypeAnnotation") + : assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true, + }, + decorators: { + validate: chain( + assertValueType("array"), + assertEach(assertNodeType("Decorator")), + ), + optional: true, + }, + readonly: { + validate: assertValueType("boolean"), + optional: true, + }, + declare: { + validate: assertValueType("boolean"), + optional: true, + }, + }, +}); + +defineType("ClassPrivateProperty", { + visitor: ["key", "value", "decorators"], + builder: ["key", "value", "decorators", "static"], + aliases: ["Property", "Private"], + fields: { + key: { + validate: assertNodeType("PrivateName"), + }, + value: { + validate: assertNodeType("Expression"), + optional: true, + }, + typeAnnotation: { + validate: process.env.BABEL_8_BREAKING + ? assertNodeType("TypeAnnotation", "TSTypeAnnotation") + : assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"), + optional: true, + }, + decorators: { + validate: chain( + assertValueType("array"), + assertEach(assertNodeType("Decorator")), + ), + optional: true, + }, + }, +}); + +defineType("ClassPrivateMethod", { + builder: ["kind", "key", "params", "body", "static"], + visitor: [ + "key", + "params", + "body", + "decorators", + "returnType", + "typeParameters", + ], + aliases: [ + "Function", + "Scopable", + "BlockParent", + "FunctionParent", + "Method", + "Private", + ], + fields: { + ...classMethodOrDeclareMethodCommon, + ...functionTypeAnnotationCommon, + key: { + validate: assertNodeType("PrivateName"), + }, + body: { + validate: assertNodeType("BlockStatement"), + }, + }, +}); + +defineType("PrivateName", { + visitor: ["id"], + aliases: ["Private"], + fields: { + id: { + validate: assertNodeType("Identifier"), + }, + }, +}); diff --git a/packages/babel-types/src/definitions/experimental.ts b/packages/babel-types/src/definitions/experimental.ts index e09dcfab0ef4..afc33d541798 100644 --- a/packages/babel-types/src/definitions/experimental.ts +++ b/packages/babel-types/src/definitions/experimental.ts @@ -4,11 +4,6 @@ import defineType, { assertValueType, chain, } from "./utils"; -import { - classMethodOrPropertyCommon, - classMethodOrDeclareMethodCommon, - functionTypeAnnotationCommon, -} from "./core"; defineType("ArgumentPlaceholder", {}); @@ -38,51 +33,6 @@ defineType("BindExpression", { }, }); -defineType("ClassProperty", { - visitor: ["key", "value", "typeAnnotation", "decorators"], - builder: [ - "key", - "value", - "typeAnnotation", - "decorators", - "computed", - "static", - ], - aliases: ["Property"], - fields: { - ...classMethodOrPropertyCommon, - value: { - validate: assertNodeType("Expression"), - optional: true, - }, - definite: { - validate: assertValueType("boolean"), - optional: true, - }, - typeAnnotation: { - validate: process.env.BABEL_8_BREAKING - ? assertNodeType("TypeAnnotation", "TSTypeAnnotation") - : assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"), - optional: true, - }, - decorators: { - validate: chain( - assertValueType("array"), - assertEach(assertNodeType("Decorator")), - ), - optional: true, - }, - readonly: { - validate: assertValueType("boolean"), - optional: true, - }, - declare: { - validate: assertValueType("boolean"), - optional: true, - }, - }, -}); - defineType("PipelineTopicExpression", { builder: ["expression"], visitor: ["expression"], @@ -107,64 +57,6 @@ defineType("PipelinePrimaryTopicReference", { aliases: ["Expression"], }); -defineType("ClassPrivateProperty", { - visitor: ["key", "value", "decorators"], - builder: ["key", "value", "decorators", "static"], - aliases: ["Property", "Private"], - fields: { - key: { - validate: assertNodeType("PrivateName"), - }, - value: { - validate: assertNodeType("Expression"), - optional: true, - }, - typeAnnotation: { - validate: process.env.BABEL_8_BREAKING - ? assertNodeType("TypeAnnotation", "TSTypeAnnotation") - : assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"), - optional: true, - }, - decorators: { - validate: chain( - assertValueType("array"), - assertEach(assertNodeType("Decorator")), - ), - optional: true, - }, - }, -}); - -defineType("ClassPrivateMethod", { - builder: ["kind", "key", "params", "body", "static"], - visitor: [ - "key", - "params", - "body", - "decorators", - "returnType", - "typeParameters", - ], - aliases: [ - "Function", - "Scopable", - "BlockParent", - "FunctionParent", - "Method", - "Private", - ], - fields: { - ...classMethodOrDeclareMethodCommon, - ...functionTypeAnnotationCommon, - key: { - validate: assertNodeType("PrivateName"), - }, - body: { - validate: assertNodeType("BlockStatement"), - }, - }, -}); - defineType("ImportAttribute", { visitor: ["key", "value"], fields: { @@ -211,16 +103,6 @@ defineType("ExportDefaultSpecifier", { }, }); -defineType("PrivateName", { - visitor: ["id"], - aliases: ["Private"], - fields: { - id: { - validate: assertNodeType("Identifier"), - }, - }, -}); - defineType("RecordExpression", { visitor: ["properties"], aliases: ["Expression"],