diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 6ab4c73daa37..5c9aa4b6838f 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -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(); diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json index 9a234d04ace0..6c1cea980258 100644 --- a/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/decorators/options.json @@ -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)" } diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index 5203e07424b6..a40f42f2e12e 100644 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -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; body: BlockStatement; computed: boolean; @@ -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; body: BlockStatement; computed?: boolean; @@ -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 | null; @@ -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 | null; @@ -1031,7 +1037,7 @@ export interface ClassPrivateProperty extends BaseNode { key: PrivateName; value?: Expression | null; decorators?: Array | null; - static: any; + static: boolean; definite?: boolean | null; readonly?: boolean | null; typeAnnotation?: TypeAnnotation | TSTypeAnnotation | Noop | null; @@ -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; body: BlockStatement; @@ -1678,7 +1684,7 @@ export interface TSDeclareFunction extends BaseNode { export interface TSDeclareMethod extends BaseNode { type: "TSDeclareMethod"; decorators?: Array | null; - key: Identifier | StringLiteral | NumericLiteral | Expression; + key: Identifier | StringLiteral | NumericLiteral | BigIntLiteral | Expression; typeParameters?: TSTypeParameterDeclaration | Noop | null; params: Array; returnType?: TSTypeAnnotation | Noop | null; diff --git a/packages/babel-types/src/builders/generated/index.ts b/packages/babel-types/src/builders/generated/index.ts index bbc7d7050fba..588df2349c9b 100644 --- a/packages/babel-types/src/builders/generated/index.ts +++ b/packages/babel-types/src/builders/generated/index.ts @@ -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, body: t.BlockStatement, computed: boolean = false, @@ -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 >, @@ -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 | null = null, @@ -888,6 +903,7 @@ export function classAccessorProperty( | t.Identifier | t.StringLiteral | t.NumericLiteral + | t.BigIntLiteral | t.Expression | t.PrivateName, value: t.Expression | null = null, @@ -908,9 +924,9 @@ export function classAccessorProperty( } export function classPrivateProperty( key: t.PrivateName, - value: t.Expression | null | undefined = null, - decorators: Array | null | undefined = null, - _static: any, + value: t.Expression | null = null, + decorators: Array | null = null, + _static: boolean = false, ): t.ClassPrivateProperty { return validateNode({ type: "ClassPrivateProperty", @@ -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 @@ -1866,7 +1882,12 @@ export function tsDeclareFunction( export { tsDeclareFunction as tSDeclareFunction }; export function tsDeclareMethod( decorators: Array | 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 diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index bdd8fa61a794..3a426a567e39 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -787,6 +787,7 @@ defineType("ObjectMethod", { "Identifier", "StringLiteral", "NumericLiteral", + "BigIntLiteral", ); const computed = assertNodeType("Expression"); @@ -800,6 +801,7 @@ defineType("ObjectMethod", { "Identifier", "StringLiteral", "NumericLiteral", + "BigIntLiteral", ]; return validator; })(), @@ -1825,6 +1827,7 @@ export const classMethodOrPropertyCommon = { "Identifier", "StringLiteral", "NumericLiteral", + "BigIntLiteral", "Expression", ), ), @@ -2222,6 +2225,7 @@ defineType("ClassAccessorProperty", { "Identifier", "StringLiteral", "NumericLiteral", + "BigIntLiteral", "PrivateName", ); const computed = assertNodeType("Expression"); @@ -2235,6 +2239,7 @@ defineType("ClassAccessorProperty", { "Identifier", "StringLiteral", "NumericLiteral", + "BigIntLiteral", "Expression", "PrivateName", ), @@ -2311,6 +2316,10 @@ defineType("ClassPrivateProperty", { ), optional: true, }, + static: { + validate: assertValueType("boolean"), + default: false, + }, readonly: { validate: assertValueType("boolean"), optional: true, @@ -2347,6 +2356,10 @@ defineType("ClassPrivateMethod", { fields: { ...classMethodOrDeclareMethodCommon, ...functionTypeAnnotationCommon, + kind: { + validate: assertOneOf("get", "set", "method"), + default: "method", + }, key: { validate: assertNodeType("PrivateName"), }, diff --git a/packages/babel-types/test/builders/experimental/__snapshots__/classProperty.js.snap b/packages/babel-types/test/builders/es2022/__snapshots__/classProperty.js.snap similarity index 100% rename from packages/babel-types/test/builders/experimental/__snapshots__/classProperty.js.snap rename to packages/babel-types/test/builders/es2022/__snapshots__/classProperty.js.snap diff --git a/packages/babel-types/test/builders/experimental/classProperty.js b/packages/babel-types/test/builders/es2022/classProperty.js similarity index 100% rename from packages/babel-types/test/builders/experimental/classProperty.js rename to packages/babel-types/test/builders/es2022/classProperty.js