Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type-only import test case for dependencyExtractor #15307

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,32 @@ describe('dependencyExtractor', () => {
);
});

it('should not extract dependencies from `import type/typeof` statements', () => {
it('should not extract dependencies from `import type/typeof` statements, or type-only imports', () => {
const code = `
// Bad
import typeof {foo} from 'inv1';
import type {foo} from 'inv2';
import {type foo, typeof bar} from 'inv3';
import {
type foo,
typeof bar,
Copy link
Author

@CoryDanielson CoryDanielson Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this import ends with a , which is an interesting wrinkle to account for

  • if all named exports are split by a comma, you can have a trailing item that is just space character(s)

} from 'inv4'
// Good
import {foo, typeof bar} from 'inv5';
import {type foo, bar} from 'inv6';
import {
foo,
typeof bar
} from 'inv7';
import {
type foo,
bar
} from 'inv8';
import TheDefaultExport, {type foo, type bar} from 'inv9';
`;
expect(extractor.extract(code)).toEqual(new Set([]));
expect(extractor.extract(code)).toEqual(
new Set(['inv5', 'inv6', 'inv7', 'inv8', 'inv9']),
);
});

it('should extract dependencies from `export` statements', () => {
Expand Down
Loading