| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-06-26 17:23:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { OriginalSource, RawSource } = require("webpack-sources"); | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | const AsyncDependenciesBlock = require("./AsyncDependenciesBlock"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const Module = require("./Module"); | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | const RuntimeGlobals = require("./RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | const Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | const WebpackError = require("./WebpackError"); | 
					
						
							| 
									
										
										
										
											2018-10-18 15:20:59 +08:00
										 |  |  | const { | 
					
						
							| 
									
										
										
										
											2018-12-20 15:51:54 +08:00
										 |  |  | 	compareLocations, | 
					
						
							| 
									
										
										
										
											2018-10-18 15:20:59 +08:00
										 |  |  | 	concatComparators, | 
					
						
							|  |  |  | 	compareSelect, | 
					
						
							|  |  |  | 	keepOriginalOrder | 
					
						
							|  |  |  | } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | const { compareModulesById } = require("./util/comparators"); | 
					
						
							| 
									
										
										
										
											2018-12-28 20:54:10 +08:00
										 |  |  | const { contextify } = require("./util/identifier"); | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | const makeSerializable = require("./util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 |  |  | /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */ | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | /** @typedef {import("./ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2019-06-14 17:44:54 +08:00
										 |  |  | /** @typedef {import("./ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./Compilation")} Compilation */ | 
					
						
							|  |  |  | /** @typedef {import("./DependencyTemplates")} DependencyTemplates */ | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */ | 
					
						
							|  |  |  | /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */ | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */ | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | /** @typedef {import("./ModuleGraph")} ModuleGraph */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | /** @typedef {import("./dependencies/ContextElementDependency")} ContextElementDependency */ | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {"sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"} ContextMode Context mode */ | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-06-14 17:44:54 +08:00
										 |  |  |  * @typedef {Object} ContextOptions | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  |  * @property {ContextMode} mode | 
					
						
							|  |  |  |  * @property {boolean} recursive | 
					
						
							|  |  |  |  * @property {RegExp} regExp | 
					
						
							| 
									
										
										
										
											2019-06-14 17:44:54 +08:00
										 |  |  |  * @property {"strict"|boolean=} namespaceObject | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  |  * @property {string=} addon | 
					
						
							|  |  |  |  * @property {string=} chunkName | 
					
						
							|  |  |  |  * @property {RegExp=} include | 
					
						
							|  |  |  |  * @property {RegExp=} exclude | 
					
						
							| 
									
										
										
										
											2019-06-14 17:44:54 +08:00
										 |  |  |  * @property {RawChunkGroupOptions=} groupOptions | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ContextModuleOptionsExtras | 
					
						
							|  |  |  |  * @property {string} resource | 
					
						
							|  |  |  |  * @property {string=} resourceQuery | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  |  * @property {TODO} resolveOptions | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 17:44:54 +08:00
										 |  |  | /** @typedef {ContextOptions & ContextModuleOptionsExtras} ContextModuleOptions */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-10 16:23:28 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @callback ResolveDependenciesCallback | 
					
						
							|  |  |  |  * @param {Error=} err | 
					
						
							|  |  |  |  * @param {ContextElementDependency[]} dependencies | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @callback ResolveDependencies | 
					
						
							|  |  |  |  * @param {TODO} fs | 
					
						
							|  |  |  |  * @param {TODO} options | 
					
						
							|  |  |  |  * @param {ResolveDependenciesCallback} callback | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | const TYPES = new Set(["javascript"]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | class ContextModule extends Module { | 
					
						
							| 
									
										
										
										
											2018-07-10 16:23:28 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ResolveDependencies} resolveDependencies function to get dependencies in this context | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | 	 * @param {ContextModuleOptions} options options object | 
					
						
							| 
									
										
										
										
											2018-07-10 16:23:28 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 	constructor(resolveDependencies, options) { | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 		let resource; | 
					
						
							|  |  |  | 		let resourceQuery; | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 		if (options.resourceQuery) { | 
					
						
							| 
									
										
										
										
											2017-11-16 14:20:50 +08:00
										 |  |  | 			resource = options.resource; | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 			resourceQuery = options.resourceQuery; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			const queryIdx = options.resource.indexOf("?"); | 
					
						
							|  |  |  | 			if (queryIdx >= 0) { | 
					
						
							|  |  |  | 				resource = options.resource.substr(0, queryIdx); | 
					
						
							|  |  |  | 				resourceQuery = options.resource.substr(queryIdx); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				resource = options.resource; | 
					
						
							|  |  |  | 				resourceQuery = ""; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-11-16 14:20:50 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-01-31 04:40:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		super("javascript/dynamic", resource); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Factory
 | 
					
						
							|  |  |  | 		this.resolveDependencies = resolveDependencies; | 
					
						
							| 
									
										
										
										
											2020-03-30 16:01:52 +08:00
										 |  |  | 		/** @type {Omit<ContextModuleOptions, "resolveOptions">} */ | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 		this.options = { | 
					
						
							| 
									
										
										
										
											2017-11-16 14:20:50 +08:00
										 |  |  | 			resource: resource, | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 			resourceQuery: resourceQuery, | 
					
						
							|  |  |  | 			mode: options.mode, | 
					
						
							|  |  |  | 			recursive: options.recursive, | 
					
						
							|  |  |  | 			addon: options.addon, | 
					
						
							|  |  |  | 			regExp: options.regExp, | 
					
						
							|  |  |  | 			include: options.include, | 
					
						
							|  |  |  | 			exclude: options.exclude, | 
					
						
							|  |  |  | 			chunkName: options.chunkName, | 
					
						
							|  |  |  | 			groupOptions: options.groupOptions, | 
					
						
							|  |  |  | 			namespaceObject: options.namespaceObject | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (options.resolveOptions !== undefined) { | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 			this.resolveOptions = options.resolveOptions; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Info from Build
 | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this._contextDependencies = new Set([this.context]); | 
					
						
							| 
									
										
										
										
											2017-11-06 20:02:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (typeof options.mode !== "string") { | 
					
						
							| 
									
										
										
										
											2017-10-16 20:49:51 +08:00
										 |  |  | 			throw new Error("options.mode is a required option"); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-13 08:17:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 02:02:30 +08:00
										 |  |  | 		this._identifier = this._createIdentifier(); | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this._forceBuild = true; | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2020-03-10 09:59:46 +08:00
										 |  |  | 	 * @returns {Set<string>} types available (do not mutate) | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	getSourceTypes() { | 
					
						
							|  |  |  | 		return TYPES; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Assuming this module is in the cache. Update the (cached) module with | 
					
						
							|  |  |  | 	 * the fresh module from the factory. Usually updates internal references | 
					
						
							|  |  |  | 	 * and properties. | 
					
						
							|  |  |  | 	 * @param {Module} module fresh module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-03-28 22:19:15 +08:00
										 |  |  | 	updateCacheModule(module) { | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 		const m = /** @type {ContextModule} */ (module); | 
					
						
							|  |  |  | 		this.resolveDependencies = m.resolveDependencies; | 
					
						
							|  |  |  | 		this.options = m.options; | 
					
						
							|  |  |  | 		this.resolveOptions = m.resolveOptions; | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 17:26:47 +08:00
										 |  |  | 	prettyRegExp(regexString) { | 
					
						
							|  |  |  | 		// remove the "/" at the front and the beginning
 | 
					
						
							|  |  |  | 		// "/foo/" -> "foo"
 | 
					
						
							|  |  |  | 		return regexString.substring(1, regexString.length - 1); | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 02:02:30 +08:00
										 |  |  | 	_createIdentifier() { | 
					
						
							| 
									
										
										
										
											2017-02-18 17:29:21 +08:00
										 |  |  | 		let identifier = this.context; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.options.resourceQuery) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|${this.options.resourceQuery}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.mode) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|${this.options.mode}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (!this.options.recursive) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += "|nonrecursive"; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.addon) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|${this.options.addon}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.regExp) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|${this.options.regExp}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.include) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|include: ${this.options.include}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.exclude) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|exclude: ${this.options.exclude}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 		if (this.options.chunkName) { | 
					
						
							|  |  |  | 			identifier += `|chunkName: ${this.options.chunkName}`; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		if (this.options.groupOptions) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += `|groupOptions: ${JSON.stringify( | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				this.options.groupOptions | 
					
						
							|  |  |  | 			)}`;
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.options.namespaceObject === "strict") { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += "|strict namespace object"; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} else if (this.options.namespaceObject) { | 
					
						
							| 
									
										
										
										
											2018-12-08 01:12:04 +08:00
										 |  |  | 			identifier += "|namespace object"; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 17:29:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return identifier; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} a unique identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-03-25 02:02:30 +08:00
										 |  |  | 	identifier() { | 
					
						
							|  |  |  | 		return this._identifier; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RequestShortener} requestShortener the request shortener | 
					
						
							|  |  |  | 	 * @returns {string} a user readable identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-18 17:29:21 +08:00
										 |  |  | 	readableIdentifier(requestShortener) { | 
					
						
							|  |  |  | 		let identifier = requestShortener.shorten(this.context); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.options.resourceQuery) { | 
					
						
							| 
									
										
										
										
											2017-12-01 19:47:14 +08:00
										 |  |  | 			identifier += ` ${this.options.resourceQuery}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.mode) { | 
					
						
							|  |  |  | 			identifier += ` ${this.options.mode}`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!this.options.recursive) { | 
					
						
							|  |  |  | 			identifier += " nonrecursive"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.addon) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` ${requestShortener.shorten(this.options.addon)}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.regExp) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.include) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.exclude) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 		if (this.options.chunkName) { | 
					
						
							|  |  |  | 			identifier += ` chunkName: ${this.options.chunkName}`; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		if (this.options.groupOptions) { | 
					
						
							|  |  |  | 			const groupOptions = this.options.groupOptions; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			for (const key of Object.keys(groupOptions)) { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				identifier += ` ${key}: ${groupOptions[key]}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.options.namespaceObject === "strict") { | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 			identifier += " strict namespace object"; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} else if (this.options.namespaceObject) { | 
					
						
							|  |  |  | 			identifier += " namespace object"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 17:29:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return identifier; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-20 22:24:35 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {LibIdentOptions} options options | 
					
						
							|  |  |  | 	 * @returns {string | null} an identifier for library inclusion | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	libIdent(options) { | 
					
						
							| 
									
										
										
										
											2019-01-19 19:40:00 +08:00
										 |  |  | 		let identifier = contextify( | 
					
						
							|  |  |  | 			options.context, | 
					
						
							|  |  |  | 			this.context, | 
					
						
							|  |  |  | 			options.associatedObjectForCache | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (this.options.mode) { | 
					
						
							|  |  |  | 			identifier += ` ${this.options.mode}`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.recursive) { | 
					
						
							|  |  |  | 			identifier += " recursive"; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.addon) { | 
					
						
							| 
									
										
										
										
											2019-01-19 19:40:00 +08:00
										 |  |  | 			identifier += ` ${contextify( | 
					
						
							|  |  |  | 				options.context, | 
					
						
							|  |  |  | 				this.options.addon, | 
					
						
							|  |  |  | 				options.associatedObjectForCache | 
					
						
							|  |  |  | 			)}`;
 | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.regExp) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.include) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (this.options.exclude) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 			identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 17:29:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return identifier; | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	invalidateBuild() { | 
					
						
							|  |  |  | 		this._forceBuild = true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-09-26 15:14:44 +08:00
										 |  |  | 	 * @param {NeedBuildContext} context context info | 
					
						
							|  |  |  | 	 * @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							| 
									
										
										
										
											2018-07-25 18:38:34 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 	needBuild({ fileSystemInfo }, callback) { | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 		// build if enforced
 | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		if (this._forceBuild) return callback(null, true); | 
					
						
							| 
									
										
										
										
											2017-02-18 18:09:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 		// always build when we have no snapshot
 | 
					
						
							|  |  |  | 		if (!this.buildInfo.snapshot) return callback(null, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => { | 
					
						
							|  |  |  | 			callback(err, !valid); | 
					
						
							| 
									
										
										
										
											2018-09-27 13:22:19 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 	 * @param {WebpackOptions} options webpack options | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @param {Compilation} compilation the compilation | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 	 * @param {ResolverWithOptions} resolver the resolver | 
					
						
							|  |  |  | 	 * @param {InputFileSystem} fs the file system | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 	 * @param {function(WebpackError=): void} callback callback function | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	build(options, compilation, resolver, fs, callback) { | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this._forceBuild = false; | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 		this.buildMeta = {}; | 
					
						
							|  |  |  | 		this.buildInfo = { | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 			snapshot: undefined, | 
					
						
							| 
									
										
										
										
											2017-12-06 19:09:17 +08:00
										 |  |  | 			contextDependencies: this._contextDependencies | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 		this.dependencies.length = 0; | 
					
						
							|  |  |  | 		this.blocks.length = 0; | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 		const startTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 		this.resolveDependencies(fs, this.options, (err, dependencies) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-02-01 01:00:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			// abort if something failed
 | 
					
						
							|  |  |  | 			// this will create an empty context
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (!dependencies) { | 
					
						
							| 
									
										
										
										
											2017-02-18 18:09:18 +08:00
										 |  |  | 				callback(); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2016-06-23 00:24:10 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-02-18 18:09:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			// enhance dependencies with meta info
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const dep of dependencies) { | 
					
						
							| 
									
										
										
										
											2018-07-10 16:23:28 +08:00
										 |  |  | 				dep.loc = { | 
					
						
							|  |  |  | 					name: dep.userRequest | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 				dep.request = this.options.addon + dep.request; | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-18 15:20:59 +08:00
										 |  |  | 			dependencies.sort( | 
					
						
							|  |  |  | 				concatComparators( | 
					
						
							|  |  |  | 					compareSelect(a => a.loc, compareLocations), | 
					
						
							|  |  |  | 					keepOriginalOrder(this.dependencies) | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-02-18 18:09:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (this.options.mode === "sync" || this.options.mode === "eager") { | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 				// if we have an sync or eager context
 | 
					
						
							|  |  |  | 				// just add all dependencies and continue
 | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 				this.dependencies = dependencies; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (this.options.mode === "lazy-once") { | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 				// for the lazy-once mode create a new async dependency block
 | 
					
						
							|  |  |  | 				// and add that block to this context
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 					const block = new AsyncDependenciesBlock({ | 
					
						
							|  |  |  | 						...this.options.groupOptions, | 
					
						
							|  |  |  | 						name: this.options.chunkName | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					for (const dep of dependencies) { | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 						block.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 					this.addBlock(block); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if ( | 
					
						
							|  |  |  | 				this.options.mode === "weak" || | 
					
						
							|  |  |  | 				this.options.mode === "async-weak" | 
					
						
							|  |  |  | 			) { | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 				// we mark all dependencies as weak
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const dep of dependencies) { | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 					dep.weak = true; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 				this.dependencies = dependencies; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (this.options.mode === "lazy") { | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 				// if we are lazy create a new async dependency block per dependency
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 				// and add all blocks to this context
 | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				let index = 0; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				for (const dep of dependencies) { | 
					
						
							| 
									
										
										
										
											2017-10-14 05:31:15 +08:00
										 |  |  | 					let chunkName = this.options.chunkName; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					if (chunkName) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 						if (!/\[(index|request)\]/.test(chunkName)) { | 
					
						
							|  |  |  | 							chunkName += "[index]"; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2019-06-14 17:44:54 +08:00
										 |  |  | 						chunkName = chunkName.replace(/\[index\]/g, `${index++}`); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						chunkName = chunkName.replace( | 
					
						
							|  |  |  | 							/\[request\]/g, | 
					
						
							|  |  |  | 							Template.toPath(dep.userRequest) | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					const block = new AsyncDependenciesBlock( | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 						{ | 
					
						
							|  |  |  | 							...this.options.groupOptions, | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 							name: chunkName | 
					
						
							| 
									
										
										
										
											2019-06-19 19:16:05 +08:00
										 |  |  | 						}, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						dep.loc, | 
					
						
							|  |  |  | 						dep.userRequest | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 					block.addDependency(dep); | 
					
						
							|  |  |  | 					this.addBlock(block); | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-10-16 20:49:51 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				callback( | 
					
						
							| 
									
										
										
										
											2018-09-12 00:47:55 +08:00
										 |  |  | 					new WebpackError(`Unsupported mode "${this.options.mode}" in context`) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-10-16 20:49:51 +08:00
										 |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 			compilation.fileSystemInfo.createSnapshot( | 
					
						
							|  |  |  | 				startTime, | 
					
						
							|  |  |  | 				null, | 
					
						
							|  |  |  | 				[this.context], | 
					
						
							|  |  |  | 				null, | 
					
						
							|  |  |  | 				{}, | 
					
						
							|  |  |  | 				(err, snapshot) => { | 
					
						
							|  |  |  | 					if (err) return callback(err); | 
					
						
							|  |  |  | 					this.buildInfo.snapshot = snapshot; | 
					
						
							|  |  |  | 					callback(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2015-07-01 06:19:52 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-07-26 20:48:42 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ContextElementDependency[]} dependencies all dependencies | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	 * @returns {TODO} TODO | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	getUserRequestMap(dependencies, chunkGraph) { | 
					
						
							|  |  |  | 		const moduleGraph = chunkGraph.moduleGraph; | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 		// if we filter first we get a new array
 | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 		// therefore we don't need to create a clone of dependencies explicitly
 | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 		// therefore the order of this is !important!
 | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 		const sortedDependencies = dependencies | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 			.filter(dependency => moduleGraph.getModule(dependency)) | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 			.sort((a, b) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (a.userRequest === b.userRequest) { | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 					return 0; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 				return a.userRequest < b.userRequest ? -1 : 1; | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		const map = Object.create(null); | 
					
						
							|  |  |  | 		for (const dep of sortedDependencies) { | 
					
						
							|  |  |  | 			const module = moduleGraph.getModule(dep); | 
					
						
							|  |  |  | 			map[dep.userRequest] = chunkGraph.getModuleId(module); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return map; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ContextElementDependency[]} dependencies all dependencies | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 	 * @returns {TODO} TODO | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	getFakeMap(dependencies, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (!this.options.namespaceObject) { | 
					
						
							|  |  |  | 			return 9; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		const moduleGraph = chunkGraph.moduleGraph; | 
					
						
							| 
									
										
										
										
											2019-12-05 05:54:26 +08:00
										 |  |  | 		// bitfield
 | 
					
						
							|  |  |  | 		let hasType = 0; | 
					
						
							|  |  |  | 		const comparator = compareModulesById(chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 		// if we filter first we get a new array
 | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 		// therefore we don't need to create a clone of dependencies explicitly
 | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 		// therefore the order of this is !important!
 | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 		const sortedModules = dependencies | 
					
						
							|  |  |  | 			.map(dependency => moduleGraph.getModule(dependency)) | 
					
						
							|  |  |  | 			.filter(Boolean) | 
					
						
							|  |  |  | 			.sort(comparator); | 
					
						
							|  |  |  | 		const fakeMap = Object.create(null); | 
					
						
							|  |  |  | 		for (const module of sortedModules) { | 
					
						
							|  |  |  | 			const exportsType = module.getExportsType( | 
					
						
							|  |  |  | 				this.options.namespaceObject === "strict" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			const id = chunkGraph.getModuleId(module); | 
					
						
							|  |  |  | 			switch (exportsType) { | 
					
						
							|  |  |  | 				case "namespace": | 
					
						
							|  |  |  | 					fakeMap[id] = 9; | 
					
						
							|  |  |  | 					hasType |= 1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case "dynamic": | 
					
						
							|  |  |  | 					fakeMap[id] = 7; | 
					
						
							|  |  |  | 					hasType |= 2; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case "dynamic-default": | 
					
						
							|  |  |  | 				case "default-only": | 
					
						
							|  |  |  | 					fakeMap[id] = 1; | 
					
						
							|  |  |  | 					hasType |= 4; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case "default-with-named": | 
					
						
							|  |  |  | 					fakeMap[id] = 3; | 
					
						
							|  |  |  | 					hasType |= 8; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					throw new Error(`Unexpected exports type ${exportsType}`); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-12-05 05:54:26 +08:00
										 |  |  | 		if (hasType === 1) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			return 9; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-12-05 05:54:26 +08:00
										 |  |  | 		if (hasType === 2) { | 
					
						
							|  |  |  | 			return 7; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (hasType === 4) { | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (hasType === 8) { | 
					
						
							|  |  |  | 			return 3; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-12-05 05:54:26 +08:00
										 |  |  | 		if (hasType === 0) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 			return 9; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 		return fakeMap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | 	getFakeMapInitStatement(fakeMap) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return typeof fakeMap === "object" | 
					
						
							|  |  |  | 			? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};` | 
					
						
							|  |  |  | 			: ""; | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-06 10:18:40 +08:00
										 |  |  | 	getReturn(type) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (type === 9) { | 
					
						
							|  |  |  | 			return "__webpack_require__(id)"; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 		return `${RuntimeGlobals.createFakeNamespaceObject}(id, ${type})`; | 
					
						
							| 
									
										
										
										
											2018-01-06 10:18:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (typeof fakeMap === "number") { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			return `return ${this.getReturn(fakeMap)};`; | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-06-13 16:51:12 +08:00
										 |  |  | 		return `return ${RuntimeGlobals.createFakeNamespaceObject}(id, ${fakeMapDataExpression})`; | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} dependencies TODO | 
					
						
							|  |  |  | 	 * @param {TODO} id TODO | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @returns {string} source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getSyncSource(dependencies, id, chunkGraph) { | 
					
						
							|  |  |  | 		const map = this.getUserRequestMap(dependencies, chunkGraph); | 
					
						
							|  |  |  | 		const fakeMap = this.getFakeMap(dependencies, chunkGraph); | 
					
						
							| 
									
										
										
										
											2018-01-06 10:18:40 +08:00
										 |  |  | 		const returnModuleObject = this.getReturnModuleObjectSource(fakeMap); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 		return `var map = ${JSON.stringify(map, null, "\t")};
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | ${this.getFakeMapInitStatement(fakeMap)} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | function webpackContext(req) { | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 	var id = webpackContextResolve(req); | 
					
						
							|  |  |  | 	${returnModuleObject} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | function webpackContextResolve(req) { | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 	if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 		var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 		e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 		throw e; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 	return map[req]; | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | webpackContext.keys = function webpackContextKeys() { | 
					
						
							|  |  |  | 	return Object.keys(map); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | webpackContext.resolve = webpackContextResolve; | 
					
						
							|  |  |  | module.exports = webpackContext; | 
					
						
							|  |  |  | webpackContext.id = ${JSON.stringify(id)};`;
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} dependencies TODO | 
					
						
							|  |  |  | 	 * @param {TODO} id TODO | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @returns {string} source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	getWeakSyncSource(dependencies, id, chunkGraph) { | 
					
						
							|  |  |  | 		const map = this.getUserRequestMap(dependencies, chunkGraph); | 
					
						
							|  |  |  | 		const fakeMap = this.getFakeMap(dependencies, chunkGraph); | 
					
						
							| 
									
										
										
										
											2018-01-06 10:18:40 +08:00
										 |  |  | 		const returnModuleObject = this.getReturnModuleObjectSource(fakeMap); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 		return `var map = ${JSON.stringify(map, null, "\t")};
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | ${this.getFakeMapInitStatement(fakeMap)} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | function webpackContext(req) { | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 	var id = webpackContextResolve(req); | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 	if(!${RuntimeGlobals.moduleFactories}[id]) { | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 		var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)"); | 
					
						
							|  |  |  | 		e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 		throw e; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 	${returnModuleObject} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | function webpackContextResolve(req) { | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 	if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 		var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 		e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 		throw e; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 	return map[req]; | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | webpackContext.keys = function webpackContextKeys() { | 
					
						
							|  |  |  | 	return Object.keys(map); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | webpackContext.resolve = webpackContextResolve; | 
					
						
							| 
									
										
										
										
											2017-07-26 21:13:39 +08:00
										 |  |  | webpackContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} dependencies TODO | 
					
						
							|  |  |  | 	 * @param {TODO} id TODO | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	 * @param {Object} context context | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} context.chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	 * @returns {string} source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	getAsyncWeakSource(dependencies, id, { chunkGraph, runtimeTemplate }) { | 
					
						
							|  |  |  | 		const arrow = runtimeTemplate.supportsArrowFunction(); | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		const map = this.getUserRequestMap(dependencies, chunkGraph); | 
					
						
							|  |  |  | 		const fakeMap = this.getFakeMap(dependencies, chunkGraph); | 
					
						
							| 
									
										
										
										
											2018-01-06 10:18:40 +08:00
										 |  |  | 		const returnModuleObject = this.getReturnModuleObjectSource(fakeMap); | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return `var map = ${JSON.stringify(map, null, "\t")};
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | ${this.getFakeMapInitStatement(fakeMap)} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | function webpackAsyncContext(req) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return webpackAsyncContextResolve(req).then(${ | 
					
						
							|  |  |  | 		arrow ? "id =>" : "function(id)" | 
					
						
							|  |  |  | 	} { | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 		if(!${RuntimeGlobals.moduleFactories}[id]) { | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 			var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)"); | 
					
						
							|  |  |  | 			e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 			throw e; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 		${returnModuleObject} | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | function webpackAsyncContextResolve(req) { | 
					
						
							|  |  |  | 	// Here Promise.resolve().then() is used instead of new Promise() to prevent
 | 
					
						
							| 
									
										
										
										
											2018-02-26 10:50:05 +08:00
										 |  |  | 	// uncaught exception popping up in devtools
 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return Promise.resolve().then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 		if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 			var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 			e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 			throw e; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		return map[req]; | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-03 22:05:22 +08:00
										 |  |  | webpackAsyncContext.keys = ${runtimeTemplate.returningFunction( | 
					
						
							|  |  |  | 			"Object.keys(map)" | 
					
						
							|  |  |  | 		)}; | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | webpackAsyncContext.resolve = webpackAsyncContextResolve; | 
					
						
							|  |  |  | webpackAsyncContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackAsyncContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} dependencies TODO | 
					
						
							|  |  |  | 	 * @param {TODO} id TODO | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	 * @param {Object} context context | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} context.chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	 * @returns {string} source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	getEagerSource(dependencies, id, { chunkGraph, runtimeTemplate }) { | 
					
						
							|  |  |  | 		const arrow = runtimeTemplate.supportsArrowFunction(); | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		const map = this.getUserRequestMap(dependencies, chunkGraph); | 
					
						
							|  |  |  | 		const fakeMap = this.getFakeMap(dependencies, chunkGraph); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const thenFunction = | 
					
						
							| 
									
										
										
										
											2018-05-03 00:09:24 +08:00
										 |  |  | 			fakeMap !== 9 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 				? `${arrow ? "id =>" : "function(id)"} {
 | 
					
						
							| 
									
										
										
										
											2018-05-03 00:09:24 +08:00
										 |  |  | 		${this.getReturnModuleObjectSource(fakeMap)} | 
					
						
							|  |  |  | 	}`
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				: "__webpack_require__"; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 		return `var map = ${JSON.stringify(map, null, "\t")};
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | ${this.getFakeMapInitStatement(fakeMap)} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | function webpackAsyncContext(req) { | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 	return webpackAsyncContextResolve(req).then(${thenFunction}); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | function webpackAsyncContextResolve(req) { | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 	// Here Promise.resolve().then() is used instead of new Promise() to prevent
 | 
					
						
							| 
									
										
										
										
											2018-02-26 10:50:05 +08:00
										 |  |  | 	// uncaught exception popping up in devtools
 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return Promise.resolve().then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 		if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 			var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 			e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 			throw e; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		return map[req]; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-03 22:05:22 +08:00
										 |  |  | webpackAsyncContext.keys = ${runtimeTemplate.returningFunction( | 
					
						
							|  |  |  | 			"Object.keys(map)" | 
					
						
							|  |  |  | 		)}; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | webpackAsyncContext.resolve = webpackAsyncContextResolve; | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | webpackAsyncContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackAsyncContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} block TODO | 
					
						
							|  |  |  | 	 * @param {TODO} dependencies TODO | 
					
						
							|  |  |  | 	 * @param {TODO} id TODO | 
					
						
							|  |  |  | 	 * @param {Object} options options object | 
					
						
							|  |  |  | 	 * @param {RuntimeTemplate} options.runtimeTemplate the runtime template | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} options.chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @returns {string} source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-11-20 16:31:36 +08:00
										 |  |  | 	getLazyOnceSource(block, dependencies, id, { runtimeTemplate, chunkGraph }) { | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 		const promise = runtimeTemplate.blockPromise({ | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | 			chunkGraph, | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 			block, | 
					
						
							| 
									
										
										
										
											2018-11-17 01:18:44 +08:00
										 |  |  | 			message: "lazy-once context", | 
					
						
							| 
									
										
										
										
											2018-11-20 16:31:36 +08:00
										 |  |  | 			runtimeRequirements: new Set() | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		const arrow = runtimeTemplate.supportsArrowFunction(); | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		const map = this.getUserRequestMap(dependencies, chunkGraph); | 
					
						
							|  |  |  | 		const fakeMap = this.getFakeMap(dependencies, chunkGraph); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const thenFunction = | 
					
						
							| 
									
										
										
										
											2018-05-03 00:09:24 +08:00
										 |  |  | 			fakeMap !== 9 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 				? `${arrow ? "id =>" : "function(id)"} {
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:20 +08:00
										 |  |  | 		${this.getReturnModuleObjectSource(fakeMap)}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	}`
 | 
					
						
							|  |  |  | 				: "__webpack_require__"; | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 		return `var map = ${JSON.stringify(map, null, "\t")};
 | 
					
						
							| 
									
										
										
										
											2017-12-23 01:23:33 +08:00
										 |  |  | ${this.getFakeMapInitStatement(fakeMap)} | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | function webpackAsyncContext(req) { | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 	return webpackAsyncContextResolve(req).then(${thenFunction}); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | function webpackAsyncContextResolve(req) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return ${promise}.then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 		if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 			var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 			e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 			throw e; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		return map[req]; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-12-03 22:05:22 +08:00
										 |  |  | webpackAsyncContext.keys = ${runtimeTemplate.returningFunction( | 
					
						
							|  |  |  | 			"Object.keys(map)" | 
					
						
							|  |  |  | 		)}; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | webpackAsyncContext.resolve = webpackAsyncContextResolve; | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | webpackAsyncContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackAsyncContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {TODO} blocks TODO | 
					
						
							|  |  |  | 	 * @param {TODO} id TODO | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	 * @param {Object} context context | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} context.chunkGraph the chunk graph | 
					
						
							|  |  |  | 	 * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	 * @returns {string} source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	getLazySource(blocks, id, { chunkGraph, runtimeTemplate }) { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 		const moduleGraph = chunkGraph.moduleGraph; | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		const arrow = runtimeTemplate.supportsArrowFunction(); | 
					
						
							| 
									
										
										
										
											2017-02-18 20:01:29 +08:00
										 |  |  | 		let hasMultipleOrNoChunks = false; | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		let hasNoChunk = true; | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		const fakeMap = this.getFakeMap( | 
					
						
							|  |  |  | 			blocks.map(b => b.dependencies[0]), | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 			chunkGraph | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		const hasFakeMap = typeof fakeMap === "object"; | 
					
						
							| 
									
										
										
										
											2019-02-07 16:41:34 +08:00
										 |  |  | 		const items = blocks | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			.map(block => { | 
					
						
							|  |  |  | 				const dependency = block.dependencies[0]; | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					dependency: dependency, | 
					
						
							| 
									
										
										
										
											2018-07-24 21:30:37 +08:00
										 |  |  | 					module: moduleGraph.getModule(dependency), | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 					block: block, | 
					
						
							| 
									
										
										
										
											2019-02-07 16:41:34 +08:00
										 |  |  | 					userRequest: dependency.userRequest, | 
					
						
							|  |  |  | 					chunks: undefined | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2019-02-07 16:41:34 +08:00
										 |  |  | 			.filter(item => item.module); | 
					
						
							|  |  |  | 		for (const item of items) { | 
					
						
							|  |  |  | 			const chunkGroup = chunkGraph.getBlockChunkGroup(item.block); | 
					
						
							|  |  |  | 			const chunks = (chunkGroup && chunkGroup.chunks) || []; | 
					
						
							|  |  |  | 			item.chunks = chunks; | 
					
						
							|  |  |  | 			if (chunks.length > 0) { | 
					
						
							|  |  |  | 				hasNoChunk = false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (chunks.length !== 1) { | 
					
						
							|  |  |  | 				hasMultipleOrNoChunks = true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const shortMode = hasNoChunk && !hasFakeMap; | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 		const sortedItems = items.sort((a, b) => { | 
					
						
							|  |  |  | 			if (a.userRequest === b.userRequest) return 0; | 
					
						
							|  |  |  | 			return a.userRequest < b.userRequest ? -1 : 1; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		const map = Object.create(null); | 
					
						
							|  |  |  | 		for (const item of sortedItems) { | 
					
						
							|  |  |  | 			const moduleId = chunkGraph.getModuleId(item.module); | 
					
						
							|  |  |  | 			if (shortMode) { | 
					
						
							|  |  |  | 				map[item.userRequest] = moduleId; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const arrayStart = [moduleId]; | 
					
						
							|  |  |  | 				if (hasFakeMap) { | 
					
						
							|  |  |  | 					arrayStart.push(fakeMap[moduleId]); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 				map[item.userRequest] = arrayStart.concat( | 
					
						
							|  |  |  | 					item.chunks.map(chunk => chunk.id) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		const chunksStartPosition = hasFakeMap ? 2 : 1; | 
					
						
							|  |  |  | 		const requestPrefix = hasNoChunk | 
					
						
							|  |  |  | 			? "Promise.resolve()" | 
					
						
							|  |  |  | 			: hasMultipleOrNoChunks | 
					
						
							| 
									
										
										
										
											2019-06-13 16:51:12 +08:00
										 |  |  | 			? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))` | 
					
						
							| 
									
										
										
										
											2018-11-05 21:36:15 +08:00
										 |  |  | 			: `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		const returnModuleObject = this.getReturnModuleObjectSource( | 
					
						
							|  |  |  | 			fakeMap, | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 			shortMode ? "invalid" : "ids[1]" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 		const webpackAsyncContext = | 
					
						
							|  |  |  | 			requestPrefix === "Promise.resolve()" | 
					
						
							|  |  |  | 				? `${shortMode ? "" : ""}
 | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | function webpackAsyncContext(req) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return Promise.resolve().then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 		if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 			var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							|  |  |  | 			e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 			throw e; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		${shortMode ? "var id = map[req];" : "var ids = map[req], id = ids[0];"} | 
					
						
							|  |  |  | 		${returnModuleObject} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }`
 | 
					
						
							|  |  |  | 				: `function webpackAsyncContext(req) {
 | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 	if(!${RuntimeGlobals.hasOwnProperty}(map, req)) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		return Promise.resolve().then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 			var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 			e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 			throw e; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var ids = map[req], id = ids[0]; | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return ${requestPrefix}.then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2017-12-04 19:07:43 +08:00
										 |  |  | 		${returnModuleObject} | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2019-02-06 00:29:27 +08:00
										 |  |  | }`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return `var map = ${JSON.stringify(map, null, "\t")};
 | 
					
						
							|  |  |  | ${webpackAsyncContext} | 
					
						
							| 
									
										
										
										
											2019-12-03 22:05:22 +08:00
										 |  |  | webpackAsyncContext.keys = ${runtimeTemplate.returningFunction( | 
					
						
							|  |  |  | 			"Object.keys(map)" | 
					
						
							|  |  |  | 		)}; | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | webpackAsyncContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackAsyncContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	getSourceForEmptyContext(id, runtimeTemplate) { | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 		return `function webpackEmptyContext(req) {
 | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 	var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 	e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 	throw e; | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | webpackEmptyContext.keys = ${runtimeTemplate.returningFunction("[]")}; | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | webpackEmptyContext.resolve = webpackEmptyContext; | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | webpackEmptyContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackEmptyContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	getSourceForEmptyAsyncContext(id, runtimeTemplate) { | 
					
						
							|  |  |  | 		const arrow = runtimeTemplate.supportsArrowFunction(); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 		return `function webpackEmptyAsyncContext(req) {
 | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 	// Here Promise.resolve().then() is used instead of new Promise() to prevent
 | 
					
						
							| 
									
										
										
										
											2018-02-26 10:50:05 +08:00
										 |  |  | 	// uncaught exception popping up in devtools
 | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	return Promise.resolve().then(${arrow ? "() =>" : "function()"} { | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 		var e = new Error("Cannot find module '" + req + "'"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:50:09 +08:00
										 |  |  | 		e.code = 'MODULE_NOT_FOUND'; | 
					
						
							|  |  |  | 		throw e; | 
					
						
							| 
									
										
										
										
											2017-07-26 20:49:37 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | webpackEmptyAsyncContext.keys = ${runtimeTemplate.returningFunction("[]")}; | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext; | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | webpackEmptyAsyncContext.id = ${JSON.stringify(id)}; | 
					
						
							|  |  |  | module.exports = webpackEmptyAsyncContext;`;
 | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {string} asyncMode module mode | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 	 * @param {CodeGenerationContext} context context info | 
					
						
							| 
									
										
										
										
											2018-08-23 02:17:49 +08:00
										 |  |  | 	 * @returns {string} the source code | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 	getSourceString(asyncMode, { runtimeTemplate, chunkGraph }) { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:56:48 +08:00
										 |  |  | 		const id = chunkGraph.getModuleId(this); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (asyncMode === "lazy") { | 
					
						
							|  |  |  | 			if (this.blocks && this.blocks.length > 0) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 				return this.getLazySource(this.blocks, id, { | 
					
						
							|  |  |  | 					runtimeTemplate, | 
					
						
							|  |  |  | 					chunkGraph | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			return this.getSourceForEmptyAsyncContext(id, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (asyncMode === "eager") { | 
					
						
							|  |  |  | 			if (this.dependencies && this.dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 				return this.getEagerSource(this.dependencies, id, { | 
					
						
							|  |  |  | 					chunkGraph, | 
					
						
							|  |  |  | 					runtimeTemplate | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			return this.getSourceForEmptyAsyncContext(id, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (asyncMode === "lazy-once") { | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			const block = this.blocks[0]; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (block) { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 				return this.getLazyOnceSource(block, block.dependencies, id, { | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 					runtimeTemplate, | 
					
						
							| 
									
										
										
										
											2018-11-20 16:31:36 +08:00
										 |  |  | 					chunkGraph | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			return this.getSourceForEmptyAsyncContext(id, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2017-05-05 00:37:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (asyncMode === "async-weak") { | 
					
						
							|  |  |  | 			if (this.dependencies && this.dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 				return this.getAsyncWeakSource(this.dependencies, id, { | 
					
						
							|  |  |  | 					chunkGraph, | 
					
						
							|  |  |  | 					runtimeTemplate | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 			return this.getSourceForEmptyAsyncContext(id, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (asyncMode === "weak") { | 
					
						
							|  |  |  | 			if (this.dependencies && this.dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 				return this.getWeakSyncSource(this.dependencies, id, chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-07-26 01:21:02 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.dependencies && this.dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2018-08-28 17:50:33 +08:00
										 |  |  | 			return this.getSyncSource(this.dependencies, id, chunkGraph); | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		return this.getSourceForEmptyContext(id, runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getSource(sourceString) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (this.useSourceMap) { | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 			return new OriginalSource(sourceString, this.identifier()); | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 		return new RawSource(sourceString); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 	 * @param {CodeGenerationContext} context context for code generation | 
					
						
							|  |  |  | 	 * @returns {CodeGenerationResult} result | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 	codeGeneration(context) { | 
					
						
							|  |  |  | 		const { chunkGraph } = context; | 
					
						
							|  |  |  | 		const sources = new Map(); | 
					
						
							|  |  |  | 		sources.set( | 
					
						
							|  |  |  | 			"javascript", | 
					
						
							|  |  |  | 			this.getSource(this.getSourceString(this.options.mode, context)) | 
					
						
							| 
									
										
										
										
											2017-02-18 19:41:39 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		const set = new Set(); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		const allDeps = /** @type {ContextElementDependency[]} */ (this.dependencies.concat( | 
					
						
							|  |  |  | 			this.blocks.map(b => b.dependencies[0]) | 
					
						
							|  |  |  | 		)); | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 		set.add(RuntimeGlobals.module); | 
					
						
							|  |  |  | 		set.add(RuntimeGlobals.hasOwnProperty); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 		if (allDeps.length > 0) { | 
					
						
							|  |  |  | 			const asyncMode = this.options.mode; | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 			set.add(RuntimeGlobals.require); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 			if (asyncMode === "weak") { | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 				set.add(RuntimeGlobals.moduleFactories); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 			} else if (asyncMode === "async-weak") { | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 				set.add(RuntimeGlobals.moduleFactories); | 
					
						
							|  |  |  | 				set.add(RuntimeGlobals.ensureChunk); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 			} else if (asyncMode === "lazy" || asyncMode === "lazy-once") { | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 				set.add(RuntimeGlobals.ensureChunk); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (this.getFakeMap(allDeps, chunkGraph) !== 9) { | 
					
						
							| 
									
										
										
										
											2020-01-29 17:28:33 +08:00
										 |  |  | 				set.add(RuntimeGlobals.createFakeNamespaceObject); | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-09 04:29:46 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			sources, | 
					
						
							|  |  |  | 			runtimeRequirements: set | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-11-06 02:03:12 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-12-04 18:23:40 +08:00
										 |  |  | 	 * @param {string=} type the source type for which the size should be estimated | 
					
						
							| 
									
										
										
										
											2019-05-13 18:29:29 +08:00
										 |  |  | 	 * @returns {number} the estimated size of the module (must be non-zero) | 
					
						
							| 
									
										
										
										
											2018-07-25 18:12:17 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-12-04 18:23:40 +08:00
										 |  |  | 	size(type) { | 
					
						
							| 
									
										
										
										
											2017-02-18 18:13:39 +08:00
										 |  |  | 		// base penalty
 | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 		let size = 160; | 
					
						
							| 
									
										
										
										
											2017-02-18 18:13:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 00:51:26 +08:00
										 |  |  | 		// if we don't have dependencies we stop here.
 | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 		for (const dependency of this.dependencies) { | 
					
						
							| 
									
										
										
										
											2018-06-08 19:20:57 +08:00
										 |  |  | 			const element = /** @type {ContextElementDependency} */ (dependency); | 
					
						
							| 
									
										
										
										
											2020-01-17 04:22:05 +08:00
										 |  |  | 			size += 5 + element.userRequest.length; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return size; | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 		// constructor
 | 
					
						
							|  |  |  | 		write(this.options); | 
					
						
							|  |  |  | 		// deserialize
 | 
					
						
							|  |  |  | 		write(this._forceBuild); | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		const obj = new ContextModule(null, read()); | 
					
						
							|  |  |  | 		obj.deserialize(context); | 
					
						
							|  |  |  | 		return obj; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 		this._forceBuild = read(); | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-04 19:34:34 +08:00
										 |  |  | makeSerializable(ContextModule, "webpack/lib/ContextModule"); | 
					
						
							| 
									
										
										
										
											2018-10-18 21:52:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 17:12:09 +08:00
										 |  |  | module.exports = ContextModule; |