mirror of https://github.com/webpack/webpack.git
avoid leaking processed assets
This commit is contained in:
parent
b3e26cb5a8
commit
3caf3e95a8
|
|
@ -358,12 +358,13 @@ class Compilation {
|
|||
const { fn, additionalAssets, ...remainingTap } = tap;
|
||||
const additionalAssetsFn =
|
||||
additionalAssets === true ? fn : additionalAssets;
|
||||
let processedAssets = undefined;
|
||||
const processedAssets = additionalAssetsFn ? new WeakSet() : undefined;
|
||||
switch (type) {
|
||||
case "sync":
|
||||
if (additionalAssetsFn) {
|
||||
this.hooks.processAdditionalAssets.tap(name, assets => {
|
||||
if (processedAssets === this.assets) additionalAssetsFn(assets);
|
||||
if (processedAssets.has(this.assets))
|
||||
additionalAssetsFn(assets);
|
||||
});
|
||||
}
|
||||
return {
|
||||
|
|
@ -375,7 +376,8 @@ class Compilation {
|
|||
} catch (e) {
|
||||
return callback(e);
|
||||
}
|
||||
processedAssets = this.assets;
|
||||
if (processedAssets !== undefined)
|
||||
processedAssets.add(this.assets);
|
||||
const newAssets = popNewAssets(assets);
|
||||
if (newAssets !== undefined) {
|
||||
this.hooks.processAdditionalAssets.callAsync(
|
||||
|
|
@ -392,7 +394,7 @@ class Compilation {
|
|||
this.hooks.processAdditionalAssets.tapAsync(
|
||||
name,
|
||||
(assets, callback) => {
|
||||
if (processedAssets === this.assets)
|
||||
if (processedAssets.has(this.assets))
|
||||
return additionalAssetsFn(assets, callback);
|
||||
callback();
|
||||
}
|
||||
|
|
@ -403,7 +405,8 @@ class Compilation {
|
|||
fn: (assets, callback) => {
|
||||
fn(assets, err => {
|
||||
if (err) return callback(err);
|
||||
processedAssets = this.assets;
|
||||
if (processedAssets !== undefined)
|
||||
processedAssets.add(this.assets);
|
||||
const newAssets = popNewAssets(assets);
|
||||
if (newAssets !== undefined) {
|
||||
this.hooks.processAdditionalAssets.callAsync(
|
||||
|
|
@ -419,7 +422,7 @@ class Compilation {
|
|||
case "promise":
|
||||
if (additionalAssetsFn) {
|
||||
this.hooks.processAdditionalAssets.tapPromise(name, assets => {
|
||||
if (processedAssets === this.assets)
|
||||
if (processedAssets.has(this.assets))
|
||||
return additionalAssetsFn(assets);
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
|
@ -430,7 +433,8 @@ class Compilation {
|
|||
const p = fn(assets);
|
||||
if (!p || !p.then) return p;
|
||||
return p.then(() => {
|
||||
processedAssets = this.assets;
|
||||
if (processedAssets !== undefined)
|
||||
processedAssets.add(this.assets);
|
||||
const newAssets = popNewAssets(assets);
|
||||
if (newAssets !== undefined) {
|
||||
return this.hooks.processAdditionalAssets.promise(
|
||||
|
|
|
|||
Loading…
Reference in New Issue