Skip to content

Commit

Permalink
fix: Improve membership inference for flow types
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 21, 2018
1 parent eb2cc4c commit 22469f3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
34 changes: 34 additions & 0 deletions __tests__/lib/infer/membership.js
Expand Up @@ -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'
});
});
15 changes: 15 additions & 0 deletions src/infer/membership.js
Expand Up @@ -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;
};
};

0 comments on commit 22469f3

Please sign in to comment.