committed by
Nicolò Ribaudo
parent
d83d141e00
commit
ab62a94399
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user