Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[babel 8] ObjectTypeAnnotation fields must always be arrays #14465

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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