feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -84,10 +84,11 @@ class ArrayPushCallbackChunkFormatPlugin {
);
if (runtimeModules.length > 0 || entries.length > 0) {
const runtime = new ConcatSource(
(runtimeTemplate.supportsArrowFunction()
? `${RuntimeGlobals.require} =>`
: `function(${RuntimeGlobals.require})`) +
" { // webpackRuntimeModules\n"
`${
runtimeTemplate.supportsArrowFunction()
? `${RuntimeGlobals.require} =>`
: `function(${RuntimeGlobals.require})`
} { // webpackRuntimeModules\n`
);
if (runtimeModules.length > 0) {
runtime.add(

View File

@@ -184,7 +184,7 @@ class BasicEvaluatedExpression {
asCompileTimeValue() {
switch (this.type) {
case TypeUndefined:
return undefined;
return;
case TypeNull:
return null;
case TypeString:
@@ -252,7 +252,6 @@ class BasicEvaluatedExpression {
const str = this.asString();
if (typeof str === "string") return str !== "";
}
return undefined;
}
/**
@@ -275,8 +274,6 @@ class BasicEvaluatedExpression {
if (this.isConstArray()) return false;
if (this.isTemplateString()) return false;
if (this.isRegExp()) return false;
return undefined;
}
/**
@@ -292,12 +289,12 @@ class BasicEvaluatedExpression {
if (this.isBigInt()) return `${this.bigint}`;
if (this.isRegExp()) return `${this.regExp}`;
if (this.isArray()) {
let array = [];
const array = [];
for (const item of /** @type {BasicEvaluatedExpression[]} */ (
this.items
)) {
const itemStr = item.asString();
if (itemStr === undefined) return undefined;
if (itemStr === undefined) return;
array.push(itemStr);
}
return `${array}`;
@@ -309,12 +306,11 @@ class BasicEvaluatedExpression {
this.parts
)) {
const partStr = part.asString();
if (partStr === undefined) return undefined;
if (partStr === undefined) return;
str += partStr;
}
return str;
}
return undefined;
}
/**
@@ -390,7 +386,6 @@ class BasicEvaluatedExpression {
/**
* Set's the value of this expression to a particular identifier and its members.
*
* @param {string | VariableInfoInterface} identifier identifier to set
* @param {string | VariableInfoInterface} rootInfo root info
* @param {() => string[]} getMembers members
@@ -417,7 +412,6 @@ class BasicEvaluatedExpression {
/**
* Wraps an array of expressions with a prefix and postfix expression.
*
* @param {BasicEvaluatedExpression | null | undefined} prefix Expression to be added before the innerExpressions
* @param {BasicEvaluatedExpression | null | undefined} postfix Expression to be added after the innerExpressions
* @param {BasicEvaluatedExpression[] | undefined} innerExpressions Expressions to be wrapped
@@ -434,7 +428,6 @@ class BasicEvaluatedExpression {
/**
* Stores the options of a conditional expression.
*
* @param {BasicEvaluatedExpression[]} options optional (consequent/alternate) expressions to be set
* @returns {this} this
*/
@@ -447,7 +440,6 @@ class BasicEvaluatedExpression {
/**
* Adds options to a conditional expression.
*
* @param {BasicEvaluatedExpression[]} options optional (consequent/alternate) expressions to be added
* @returns {this} this
*/
@@ -465,7 +457,6 @@ class BasicEvaluatedExpression {
/**
* Set's the value of this expression to an array of expressions.
*
* @param {BasicEvaluatedExpression[]} items expressions to set
* @returns {this} this
*/
@@ -478,7 +469,6 @@ class BasicEvaluatedExpression {
/**
* Set's the value of this expression to an array of strings.
*
* @param {string[]} array array to set
* @returns {this} this
*/
@@ -492,7 +482,6 @@ class BasicEvaluatedExpression {
/**
* Set's the value of this expression to a processed/unprocessed template string. Used
* for evaluating TemplateLiteral expressions in the JavaScript Parser.
*
* @param {BasicEvaluatedExpression[]} quasis template string quasis
* @param {BasicEvaluatedExpression[]} parts template string parts
* @param {"cooked" | "raw"} kind template string kind
@@ -522,7 +511,6 @@ class BasicEvaluatedExpression {
/**
* Set's the value of the expression to nullish.
*
* @param {boolean} value true, if the expression is nullish
* @returns {this} this
*/
@@ -536,7 +524,6 @@ class BasicEvaluatedExpression {
/**
* Set's the range for the expression.
*
* @param {[number, number]} range range to set
* @returns {this} this
*/
@@ -547,7 +534,6 @@ class BasicEvaluatedExpression {
/**
* Set whether or not the expression has side effects.
*
* @param {boolean} sideEffects true, if the expression has side effects
* @returns {this} this
*/
@@ -558,7 +544,6 @@ class BasicEvaluatedExpression {
/**
* Set the expression node for the expression.
*
* @param {Node | undefined} expression expression
* @returns {this} this
*/

View File

@@ -30,4 +30,4 @@ const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
}
return chunks;
};
exports.getAllChunks = getAllChunks;
module.exports.getAllChunks = getAllChunks;

View File

@@ -51,7 +51,7 @@ class CommonJsChunkFormatPlugin {
const source = new ConcatSource();
source.add(`exports.id = ${JSON.stringify(chunk.id)};\n`);
source.add(`exports.ids = ${JSON.stringify(chunk.ids)};\n`);
source.add(`exports.modules = `);
source.add("exports.modules = ");
source.add(modules);
source.add(";\n");
const runtimeModules =
@@ -85,7 +85,8 @@ class CommonJsChunkFormatPlugin {
const runtimeOutputName = compilation
.getPath(
getChunkFilenameTemplate(
runtimeChunk,
/** @type {Chunk} */
(runtimeChunk),
compilation.outputOptions
),
{

View File

@@ -53,8 +53,9 @@ class EnableChunkLoadingPlugin {
"EnableChunkLoadingPlugin need to be used to enable this type of chunk loading. " +
'This usually happens through the "output.enabledChunkLoadingTypes" option. ' +
'If you are using a function as entry which sets "chunkLoading", you need to add all potential chunk loading types to "output.enabledChunkLoadingTypes". ' +
"These types are enabled: " +
Array.from(getEnabledTypes(compiler)).join(", ")
`These types are enabled: ${Array.from(
getEnabledTypes(compiler)
).join(", ")}`
);
}
}
@@ -85,7 +86,7 @@ class EnableChunkLoadingPlugin {
break;
}
case "require": {
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
const CommonJsChunkLoadingPlugin = require("../node/CommonJsChunkLoadingPlugin");
new CommonJsChunkLoadingPlugin({
asyncChunkLoading: false
@@ -93,7 +94,7 @@ class EnableChunkLoadingPlugin {
break;
}
case "async-node": {
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
const CommonJsChunkLoadingPlugin = require("../node/CommonJsChunkLoadingPlugin");
new CommonJsChunkLoadingPlugin({
asyncChunkLoading: true

View File

@@ -9,15 +9,19 @@ const util = require("util");
const { RawSource, ReplaceSource } = require("webpack-sources");
const Generator = require("../Generator");
const InitFragment = require("../InitFragment");
const { JS_TYPES } = require("../ModuleSourceTypesConstants");
const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../DependenciesBlock")} DependenciesBlock */
/** @typedef {import("../Dependency")} Dependency */
/** @typedef {import("../DependencyTemplate")} DependencyTemplate */
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
/** @typedef {import("../Module")} Module */
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
/** @typedef {import("../Module").SourceTypes} SourceTypes */
/** @typedef {import("../NormalModule")} NormalModule */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
@@ -25,21 +29,26 @@ const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibi
// replace with newer constructs
const deprecatedGetInitFragments = util.deprecate(
/**
* @param {DependencyTemplate} template template
* @param {Dependency} dependency dependency
* @param {DependencyTemplateContext} templateContext template context
* @returns {InitFragment<GenerateContext>[]} init fragments
*/
(template, dependency, templateContext) =>
template.getInitFragments(dependency, templateContext),
/** @type {DependencyTemplate & { getInitFragments: function(Dependency, DependencyTemplateContext): InitFragment<GenerateContext>[] }} */
(template).getInitFragments(dependency, templateContext),
"DependencyTemplate.getInitFragment is deprecated (use apply(dep, source, { initFragments }) instead)",
"DEP_WEBPACK_JAVASCRIPT_GENERATOR_GET_INIT_FRAGMENTS"
);
const TYPES = new Set(["javascript"]);
class JavascriptGenerator extends Generator {
/**
* @param {NormalModule} module fresh module
* @returns {Set<string>} available types (do not mutate)
* @returns {SourceTypes} available types (do not mutate)
*/
getTypes(module) {
return TYPES;
return JS_TYPES;
}
/**
@@ -84,7 +93,7 @@ class JavascriptGenerator extends Generator {
/**
* @param {NormalModule} module module for which the code should be generated
* @param {GenerateContext} generateContext context for generate
* @returns {Source} generated code
* @returns {Source | null} generated code
*/
generate(module, generateContext) {
const originalSource = module.originalSource();
@@ -93,6 +102,7 @@ class JavascriptGenerator extends Generator {
}
const source = new ReplaceSource(originalSource);
/** @type {InitFragment<GenerateContext>[]} */
const initFragments = [];
this.sourceModule(module, initFragments, source, generateContext);
@@ -102,7 +112,7 @@ class JavascriptGenerator extends Generator {
/**
* @param {Module} module the module to generate
* @param {InitFragment[]} initFragments mutable list of init fragments
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
* @param {ReplaceSource} source the current replace source which can be modified
* @param {GenerateContext} generateContext the generateContext
* @returns {void}
@@ -144,7 +154,7 @@ class JavascriptGenerator extends Generator {
/**
* @param {Module} module the module to generate
* @param {DependenciesBlock} block the dependencies block which will be processed
* @param {InitFragment[]} initFragments mutable list of init fragments
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
* @param {ReplaceSource} source the current replace source which can be modified
* @param {GenerateContext} generateContext the generateContext
* @returns {void}
@@ -174,24 +184,26 @@ class JavascriptGenerator extends Generator {
/**
* @param {Module} module the current module
* @param {Dependency} dependency the dependency to generate
* @param {InitFragment[]} initFragments mutable list of init fragments
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
* @param {ReplaceSource} source the current replace source which can be modified
* @param {GenerateContext} generateContext the render context
* @returns {void}
*/
sourceDependency(module, dependency, initFragments, source, generateContext) {
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
dependency.constructor
);
const constructor =
/** @type {new (...args: EXPECTED_ANY[]) => Dependency} */
(dependency.constructor);
const template = generateContext.dependencyTemplates.get(constructor);
if (!template) {
throw new Error(
"No template for dependency: " + dependency.constructor.name
`No template for dependency: ${dependency.constructor.name}`
);
}
/** @type {InitFragment<GenerateContext>[] | undefined} */
let chunkInitFragments;
/** @type {DependencyTemplateContext} */
const templateContext = {
runtimeTemplate: generateContext.runtimeTemplate,
dependencyTemplates: generateContext.dependencyTemplates,
@@ -201,11 +213,15 @@ class JavascriptGenerator extends Generator {
runtime: generateContext.runtime,
runtimeRequirements: generateContext.runtimeRequirements,
concatenationScope: generateContext.concatenationScope,
codeGenerationResults: generateContext.codeGenerationResults,
codeGenerationResults:
/** @type {NonNullable<GenerateContext["codeGenerationResults"]>} */
(generateContext.codeGenerationResults),
initFragments,
get chunkInitFragments() {
if (!chunkInitFragments) {
const data = generateContext.getData();
const data =
/** @type {NonNullable<GenerateContext["getData"]>} */
(generateContext.getData)();
chunkInitFragments = data.get("chunkInitFragments");
if (!chunkInitFragments) {
chunkInitFragments = [];

View File

@@ -31,25 +31,42 @@ const Template = require("../Template");
const { last, someInIterable } = require("../util/IterableHelpers");
const StringXor = require("../util/StringXor");
const { compareModulesByIdentifier } = require("../util/comparators");
const {
getPathInAst,
getAllReferences,
RESERVED_NAMES,
findNewName,
addScopeSymbols,
getUsedNamesInScopeInfo
} = require("../util/concatenate");
const createHash = require("../util/createHash");
const { getPathInAst, getAllReferences } = require("../util/mergeScope");
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
const { intersectRuntime } = require("../util/runtime");
const JavascriptGenerator = require("./JavascriptGenerator");
const JavascriptParser = require("./JavascriptParser");
/** @typedef {import("eslint-scope").Reference} Reference */
/** @typedef {import("eslint-scope").Scope} Scope */
/** @typedef {import("eslint-scope").Variable} Variable */
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
/** @typedef {import("../Compilation").ModuleObject} ModuleObject */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
/** @typedef {import("../Entrypoint")} Entrypoint */
/** @typedef {import("../Module")} Module */
/** @typedef {import("../Module").BuildInfo} BuildInfo */
/** @typedef {import("../ModuleGraph")} ModuleGraph */
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
/** @typedef {import("../WebpackError")} WebpackError */
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
/** @typedef {import("../util/Hash")} Hash */
/** @typedef {import("../util/createHash").Algorithm} Algorithm */
/**
* @param {Chunk} chunk a chunk
@@ -59,9 +76,28 @@ const JavascriptParser = require("./JavascriptParser");
const chunkHasJs = (chunk, chunkGraph) => {
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true;
return chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
? true
: false;
return Boolean(
chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
);
};
/**
* @param {Chunk} chunk a chunk
* @param {ChunkGraph} chunkGraph the chunk graph
* @returns {boolean} true, when a JS file is needed for this chunk
*/
const chunkHasRuntimeOrJs = (chunk, chunkGraph) => {
if (
chunkGraph.getChunkModulesIterableBySourceType(
chunk,
WEBPACK_MODULE_TYPE_RUNTIME
)
)
return true;
return Boolean(
chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript")
);
};
/**
@@ -96,7 +132,7 @@ const printGeneratedCodeForStack = (module, code) => {
* @property {ModuleGraph} moduleGraph the module graph
* @property {ChunkGraph} chunkGraph the chunk graph
* @property {CodeGenerationResults} codeGenerationResults results of code generation
* @property {boolean} strictMode rendering in strict context
* @property {boolean | undefined} strictMode rendering in strict context
*/
/**
@@ -108,7 +144,7 @@ const printGeneratedCodeForStack = (module, code) => {
* @property {ChunkGraph} chunkGraph the chunk graph
* @property {CodeGenerationResults} codeGenerationResults results of code generation
* @property {string} hash hash to be used for render call
* @property {boolean} strictMode rendering in strict context
* @property {boolean | undefined} strictMode rendering in strict context
*/
/**
@@ -120,7 +156,7 @@ const printGeneratedCodeForStack = (module, code) => {
* @property {ChunkGraph} chunkGraph the chunk graph
* @property {CodeGenerationResults} codeGenerationResults results of code generation
* @property {InitFragment<ChunkRenderContext>[]} chunkInitFragments init fragments for the chunk
* @property {boolean} strictMode rendering in strict context
* @property {boolean | undefined} strictMode rendering in strict context
*/
/**
@@ -146,11 +182,11 @@ const printGeneratedCodeForStack = (module, code) => {
* @property {SyncWaterfallHook<[Source, RenderContext]>} render
* @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
* @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
* @property {SyncBailHook<[Module, RenderBootstrapContext], string>} inlineInRuntimeBailout
* @property {SyncBailHook<[Module, RenderBootstrapContext], string | void>} inlineInRuntimeBailout
* @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
* @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
* @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
* @property {SyncBailHook<[Chunk, RenderContext], boolean>} useSourceMap
* @property {SyncBailHook<[Chunk, RenderContext], boolean | void>} useSourceMap
*/
/** @type {WeakMap<Compilation, CompilationHooks>} */
@@ -158,6 +194,8 @@ const compilationHooksMap = new WeakMap();
const PLUGIN_NAME = "JavascriptModulesPlugin";
/** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */
class JavascriptModulesPlugin {
/**
* @param {Compilation} compilation the compilation
@@ -226,34 +264,22 @@ class JavascriptModulesPlugin {
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
normalModuleFactory.hooks.createParser
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
.tap(PLUGIN_NAME, options => {
return new JavascriptParser("auto");
});
.tap(PLUGIN_NAME, options => new JavascriptParser("auto"));
normalModuleFactory.hooks.createParser
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
.tap(PLUGIN_NAME, options => {
return new JavascriptParser("script");
});
.tap(PLUGIN_NAME, options => new JavascriptParser("script"));
normalModuleFactory.hooks.createParser
.for(JAVASCRIPT_MODULE_TYPE_ESM)
.tap(PLUGIN_NAME, options => {
return new JavascriptParser("module");
});
.tap(PLUGIN_NAME, options => new JavascriptParser("module"));
normalModuleFactory.hooks.createGenerator
.for(JAVASCRIPT_MODULE_TYPE_AUTO)
.tap(PLUGIN_NAME, () => {
return new JavascriptGenerator();
});
.tap(PLUGIN_NAME, () => new JavascriptGenerator());
normalModuleFactory.hooks.createGenerator
.for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
.tap(PLUGIN_NAME, () => {
return new JavascriptGenerator();
});
.tap(PLUGIN_NAME, () => new JavascriptGenerator());
normalModuleFactory.hooks.createGenerator
.for(JAVASCRIPT_MODULE_TYPE_ESM)
.tap(PLUGIN_NAME, () => {
return new JavascriptGenerator();
});
.tap(PLUGIN_NAME, () => new JavascriptGenerator());
compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
const {
hash,
@@ -267,13 +293,14 @@ class JavascriptModulesPlugin {
} = options;
const hotUpdateChunk = chunk instanceof HotUpdateChunk ? chunk : null;
let render;
const filenameTemplate =
JavascriptModulesPlugin.getChunkFilenameTemplate(
chunk,
outputOptions
);
let render;
if (hotUpdateChunk) {
render = () =>
this.renderChunk(
@@ -289,6 +316,10 @@ class JavascriptModulesPlugin {
hooks
);
} else if (chunk.hasRuntime()) {
if (!chunkHasRuntimeOrJs(chunk, chunkGraph)) {
return result;
}
render = () =>
this.renderMain(
{
@@ -374,7 +405,7 @@ class JavascriptModulesPlugin {
hashFunction
}
} = compilation;
const hash = createHash(hashFunction);
const hash = createHash(/** @type {Algorithm} */ (hashFunction));
if (hashSalt) hash.update(hashSalt);
if (chunk.hasRuntime()) {
this.updateHashWithBootstrap(
@@ -424,7 +455,8 @@ class JavascriptModulesPlugin {
const digest = /** @type {string} */ (hash.digest(hashDigest));
chunk.contentHash.javascript = nonNumericOnlyHash(
digest,
hashDigestLength
/** @type {number} */
(hashDigestLength)
);
});
compilation.hooks.additionalTreeRuntimeRequirements.tap(
@@ -443,7 +475,7 @@ class JavascriptModulesPlugin {
compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
const source = options.codeGenerationResult.sources.get("javascript");
if (source === undefined) return;
const { module, moduleObject } = options;
const { module } = options;
const code = source.source();
const fn = vm.runInThisContext(
@@ -453,6 +485,11 @@ class JavascriptModulesPlugin {
lineOffset: -1
}
);
const moduleObject =
/** @type {ModuleObject} */
(options.moduleObject);
try {
fn.call(
moduleObject.exports,
@@ -460,12 +497,13 @@ class JavascriptModulesPlugin {
moduleObject.exports,
context.__webpack_require__
);
} catch (e) {
e.stack += printGeneratedCodeForStack(
} catch (err) {
/** @type {Error} */
(err).stack += printGeneratedCodeForStack(
options.module,
/** @type {string} */ (code)
);
throw e;
throw err;
}
});
compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => {
@@ -482,26 +520,32 @@ class JavascriptModulesPlugin {
}
);
try {
// eslint-disable-next-line no-useless-call
fn.call(null, context.__webpack_require__);
} catch (e) {
e.stack += printGeneratedCodeForStack(options.module, code);
throw e;
} catch (err) {
/** @type {Error} */
(err).stack += printGeneratedCodeForStack(options.module, code);
throw err;
}
});
}
);
}
/**
* @param {Chunk} chunk chunk
* @param {OutputOptions} outputOptions output options
* @returns {TemplatePath} used filename template
*/
static getChunkFilenameTemplate(chunk, outputOptions) {
if (chunk.filenameTemplate) {
return chunk.filenameTemplate;
} else if (chunk instanceof HotUpdateChunk) {
return outputOptions.hotUpdateChunkFilename;
return /** @type {TemplatePath} */ (outputOptions.hotUpdateChunkFilename);
} else if (chunk.canBeInitial()) {
return outputOptions.filename;
} else {
return outputOptions.chunkFilename;
return /** @type {TemplatePath} */ (outputOptions.filename);
}
return /** @type {TemplatePath} */ (outputOptions.chunkFilename);
}
/**
@@ -509,7 +553,7 @@ class JavascriptModulesPlugin {
* @param {ChunkRenderContext} renderContext options object
* @param {CompilationHooks} hooks hooks
* @param {boolean} factory true: renders as factory method, false: pure module content
* @returns {Source} the newly generated source from rendering
* @returns {Source | null} the newly generated source from rendering
*/
renderModule(module, renderContext, hooks, factory) {
const {
@@ -549,7 +593,9 @@ class JavascriptModulesPlugin {
const needThisAsExports = runtimeRequirements.has(
RuntimeGlobals.thisAsExports
);
const needStrict = module.buildInfo.strict && !strictMode;
const needStrict =
/** @type {BuildInfo} */
(module.buildInfo).strict && !strictMode;
const cacheEntry = this._moduleFactoryCache.get(
moduleSourcePostContent
);
@@ -570,19 +616,19 @@ class JavascriptModulesPlugin {
args.push(
needModule
? module.moduleArgument
: "__unused_webpack_" + module.moduleArgument
: `__unused_webpack_${module.moduleArgument}`
);
if (needExports || needRequire)
args.push(
needExports
? module.exportsArgument
: "__unused_webpack_" + module.exportsArgument
: `__unused_webpack_${module.exportsArgument}`
);
if (needRequire) args.push(RuntimeGlobals.require);
if (!needThisAsExports && runtimeTemplate.supportsArrowFunction()) {
factorySource.add("/***/ ((" + args.join(", ") + ") => {\n\n");
factorySource.add(`/***/ ((${args.join(", ")}) => {\n\n`);
} else {
factorySource.add("/***/ (function(" + args.join(", ") + ") {\n\n");
factorySource.add(`/***/ (function(${args.join(", ")}) {\n\n`);
}
if (needStrict) {
factorySource.add('"use strict";\n');
@@ -615,9 +661,10 @@ class JavascriptModulesPlugin {
),
"JavascriptModulesPlugin.getCompilationHooks().renderModulePackage"
);
} catch (e) {
e.module = module;
throw e;
} catch (err) {
/** @type {WebpackError} */
(err).module = module;
throw err;
}
}
@@ -636,7 +683,10 @@ class JavascriptModulesPlugin {
const allModules = modules ? Array.from(modules) : [];
let strictHeader;
let allStrict = renderContext.strictMode;
if (!allStrict && allModules.every(m => m.buildInfo.strict)) {
if (
!allStrict &&
allModules.every(m => /** @type {BuildInfo} */ (m.buildInfo).strict)
) {
const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
strictHeader = strictBailout
? `// runtime can't be in strict mode because ${strictBailout}.\n`
@@ -718,7 +768,7 @@ class JavascriptModulesPlugin {
inlinedModules = new Set(chunkGraph.getChunkEntryModulesIterable(chunk));
}
let source = new ConcatSource();
const source = new ConcatSource();
let prefix;
if (iife) {
if (runtimeTemplate.supportsArrowFunction()) {
@@ -731,16 +781,20 @@ class JavascriptModulesPlugin {
prefix = "/******/ ";
}
let allStrict = renderContext.strictMode;
if (!allStrict && allModules.every(m => m.buildInfo.strict)) {
if (
!allStrict &&
allModules.every(m => /** @type {BuildInfo} */ (m.buildInfo).strict)
) {
const strictBailout = hooks.strictRuntimeBailout.call(renderContext);
if (strictBailout) {
source.add(
prefix +
`// runtime can't be in strict mode because ${strictBailout}.\n`
`${
prefix
}// runtime can't be in strict mode because ${strictBailout}.\n`
);
} else {
allStrict = true;
source.add(prefix + '"use strict";\n');
source.add(`${prefix}"use strict";\n`);
}
}
@@ -767,7 +821,7 @@ class JavascriptModulesPlugin {
runtimeRequirements.has(RuntimeGlobals.moduleFactoriesAddOnly) ||
runtimeRequirements.has(RuntimeGlobals.require)
) {
source.add(prefix + "var __webpack_modules__ = (");
source.add(`${prefix}var __webpack_modules__ = (`);
source.add(chunkModules || "{}");
source.add(");\n");
source.add(
@@ -776,7 +830,7 @@ class JavascriptModulesPlugin {
}
if (bootstrap.header.length > 0) {
const header = Template.asString(bootstrap.header) + "\n";
const header = `${Template.asString(bootstrap.header)}\n`;
source.add(
new PrefixSource(
prefix,
@@ -810,7 +864,7 @@ class JavascriptModulesPlugin {
}
if (inlinedModules) {
if (bootstrap.beforeStartup.length > 0) {
const beforeStartup = Template.asString(bootstrap.beforeStartup) + "\n";
const beforeStartup = `${Template.asString(bootstrap.beforeStartup)}\n`;
source.add(
new PrefixSource(
prefix,
@@ -820,28 +874,36 @@ class JavascriptModulesPlugin {
)
);
}
const lastInlinedModule = last(inlinedModules);
const lastInlinedModule = /** @type {Module} */ (last(inlinedModules));
const startupSource = new ConcatSource();
if (runtimeRequirements.has(RuntimeGlobals.exports)) {
startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
}
const renamedInlinedModule = this.renameInlineModule(
allModules,
renderContext,
inlinedModules,
chunkRenderContext,
hooks
);
const avoidEntryIife = compilation.options.optimization.avoidEntryIife;
/** @type {Map<Module, Source> | false} */
let renamedInlinedModule = false;
if (avoidEntryIife) {
renamedInlinedModule = this.getRenamedInlineModule(
allModules,
renderContext,
inlinedModules,
chunkRenderContext,
hooks,
allStrict,
Boolean(chunkModules)
);
}
for (const m of inlinedModules) {
const renderedModule =
renamedInlinedModule.get(m) ||
this.renderModule(m, chunkRenderContext, hooks, false);
const renderedModule = renamedInlinedModule
? renamedInlinedModule.get(m)
: this.renderModule(m, chunkRenderContext, hooks, false);
if (renderedModule) {
const innerStrict = !allStrict && m.buildInfo.strict;
const innerStrict =
!allStrict && /** @type {BuildInfo} */ (m.buildInfo).strict;
const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
m,
chunk.runtime
@@ -849,19 +911,21 @@ class JavascriptModulesPlugin {
const exports = runtimeRequirements.has(RuntimeGlobals.exports);
const webpackExports =
exports && m.exportsArgument === RuntimeGlobals.exports;
let iife = innerStrict
? "it need to be in strict mode."
const iife = innerStrict
? "it needs to be in strict mode."
: inlinedModules.size > 1
? // TODO check globals and top-level declarations of other entries and chunk modules
// to make a better decision
"it need to be isolated against other entry modules."
: exports && !webpackExports
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
: hooks.embedInRuntimeBailout.call(m, renderContext);
"it needs to be isolated against other entry modules."
: chunkModules && !renamedInlinedModule
? "it needs to be isolated against other modules in the chunk."
: exports && !webpackExports
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
: hooks.embedInRuntimeBailout.call(m, renderContext);
let footer;
if (iife !== undefined) {
startupSource.add(
`// This entry need to be wrapped in an IIFE because ${iife}\n`
`// This entry needs to be wrapped in an IIFE because ${iife}\n`
);
const arrow = runtimeTemplate.supportsArrowFunction();
if (arrow) {
@@ -899,7 +963,7 @@ class JavascriptModulesPlugin {
})
);
if (bootstrap.afterStartup.length > 0) {
const afterStartup = Template.asString(bootstrap.afterStartup) + "\n";
const afterStartup = `${Template.asString(bootstrap.afterStartup)}\n`;
source.add(
new PrefixSource(
prefix,
@@ -910,9 +974,10 @@ class JavascriptModulesPlugin {
);
}
} else {
const lastEntryModule = last(
chunkGraph.getChunkEntryModulesIterable(chunk)
);
const lastEntryModule =
/** @type {Module} */
(last(chunkGraph.getChunkEntryModulesIterable(chunk)));
/** @type {function(string[], string): Source} */
const toSource = useSourceMap
? (content, name) =>
new OriginalSource(Template.asString(content), name)
@@ -992,7 +1057,8 @@ class JavascriptModulesPlugin {
*/
updateHashWithBootstrap(hash, renderContext, hooks) {
const bootstrap = this.renderBootstrap(renderContext, hooks);
for (const key of Object.keys(bootstrap)) {
for (const _k of Object.keys(bootstrap)) {
const key = /** @type {keyof Bootstrap} */ (_k);
hash.update(key);
if (Array.isArray(bootstrap[key])) {
for (const line of bootstrap[key]) {
@@ -1007,7 +1073,7 @@ class JavascriptModulesPlugin {
/**
* @param {RenderBootstrapContext} renderContext options object
* @param {CompilationHooks} hooks hooks
* @returns {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} the generated source of the bootstrap code
* @returns {Bootstrap} the generated source of the bootstrap code
*/
renderBootstrap(renderContext, hooks) {
const {
@@ -1047,7 +1113,7 @@ class JavascriptModulesPlugin {
allowInlineStartup: true
};
let { header: buf, startup, beforeStartup, afterStartup } = result;
const { header: buf, startup, beforeStartup, afterStartup } = result;
if (result.allowInlineStartup && moduleFactories) {
startup.push(
@@ -1117,7 +1183,13 @@ class JavascriptModulesPlugin {
entryModule,
entrypoint
] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) {
const chunks = entrypoint.chunks.filter(c => c !== chunk);
if (!chunkGraph.getModuleSourceTypes(entryModule).has("javascript")) {
i--;
continue;
}
const chunks =
/** @type {Entrypoint} */
(entrypoint).chunks.filter(c => c !== chunk);
if (result.allowInlineStartup && chunks.length > 0) {
buf2.push(
"// This entry module depends on other loaded chunks and execution need to be delayed"
@@ -1403,23 +1475,43 @@ class JavascriptModulesPlugin {
* @param {Set<Module>} inlinedModules inlinedModules
* @param {ChunkRenderContext} chunkRenderContext chunkRenderContext
* @param {CompilationHooks} hooks hooks
* @returns {Map<Module, Source>} renamed inlined modules
* @param {boolean | undefined} allStrict allStrict
* @param {boolean} hasChunkModules hasChunkModules
* @returns {Map<Module, Source> | false} renamed inlined modules
*/
renameInlineModule(
getRenamedInlineModule(
allModules,
renderContext,
inlinedModules,
chunkRenderContext,
hooks
hooks,
allStrict,
hasChunkModules
) {
const innerStrict =
!allStrict &&
allModules.every(m => /** @type {BuildInfo} */ (m.buildInfo).strict);
const isMultipleEntries = inlinedModules.size > 1;
const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
// TODO:
// This step is before the IIFE reason calculation. Ideally, it should only be executed when this function can optimize the
// IIFE reason. Otherwise, it should directly return false. There are four reasons now, we have skipped two already, the left
// one is 'it uses a non-standard name for the exports'.
if (isMultipleEntries || innerStrict || !singleEntryWithModules) {
return false;
}
/** @type {Map<Module, Source>} */
const renamedInlinedModules = new Map();
const { runtimeTemplate } = renderContext;
/** @type {Map<Module, { source: Source, ast: any, variables: Set<Variable>, usedInNonInlined: Set<Variable>}>} */
/** @typedef {{ source: Source, module: Module, ast: any, variables: Set<Variable>, through: Set<Reference>, usedInNonInlined: Set<Variable>, moduleScope: Scope }} Info */
/** @type {Map<Module, Info>} */
const inlinedModulesToInfo = new Map();
/** @type {Set<string>} */
const nonInlinedModuleThroughIdentifiers = new Set();
/** @type {Map<Module, Source>} */
const renamedInlinedModules = new Map();
for (const m of allModules) {
const isInlinedModule = inlinedModules && inlinedModules.has(m);
@@ -1427,7 +1519,7 @@ class JavascriptModulesPlugin {
m,
chunkRenderContext,
hooks,
isInlinedModule ? false : true
!isInlinedModule
);
if (!moduleSource) continue;
@@ -1443,14 +1535,17 @@ class JavascriptModulesPlugin {
ignoreEval: true
});
const globalScope = scopeManager.acquire(ast);
const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
if (inlinedModules && inlinedModules.has(m)) {
const moduleScope = globalScope.childScopes[0];
inlinedModulesToInfo.set(m, {
source: moduleSource,
ast,
module: m,
variables: new Set(moduleScope.variables),
usedInNonInlined: new Set()
through: new Set(moduleScope.through),
usedInNonInlined: new Set(),
moduleScope
});
} else {
for (const ref of globalScope.through) {
@@ -1461,7 +1556,10 @@ class JavascriptModulesPlugin {
for (const [, { variables, usedInNonInlined }] of inlinedModulesToInfo) {
for (const variable of variables) {
if (nonInlinedModuleThroughIdentifiers.has(variable.name)) {
if (
nonInlinedModuleThroughIdentifiers.has(variable.name) ||
RESERVED_NAMES.has(variable.name)
) {
usedInNonInlined.add(variable);
}
}
@@ -1475,36 +1573,70 @@ class JavascriptModulesPlugin {
continue;
}
const usedNames = new Set(
Array.from(inlinedModulesToInfo.get(m).variables).map(v => v.name)
const info = /** @type {Info} */ (inlinedModulesToInfo.get(m));
const allUsedNames = new Set(
Array.from(info.through, v => v.identifier.name)
);
for (const variable of usedInNonInlined) {
allUsedNames.add(variable.name);
}
for (const variable of info.variables) {
allUsedNames.add(variable.name);
const references = getAllReferences(variable);
const allIdentifiers = new Set(
references.map(r => r.identifier).concat(variable.identifiers)
);
const newName = this.findNewName(
variable.name,
usedNames,
m.readableIdentifier(runtimeTemplate.requestShortener)
const usedNamesInScopeInfo = new Map();
const ignoredScopes = new Set();
const name = variable.name;
const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
usedNamesInScopeInfo,
info.module.identifier(),
name
);
usedNames.add(newName);
for (const identifier of allIdentifiers) {
const r = identifier.range;
const path = getPathInAst(ast, identifier);
if (path && path.length > 1) {
const maybeProperty =
path[1].type === "AssignmentPattern" && path[1].left === path[0]
? path[2]
: path[1];
if (maybeProperty.type === "Property" && maybeProperty.shorthand) {
source.insert(r[1], `: ${newName}`);
continue;
}
if (allUsedNames.has(name) || usedNames.has(name)) {
const references = getAllReferences(variable);
for (const ref of references) {
addScopeSymbols(
ref.from,
usedNames,
alreadyCheckedScopes,
ignoredScopes
);
}
source.replace(r[0], r[1] - 1, newName);
const newName = findNewName(
variable.name,
allUsedNames,
usedNames,
m.readableIdentifier(runtimeTemplate.requestShortener)
);
allUsedNames.add(newName);
for (const identifier of allIdentifiers) {
const r = /** @type {Range} */ (identifier.range);
const path = getPathInAst(ast, identifier);
if (path && path.length > 1) {
const maybeProperty =
path[1].type === "AssignmentPattern" && path[1].left === path[0]
? path[2]
: path[1];
if (
maybeProperty.type === "Property" &&
maybeProperty.shorthand
) {
source.insert(r[1], `: ${newName}`);
continue;
}
}
source.replace(r[0], r[1] - 1, newName);
}
} else {
allUsedNames.add(name);
}
}
@@ -1513,38 +1645,6 @@ class JavascriptModulesPlugin {
return renamedInlinedModules;
}
/**
* @param {string} oldName oldName
* @param {Set<string>} usedName usedName
* @param {string} extraInfo extraInfo
* @returns {string} extraInfo
*/
findNewName(oldName, usedName, extraInfo) {
let name = oldName;
// Remove uncool stuff
extraInfo = extraInfo.replace(
/\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
""
);
const splittedInfo = extraInfo.split("/");
while (splittedInfo.length) {
name = splittedInfo.pop() + (name ? "_" + name : "");
const nameIdent = Template.toIdentifier(name);
if (!usedName.has(nameIdent)) {
return nameIdent;
}
}
let i = 0;
let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
while (usedName.has(nameWithNumber)) {
i++;
nameWithNumber = Template.toIdentifier(`${name}_${i}`);
}
return nameWithNumber;
}
}
module.exports = JavascriptModulesPlugin;

File diff suppressed because it is too large Load Diff

View File

@@ -21,8 +21,8 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
* @param {(string[] | null)=} runtimeRequirements runtime requirements
* @returns {function(Expression): true} plugin function
*/
exports.toConstantDependency = (parser, value, runtimeRequirements) => {
return function constDependency(expr) {
module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
function constDependency(expr) {
const dep = new ConstDependency(
value,
/** @type {Range} */ (expr.range),
@@ -32,43 +32,39 @@ exports.toConstantDependency = (parser, value, runtimeRequirements) => {
parser.state.module.addPresentationalDependency(dep);
return true;
};
};
/**
* @param {string} value the string value
* @returns {function(Expression): BasicEvaluatedExpression} plugin function
*/
exports.evaluateToString = value => {
return function stringExpression(expr) {
module.exports.evaluateToString = value =>
function stringExpression(expr) {
return new BasicEvaluatedExpression()
.setString(value)
.setRange(/** @type {Range} */ (expr.range));
};
};
/**
* @param {number} value the number value
* @returns {function(Expression): BasicEvaluatedExpression} plugin function
*/
exports.evaluateToNumber = value => {
return function stringExpression(expr) {
module.exports.evaluateToNumber = value =>
function stringExpression(expr) {
return new BasicEvaluatedExpression()
.setNumber(value)
.setRange(/** @type {Range} */ (expr.range));
};
};
/**
* @param {boolean} value the boolean value
* @returns {function(Expression): BasicEvaluatedExpression} plugin function
*/
exports.evaluateToBoolean = value => {
return function booleanExpression(expr) {
module.exports.evaluateToBoolean = value =>
function booleanExpression(expr) {
return new BasicEvaluatedExpression()
.setBoolean(value)
.setRange(/** @type {Range} */ (expr.range));
};
};
/**
* @param {string} identifier identifier
@@ -77,9 +73,14 @@ exports.evaluateToBoolean = value => {
* @param {boolean|null=} truthy is truthy, null if nullish
* @returns {function(Expression): BasicEvaluatedExpression} callback
*/
exports.evaluateToIdentifier = (identifier, rootInfo, getMembers, truthy) => {
return function identifierExpression(expr) {
let evaluatedExpression = new BasicEvaluatedExpression()
module.exports.evaluateToIdentifier = (
identifier,
rootInfo,
getMembers,
truthy
) =>
function identifierExpression(expr) {
const evaluatedExpression = new BasicEvaluatedExpression()
.setIdentifier(identifier, rootInfo, getMembers)
.setSideEffects(false)
.setRange(/** @type {Range} */ (expr.range));
@@ -97,15 +98,14 @@ exports.evaluateToIdentifier = (identifier, rootInfo, getMembers, truthy) => {
return evaluatedExpression;
};
};
/**
* @param {JavascriptParser} parser the parser
* @param {string} message the message
* @returns {function(Expression): boolean | undefined} callback to handle unsupported expression
*/
exports.expressionIsUnsupported = (parser, message) => {
return function unsupportedExpression(expr) {
module.exports.expressionIsUnsupported = (parser, message) =>
function unsupportedExpression(expr) {
const dep = new ConstDependency(
"(void 0)",
/** @type {Range} */ (expr.range),
@@ -122,8 +122,7 @@ exports.expressionIsUnsupported = (parser, message) => {
);
return true;
};
};
exports.skipTraversal = () => true;
module.exports.skipTraversal = () => true;
exports.approve = () => true;
module.exports.approve = () => true;

View File

@@ -15,6 +15,7 @@ const { getAllChunks } = require("./ChunkHelpers");
/** @typedef {import("../Chunk").ChunkId} ChunkId */
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
/** @typedef {import("../Entrypoint")} Entrypoint */
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
/** @typedef {import("../ChunkGroup")} ChunkGroup */
@@ -23,6 +24,9 @@ const { getAllChunks } = require("./ChunkHelpers");
const EXPORT_PREFIX = `var ${RuntimeGlobals.exports} = `;
/** @typedef {Set<Chunk>} Chunks */
/** @typedef {ModuleId[]} ModuleIds */
/**
* @param {ChunkGraph} chunkGraph chunkGraph
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
@@ -31,7 +35,7 @@ const EXPORT_PREFIX = `var ${RuntimeGlobals.exports} = `;
* @param {boolean} passive true: passive startup with on chunks loaded
* @returns {string} runtime code
*/
exports.generateEntryStartup = (
module.exports.generateEntryStartup = (
chunkGraph,
runtimeTemplate,
entries,
@@ -46,9 +50,16 @@ exports.generateEntryStartup = (
)}`
];
const runModule = id => {
return `__webpack_exec__(${JSON.stringify(id)})`;
};
/**
* @param {ModuleId} id id
* @returns {string} fn to execute
*/
const runModule = id => `__webpack_exec__(${JSON.stringify(id)})`;
/**
* @param {Chunks} chunks chunks
* @param {ModuleIds} moduleIds module ids
* @param {boolean=} final true when final, otherwise false
*/
const outputCombination = (chunks, moduleIds, final) => {
if (chunks.size === 0) {
runtime.push(
@@ -71,16 +82,19 @@ exports.generateEntryStartup = (
}
};
let currentChunks = undefined;
let currentModuleIds = undefined;
/** @type {Chunks | undefined} */
let currentChunks;
/** @type {ModuleIds | undefined} */
let currentModuleIds;
for (const [module, entrypoint] of entries) {
const runtimeChunk =
/** @type {Entrypoint} */
(entrypoint).getRuntimeChunk();
const moduleId = chunkGraph.getModuleId(module);
const moduleId = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
const chunks = getAllChunks(
/** @type {Entrypoint} */ (entrypoint),
/** @type {Entrypoint} */
(entrypoint),
chunk,
runtimeChunk
);
@@ -89,10 +103,14 @@ exports.generateEntryStartup = (
currentChunks.size === chunks.size &&
isSubset(currentChunks, chunks)
) {
currentModuleIds.push(moduleId);
/** @type {ModuleIds} */
(currentModuleIds).push(moduleId);
} else {
if (currentChunks) {
outputCombination(currentChunks, currentModuleIds);
outputCombination(
currentChunks,
/** @type {ModuleIds} */ (currentModuleIds)
);
}
currentChunks = chunks;
currentModuleIds = [moduleId];
@@ -101,7 +119,12 @@ exports.generateEntryStartup = (
// output current modules with export prefix
if (currentChunks) {
outputCombination(currentChunks, currentModuleIds, true);
outputCombination(
currentChunks,
/** @type {ModuleIds} */
(currentModuleIds),
true
);
}
runtime.push("");
return Template.asString(runtime);
@@ -114,7 +137,12 @@ exports.generateEntryStartup = (
* @param {Chunk} chunk chunk
* @returns {void}
*/
exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
module.exports.updateHashForEntryStartup = (
hash,
chunkGraph,
entries,
chunk
) => {
for (const [module, entrypoint] of entries) {
const runtimeChunk =
/** @type {Entrypoint} */
@@ -137,7 +165,7 @@ exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
* @param {function(Chunk, ChunkGraph): boolean} filterFn filter function
* @returns {Set<number | string>} initially fulfilled chunk ids
*/
exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
module.exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
const initialChunkIds = new Set(chunk.ids);
for (const c of chunk.getAllInitialChunks()) {
if (c === chunk || filterFn(c, chunkGraph)) continue;