Skip to content

Commit

Permalink
Avoid parsing .require(…) method calls (jestjs#3777)
Browse files Browse the repository at this point in the history
This makes sure that a match for `require` is not preceded by a dot and whitespace, thus skipping over method calls to `.require(…)`.
  • Loading branch information
davidaurelio authored and cpojer committed Jun 9, 2017
1 parent 207d446 commit 9fb9e53
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/jest-haste-map/src/lib/extractRequires.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const lineCommentRe = /\/\/.*/g;
const replacePatterns = {
EXPORT_RE: /(\bexport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g,
IMPORT_RE: /(\bimport\s+(?:[^'"]+\s+from\s+)??)(['"])([^'"]+)(\2)/g,
REQUIRE_EXTENSIONS_PATTERN: /(\b(?:require\s*?\.\s*?(?:requireActual|requireMock)|jest\s*?\.\s*?genMockFromModule)\s*?\(\s*?)([`'"])([^`'"]+)(\2\s*?\))/g,
REQUIRE_RE: /(\brequire\s*?\(\s*?)([`'"])([^`'"]+)(\2\s*?\))/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,
};

function extractRequires(code: string): Array<string> {
Expand Down

0 comments on commit 9fb9e53

Please sign in to comment.