Skip to content

Commit

Permalink
fix(types): Fix types because array fields in ObjectTypeAnnotation
Browse files Browse the repository at this point in the history
…are always present
  • Loading branch information
danez committed Apr 14, 2022
1 parent e71843a commit 82ad2f2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
16 changes: 6 additions & 10 deletions packages/babel-generator/test/index.js
Expand Up @@ -438,12 +438,9 @@ describe("programmatic generation", function () {
});

it("flow object indentation", function () {
const objectStatement = t.objectTypeAnnotation(
[t.objectTypeProperty(t.identifier("bar"), t.stringTypeAnnotation())],
null,
null,
null,
);
const objectStatement = t.objectTypeAnnotation([
t.objectTypeProperty(t.identifier("bar"), t.stringTypeAnnotation()),
]);

const output = generate(objectStatement).code;
expect(output).toBe(`{
Expand All @@ -454,9 +451,9 @@ describe("programmatic generation", function () {
it("flow object exact", function () {
const objectStatement = t.objectTypeAnnotation(
[t.objectTypeProperty(t.identifier("bar"), t.stringTypeAnnotation())],
null,
null,
null,
undefined,
undefined,
undefined,
true,
);

Expand All @@ -476,7 +473,6 @@ describe("programmatic generation", function () {
t.numberTypeAnnotation(),
),
],
null,
);

const output = generate(objectStatement).code;
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-types/src/ast-types/generated/index.ts
Expand Up @@ -1242,9 +1242,9 @@ export interface NumberTypeAnnotation extends BaseNode {
export interface ObjectTypeAnnotation extends BaseNode {
type: "ObjectTypeAnnotation";
properties: Array<ObjectTypeProperty | ObjectTypeSpreadProperty>;
indexers?: Array<ObjectTypeIndexer> | null;
callProperties?: Array<ObjectTypeCallProperty> | null;
internalSlots?: Array<ObjectTypeInternalSlot> | null;
indexers: Array<ObjectTypeIndexer>;
callProperties: Array<ObjectTypeCallProperty>;
internalSlots: Array<ObjectTypeInternalSlot>;
exact: boolean;
inexact?: boolean | null;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-types/src/builders/generated/index.ts
Expand Up @@ -727,9 +727,9 @@ export function numberTypeAnnotation(): t.NumberTypeAnnotation {
}
export function objectTypeAnnotation(
properties: Array<t.ObjectTypeProperty | t.ObjectTypeSpreadProperty>,
indexers?: Array<t.ObjectTypeIndexer> | null,
callProperties?: Array<t.ObjectTypeCallProperty> | null,
internalSlots?: Array<t.ObjectTypeInternalSlot> | null,
indexers?: Array<t.ObjectTypeIndexer>,
callProperties?: Array<t.ObjectTypeCallProperty>,
internalSlots?: Array<t.ObjectTypeInternalSlot>,
exact?: boolean,
): t.ObjectTypeAnnotation {
return builder.apply("ObjectTypeAnnotation", arguments);
Expand Down
12 changes: 9 additions & 3 deletions packages/babel-types/src/definitions/flow.ts
Expand Up @@ -272,9 +272,15 @@ defineType("ObjectTypeAnnotation", {
properties: validate(
arrayOfType(["ObjectTypeProperty", "ObjectTypeSpreadProperty"]),
),
indexers: validateOptional(arrayOfType("ObjectTypeIndexer")),
callProperties: validateOptional(arrayOfType("ObjectTypeCallProperty")),
internalSlots: validateOptional(arrayOfType("ObjectTypeInternalSlot")),
indexers: { validate: arrayOfType("ObjectTypeIndexer"), default: [] },
callProperties: {
validate: arrayOfType("ObjectTypeCallProperty"),
default: [],
},
internalSlots: {
validate: arrayOfType("ObjectTypeInternalSlot"),
default: [],
},
exact: {
validate: assertValueType("boolean"),
default: false,
Expand Down

0 comments on commit 82ad2f2

Please sign in to comment.