diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index 99b5955222..ffb8811358 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -328,6 +328,23 @@ describe("programmatic generation", function() { ); }); + it("flow object exact", function() { + const objectStatement = t.objectTypeAnnotation( + [t.objectTypeProperty(t.identifier("bar"), t.stringTypeAnnotation())], + null, + null, + true, + ); + + const output = generate(objectStatement).code; + assert.equal( + output, + `{| + bar: string +|}`, + ); + }); + it("flow object indentation with empty leading ObjectTypeProperty", function() { const objectStatement = t.objectTypeAnnotation( [], diff --git a/packages/babel-types/README.md b/packages/babel-types/README.md index 2f2868c500..a48301c15c 100644 --- a/packages/babel-types/README.md +++ b/packages/babel-types/README.md @@ -1499,7 +1499,7 @@ Aliases: `UserWhitespacable`, `Property`, `ObjectMember` ### objectTypeAnnotation ```javascript -t.objectTypeAnnotation(properties, indexers, callProperties) +t.objectTypeAnnotation(properties, indexers, callProperties, exact) ``` See also `t.isObjectTypeAnnotation(node, opts)` and `t.assertObjectTypeAnnotation(node, opts)`. @@ -1509,7 +1509,7 @@ Aliases: `Flow`, `FlowType` - `properties`: `Array` (required) - `indexers`: `Array` (default: `null`) - `callProperties`: `Array` (default: `null`) - - `exact`: `boolean` (default: `null`) + - `exact`: `boolean` (default: `false`) --- diff --git a/packages/babel-types/src/definitions/flow.js b/packages/babel-types/src/definitions/flow.js index 709d179db7..cbd75c7775 100644 --- a/packages/babel-types/src/definitions/flow.js +++ b/packages/babel-types/src/definitions/flow.js @@ -252,13 +252,17 @@ defineType("NumberTypeAnnotation", { defineType("ObjectTypeAnnotation", { visitor: ["properties", "indexers", "callProperties"], aliases: ["Flow", "FlowType"], + builder: ["properties", "indexers", "callProperties", "exact"], fields: { properties: validate( arrayOfType(["ObjectTypeProperty", "ObjectTypeSpreadProperty"]), ), indexers: validateOptional(arrayOfType("ObjectTypeIndexer")), callProperties: validateOptional(arrayOfType("ObjectTypeCallProperty")), - exact: validate(assertValueType("boolean")), + exact: { + validate: assertValueType("boolean"), + default: false, + }, }, });