Skip to content

Commit

Permalink
Add support in babel-types babel-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Apr 7, 2021
1 parent 69a1f2b commit bc141f2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/babel-generator/src/generators/typescript.ts
Expand Up @@ -127,6 +127,11 @@ export function tsPrintPropertyOrMethodName(this: Printer, node) {
}

export function TSMethodSignature(this: Printer, node: t.TSMethodSignature) {
const { kind } = node;
if (kind === "set" || kind === "get") {
this.word(kind);
this.space();
}
this.tsPrintPropertyOrMethodName(node);
this.tsPrintSignatureDeclarationBase(node);
this.token(";");
Expand Down
@@ -0,0 +1,4 @@
interface Foo {
get foo();
set bar(v);
}
@@ -0,0 +1,4 @@
interface Foo {
get foo();
set bar(v);
}
1 change: 1 addition & 0 deletions packages/babel-types/src/ast-types/generated/index.ts
Expand Up @@ -1701,6 +1701,7 @@ export interface TSMethodSignature extends BaseNode {
parameters: Array<Identifier | RestElement>;
typeAnnotation?: TSTypeAnnotation | null;
computed?: boolean | null;
kind: "method" | "get" | "set";
optional?: boolean | null;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/babel-types/src/definitions/typescript.ts
Expand Up @@ -118,6 +118,9 @@ defineType("TSMethodSignature", {
fields: {
...signatureDeclarationCommon,
...namedTypeElementCommon,
kind: {
validate: assertOneOf("method", "get", "set"),
},
},
});

Expand Down

0 comments on commit bc141f2

Please sign in to comment.