Skip to content

Commit

Permalink
refactor: move ES2022 AST nodes to core
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 22, 2021
1 parent 22e5afc commit 66b2c4b
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 118 deletions.
114 changes: 114 additions & 0 deletions packages/babel-types/src/definitions/core.ts
Expand Up @@ -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"),
},
},
});
118 changes: 0 additions & 118 deletions packages/babel-types/src/definitions/experimental.ts
Expand Up @@ -4,11 +4,6 @@ import defineType, {
assertValueType,
chain,
} from "./utils";
import {
classMethodOrPropertyCommon,
classMethodOrDeclareMethodCommon,
functionTypeAnnotationCommon,
} from "./core";

defineType("ArgumentPlaceholder", {});

Expand Down Expand Up @@ -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"],
Expand All @@ -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: {
Expand Down Expand Up @@ -211,16 +103,6 @@ defineType("ExportDefaultSpecifier", {
},
});

defineType("PrivateName", {
visitor: ["id"],
aliases: ["Private"],
fields: {
id: {
validate: assertNodeType("Identifier"),
},
},
});

defineType("RecordExpression", {
visitor: ["properties"],
aliases: ["Expression"],
Expand Down

0 comments on commit 66b2c4b

Please sign in to comment.