Fix invalid print output when empty array is passed to t.tsInterfaceDeclaration (#12921)
If you pass an empty array as `extends` in `t.tsInterfaceDeclaration` you'll get an invalid code printed
```ts
t.tsInterfaceDeclaration(
t.identifier('x'),
undefined,
[],
t.tsInterfaceBody([])
)
```
You will get
```ts
interface A extends {}
```
Which is an invalid TS, this PR fixes that
This commit is contained in:
parent
4c343ac853
commit
d05fdbc3c7
@ -435,7 +435,7 @@ export function TSInterfaceDeclaration(
|
||||
this.space();
|
||||
this.print(id, node);
|
||||
this.print(typeParameters, node);
|
||||
if (extendz) {
|
||||
if (extendz?.length) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
|
||||
@ -735,6 +735,19 @@ describe("programmatic generation", function () {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("typescript interface declaration", () => {
|
||||
it("empty extends array", () => {
|
||||
const tsInterfaceDeclaration = t.tsInterfaceDeclaration(
|
||||
t.identifier("A"),
|
||||
undefined,
|
||||
[],
|
||||
t.tsInterfaceBody([]),
|
||||
);
|
||||
const output = generate(tsInterfaceDeclaration).code;
|
||||
expect(output).toBe("interface A {}");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("CodeGenerator", function () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user