make isReferenced() recognise ObjectTypeProperty (#8060)

fixes #8057
This commit is contained in:
Peter Leonov
2018-05-31 00:07:56 +02:00
committed by Nicolò Ribaudo
parent d83d141e00
commit ab62a94399
2 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -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);
});
});
});