Skip to content

Commit

Permalink
Allow nullish extends in interfaceish
Browse files Browse the repository at this point in the history
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
  • Loading branch information
saitonakamura committed Feb 28, 2021
1 parent 265424d commit 4373398
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-generator/src/generators/flow.ts
Expand Up @@ -360,7 +360,7 @@ export function _interfaceish(
) {
this.print(node.id, node);
this.print(node.typeParameters, node);
if (node.extends.length) {
if (node.extends && node.extends.length) {
this.space();
this.word("extends");
this.space();
Expand Down
11 changes: 11 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -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(
Expand Down

0 comments on commit 4373398

Please sign in to comment.