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

BREAKING CHANGE: The 2., 3., and 4. parameter to the builder for `ObjectTypeAnnotation` do not accept null anymore. Use undefined.
  • Loading branch information
danez committed Apr 21, 2022
1 parent f51fc61 commit 4882ccc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 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
18 changes: 15 additions & 3 deletions packages/babel-types/src/definitions/flow.ts
Expand Up @@ -272,9 +272,21 @@ defineType("ObjectTypeAnnotation", {
properties: validate(
arrayOfType(["ObjectTypeProperty", "ObjectTypeSpreadProperty"]),
),
indexers: validateOptional(arrayOfType("ObjectTypeIndexer")),
callProperties: validateOptional(arrayOfType("ObjectTypeCallProperty")),
internalSlots: validateOptional(arrayOfType("ObjectTypeInternalSlot")),
indexers: {
validate: arrayOfType("ObjectTypeIndexer"),
optional: process.env.BABEL_8_BREAKING ? false : true,
default: process.env.BABEL_8_BREAKING ? [] : undefined,
},
callProperties: {
validate: arrayOfType("ObjectTypeCallProperty"),
optional: process.env.BABEL_8_BREAKING ? false : true,
default: process.env.BABEL_8_BREAKING ? [] : undefined,
},
internalSlots: {
validate: arrayOfType("ObjectTypeInternalSlot"),
optional: process.env.BABEL_8_BREAKING ? false : true,
default: process.env.BABEL_8_BREAKING ? [] : undefined,
},
exact: {
validate: assertValueType("boolean"),
default: false,
Expand Down

0 comments on commit 4882ccc

Please sign in to comment.