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

Ignore import type for extract_requires #4079

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,16 @@ describe('extractRequires', () => {

expect(extractRequires(code)).toEqual(['module1']);
});

it('ignores type imports', () => {
const code = [
"import type foo from 'bar';",
"import type {",
" bar,",
" baz,",
"} from 'wham'",
].join('\r\n');

expect(extractRequires(code)).toEqual([]);
});
});
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/lib/extract_requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const blockCommentRe = /\/\*[^]*?\*\//g;
const lineCommentRe = /\/\/.*/g;

const replacePatterns = {
EXPORT_RE: /(\bexport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there any tests that cover this currently? I didn't see anything and I'm not sure how it is used so I wasn't able to add a test for this.

Copy link
Member

Choose a reason for hiding this comment

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

Nope, probably no tests :) Feel free to send one, it's the same as import, just that it exports also:

export foo from 'foo-module';
export type foo from 'foo-module';

we want to ignore the latter.

IMPORT_RE: /(\bimport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g,
EXPORT_RE: /(\bexport\s+(?!type )(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g,
IMPORT_RE: /(\bimport\s+(?!type )(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g,
REQUIRE_EXTENSIONS_PATTERN: /(?:^|[^.]\s*)(\b(?:require\s*?\.\s*?(?:requireActual|requireMock)|jest\s*?\.\s*?genMockFromModule)\s*?\(\s*?)([`'"])([^`'"]+)(\2\s*?\))/g,
REQUIRE_RE: /(?:^|[^.]\s*)(\brequire\s*?\(\s*?)([`'"])([^`'"]+)(\2\s*?\))/g,
};
Expand Down