From eb2cc4c0ed4a9c512593c85fbf71ccc8c903a868 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 20 Feb 2018 16:54:31 -0800 Subject: [PATCH 1/2] core: Delete commented out code --- src/infer/membership.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/infer/membership.js b/src/infer/membership.js index 1fc0b51a5..5df20a774 100644 --- a/src/infer/membership.js +++ b/src/infer/membership.js @@ -397,18 +397,6 @@ 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]); - } - */ - return comment; }; }; From 22469f32d72511ba8313080e5fd0f9be2516a083 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 20 Feb 2018 17:25:23 -0800 Subject: [PATCH 2/2] fix: Improve membership inference for flow types --- __tests__/lib/infer/membership.js | 34 +++++++++++++++++++++++++++++++ src/infer/membership.js | 15 ++++++++++++++ 2 files changed, 49 insertions(+) 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 5df20a774..95d5800ce 100644 --- a/src/infer/membership.js +++ b/src/infer/membership.js @@ -397,6 +397,21 @@ module.exports = function() { } } + // 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; }; };