| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							|  |  |  | const RuntimeModule = require("../RuntimeModule"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("../MainTemplate")} MainTemplate */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-02 23:02:48 +08:00
										 |  |  | class CompatRuntimeModule extends RuntimeModule { | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	constructor() { | 
					
						
							|  |  |  | 		super("compat", 10); | 
					
						
							| 
									
										
										
										
											2020-09-02 00:09:28 +08:00
										 |  |  | 		this.fullHash = true; | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} runtime code | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	generate() { | 
					
						
							|  |  |  | 		const { chunk, compilation } = this; | 
					
						
							| 
									
										
										
										
											2019-09-30 16:08:08 +08:00
										 |  |  | 		const { | 
					
						
							|  |  |  | 			chunkGraph, | 
					
						
							|  |  |  | 			runtimeTemplate, | 
					
						
							|  |  |  | 			mainTemplate, | 
					
						
							|  |  |  | 			moduleTemplates, | 
					
						
							|  |  |  | 			dependencyTemplates | 
					
						
							|  |  |  | 		} = compilation; | 
					
						
							|  |  |  | 		const bootstrap = mainTemplate.hooks.bootstrap.call( | 
					
						
							|  |  |  | 			"", | 
					
						
							|  |  |  | 			chunk, | 
					
						
							|  |  |  | 			compilation.hash || "XXXX", | 
					
						
							|  |  |  | 			moduleTemplates.javascript, | 
					
						
							|  |  |  | 			dependencyTemplates | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 		const localVars = mainTemplate.hooks.localVars.call( | 
					
						
							|  |  |  | 			"", | 
					
						
							|  |  |  | 			chunk, | 
					
						
							|  |  |  | 			compilation.hash || "XXXX" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const requireExtensions = mainTemplate.hooks.requireExtensions.call( | 
					
						
							|  |  |  | 			"", | 
					
						
							|  |  |  | 			chunk, | 
					
						
							|  |  |  | 			compilation.hash || "XXXX" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk); | 
					
						
							|  |  |  | 		let requireEnsure = ""; | 
					
						
							|  |  |  | 		if (runtimeRequirements.has(RuntimeGlobals.ensureChunk)) { | 
					
						
							|  |  |  | 			const requireEnsureHandler = mainTemplate.hooks.requireEnsure.call( | 
					
						
							|  |  |  | 				"", | 
					
						
							|  |  |  | 				chunk, | 
					
						
							|  |  |  | 				compilation.hash || "XXXX", | 
					
						
							|  |  |  | 				"chunkId" | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			if (requireEnsureHandler) { | 
					
						
							|  |  |  | 				requireEnsure = `${ | 
					
						
							|  |  |  | 					RuntimeGlobals.ensureChunkHandlers | 
					
						
							|  |  |  | 				}.compat = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 					"chunkId, promises", | 
					
						
							|  |  |  | 					requireEnsureHandler | 
					
						
							|  |  |  | 				)};`;
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-30 16:08:08 +08:00
										 |  |  | 		return [bootstrap, localVars, requireEnsure, requireExtensions] | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | 			.filter(Boolean) | 
					
						
							|  |  |  | 			.join("\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-07-02 23:02:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {boolean} true, if the runtime module should get it's own scope | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	shouldIsolate() { | 
					
						
							|  |  |  | 		// We avoid isolating this to have better backward-compat
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-26 21:51:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-02 23:02:48 +08:00
										 |  |  | module.exports = CompatRuntimeModule; |