Allow nullish extends in interfaceish (#12920)
* Allow nullish extends in interfaceish
Otherwise code such as
```ts
t.interfaceDeclaration(
t.identifier('id'),
undefined,
undefined,
t.objectTypeAnnotation([])
)
```
Will fail when priting with ` TypeError: unknown: Cannot read property 'length' of null`
Despite nullish values being allowed in `t.interfaceDeclaration` definitions
* Update packages/babel-generator/src/generators/flow.ts
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
parent
b62fc3d44f
commit
4c343ac853
@ -360,7 +360,7 @@ export function _interfaceish(
|
||||
) {
|
||||
this.print(node.id, node);
|
||||
this.print(node.typeParameters, node);
|
||||
if (node.extends.length) {
|
||||
if (node.extends?.length) {
|
||||
this.space();
|
||||
this.word("extends");
|
||||
this.space();
|
||||
|
||||
@ -462,6 +462,17 @@ describe("programmatic generation", function () {
|
||||
}`);
|
||||
});
|
||||
|
||||
it("flow interface with nullish extends", () => {
|
||||
const interfaceDeclaration = t.interfaceDeclaration(
|
||||
t.identifier("A"),
|
||||
undefined,
|
||||
undefined,
|
||||
t.objectTypeAnnotation([]),
|
||||
);
|
||||
const output = generate(interfaceDeclaration).code;
|
||||
expect(output).toBe("interface A {}");
|
||||
});
|
||||
|
||||
describe("directives", function () {
|
||||
it("preserves escapes", function () {
|
||||
const directive = t.directive(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user