Skip to content

Commit 5c85fd2

Browse files
committed
feat: add decorators to ClassDeclaration and ClassProperty
1 parent 73a1b7e commit 5c85fd2

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/def/es-proposals.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@ export default function (fork: Fork) {
2020
.field("all", Boolean, defaults["false"]);
2121

2222
// Decorators
23+
// https://github.com/tc39/proposal-decorators
2324
def("Decorator")
2425
.bases("Node")
2526
.build("expression")
2627
.field("expression", def("Expression"));
2728

28-
def("Property")
29-
.field("decorators",
30-
or([def("Decorator")], null),
31-
defaults["null"]);
32-
33-
def("MethodDefinition")
34-
.field("decorators",
35-
or([def("Decorator")], null),
36-
defaults["null"]);
29+
[
30+
"ClassDeclaration",
31+
"Property",
32+
"ClassProperty",
33+
"MethodDefinition"
34+
].forEach(decl => {
35+
def(decl)
36+
.field("decorators",
37+
or([def("Decorator")], null),
38+
defaults["null"]);
39+
});
3740

3841
// Private names
3942
def("PrivateName")

src/gen/builders.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ export interface ClassPropertyBuilder {
879879
access?: "public" | "private" | "protected" | undefined;
880880
comments?: K.CommentKind[] | null;
881881
computed?: boolean;
882+
decorators?: K.DecoratorKind[] | null;
882883
key: K.LiteralKind | K.IdentifierKind | K.ExpressionKind;
883884
loc?: K.SourceLocationKind | null;
884885
static?: boolean;
@@ -923,6 +924,7 @@ export interface ClassDeclarationBuilder {
923924
params: {
924925
body: K.ClassBodyKind;
925926
comments?: K.CommentKind[] | null;
927+
decorators?: K.DecoratorKind[] | null;
926928
id: K.IdentifierKind | null;
927929
implements?: K.ClassImplementsKind[] | K.TSExpressionWithTypeArgumentsKind[];
928930
loc?: K.SourceLocationKind | null;
@@ -1271,6 +1273,7 @@ export interface ClassPrivatePropertyBuilder {
12711273
access?: "public" | "private" | "protected" | undefined;
12721274
comments?: K.CommentKind[] | null;
12731275
computed?: boolean;
1276+
decorators?: K.DecoratorKind[] | null;
12741277
key: K.PrivateNameKind;
12751278
loc?: K.SourceLocationKind | null;
12761279
static?: boolean;
@@ -2126,6 +2129,7 @@ export interface PropertyDefinitionBuilder {
21262129
access?: "public" | "private" | "protected" | undefined;
21272130
comments?: K.CommentKind[] | null;
21282131
computed?: boolean;
2132+
decorators?: K.DecoratorKind[] | null;
21292133
key: K.LiteralKind | K.IdentifierKind | K.ExpressionKind;
21302134
loc?: K.SourceLocationKind | null;
21312135
static?: boolean;

src/gen/namedTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export namespace namedTypes {
432432
type: "ClassProperty";
433433
key: K.LiteralKind | K.IdentifierKind | K.ExpressionKind;
434434
computed?: boolean;
435+
decorators?: K.DecoratorKind[] | null;
435436
value: K.ExpressionKind | null;
436437
static?: boolean;
437438
typeAnnotation?: K.TypeAnnotationKind | K.TSTypeAnnotationKind | null;
@@ -454,6 +455,7 @@ export namespace namedTypes {
454455
id: K.IdentifierKind | null;
455456
body: K.ClassBodyKind;
456457
superClass?: K.ExpressionKind | null;
458+
decorators?: K.DecoratorKind[] | null;
457459
typeParameters?: K.TypeParameterDeclarationKind | K.TSTypeParameterDeclarationKind | null;
458460
superTypeParameters?: K.TypeParameterInstantiationKind | K.TSTypeParameterInstantiationKind | null;
459461
implements?: K.ClassImplementsKind[] | K.TSExpressionWithTypeArgumentsKind[];

0 commit comments

Comments
 (0)