Skip to content

Commit 22469f3

Browse files
committed
fix: Improve membership inference for flow types
1 parent eb2cc4c commit 22469f3

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

__tests__/lib/infer/membership.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,37 @@ test('inferMembership - export', function() {
633633
scope: 'instance'
634634
});
635635
});
636+
637+
test('inferMembership - flow interface', function() {
638+
expect(
639+
pick(
640+
evaluate(`
641+
interface Foo {
642+
/** Test */
643+
bar: number
644+
}
645+
`)[0],
646+
['memberof', 'scope']
647+
)
648+
).toEqual({
649+
memberof: 'Foo',
650+
scope: 'instance'
651+
});
652+
});
653+
654+
test('inferMembership - flow object type alias', function() {
655+
expect(
656+
pick(
657+
evaluate(`
658+
type Foo = {
659+
/** Test */
660+
bar: number
661+
}
662+
`)[0],
663+
['memberof', 'scope']
664+
)
665+
).toEqual({
666+
memberof: 'Foo',
667+
scope: 'instance'
668+
});
669+
});

src/infer/membership.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,21 @@ module.exports = function() {
397397
}
398398
}
399399

400+
// type Foo = { bar: T }
401+
// interface Foo { bar: T }
402+
if (
403+
path.isObjectTypeProperty() &&
404+
path.parentPath.isObjectTypeAnnotation() &&
405+
(path.parentPath.parentPath.isTypeAlias() ||
406+
path.parentPath.parentPath.isInterfaceDeclaration())
407+
) {
408+
return inferMembershipFromIdentifiers(
409+
comment,
410+
[path.parentPath.parentPath.get('id').node.name],
411+
'instance'
412+
);
413+
}
414+
400415
return comment;
401416
};
402417
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy