| | |
| | | const { tryRunOrWebpackError } = require("../HookWebpackError"); |
| | | const HotUpdateChunk = require("../HotUpdateChunk"); |
| | | const InitFragment = require("../InitFragment"); |
| | | const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants"); |
| | | const { |
| | | JAVASCRIPT_MODULE_TYPE_AUTO, |
| | | JAVASCRIPT_MODULE_TYPE_DYNAMIC, |
| | |
| | | const Template = require("../Template"); |
| | | const { last, someInIterable } = require("../util/IterableHelpers"); |
| | | const StringXor = require("../util/StringXor"); |
| | | const { compareModulesByIdOrIdentifier } = require("../util/comparators"); |
| | | const { compareModulesByFullName } = require("../util/comparators"); |
| | | const { |
| | | RESERVED_NAMES, |
| | | addScopeSymbols, |
| | |
| | | /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */ |
| | | /** @typedef {import("../Chunk")} Chunk */ |
| | | /** @typedef {import("../ChunkGraph")} ChunkGraph */ |
| | | /** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */ |
| | | /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */ |
| | | /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */ |
| | | /** @typedef {import("../Compilation").ExecuteModuleObject} ExecuteModuleObject */ |
| | | /** @typedef {import("../Compilation").WebpackRequire} WebpackRequire */ |
| | | /** @typedef {import("../Compiler")} Compiler */ |
| | | /** @typedef {import("../DependencyTemplates")} DependencyTemplates */ |
| | | /** @typedef {import("../Entrypoint")} Entrypoint */ |
| | | /** @typedef {import("../Module")} Module */ |
| | | /** @typedef {import("../Module").BuildInfo} BuildInfo */ |
| | | /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */ |
| | | /** @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/concatenate").ScopeSet} ScopeSet */ |
| | | /** @typedef {import("../util/concatenate").UsedNamesInScopeInfo} UsedNamesInScopeInfo */ |
| | | |
| | | /** @type {WeakMap<ChunkGraph, WeakMap<Chunk, boolean>>} */ |
| | | const chunkHasJsCache = new WeakMap(); |
| | | |
| | | /** |
| | | * Returns true, when a JS file is needed for this chunk. |
| | | * @param {Chunk} chunk a chunk |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @returns {boolean} true, when a JS file is needed for this chunk |
| | | */ |
| | | const _chunkHasJs = (chunk, chunkGraph) => { |
| | | if (chunkGraph.getNumberOfEntryModules(chunk) > 0) { |
| | | for (const module of chunkGraph.getChunkEntryModulesIterable(chunk)) { |
| | | if (chunkGraph.getModuleSourceTypes(module).has(JAVASCRIPT_TYPE)) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return Boolean( |
| | | chunkGraph.getChunkModulesIterableBySourceType(chunk, JAVASCRIPT_TYPE) |
| | | ); |
| | | }; |
| | | |
| | | /** |
| | | * Returns true, when a JS file is needed for this chunk. |
| | | * @param {Chunk} chunk a chunk |
| | | * @param {ChunkGraph} chunkGraph the chunk graph |
| | | * @returns {boolean} true, when a JS file is needed for this chunk |
| | | */ |
| | | const chunkHasJs = (chunk, chunkGraph) => { |
| | | if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return true; |
| | | let innerCache = chunkHasJsCache.get(chunkGraph); |
| | | if (innerCache === undefined) { |
| | | innerCache = new WeakMap(); |
| | | chunkHasJsCache.set(chunkGraph, innerCache); |
| | | } |
| | | |
| | | return Boolean( |
| | | chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript") |
| | | ); |
| | | const cachedResult = innerCache.get(chunk); |
| | | if (cachedResult !== undefined) { |
| | | return cachedResult; |
| | | } |
| | | |
| | | const result = _chunkHasJs(chunk, chunkGraph); |
| | | innerCache.set(chunk, result); |
| | | return result; |
| | | }; |
| | | |
| | | /** |
| | | * Chunk has runtime or js. |
| | | * @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 (chunkHasJs(chunk, chunkGraph)) { |
| | | return true; |
| | | } |
| | | |
| | | if ( |
| | | chunkGraph.getChunkModulesIterableBySourceType( |
| | | chunk, |
| | | WEBPACK_MODULE_TYPE_RUNTIME |
| | | ) |
| | | ) { |
| | | return true; |
| | | for (const chunkGroup of chunk.groupsIterable) { |
| | | for (const c of chunkGroup.chunks) { |
| | | if (chunkHasJs(c, chunkGraph)) return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | return Boolean( |
| | | chunkGraph.getChunkModulesIterableBySourceType(chunk, "javascript") |
| | | ); |
| | | return false; |
| | | }; |
| | | |
| | | /** |
| | | * Print generated code for stack. |
| | | * @param {Module} module a module |
| | | * @param {string} code the code |
| | | * @returns {string} generated code for the stack |
| | |
| | | return `\n\nGenerated code for ${module.identifier()}\n${lines |
| | | .map( |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {string} line the line |
| | | * @param {number} i the index |
| | | * @param {string[]} _lines the lines |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Defines the render context type used by this module. |
| | | * @typedef {object} RenderContext |
| | | * @property {Chunk} chunk the chunk |
| | | * @property {DependencyTemplates} dependencyTemplates the dependency templates |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the main render context type used by this module. |
| | | * @typedef {object} MainRenderContext |
| | | * @property {Chunk} chunk the chunk |
| | | * @property {DependencyTemplates} dependencyTemplates the dependency templates |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the chunk render context type used by this module. |
| | | * @typedef {object} ChunkRenderContext |
| | | * @property {Chunk} chunk the chunk |
| | | * @property {DependencyTemplates} dependencyTemplates the dependency templates |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the render bootstrap context type used by this module. |
| | | * @typedef {object} RenderBootstrapContext |
| | | * @property {Chunk} chunk the chunk |
| | | * @property {CodeGenerationResults} codeGenerationResults results of code generation |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the startup render context type used by this module. |
| | | * @typedef {object} StartupRenderContext |
| | | * @property {Chunk} chunk the chunk |
| | | * @property {DependencyTemplates} dependencyTemplates the dependency templates |
| | |
| | | * @property {ChunkGraph} chunkGraph the chunk graph |
| | | * @property {CodeGenerationResults} codeGenerationResults results of code generation |
| | | * @property {boolean | undefined} strictMode rendering in strict context |
| | | * @property {boolean } inlined inlined |
| | | * @property {boolean=} inlined inlined |
| | | * @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE |
| | | * @property {boolean=} needExportsDeclaration whether the top-level exports declaration needs to be generated |
| | | */ |
| | | |
| | | /** |
| | | * Defines the module render context type used by this module. |
| | | * @typedef {object} ModuleRenderContext |
| | | * @property {Chunk} chunk the chunk |
| | | * @property {DependencyTemplates} dependencyTemplates the dependency templates |
| | |
| | | * @property {boolean | undefined} strictMode rendering in strict context |
| | | * @property {boolean} factory true: renders as factory method, false: pure module content |
| | | * @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE, existing only when `factory` is set to false |
| | | * @property {boolean=} renderInObject render module in object container |
| | | */ |
| | | |
| | | /** |
| | | * Defines the compilation hooks type used by this module. |
| | | * @typedef {object} CompilationHooks |
| | | * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContent |
| | | * @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContainer |
| | |
| | | |
| | | class JavascriptModulesPlugin { |
| | | /** |
| | | * Returns the attached hooks. |
| | | * @param {Compilation} compilation the compilation |
| | | * @returns {CompilationHooks} the attached hooks |
| | | */ |
| | |
| | | |
| | | constructor(options = {}) { |
| | | this.options = options; |
| | | /** @type {WeakMap<Source, { source: Source, needModule:boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined }>} */ |
| | | /** @type {WeakMap<Source, { source: Source, needModule: boolean, needExports: boolean, needRequire: boolean, needThisAsExports: boolean, needStrict: boolean | undefined, renderShorthand: boolean }>} */ |
| | | this._moduleFactoryCache = new WeakMap(); |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | outputOptions |
| | | ); |
| | | |
| | | /** @type {() => Source} */ |
| | | let render; |
| | | |
| | | if (hotUpdateChunk) { |
| | |
| | | }); |
| | | const modules = chunkGraph.getChunkModulesIterableBySourceType( |
| | | chunk, |
| | | "javascript" |
| | | JAVASCRIPT_TYPE |
| | | ); |
| | | if (modules) { |
| | | const xor = new StringXor(); |
| | |
| | | } |
| | | ); |
| | | compilation.hooks.executeModule.tap(PLUGIN_NAME, (options, context) => { |
| | | const source = options.codeGenerationResult.sources.get("javascript"); |
| | | const source = |
| | | options.codeGenerationResult.sources.get(JAVASCRIPT_TYPE); |
| | | if (source === undefined) return; |
| | | const { module } = options; |
| | | const code = source.source(); |
| | | |
| | | /** @type {(this: ExecuteModuleObject["exports"], exports: ExecuteModuleObject["exports"], moduleObject: ExecuteModuleObject, webpackRequire: WebpackRequire) => void} */ |
| | | const fn = vm.runInThisContext( |
| | | `(function(${module.moduleArgument}, ${module.exportsArgument}, ${RuntimeGlobals.require}) {\n${code}\n/**/})`, |
| | | { |
| | |
| | | moduleObject.exports, |
| | | moduleObject, |
| | | moduleObject.exports, |
| | | context.__webpack_require__ |
| | | /** @type {WebpackRequire} */ |
| | | (context.__webpack_require__) |
| | | ); |
| | | } catch (err) { |
| | | /** @type {Error} */ |
| | |
| | | let code = source.source(); |
| | | if (typeof code !== "string") code = code.toString(); |
| | | |
| | | /** @type {(this: null, webpackRequire: WebpackRequire) => void} */ |
| | | const fn = vm.runInThisContext( |
| | | `(function(${RuntimeGlobals.require}) {\n${code}\n/**/})`, |
| | | { |
| | |
| | | ); |
| | | try { |
| | | // eslint-disable-next-line no-useless-call |
| | | fn.call(null, context.__webpack_require__); |
| | | fn.call( |
| | | null, |
| | | /** @type {WebpackRequire} */ |
| | | (context.__webpack_require__) |
| | | ); |
| | | } catch (err) { |
| | | /** @type {Error} */ |
| | | (err).stack += printGeneratedCodeForStack(options.module, code); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets chunk filename template. |
| | | * @param {Chunk} chunk chunk |
| | | * @param {OutputOptions} outputOptions output options |
| | | * @returns {TemplatePath} used filename template |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders the newly generated source from rendering. |
| | | * @param {Module} module the rendered module |
| | | * @param {ModuleRenderContext} renderContext options object |
| | | * @param {CompilationHooks} hooks hooks |
| | |
| | | runtimeTemplate, |
| | | codeGenerationResults, |
| | | strictMode, |
| | | factory |
| | | factory, |
| | | renderInObject |
| | | } = renderContext; |
| | | try { |
| | | const codeGenResult = codeGenerationResults.get(module, chunk.runtime); |
| | | const moduleSource = codeGenResult.sources.get("javascript"); |
| | | const moduleSource = codeGenResult.sources.get(JAVASCRIPT_TYPE); |
| | | if (!moduleSource) return null; |
| | | if (codeGenResult.data !== undefined) { |
| | | const chunkInitFragments = codeGenResult.data.get("chunkInitFragments"); |
| | |
| | | hooks.renderModuleContent.call(moduleSource, module, renderContext), |
| | | "JavascriptModulesPlugin.getCompilationHooks().renderModuleContent" |
| | | ); |
| | | /** @type {Source} */ |
| | | let moduleSourcePostContainer; |
| | | if (factory) { |
| | | const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements( |
| | |
| | | const cacheEntry = this._moduleFactoryCache.get( |
| | | moduleSourcePostContent |
| | | ); |
| | | const renderShorthand = |
| | | renderInObject === true && runtimeTemplate.supportsMethodShorthand(); |
| | | /** @type {Source} */ |
| | | let source; |
| | | if ( |
| | | cacheEntry && |
| | |
| | | cacheEntry.needExports === needExports && |
| | | cacheEntry.needRequire === needRequire && |
| | | cacheEntry.needThisAsExports === needThisAsExports && |
| | | cacheEntry.needStrict === needStrict |
| | | cacheEntry.needStrict === needStrict && |
| | | cacheEntry.renderShorthand === renderShorthand |
| | | ) { |
| | | source = cacheEntry.source; |
| | | } else { |
| | | const factorySource = new ConcatSource(); |
| | | /** @type {string[]} */ |
| | | const args = []; |
| | | if (needExports || needRequire || needModule) { |
| | | args.push( |
| | |
| | | ); |
| | | } |
| | | if (needRequire) args.push(RuntimeGlobals.require); |
| | | if (!needThisAsExports && runtimeTemplate.supportsArrowFunction()) { |
| | | |
| | | if (renderShorthand) { |
| | | // we can optimize function to methodShorthand if render module factory in object |
| | | factorySource.add(`(${args.join(", ")}) {\n\n`); |
| | | } else if ( |
| | | !needThisAsExports && |
| | | runtimeTemplate.supportsArrowFunction() |
| | | ) { |
| | | factorySource.add(`/***/ ((${args.join(", ")}) => {\n\n`); |
| | | } else { |
| | | factorySource.add(`/***/ (function(${args.join(", ")}) {\n\n`); |
| | | } |
| | | |
| | | if (needStrict) { |
| | | factorySource.add('"use strict";\n'); |
| | | } |
| | | factorySource.add(moduleSourcePostContent); |
| | | factorySource.add("\n\n/***/ })"); |
| | | factorySource.add(`\n\n/***/ }${renderShorthand ? "" : ")"}`); |
| | | source = new CachedSource(factorySource); |
| | | this._moduleFactoryCache.set(moduleSourcePostContent, { |
| | | source, |
| | |
| | | needExports, |
| | | needRequire, |
| | | needThisAsExports, |
| | | needStrict |
| | | needStrict, |
| | | renderShorthand |
| | | }); |
| | | } |
| | | moduleSourcePostContainer = tryRunOrWebpackError( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders the rendered source. |
| | | * @param {RenderContext} renderContext the render context |
| | | * @param {CompilationHooks} hooks hooks |
| | | * @returns {Source} the rendered source |
| | | */ |
| | | renderChunk(renderContext, hooks) { |
| | | const { chunk, chunkGraph } = renderContext; |
| | | const { chunk, chunkGraph, runtimeTemplate } = renderContext; |
| | | const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType( |
| | | chunk, |
| | | "javascript", |
| | | compareModulesByIdOrIdentifier(chunkGraph) |
| | | JAVASCRIPT_TYPE, |
| | | compareModulesByFullName(runtimeTemplate.compilation.compiler) |
| | | ); |
| | | const allModules = modules ? [...modules] : []; |
| | | /** @type {undefined | string} */ |
| | | let strictHeader; |
| | | let allStrict = renderContext.strictMode; |
| | | if ( |
| | |
| | | strictMode: allStrict |
| | | }; |
| | | const moduleSources = |
| | | Template.renderChunkModules(chunkRenderContext, allModules, (module) => |
| | | this.renderModule( |
| | | module, |
| | | { ...chunkRenderContext, factory: true }, |
| | | hooks |
| | | ) |
| | | Template.renderChunkModules( |
| | | chunkRenderContext, |
| | | allModules, |
| | | (module, renderInObject) => |
| | | this.renderModule( |
| | | module, |
| | | { ...chunkRenderContext, factory: true, renderInObject }, |
| | | hooks |
| | | ) |
| | | ) || new RawSource("{}"); |
| | | let source = tryRunOrWebpackError( |
| | | () => hooks.renderChunk.call(moduleSources, chunkRenderContext), |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders the newly generated source from rendering. |
| | | * @param {MainRenderContext} renderContext options object |
| | | * @param {CompilationHooks} hooks hooks |
| | | * @param {Compilation} compilation the compilation |
| | |
| | | const allModules = [ |
| | | ...(chunkGraph.getOrderedChunkModulesIterableBySourceType( |
| | | chunk, |
| | | "javascript", |
| | | compareModulesByIdOrIdentifier(chunkGraph) |
| | | JAVASCRIPT_TYPE, |
| | | compareModulesByFullName(runtimeTemplate.compilation.compiler) |
| | | ) || []) |
| | | ]; |
| | | |
| | |
| | | } |
| | | |
| | | const source = new ConcatSource(); |
| | | /** @type {string} */ |
| | | let prefix; |
| | | if (iife) { |
| | | if (runtimeTemplate.supportsArrowFunction()) { |
| | |
| | | (m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m)) |
| | | ) |
| | | : allModules, |
| | | (module) => |
| | | (module, renderInObject) => |
| | | this.renderModule( |
| | | module, |
| | | { ...chunkRenderContext, factory: true }, |
| | | { ...chunkRenderContext, factory: true, renderInObject }, |
| | | hooks |
| | | ), |
| | | prefix |
| | |
| | | const lastInlinedModule = /** @type {Module} */ (last(inlinedModules)); |
| | | const startupSource = new ConcatSource(); |
| | | |
| | | if (runtimeRequirements.has(RuntimeGlobals.exports)) { |
| | | startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`); |
| | | } |
| | | |
| | | const avoidEntryIife = compilation.options.optimization.avoidEntryIife; |
| | | /** @type {Map<Module, Source> | false} */ |
| | | let renamedInlinedModule = false; |
| | |
| | | ); |
| | | |
| | | if (renderedModule) { |
| | | /** @type {string} */ |
| | | let footer; |
| | | if (iife !== undefined) { |
| | | startupSource.add( |
| | |
| | | `${RuntimeGlobals.exports} = ${RuntimeGlobals.onChunksLoaded}(${RuntimeGlobals.exports});\n` |
| | | ); |
| | | } |
| | | source.add( |
| | | hooks.renderStartup.call(startupSource, lastInlinedModule, { |
| | | ...renderContext, |
| | | inlined: true, |
| | | inlinedInIIFE |
| | | }) |
| | | /** @type {StartupRenderContext} */ |
| | | const startupRenderContext = { |
| | | ...renderContext, |
| | | inlined: true, |
| | | inlinedInIIFE, |
| | | needExportsDeclaration: runtimeRequirements.has(RuntimeGlobals.exports) |
| | | }; |
| | | let renderedStartup = hooks.renderStartup.call( |
| | | startupSource, |
| | | lastInlinedModule, |
| | | startupRenderContext |
| | | ); |
| | | const lastInlinedModuleRequirements = |
| | | chunkGraph.getModuleRuntimeRequirements( |
| | | lastInlinedModule, |
| | | chunk.runtime |
| | | ); |
| | | if ( |
| | | // `onChunksLoaded` reads and reassigns `__webpack_exports__` |
| | | runtimeRequirements.has(RuntimeGlobals.onChunksLoaded) || |
| | | // Top-level `__webpack_exports__` will be returned |
| | | runtimeRequirements.has(RuntimeGlobals.returnExportsFromRuntime) || |
| | | // Custom exports argument aliases from `__webpack_exports__` |
| | | (lastInlinedModuleRequirements.has(RuntimeGlobals.exports) && |
| | | lastInlinedModule.exportsArgument !== RuntimeGlobals.exports) |
| | | ) { |
| | | startupRenderContext.needExportsDeclaration = true; |
| | | } |
| | | if (startupRenderContext.needExportsDeclaration) { |
| | | renderedStartup = new ConcatSource( |
| | | `var ${RuntimeGlobals.exports} = {};\n`, |
| | | renderedStartup |
| | | ); |
| | | } |
| | | source.add(renderedStartup); |
| | | if (bootstrap.afterStartup.length > 0) { |
| | | const afterStartup = `${Template.asString(bootstrap.afterStartup)}\n`; |
| | | source.add( |
| | |
| | | lastEntryModule, |
| | | { |
| | | ...renderContext, |
| | | inlined: false |
| | | inlined: false, |
| | | needExportsDeclaration: true |
| | | } |
| | | ), |
| | | toSource(bootstrap.afterStartup, "webpack/after-startup"), |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates hash with bootstrap. |
| | | * @param {Hash} hash the hash to be updated |
| | | * @param {RenderBootstrapContext} renderContext options object |
| | | * @param {CompilationHooks} hooks hooks |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders the generated source of the bootstrap code. |
| | | * @param {RenderBootstrapContext} renderContext options object |
| | | * @param {CompilationHooks} hooks hooks |
| | | * @returns {Bootstrap} the generated source of the bootstrap code |
| | |
| | | requireFunction || interceptModuleExecution || moduleUsed; |
| | | |
| | | /** |
| | | * @type {{startup: string[], beforeStartup: string[], header: string[], afterStartup: string[], allowInlineStartup: boolean}} |
| | | * @type {{ startup: string[], beforeStartup: string[], header: string[], afterStartup: string[], allowInlineStartup: boolean }} |
| | | */ |
| | | const result = { |
| | | header: [], |
| | |
| | | const runtimeRequirements = |
| | | chunkGraph.getTreeRuntimeRequirements(chunk); |
| | | buf2.push("// Load entry module and return exports"); |
| | | let i = chunkGraph.getNumberOfEntryModules(chunk); |
| | | |
| | | /** @type {EntryModuleWithChunkGroup[]} */ |
| | | const jsEntries = []; |
| | | for (const [ |
| | | entryModule, |
| | | entrypoint |
| | | ] of chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)) { |
| | | if (!chunkGraph.getModuleSourceTypes(entryModule).has("javascript")) { |
| | | i--; |
| | | if ( |
| | | chunkGraph.getModuleSourceTypes(entryModule).has(JAVASCRIPT_TYPE) |
| | | ) { |
| | | jsEntries.push([entryModule, entrypoint]); |
| | | continue; |
| | | } |
| | | } |
| | | let i = jsEntries.length; |
| | | for (const [entryModule, entrypoint] of jsEntries) { |
| | | const chunks = |
| | | /** @type {Entrypoint} */ |
| | | (entrypoint).chunks.filter((c) => c !== chunk); |
| | |
| | | result.allowInlineStartup = false; |
| | | } |
| | | |
| | | /** @type {undefined | CodeGenerationResultData} */ |
| | | let data; |
| | | if (codeGenerationResults.has(entryModule, chunk.runtime)) { |
| | | const result = codeGenerationResults.get( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Renders the generated source of the require function. |
| | | * @param {RenderBootstrapContext} renderContext options object |
| | | * @param {CompilationHooks} hooks hooks |
| | | * @returns {string} the generated source of the require function |
| | |
| | | runtimeTemplate: { outputOptions } |
| | | } = renderContext; |
| | | const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk); |
| | | |
| | | /** |
| | | * Renders missing module error. |
| | | * @param {string} condition guard expression |
| | | * @returns {string[]} source |
| | | */ |
| | | const renderMissingModuleError = (condition) => |
| | | outputOptions.pathinfo |
| | | ? [ |
| | | `if (${condition}) {`, |
| | | Template.indent([ |
| | | "delete __webpack_module_cache__[moduleId];", |
| | | 'var e = new Error("Cannot find module \'" + moduleId + "\'");', |
| | | "e.code = 'MODULE_NOT_FOUND';", |
| | | "throw e;" |
| | | ]), |
| | | "}" |
| | | ] |
| | | : []; |
| | | |
| | | const moduleExecution = runtimeRequirements.has( |
| | | RuntimeGlobals.interceptModuleExecution |
| | | ) |
| | | ? Template.asString([ |
| | | `var execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`, |
| | | `${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`, |
| | | ...renderMissingModuleError("!execOptions.factory"), |
| | | "module = execOptions.module;", |
| | | "execOptions.factory.call(module.exports, module, module.exports, execOptions.require);" |
| | | ]) |
| | | : runtimeRequirements.has(RuntimeGlobals.thisAsExports) |
| | | ? Template.asString([ |
| | | ...renderMissingModuleError("!(moduleId in __webpack_modules__)"), |
| | | `__webpack_modules__[moduleId].call(module.exports, module, module.exports, ${RuntimeGlobals.require});` |
| | | ]) |
| | | : Template.asString([ |
| | | ...renderMissingModuleError("!(moduleId in __webpack_modules__)"), |
| | | `__webpack_modules__[moduleId](module, module.exports, ${RuntimeGlobals.require});` |
| | | ]); |
| | | const needModuleId = runtimeRequirements.has(RuntimeGlobals.moduleId); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Get renamed inline module. |
| | | * @param {Compilation} compilation compilation |
| | | * @param {Module[]} allModules allModules |
| | | * @param {MainRenderContext} renderContext renderContext |
| | |
| | | const inlinedModulesToInfo = new Map(); |
| | | /** @type {Set<string>} */ |
| | | const nonInlinedModuleThroughIdentifiers = new Set(); |
| | | /** @type {Map<Module, Source>} */ |
| | | |
| | | for (const m of allModules) { |
| | | const isInlinedModule = inlinedModules && inlinedModules.has(m); |
| | |
| | | } |
| | | |
| | | for (const variable of info.variables) { |
| | | /** @type {UsedNamesInScopeInfo} */ |
| | | const usedNamesInScopeInfo = new Map(); |
| | | /** @type {ScopeSet} */ |
| | | const ignoredScopes = new Set(); |
| | | |
| | | const name = variable.name; |