Skip to content

Commit

Permalink
Ignore import type for extract_requires (jestjs#4079)
Browse files Browse the repository at this point in the history
  • Loading branch information
elicwhite authored and cpojer committed Jul 19, 2017
1 parent bab5689 commit 2f419d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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,
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

0 comments on commit 2f419d9

Please sign in to comment.