Skip to content

Commit

Permalink
Cache regex creation
Browse files Browse the repository at this point in the history
This is preventive measure to avoid unnecessary regex creation, although the impact is questionable since the fallback pragma is created once at most before the dependencies are collected. So we probably get a single cache hit if we are lucky
  • Loading branch information
lustoykov committed Jan 17, 2019
1 parent 213383a commit 887aa95
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/core/parcel-bundler/src/transforms/babel/jsx.js
Expand Up @@ -24,9 +24,17 @@ function createJSXRegexFor(dependency) {
* package.json is empty or missing yet and therefore pragma cannot
* be determined based on pkg.dependencies / pkg.devDependencies
*/
const cacheJsxRegexFor = {};
function maybeCreateFallbackPragma(asset) {
for (const dep in JSX_PRAGMA) {
if (asset.contents.match(createJSXRegexFor(dep))) {
let regex = cacheJsxRegexFor[dep];

if (!regex) {
regex = createJSXRegexFor(dep);
cacheJsxRegexFor[dep] = regex;
}

if (asset.contents.match(regex)) {
return JSX_PRAGMA[dep];
}
}
Expand Down

0 comments on commit 887aa95

Please sign in to comment.