diff --git a/packages/babel-types/src/validators/isReferenced.js b/packages/babel-types/src/validators/isReferenced.js index 4ff3b9a790..07c58cc138 100644 --- a/packages/babel-types/src/validators/isReferenced.js +++ b/packages/babel-types/src/validators/isReferenced.js @@ -116,6 +116,11 @@ export default function isReferenced(node: Object, parent: Object): boolean { // no: NODE.target case "MetaProperty": return false; + + // yes: type X = { somePropert: NODE } + // no: type X = { NODE: OtherType } + case "ObjectTypeProperty": + return parent.key !== node; } return true; diff --git a/packages/babel-types/test/validators.js b/packages/babel-types/test/validators.js index 3582a71936..aaa02da501 100644 --- a/packages/babel-types/test/validators.js +++ b/packages/babel-types/test/validators.js @@ -95,4 +95,23 @@ describe("validators", function() { expect(t.isNodesEquivalent(pattern, pattern)).toBe(true); }); }); + + describe("isReferenced", function() { + it("returns false if node is a key of ObjectTypeProperty", function() { + const node = t.identifier("a"); + const parent = t.objectTypeProperty(node, t.numberTypeAnnotation()); + + expect(t.isReferenced(node, parent)).toBe(false); + }); + + it("returns true if node is a value of ObjectTypeProperty", function() { + const node = t.identifier("a"); + const parent = t.objectTypeProperty( + t.identifier("someKey"), + t.genericTypeAnnotation(node), + ); + + expect(t.isReferenced(node, parent)).toBe(true); + }); + }); });