-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest-haste-map): support dependencyExtractor written in ESM
- Loading branch information
1 parent
3d04f33
commit 5c21bae
Showing
10 changed files
with
287 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/jest-haste-map/src/__tests__/dependencyExtractor.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const blockCommentRe = /\/\*[^]*?\*\//g; | ||
const lineCommentRe = /\/\/.*/g; | ||
const LOAD_MODULE_RE = | ||
/(?:^|[^.]\s*)(\bloadModule\s*?\(\s*?)([`'"])([^`'"]+)(\2\s*?\))/g; | ||
|
||
export function extract(code, filePath, defaultDependencyExtractor) { | ||
const dependencies = defaultDependencyExtractor(code); | ||
|
||
const addDependency = (match, pre, quot, dep, post) => { | ||
dependencies.add(dep); | ||
return match; | ||
}; | ||
|
||
code | ||
.replace(blockCommentRe, '') | ||
.replace(lineCommentRe, '') | ||
.replace(LOAD_MODULE_RE, addDependency); | ||
|
||
return dependencies; | ||
} | ||
|
||
let cacheKey; | ||
|
||
export function getCacheKey() { | ||
return cacheKey; | ||
} | ||
|
||
export function setCacheKey(key) { | ||
cacheKey = key; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.