Skip to content

Commit 8adaa74

Browse files
authored
Merge pull request webpack#7348 from webpack/refactor/nmf_cache
Use a WeakMap instead of mutating objects in NMF
2 parents 8b19f20 + 8df9f5f commit 8adaa74

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/NormalModuleFactory.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const identToLoaderRequest = resultString => {
4646
}
4747
};
4848

49+
const dependencyCache = new WeakMap();
50+
4951
class NormalModuleFactory extends Tapable {
5052
constructor(context, resolverFactory, options) {
5153
super();
@@ -329,7 +331,7 @@ class NormalModuleFactory extends Tapable {
329331

330332
create(data, callback) {
331333
const dependencies = data.dependencies;
332-
const cacheEntry = dependencies[0].__NormalModuleFactoryCache;
334+
const cacheEntry = dependencyCache.get(dependencies[0]);
333335
if (cacheEntry) return callback(null, cacheEntry);
334336
const context = data.context || this.context;
335337
const resolveOptions = data.resolveOptions || EMPTY_RESOLVE_OPTIONS;
@@ -359,7 +361,7 @@ class NormalModuleFactory extends Tapable {
359361

360362
if (module && this.cachePredicate(module)) {
361363
for (const d of dependencies) {
362-
d.__NormalModuleFactoryCache = module;
364+
dependencyCache.set(d, module);
363365
}
364366
}
365367

0 commit comments

Comments
 (0)