Skip to content

Commit

Permalink
Misc fixes to @babel/types AST definitions (#14730)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 7, 2022
1 parent cc67a6e commit 1c79224
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/statement.js
Expand Up @@ -525,7 +525,7 @@ export default class StatementParser extends ExpressionParser {
}

parseDecorator(): N.Decorator {
this.expectOnePlugin(["decorators-legacy", "decorators"]);
this.expectOnePlugin(["decorators", "decorators-legacy"]);

const node = this.startNode();
this.next();
Expand Down
@@ -1,4 +1,4 @@
{
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): \"decorators-legacy\", \"decorators\". (1:0)",
"plugins": []
"plugins": [],
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): \"decorators\", \"decorators-legacy\". (1:0)"
}
20 changes: 13 additions & 7 deletions packages/babel-types/src/ast-types/generated/index.ts
Expand Up @@ -578,7 +578,7 @@ export interface ObjectExpression extends BaseNode {
export interface ObjectMethod extends BaseNode {
type: "ObjectMethod";
kind: "method" | "get" | "set";
key: Expression | Identifier | StringLiteral | NumericLiteral;
key: Expression | Identifier | StringLiteral | NumericLiteral | BigIntLiteral;
params: Array<Identifier | Pattern | RestElement>;
body: BlockStatement;
computed: boolean;
Expand Down Expand Up @@ -879,7 +879,7 @@ export interface MetaProperty extends BaseNode {
export interface ClassMethod extends BaseNode {
type: "ClassMethod";
kind?: "get" | "set" | "method" | "constructor";
key: Identifier | StringLiteral | NumericLiteral | Expression;
key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
body: BlockStatement;
computed?: boolean;
Expand Down Expand Up @@ -992,7 +992,7 @@ export interface OptionalCallExpression extends BaseNode {

export interface ClassProperty extends BaseNode {
type: "ClassProperty";
key: Identifier | StringLiteral | NumericLiteral | Expression;
key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression;
value?: Expression | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
decorators?: Array<Decorator> | null;
Expand All @@ -1010,7 +1010,13 @@ export interface ClassProperty extends BaseNode {

export interface ClassAccessorProperty extends BaseNode {
type: "ClassAccessorProperty";
key: Identifier | StringLiteral | NumericLiteral | Expression | PrivateName;
key:
| Identifier
| StringLiteral
| NumericLiteral
| BigIntLiteral
| Expression
| PrivateName;
value?: Expression | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
decorators?: Array<Decorator> | null;
Expand All @@ -1031,7 +1037,7 @@ export interface ClassPrivateProperty extends BaseNode {
key: PrivateName;
value?: Expression | null;
decorators?: Array<Decorator> | null;
static: any;
static: boolean;
definite?: boolean | null;
readonly?: boolean | null;
typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null;
Expand All @@ -1040,7 +1046,7 @@ export interface ClassPrivateProperty extends BaseNode {

export interface ClassPrivateMethod extends BaseNode {
type: "ClassPrivateMethod";
kind?: "get" | "set" | "method" | "constructor";
kind: "get" | "set" | "method";
key: PrivateName;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
body: BlockStatement;
Expand Down Expand Up @@ -1678,7 +1684,7 @@ export interface TSDeclareFunction extends BaseNode {
export interface TSDeclareMethod extends BaseNode {
type: "TSDeclareMethod";
decorators?: Array<Decorator> | null;
key: Identifier | StringLiteral | NumericLiteral | Expression;
key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression;
typeParameters?: TSTypeParameterDeclaration | Noop | null;
params: Array<Identifier | Pattern | RestElement | TSParameterProperty>;
returnType?: TSTypeAnnotation | Noop | null;
Expand Down
37 changes: 29 additions & 8 deletions packages/babel-types/src/builders/generated/index.ts
Expand Up @@ -364,7 +364,12 @@ export function objectExpression(
}
export function objectMethod(
kind: "method" | "get" | "set" | undefined = "method",
key: t.Expression | t.Identifier | t.StringLiteral | t.NumericLiteral,
key:
| t.Expression
| t.Identifier
| t.StringLiteral
| t.NumericLiteral
| t.BigIntLiteral,
params: Array<t.Identifier | t.Pattern | t.RestElement>,
body: t.BlockStatement,
computed: boolean = false,
Expand Down Expand Up @@ -729,7 +734,12 @@ export function metaProperty(
}
export function classMethod(
kind: "get" | "set" | "method" | "constructor" | undefined = "method",
key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.Expression,
key:
| t.Identifier
| t.StringLiteral
| t.NumericLiteral
| t.BigIntLiteral
| t.Expression,
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
>,
Expand Down Expand Up @@ -866,7 +876,12 @@ export function optionalCallExpression(
});
}
export function classProperty(
key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.Expression,
key:
| t.Identifier
| t.StringLiteral
| t.NumericLiteral
| t.BigIntLiteral
| t.Expression,
value: t.Expression | null = null,
typeAnnotation: t.TypeAnnotation | t.TSTypeAnnotation | t.Noop | null = null,
decorators: Array<t.Decorator> | null = null,
Expand All @@ -888,6 +903,7 @@ export function classAccessorProperty(
| t.Identifier
| t.StringLiteral
| t.NumericLiteral
| t.BigIntLiteral
| t.Expression
| t.PrivateName,
value: t.Expression | null = null,
Expand All @@ -908,9 +924,9 @@ export function classAccessorProperty(
}
export function classPrivateProperty(
key: t.PrivateName,
value: t.Expression | null | undefined = null,
decorators: Array<t.Decorator> | null | undefined = null,
_static: any,
value: t.Expression | null = null,
decorators: Array<t.Decorator> | null = null,
_static: boolean = false,
): t.ClassPrivateProperty {
return validateNode<t.ClassPrivateProperty>({
type: "ClassPrivateProperty",
Expand All @@ -921,7 +937,7 @@ export function classPrivateProperty(
});
}
export function classPrivateMethod(
kind: "get" | "set" | "method" | "constructor" | undefined = "method",
kind: "get" | "set" | "method" | undefined = "method",
key: t.PrivateName,
params: Array<
t.Identifier | t.Pattern | t.RestElement | t.TSParameterProperty
Expand Down Expand Up @@ -1866,7 +1882,12 @@ export function tsDeclareFunction(
export { tsDeclareFunction as tSDeclareFunction };
export function tsDeclareMethod(
decorators: Array<t.Decorator> | null | undefined = null,
key: t.Identifier | t.StringLiteral | t.NumericLiteral | t.Expression,
key:
| t.Identifier
| t.StringLiteral
| t.NumericLiteral
| t.BigIntLiteral
| t.Expression,
typeParameters:
| t.TSTypeParameterDeclaration
| t.Noop
Expand Down
13 changes: 13 additions & 0 deletions packages/babel-types/src/definitions/core.ts
Expand Up @@ -787,6 +787,7 @@ defineType("ObjectMethod", {
"Identifier",
"StringLiteral",
"NumericLiteral",
"BigIntLiteral",
);
const computed = assertNodeType("Expression");

Expand All @@ -800,6 +801,7 @@ defineType("ObjectMethod", {
"Identifier",
"StringLiteral",
"NumericLiteral",
"BigIntLiteral",
];
return validator;
})(),
Expand Down Expand Up @@ -1825,6 +1827,7 @@ export const classMethodOrPropertyCommon = {
"Identifier",
"StringLiteral",
"NumericLiteral",
"BigIntLiteral",
"Expression",
),
),
Expand Down Expand Up @@ -2222,6 +2225,7 @@ defineType("ClassAccessorProperty", {
"Identifier",
"StringLiteral",
"NumericLiteral",
"BigIntLiteral",
"PrivateName",
);
const computed = assertNodeType("Expression");
Expand All @@ -2235,6 +2239,7 @@ defineType("ClassAccessorProperty", {
"Identifier",
"StringLiteral",
"NumericLiteral",
"BigIntLiteral",
"Expression",
"PrivateName",
),
Expand Down Expand Up @@ -2311,6 +2316,10 @@ defineType("ClassPrivateProperty", {
),
optional: true,
},
static: {
validate: assertValueType("boolean"),
default: false,
},
readonly: {
validate: assertValueType("boolean"),
optional: true,
Expand Down Expand Up @@ -2347,6 +2356,10 @@ defineType("ClassPrivateMethod", {
fields: {
...classMethodOrDeclareMethodCommon,
...functionTypeAnnotationCommon,
kind: {
validate: assertOneOf("get", "set", "method"),
default: "method",
},
key: {
validate: assertNodeType("PrivateName"),
},
Expand Down

0 comments on commit 1c79224

Please sign in to comment.