From 462b11739125e059b73de2c763891dcb596ee68d Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 19 Jul 2017 13:36:02 -0700 Subject: [PATCH 1/2] Ignore import type for extract_requires --- .../src/lib/__tests__/extract_requires.test.js | 12 ++++++++++++ packages/jest-haste-map/src/lib/extract_requires.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js b/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js index fb470813bde5..6901af459941 100644 --- a/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js @@ -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([]); + }); }); diff --git a/packages/jest-haste-map/src/lib/extract_requires.js b/packages/jest-haste-map/src/lib/extract_requires.js index 0eae1a5f0055..b129475c376a 100644 --- a/packages/jest-haste-map/src/lib/extract_requires.js +++ b/packages/jest-haste-map/src/lib/extract_requires.js @@ -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, }; From cbca4b9a5a2704f50898a01e13577cd6e772935b Mon Sep 17 00:00:00 2001 From: Eli White Date: Wed, 19 Jul 2017 14:01:41 -0700 Subject: [PATCH 2/2] Add test for ignore type exports --- .../src/lib/__tests__/extract_requires.test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js b/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js index 6901af459941..b5508c676116 100644 --- a/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/extract_requires.test.js @@ -84,12 +84,22 @@ describe('extractRequires', () => { it('ignores type imports', () => { const code = [ "import type foo from 'bar';", - "import type {", - " bar,", - " baz,", + 'import type {', + ' bar,', + ' baz,', "} from 'wham'", ].join('\r\n'); expect(extractRequires(code)).toEqual([]); }); + + it('ignores type exports', () => { + const code = [ + 'export type Foo = number;', + 'export default {}', + "export * from 'module1'", + ].join('\r\n'); + + expect(extractRequires(code)).toEqual(['module1']); + }); });