diff --git a/__tests__/lib/infer/membership.js b/__tests__/lib/infer/membership.js index 22849a0a4..ee28bd5d3 100644 --- a/__tests__/lib/infer/membership.js +++ b/__tests__/lib/infer/membership.js @@ -633,3 +633,37 @@ test('inferMembership - export', function() { scope: 'instance' }); }); + +test('inferMembership - flow interface', function() { + expect( + pick( + evaluate(` + interface Foo { + /** Test */ + bar: number + } + `)[0], + ['memberof', 'scope'] + ) + ).toEqual({ + memberof: 'Foo', + scope: 'instance' + }); +}); + +test('inferMembership - flow object type alias', function() { + expect( + pick( + evaluate(` + type Foo = { + /** Test */ + bar: number + } + `)[0], + ['memberof', 'scope'] + ) + ).toEqual({ + memberof: 'Foo', + scope: 'instance' + }); +}); diff --git a/src/infer/membership.js b/src/infer/membership.js index 1fc0b51a5..95d5800ce 100644 --- a/src/infer/membership.js +++ b/src/infer/membership.js @@ -397,17 +397,20 @@ module.exports = function() { } } - // var function Foo() { - // function bar() {} - // return { bar: bar }; - // } - /* - if (n.isFunctionDeclaration(path) && - n.isBlockStatement(path.parentPath) && - n.isFunction(path.parentPath.parentPath)) { - inferMembershipFromIdentifiers(comment, [path.parentPath.parentPath.node.id.name]); + // type Foo = { bar: T } + // interface Foo { bar: T } + if ( + path.isObjectTypeProperty() && + path.parentPath.isObjectTypeAnnotation() && + (path.parentPath.parentPath.isTypeAlias() || + path.parentPath.parentPath.isInterfaceDeclaration()) + ) { + return inferMembershipFromIdentifiers( + comment, + [path.parentPath.parentPath.get('id').node.name], + 'instance' + ); } - */ return comment; };