Skip to content

Commit

Permalink
Cache regex creation
Browse files Browse the repository at this point in the history
  • Loading branch information
lustoykov committed Jan 17, 2019
1 parent 213383a commit 22bc1d4
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 22bc1d4

Please sign in to comment.