Skip to content

Commit

Permalink
[babel 8] ObjectTypeAnnotation fields must always be arrays (#14465)
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Apr 24, 2022
1 parent 0d2ae01 commit 0b9fb13
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 0b9fb13

Please sign in to comment.