webpack 4.9.1 → 4.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +755 -755
  2. package/SECURITY.md +9 -9
  3. package/buildin/global.js +20 -20
  4. package/buildin/harmony-module.js +24 -24
  5. package/buildin/module.js +22 -22
  6. package/hot/dev-server.js +61 -61
  7. package/hot/log-apply-result.js +44 -44
  8. package/hot/log.js +45 -45
  9. package/hot/only-dev-server.js +105 -105
  10. package/hot/poll.js +37 -37
  11. package/hot/signal.js +62 -62
  12. package/lib/APIPlugin.js +84 -84
  13. package/lib/AmdMainTemplatePlugin.js +87 -75
  14. package/lib/AsyncDependenciesBlock.js +66 -66
  15. package/lib/AsyncDependencyToInitialChunkError.js +31 -21
  16. package/lib/AutomaticPrefetchPlugin.js +50 -50
  17. package/lib/BannerPlugin.js +3 -1
  18. package/lib/BasicEvaluatedExpression.js +211 -208
  19. package/lib/CachePlugin.js +102 -95
  20. package/lib/CaseSensitiveModulesWarning.js +71 -53
  21. package/lib/Chunk.js +750 -722
  22. package/lib/ChunkGroup.js +13 -5
  23. package/lib/ChunkRenderError.js +32 -32
  24. package/lib/CompatibilityPlugin.js +63 -63
  25. package/lib/Compilation.js +1947 -1905
  26. package/lib/Compiler.js +508 -496
  27. package/lib/ConcurrentCompilationError.js +19 -19
  28. package/lib/ConstPlugin.js +258 -242
  29. package/lib/ContextExclusionPlugin.js +17 -17
  30. package/lib/ContextModule.js +749 -710
  31. package/lib/ContextModuleFactory.js +256 -245
  32. package/lib/ContextReplacementPlugin.js +133 -126
  33. package/lib/DefinePlugin.js +206 -197
  34. package/lib/DelegatedModule.js +101 -101
  35. package/lib/DelegatedModuleFactoryPlugin.js +89 -89
  36. package/lib/DelegatedPlugin.js +39 -39
  37. package/lib/DependenciesBlock.js +89 -87
  38. package/lib/DependenciesBlockVariable.js +52 -51
  39. package/lib/Dependency.js +51 -51
  40. package/lib/DllEntryPlugin.js +51 -51
  41. package/lib/DllModule.js +54 -54
  42. package/lib/DllModuleFactory.js +29 -29
  43. package/lib/DllPlugin.js +44 -42
  44. package/lib/DllReferencePlugin.js +84 -84
  45. package/lib/DynamicEntryPlugin.js +73 -71
  46. package/lib/EntryOptionPlugin.js +33 -33
  47. package/lib/EnvironmentPlugin.js +65 -65
  48. package/lib/ErrorHelpers.js +60 -57
  49. package/lib/EvalDevToolModulePlugin.js +27 -27
  50. package/lib/EvalDevToolModuleTemplatePlugin.js +61 -61
  51. package/lib/EvalSourceMapDevToolPlugin.js +41 -40
  52. package/lib/ExportPropertyMainTemplatePlugin.js +53 -40
  53. package/lib/ExtendedAPIPlugin.js +84 -84
  54. package/lib/ExternalModule.js +159 -159
  55. package/lib/ExternalModuleFactoryPlugin.js +110 -110
  56. package/lib/ExternalsPlugin.js +23 -23
  57. package/lib/FlagDependencyExportsPlugin.js +146 -146
  58. package/lib/FlagDependencyUsagePlugin.js +110 -104
  59. package/lib/FlagInitialModulesAsUsedPlugin.js +36 -36
  60. package/lib/FunctionModulePlugin.js +19 -19
  61. package/lib/FunctionModuleTemplatePlugin.js +100 -98
  62. package/lib/GraphHelpers.js +64 -64
  63. package/lib/HarmonyLinkingError.js +18 -18
  64. package/lib/HashedModuleIdsPlugin.js +53 -53
  65. package/lib/HotModuleReplacement.runtime.js +7 -3
  66. package/lib/HotModuleReplacementPlugin.js +413 -406
  67. package/lib/HotUpdateChunk.js +16 -16
  68. package/lib/HotUpdateChunkTemplate.js +78 -78
  69. package/lib/IgnorePlugin.js +71 -71
  70. package/lib/JavascriptGenerator.js +229 -228
  71. package/lib/JavascriptModulesPlugin.js +179 -184
  72. package/lib/JsonGenerator.js +42 -42
  73. package/lib/JsonModulesPlugin.js +30 -30
  74. package/lib/JsonParser.js +27 -26
  75. package/lib/LibManifestPlugin.js +86 -86
  76. package/lib/LibraryTemplatePlugin.js +153 -119
  77. package/lib/LoaderOptionsPlugin.js +53 -52
  78. package/lib/LoaderTargetPlugin.js +24 -24
  79. package/lib/MainTemplate.js +34 -9
  80. package/lib/Module.js +381 -377
  81. package/lib/ModuleBuildError.js +42 -42
  82. package/lib/ModuleDependencyError.js +35 -25
  83. package/lib/ModuleDependencyWarning.js +25 -25
  84. package/lib/ModuleError.js +28 -28
  85. package/lib/ModuleFilenameHelpers.js +178 -166
  86. package/lib/ModuleParseError.js +44 -44
  87. package/lib/ModuleReason.js +40 -40
  88. package/lib/ModuleTemplate.js +84 -84
  89. package/lib/ModuleWarning.js +30 -30
  90. package/lib/MultiCompiler.js +283 -271
  91. package/lib/MultiEntryPlugin.js +58 -58
  92. package/lib/MultiModule.js +81 -78
  93. package/lib/MultiModuleFactory.js +23 -23
  94. package/lib/MultiStats.js +92 -92
  95. package/lib/MultiWatching.js +38 -38
  96. package/lib/NamedChunksPlugin.js +29 -29
  97. package/lib/NamedModulesPlugin.js +57 -57
  98. package/lib/NoEmitOnErrorsPlugin.js +20 -20
  99. package/lib/NoModeWarning.js +23 -23
  100. package/lib/NodeStuffPlugin.js +179 -178
  101. package/lib/NormalModule.js +497 -490
  102. package/lib/NormalModuleFactory.js +501 -483
  103. package/lib/NormalModuleReplacementPlugin.js +51 -51
  104. package/lib/OptionsDefaulter.js +84 -80
  105. package/lib/Parser.js +2164 -2086
  106. package/lib/ParserHelpers.js +103 -100
  107. package/lib/PrefetchPlugin.js +37 -37
  108. package/lib/ProgressPlugin.js +231 -231
  109. package/lib/ProvidePlugin.js +86 -86
  110. package/lib/RawModule.js +56 -54
  111. package/lib/RecordIdsPlugin.js +166 -162
  112. package/lib/RemovedPluginError.js +13 -13
  113. package/lib/RequestShortener.js +81 -74
  114. package/lib/RequireJsStuffPlugin.js +69 -69
  115. package/lib/ResolverFactory.js +64 -64
  116. package/lib/RuleSet.js +555 -534
  117. package/lib/RuntimeTemplate.js +320 -277
  118. package/lib/SetVarMainTemplatePlugin.js +69 -57
  119. package/lib/SingleEntryPlugin.js +44 -44
  120. package/lib/SizeFormatHelpers.js +24 -24
  121. package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -49
  122. package/lib/SourceMapDevToolPlugin.js +301 -300
  123. package/lib/Stats.js +1408 -1367
  124. package/lib/Template.js +4 -2
  125. package/lib/TemplatedPathPlugin.js +173 -170
  126. package/lib/UmdMainTemplatePlugin.js +304 -264
  127. package/lib/UseStrictPlugin.js +48 -48
  128. package/lib/WarnCaseSensitiveModulesPlugin.js +37 -36
  129. package/lib/WarnNoModeSetPlugin.js +17 -17
  130. package/lib/WatchIgnorePlugin.js +100 -100
  131. package/lib/Watching.js +194 -193
  132. package/lib/WebpackError.js +25 -19
  133. package/lib/WebpackOptionsApply.js +421 -405
  134. package/lib/WebpackOptionsDefaulter.js +347 -344
  135. package/lib/WebpackOptionsValidationError.js +345 -316
  136. package/lib/compareLocations.js +56 -56
  137. package/lib/dependencies/AMDDefineDependency.js +137 -137
  138. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +336 -327
  139. package/lib/dependencies/AMDPlugin.js +250 -250
  140. package/lib/dependencies/AMDRequireArrayDependency.js +49 -49
  141. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  142. package/lib/dependencies/AMDRequireDependenciesBlock.js +43 -43
  143. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +273 -270
  144. package/lib/dependencies/AMDRequireDependency.js +135 -135
  145. package/lib/dependencies/CommonJsPlugin.js +161 -161
  146. package/lib/dependencies/CommonJsRequireContextDependency.js +23 -23
  147. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +130 -130
  148. package/lib/dependencies/ConstDependency.js +33 -33
  149. package/lib/dependencies/ContextDependency.js +68 -68
  150. package/lib/dependencies/ContextDependencyTemplateAsId.js +42 -42
  151. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +38 -38
  152. package/lib/dependencies/ContextElementDependency.js +21 -21
  153. package/lib/dependencies/DelegatedExportsDependency.js +33 -33
  154. package/lib/dependencies/DependencyReference.js +18 -18
  155. package/lib/dependencies/HarmonyAcceptDependency.js +45 -45
  156. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  157. package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -31
  158. package/lib/dependencies/HarmonyDetectionParserPlugin.js +92 -90
  159. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +139 -139
  160. package/lib/dependencies/HarmonyExportExpressionDependency.js +53 -53
  161. package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -30
  162. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -603
  163. package/lib/dependencies/HarmonyExportSpecifierDependency.js +54 -54
  164. package/lib/dependencies/HarmonyImportDependency.js +104 -94
  165. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -214
  166. package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -31
  167. package/lib/dependencies/HarmonyImportSpecifierDependency.js +166 -156
  168. package/lib/dependencies/HarmonyInitDependency.js +60 -60
  169. package/lib/dependencies/HarmonyModulesPlugin.js +146 -146
  170. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -26
  171. package/lib/dependencies/ImportContextDependency.js +23 -23
  172. package/lib/dependencies/ImportDependenciesBlock.js +18 -18
  173. package/lib/dependencies/ImportDependency.js +34 -34
  174. package/lib/dependencies/ImportEagerDependency.js +32 -32
  175. package/lib/dependencies/ImportParserPlugin.js +233 -232
  176. package/lib/dependencies/ImportPlugin.js +82 -82
  177. package/lib/dependencies/ImportWeakDependency.js +34 -34
  178. package/lib/dependencies/JsonExportsDependency.js +26 -26
  179. package/lib/dependencies/LoaderPlugin.js +98 -93
  180. package/lib/dependencies/LocalModuleDependency.js +28 -28
  181. package/lib/dependencies/LocalModulesHelpers.js +52 -45
  182. package/lib/dependencies/ModuleDependency.js +20 -20
  183. package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -17
  184. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -17
  185. package/lib/dependencies/MultiEntryDependency.js +20 -20
  186. package/lib/dependencies/NullDependency.js +20 -20
  187. package/lib/dependencies/RequireContextDependency.js +22 -22
  188. package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -56
  189. package/lib/dependencies/RequireContextPlugin.js +143 -141
  190. package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -33
  191. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -112
  192. package/lib/dependencies/RequireEnsureDependency.js +58 -58
  193. package/lib/dependencies/RequireEnsurePlugin.js +74 -74
  194. package/lib/dependencies/RequireHeaderDependency.js +26 -26
  195. package/lib/dependencies/RequireIncludeDependency.js +39 -39
  196. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -23
  197. package/lib/dependencies/RequireIncludePlugin.js +61 -61
  198. package/lib/dependencies/RequireResolveContextDependency.js +23 -23
  199. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +85 -85
  200. package/lib/dependencies/RequireResolveHeaderDependency.js +26 -26
  201. package/lib/dependencies/SingleEntryDependency.js +18 -18
  202. package/lib/dependencies/SystemPlugin.js +125 -125
  203. package/lib/dependencies/UnsupportedDependency.js +27 -27
  204. package/lib/dependencies/WebAssemblyImportDependency.js +48 -44
  205. package/lib/dependencies/WebpackMissingModule.js +20 -20
  206. package/lib/dependencies/getFunctionExpression.js +52 -52
  207. package/lib/formatLocation.js +61 -53
  208. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  209. package/lib/node/NodeEnvironmentPlugin.js +28 -28
  210. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  211. package/lib/node/NodeMainTemplate.runtime.js +27 -27
  212. package/lib/node/NodeMainTemplateAsync.runtime.js +44 -44
  213. package/lib/node/NodeMainTemplatePlugin.js +323 -320
  214. package/lib/node/NodeSourcePlugin.js +144 -140
  215. package/lib/node/NodeTargetPlugin.js +18 -18
  216. package/lib/node/NodeTemplatePlugin.js +31 -31
  217. package/lib/node/NodeWatchFileSystem.js +99 -82
  218. package/lib/node/ReadFileCompileWasmTemplatePlugin.js +52 -52
  219. package/lib/optimize/AggressiveMergingPlugin.js +87 -87
  220. package/lib/optimize/AggressiveSplittingPlugin.js +287 -281
  221. package/lib/optimize/ChunkModuleIdRangePlugin.js +68 -68
  222. package/lib/optimize/ConcatenatedModule.js +1420 -1413
  223. package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -70
  224. package/lib/optimize/FlagIncludedChunksPlugin.js +99 -99
  225. package/lib/optimize/LimitChunkCountPlugin.js +66 -66
  226. package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -75
  227. package/lib/optimize/MinChunkSizePlugin.js +77 -77
  228. package/lib/optimize/ModuleConcatenationPlugin.js +470 -457
  229. package/lib/optimize/OccurrenceOrderPlugin.js +133 -126
  230. package/lib/optimize/RemoveParentModulesPlugin.js +127 -117
  231. package/lib/optimize/RuntimeChunkPlugin.js +41 -41
  232. package/lib/optimize/SideEffectsFlagPlugin.js +158 -156
  233. package/lib/optimize/SplitChunksPlugin.js +709 -696
  234. package/lib/performance/AssetsOverSizeLimitWarning.js +30 -30
  235. package/lib/performance/EntrypointsOverSizeLimitWarning.js +31 -31
  236. package/lib/performance/NoAsyncChunksWarning.js +21 -21
  237. package/lib/performance/SizeLimitsPlugin.js +105 -105
  238. package/lib/util/Semaphore.js +41 -41
  239. package/lib/util/SortableSet.js +5 -2
  240. package/lib/util/StackedSetMap.js +12 -5
  241. package/lib/util/TrackingSet.js +35 -35
  242. package/lib/util/cachedMerge.js +35 -35
  243. package/lib/util/createHash.js +77 -77
  244. package/lib/util/identifier.js +76 -76
  245. package/lib/validateSchema.js +67 -67
  246. package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +18 -18
  247. package/lib/wasm/WasmMainTemplatePlugin.js +310 -304
  248. package/lib/wasm/WebAssemblyGenerator.js +143 -19
  249. package/lib/wasm/WebAssemblyJavascriptGenerator.js +90 -107
  250. package/lib/wasm/WebAssemblyModulesPlugin.js +80 -80
  251. package/lib/wasm/WebAssemblyParser.js +28 -5
  252. package/lib/wasm/WebAssemblyUtils.js +48 -0
  253. package/lib/web/FetchCompileWasmTemplatePlugin.js +25 -25
  254. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  255. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  256. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  257. package/lib/web/JsonpMainTemplate.runtime.js +65 -64
  258. package/lib/web/JsonpMainTemplatePlugin.js +576 -574
  259. package/lib/web/JsonpTemplatePlugin.js +23 -23
  260. package/lib/webpack.js +183 -182
  261. package/lib/webpack.web.js +31 -31
  262. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  263. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  264. package/lib/webworker/WebWorkerMainTemplate.runtime.js +65 -64
  265. package/lib/webworker/WebWorkerMainTemplatePlugin.js +179 -179
  266. package/lib/webworker/WebWorkerTemplatePlugin.js +25 -25
  267. package/package.json +9 -8
  268. package/schemas/WebpackOptions.json +1988 -1988
  269. package/schemas/ajv.absolutePath.js +55 -55
  270. package/schemas/plugins/DllPlugin.json +32 -32
  271. package/schemas/plugins/DllReferencePlugin.json +99 -99
  272. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  273. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  274. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  275. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  276. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  277. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  278. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  279. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,1413 +1,1420 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const Module = require("../Module");
8
- const Template = require("../Template");
9
- const Parser = require("../Parser");
10
- const eslintScope = require("eslint-scope");
11
- const { ConcatSource, ReplaceSource } = require("webpack-sources");
12
- const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
13
- const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
14
- const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
15
- const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportSpecifierDependency");
16
- const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency");
17
- const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
18
- const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
19
- const createHash = require("../util/createHash");
20
-
21
- const ensureNsObjSource = (
22
- info,
23
- moduleToInfoMap,
24
- requestShortener,
25
- strictHarmonyModule
26
- ) => {
27
- if (!info.hasNamespaceObject) {
28
- info.hasNamespaceObject = true;
29
- const name = info.exportMap.get(true);
30
- const nsObj = [`var ${name} = {};`];
31
- for (const exportName of info.module.buildMeta.providedExports) {
32
- const finalName = getFinalName(
33
- info,
34
- exportName,
35
- moduleToInfoMap,
36
- requestShortener,
37
- false,
38
- strictHarmonyModule
39
- );
40
- nsObj.push(
41
- `__webpack_require__.d(${name}, ${JSON.stringify(
42
- exportName
43
- )}, function() { return ${finalName}; });`
44
- );
45
- }
46
- info.namespaceObjectSource = nsObj.join("\n") + "\n";
47
- }
48
- };
49
-
50
- const getExternalImport = (
51
- importedModule,
52
- info,
53
- exportName,
54
- asCall,
55
- strictHarmonyModule
56
- ) => {
57
- const used = importedModule.isUsed(exportName);
58
- if (!used) return "/* unused reexport */undefined";
59
- const comment =
60
- used !== exportName ? ` ${Template.toNormalComment(exportName)}` : "";
61
- switch (importedModule.buildMeta.exportsType) {
62
- case "named":
63
- if (exportName === "default") {
64
- return info.name;
65
- } else if (exportName === true) {
66
- info.interopNamespaceObjectUsed = true;
67
- return info.interopNamespaceObjectName;
68
- } else {
69
- break;
70
- }
71
- case "namespace":
72
- if (exportName === true) {
73
- return info.name;
74
- } else {
75
- break;
76
- }
77
- default:
78
- if (strictHarmonyModule) {
79
- if (exportName === "default") {
80
- return info.name;
81
- } else if (exportName === true) {
82
- info.interopNamespaceObjectUsed = true;
83
- return info.interopNamespaceObjectName;
84
- } else {
85
- return "/* non-default import from non-esm module */undefined";
86
- }
87
- } else {
88
- if (exportName === "default") {
89
- info.interopDefaultAccessUsed = true;
90
- return asCall
91
- ? `${info.interopDefaultAccessName}()`
92
- : `${info.interopDefaultAccessName}.a`;
93
- } else if (exportName === true) {
94
- return info.name;
95
- } else {
96
- break;
97
- }
98
- }
99
- }
100
- const reference = `${info.name}[${JSON.stringify(used)}${comment}]`;
101
- if (asCall) return `Object(${reference})`;
102
- return reference;
103
- };
104
-
105
- const getFinalName = (
106
- info,
107
- exportName,
108
- moduleToInfoMap,
109
- requestShortener,
110
- asCall,
111
- strictHarmonyModule
112
- ) => {
113
- switch (info.type) {
114
- case "concatenated": {
115
- const directExport = info.exportMap.get(exportName);
116
- if (directExport) {
117
- if (exportName === true)
118
- ensureNsObjSource(
119
- info,
120
- moduleToInfoMap,
121
- requestShortener,
122
- strictHarmonyModule
123
- );
124
- const name = info.internalNames.get(directExport);
125
- if (!name)
126
- throw new Error(
127
- `The export "${directExport}" in "${info.module.readableIdentifier(
128
- requestShortener
129
- )}" has no internal name`
130
- );
131
- return name;
132
- }
133
- const reexport = info.reexportMap.get(exportName);
134
- if (reexport) {
135
- const refInfo = moduleToInfoMap.get(reexport.module);
136
- if (refInfo) {
137
- // module is in the concatenation
138
- return getFinalName(
139
- refInfo,
140
- reexport.exportName,
141
- moduleToInfoMap,
142
- requestShortener,
143
- asCall,
144
- strictHarmonyModule
145
- );
146
- }
147
- }
148
- const problem =
149
- `Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier(
150
- requestShortener
151
- )}"` +
152
- ` (known exports: ${Array.from(info.exportMap.keys())
153
- .filter(name => name !== true)
154
- .join(" ")}, ` +
155
- `known reexports: ${Array.from(info.reexportMap.keys()).join(" ")})`;
156
- return `${Template.toNormalComment(problem)} undefined`;
157
- }
158
- case "external": {
159
- const importedModule = info.module;
160
- return getExternalImport(
161
- importedModule,
162
- info,
163
- exportName,
164
- asCall,
165
- strictHarmonyModule
166
- );
167
- }
168
- }
169
- };
170
-
171
- const addScopeSymbols1 = (s, nameSet, scopeSet) => {
172
- let scope = s;
173
- while (scope) {
174
- if (scopeSet.has(scope)) break;
175
- scopeSet.add(scope);
176
- for (const variable of scope.variables) {
177
- nameSet.add(variable.name);
178
- }
179
- scope = scope.upper;
180
- }
181
- };
182
-
183
- const addScopeSymbols2 = (s, nameSet, scopeSet1, scopeSet2) => {
184
- let scope = s;
185
- while (scope) {
186
- if (scopeSet1.has(scope)) break;
187
- if (scopeSet2.has(scope)) break;
188
- scopeSet1.add(scope);
189
- for (const variable of scope.variables) {
190
- nameSet.add(variable.name);
191
- }
192
- scope = scope.upper;
193
- }
194
- };
195
-
196
- const getAllReferences = variable => {
197
- let set = variable.references;
198
- // Look for inner scope variables too (like in class Foo { t() { Foo } })
199
- const identifiers = new Set(variable.identifiers);
200
- for (const scope of variable.scope.childScopes) {
201
- for (const innerVar of scope.variables) {
202
- if (innerVar.identifiers.some(id => identifiers.has(id))) {
203
- set = set.concat(innerVar.references);
204
- break;
205
- }
206
- }
207
- }
208
- return set;
209
- };
210
-
211
- const getPathInAst = (ast, node) => {
212
- if (ast === node) {
213
- return [];
214
- }
215
-
216
- const nr = node.range;
217
-
218
- const enterNode = n => {
219
- if (!n) return undefined;
220
- const r = n.range;
221
- if (r) {
222
- if (r[0] <= nr[0] && r[1] >= nr[1]) {
223
- const path = getPathInAst(n, node);
224
- if (path) {
225
- path.push(n);
226
- return path;
227
- }
228
- }
229
- }
230
- return undefined;
231
- };
232
-
233
- var i;
234
- if (Array.isArray(ast)) {
235
- for (i = 0; i < ast.length; i++) {
236
- const enterResult = enterNode(ast[i]);
237
- if (typeof enterResult !== "undefined") return enterResult;
238
- }
239
- } else if (ast && typeof ast === "object") {
240
- const keys = Object.keys(ast);
241
- for (i = 0; i < keys.length; i++) {
242
- const value = ast[keys[i]];
243
- if (Array.isArray(value)) {
244
- const pathResult = getPathInAst(value, node);
245
- if (typeof pathResult !== "undefined") return pathResult;
246
- } else if (value && typeof value === "object") {
247
- const enterResult = enterNode(value);
248
- if (typeof enterResult !== "undefined") return enterResult;
249
- }
250
- }
251
- }
252
- };
253
-
254
- class ConcatenatedModule extends Module {
255
- constructor(rootModule, modules) {
256
- super("javascript/esm", null);
257
- super.setChunks(rootModule._chunks);
258
-
259
- // Info from Factory
260
- this.rootModule = rootModule;
261
-
262
- // Info from Compilation
263
- this.index = rootModule.index;
264
- this.index2 = rootModule.index2;
265
- this.depth = rootModule.depth;
266
-
267
- // Info from Optimization
268
- this.used = rootModule.used;
269
- this.usedExports = rootModule.usedExports;
270
-
271
- // Info from Build
272
- this.buildInfo = {
273
- strict: true,
274
- cacheable: modules.every(m => m.buildInfo.cacheable),
275
- moduleArgument: rootModule.buildInfo.moduleArgument,
276
- exportsArgument: rootModule.buildInfo.exportsArgument,
277
- fileDependencies: new Set(),
278
- contextDependencies: new Set(),
279
- assets: undefined
280
- };
281
- this.built = modules.some(m => m.built);
282
- this.buildMeta = rootModule.buildMeta;
283
-
284
- // Caching
285
- this._numberOfConcatenatedModules = modules.length;
286
-
287
- // Graph
288
- const modulesSet = new Set(modules);
289
- this.reasons = rootModule.reasons.filter(
290
- reason =>
291
- !(reason.dependency instanceof HarmonyImportDependency) ||
292
- !modulesSet.has(reason.module)
293
- );
294
-
295
- this.dependencies = [];
296
-
297
- this.warnings = [];
298
- this.errors = [];
299
- this._orderedConcatenationList = this._createOrderedConcatenationList(
300
- rootModule,
301
- modulesSet
302
- );
303
- for (const info of this._orderedConcatenationList) {
304
- if (info.type === "concatenated") {
305
- const m = info.module;
306
-
307
- // populate dependencies
308
- for (const d of m.dependencies.filter(
309
- dep =>
310
- !(dep instanceof HarmonyImportDependency) ||
311
- !modulesSet.has(dep.module)
312
- )) {
313
- this.dependencies.push(d);
314
- }
315
- // populate file dependencies
316
- if (m.buildInfo.fileDependencies) {
317
- for (const file of m.buildInfo.fileDependencies) {
318
- this.buildInfo.fileDependencies.add(file);
319
- }
320
- }
321
- // populate context dependencies
322
- if (m.buildInfo.contextDependencies) {
323
- for (const context of m.buildInfo.contextDependencies) {
324
- this.buildInfo.contextDependencies.add(context);
325
- }
326
- }
327
- // populate warnings
328
- for (const warning of m.warnings) this.warnings.push(warning);
329
- // populate errors
330
- for (const error of m.errors) this.errors.push(error);
331
-
332
- if (m.buildInfo.assets) {
333
- if (this.buildInfo.assets === undefined)
334
- this.buildInfo.assets = Object.create(null);
335
- Object.assign(this.buildInfo.assets, m.buildInfo.assets);
336
- }
337
- }
338
- }
339
- this._identifier = this._createIdentifier();
340
- }
341
-
342
- get modules() {
343
- return this._orderedConcatenationList
344
- .filter(info => info.type === "concatenated")
345
- .map(info => info.module);
346
- }
347
-
348
- identifier() {
349
- return this._identifier;
350
- }
351
-
352
- readableIdentifier(requestShortener) {
353
- return (
354
- this.rootModule.readableIdentifier(requestShortener) +
355
- ` + ${this._numberOfConcatenatedModules - 1} modules`
356
- );
357
- }
358
-
359
- libIdent(options) {
360
- return this.rootModule.libIdent(options);
361
- }
362
-
363
- nameForCondition() {
364
- return this.rootModule.nameForCondition();
365
- }
366
-
367
- build(options, compilation, resolver, fs, callback) {
368
- throw new Error("Cannot build this module. It should be already built.");
369
- }
370
-
371
- size() {
372
- // Guess size from embedded modules
373
- return this._orderedConcatenationList.reduce((sum, info) => {
374
- switch (info.type) {
375
- case "concatenated":
376
- return sum + info.module.size();
377
- case "external":
378
- return sum + 5;
379
- }
380
- return sum;
381
- }, 0);
382
- }
383
-
384
- _createOrderedConcatenationList(rootModule, modulesSet) {
385
- const list = [];
386
- const set = new Set();
387
-
388
- const getConcatenatedImports = module => {
389
- return module.dependencies
390
- .filter(dep => dep instanceof HarmonyImportDependency)
391
- .sort((a, b) => a.sourceOrder - b.sourceOrder)
392
- .map(dep => () => {
393
- const ref = dep.getReference();
394
- return ref && ref.module;
395
- });
396
- };
397
-
398
- const enterModule = getModule => {
399
- const module = getModule();
400
- if (!module) return;
401
- if (set.has(module)) return;
402
- set.add(module);
403
- if (modulesSet.has(module)) {
404
- const imports = getConcatenatedImports(module);
405
- imports.forEach(enterModule);
406
- list.push({
407
- type: "concatenated",
408
- module
409
- });
410
- } else {
411
- list.push({
412
- type: "external",
413
- get module() {
414
- // We need to use a getter here, because the module in the dependency
415
- // could be replaced by some other process (i. e. also replaced with a
416
- // concatenated module)
417
- return getModule();
418
- }
419
- });
420
- }
421
- };
422
-
423
- enterModule(() => rootModule);
424
-
425
- return list;
426
- }
427
-
428
- _createIdentifier() {
429
- let orderedConcatenationListIdentifiers = "";
430
- for (let i = 0; i < this._orderedConcatenationList.length; i++) {
431
- if (this._orderedConcatenationList[i].type === "concatenated") {
432
- orderedConcatenationListIdentifiers += this._orderedConcatenationList[
433
- i
434
- ].module.identifier();
435
- orderedConcatenationListIdentifiers += " ";
436
- }
437
- }
438
- const hash = createHash("md4");
439
- hash.update(orderedConcatenationListIdentifiers);
440
- return this.rootModule.identifier() + " " + hash.digest("hex");
441
- }
442
-
443
- source(dependencyTemplates, runtimeTemplate) {
444
- const requestShortener = runtimeTemplate.requestShortener;
445
- // Metainfo for each module
446
- const modulesWithInfo = this._orderedConcatenationList.map((info, idx) => {
447
- switch (info.type) {
448
- case "concatenated": {
449
- const exportMap = new Map();
450
- const reexportMap = new Map();
451
- for (const dep of info.module.dependencies) {
452
- if (dep instanceof HarmonyExportSpecifierDependency) {
453
- if (!exportMap.has(dep.name)) exportMap.set(dep.name, dep.id);
454
- } else if (dep instanceof HarmonyExportExpressionDependency) {
455
- if (!exportMap.has("default"))
456
- exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__");
457
- } else if (
458
- dep instanceof HarmonyExportImportedSpecifierDependency
459
- ) {
460
- const exportName = dep.name;
461
- const importName = dep.id;
462
- const importedModule = dep.module;
463
- if (exportName && importName) {
464
- if (!reexportMap.has(exportName)) {
465
- reexportMap.set(exportName, {
466
- module: importedModule,
467
- exportName: importName,
468
- dependency: dep
469
- });
470
- }
471
- } else if (exportName) {
472
- if (!reexportMap.has(exportName)) {
473
- reexportMap.set(exportName, {
474
- module: importedModule,
475
- exportName: true,
476
- dependency: dep
477
- });
478
- }
479
- } else if (importedModule) {
480
- for (const name of importedModule.buildMeta.providedExports) {
481
- if (dep.activeExports.has(name) || name === "default")
482
- continue;
483
- if (!reexportMap.has(name)) {
484
- reexportMap.set(name, {
485
- module: importedModule,
486
- exportName: name,
487
- dependency: dep
488
- });
489
- }
490
- }
491
- }
492
- }
493
- }
494
- return {
495
- type: "concatenated",
496
- module: info.module,
497
- index: idx,
498
- ast: undefined,
499
- internalSource: undefined,
500
- source: undefined,
501
- globalScope: undefined,
502
- moduleScope: undefined,
503
- internalNames: new Map(),
504
- exportMap: exportMap,
505
- reexportMap: reexportMap,
506
- hasNamespaceObject: false,
507
- namespaceObjectSource: null
508
- };
509
- }
510
- case "external":
511
- return {
512
- type: "external",
513
- module: info.module,
514
- index: idx,
515
- name: undefined,
516
- interopNamespaceObjectUsed: false,
517
- interopNamespaceObjectName: undefined,
518
- interopDefaultAccessUsed: false,
519
- interopDefaultAccessName: undefined
520
- };
521
- default:
522
- throw new Error(`Unsupported concatenation entry type ${info.type}`);
523
- }
524
- });
525
-
526
- // Create mapping from module to info
527
- const moduleToInfoMap = new Map();
528
- for (const m of modulesWithInfo) {
529
- moduleToInfoMap.set(m.module, m);
530
- }
531
-
532
- // Configure template decorators for dependencies
533
- const innerDependencyTemplates = new Map(dependencyTemplates);
534
-
535
- innerDependencyTemplates.set(
536
- HarmonyImportSpecifierDependency,
537
- new HarmonyImportSpecifierDependencyConcatenatedTemplate(
538
- dependencyTemplates.get(HarmonyImportSpecifierDependency),
539
- moduleToInfoMap
540
- )
541
- );
542
- innerDependencyTemplates.set(
543
- HarmonyImportSideEffectDependency,
544
- new HarmonyImportSideEffectDependencyConcatenatedTemplate(
545
- dependencyTemplates.get(HarmonyImportSideEffectDependency),
546
- moduleToInfoMap
547
- )
548
- );
549
- innerDependencyTemplates.set(
550
- HarmonyExportSpecifierDependency,
551
- new HarmonyExportSpecifierDependencyConcatenatedTemplate(
552
- dependencyTemplates.get(HarmonyExportSpecifierDependency),
553
- this.rootModule
554
- )
555
- );
556
- innerDependencyTemplates.set(
557
- HarmonyExportExpressionDependency,
558
- new HarmonyExportExpressionDependencyConcatenatedTemplate(
559
- dependencyTemplates.get(HarmonyExportExpressionDependency),
560
- this.rootModule
561
- )
562
- );
563
- innerDependencyTemplates.set(
564
- HarmonyExportImportedSpecifierDependency,
565
- new HarmonyExportImportedSpecifierDependencyConcatenatedTemplate(
566
- dependencyTemplates.get(HarmonyExportImportedSpecifierDependency),
567
- this.rootModule,
568
- moduleToInfoMap
569
- )
570
- );
571
- innerDependencyTemplates.set(
572
- HarmonyCompatibilityDependency,
573
- new HarmonyCompatibilityDependencyConcatenatedTemplate(
574
- dependencyTemplates.get(HarmonyCompatibilityDependency),
575
- this.rootModule,
576
- moduleToInfoMap
577
- )
578
- );
579
-
580
- // Must use full identifier in our cache here to ensure that the source
581
- // is updated should our dependencies list change.
582
- innerDependencyTemplates.set(
583
- "hash",
584
- innerDependencyTemplates.get("hash") + this.identifier()
585
- );
586
-
587
- // Generate source code and analyse scopes
588
- // Prepare a ReplaceSource for the final source
589
- for (const info of modulesWithInfo) {
590
- if (info.type === "concatenated") {
591
- const m = info.module;
592
- const source = m.source(innerDependencyTemplates, runtimeTemplate);
593
- const code = source.source();
594
- let ast;
595
- try {
596
- ast = Parser.parse(code, {
597
- sourceType: "module"
598
- });
599
- } catch (err) {
600
- if (
601
- err.loc &&
602
- typeof err.loc === "object" &&
603
- typeof err.loc.line === "number"
604
- ) {
605
- const lineNumber = err.loc.line;
606
- const lines = code.split("\n");
607
- err.message +=
608
- "\n| " +
609
- lines
610
- .slice(Math.max(0, lineNumber - 3), lineNumber + 2)
611
- .join("\n| ");
612
- }
613
- throw err;
614
- }
615
- const scopeManager = eslintScope.analyze(ast, {
616
- ecmaVersion: 6,
617
- sourceType: "module",
618
- optimistic: true,
619
- ignoreEval: true,
620
- impliedStrict: true
621
- });
622
- const globalScope = scopeManager.acquire(ast);
623
- const moduleScope = globalScope.childScopes[0];
624
- const resultSource = new ReplaceSource(source);
625
- info.ast = ast;
626
- info.internalSource = source;
627
- info.source = resultSource;
628
- info.globalScope = globalScope;
629
- info.moduleScope = moduleScope;
630
- }
631
- }
632
-
633
- // List of all used names to avoid conflicts
634
- const allUsedNames = new Set([
635
- "__WEBPACK_MODULE_DEFAULT_EXPORT__", // avoid using this internal name
636
-
637
- "abstract",
638
- "arguments",
639
- "async",
640
- "await",
641
- "boolean",
642
- "break",
643
- "byte",
644
- "case",
645
- "catch",
646
- "char",
647
- "class",
648
- "const",
649
- "continue",
650
- "debugger",
651
- "default",
652
- "delete",
653
- "do",
654
- "double",
655
- "else",
656
- "enum",
657
- "eval",
658
- "export",
659
- "extends",
660
- "false",
661
- "final",
662
- "finally",
663
- "float",
664
- "for",
665
- "function",
666
- "goto",
667
- "if",
668
- "implements",
669
- "import",
670
- "in",
671
- "instanceof",
672
- "int",
673
- "interface",
674
- "let",
675
- "long",
676
- "native",
677
- "new",
678
- "null",
679
- "package",
680
- "private",
681
- "protected",
682
- "public",
683
- "return",
684
- "short",
685
- "static",
686
- "super",
687
- "switch",
688
- "synchronized",
689
- "this",
690
- "throw",
691
- "throws",
692
- "transient",
693
- "true",
694
- "try",
695
- "typeof",
696
- "var",
697
- "void",
698
- "volatile",
699
- "while",
700
- "with",
701
- "yield",
702
-
703
- "module",
704
- "__dirname",
705
- "__filename",
706
- "exports",
707
-
708
- "Array",
709
- "Date",
710
- "eval",
711
- "function",
712
- "hasOwnProperty",
713
- "Infinity",
714
- "isFinite",
715
- "isNaN",
716
- "isPrototypeOf",
717
- "length",
718
- "Math",
719
- "NaN",
720
- "name",
721
- "Number",
722
- "Object",
723
- "prototype",
724
- "String",
725
- "toString",
726
- "undefined",
727
- "valueOf",
728
-
729
- "alert",
730
- "all",
731
- "anchor",
732
- "anchors",
733
- "area",
734
- "assign",
735
- "blur",
736
- "button",
737
- "checkbox",
738
- "clearInterval",
739
- "clearTimeout",
740
- "clientInformation",
741
- "close",
742
- "closed",
743
- "confirm",
744
- "constructor",
745
- "crypto",
746
- "decodeURI",
747
- "decodeURIComponent",
748
- "defaultStatus",
749
- "document",
750
- "element",
751
- "elements",
752
- "embed",
753
- "embeds",
754
- "encodeURI",
755
- "encodeURIComponent",
756
- "escape",
757
- "event",
758
- "fileUpload",
759
- "focus",
760
- "form",
761
- "forms",
762
- "frame",
763
- "innerHeight",
764
- "innerWidth",
765
- "layer",
766
- "layers",
767
- "link",
768
- "location",
769
- "mimeTypes",
770
- "navigate",
771
- "navigator",
772
- "frames",
773
- "frameRate",
774
- "hidden",
775
- "history",
776
- "image",
777
- "images",
778
- "offscreenBuffering",
779
- "open",
780
- "opener",
781
- "option",
782
- "outerHeight",
783
- "outerWidth",
784
- "packages",
785
- "pageXOffset",
786
- "pageYOffset",
787
- "parent",
788
- "parseFloat",
789
- "parseInt",
790
- "password",
791
- "pkcs11",
792
- "plugin",
793
- "prompt",
794
- "propertyIsEnum",
795
- "radio",
796
- "reset",
797
- "screenX",
798
- "screenY",
799
- "scroll",
800
- "secure",
801
- "select",
802
- "self",
803
- "setInterval",
804
- "setTimeout",
805
- "status",
806
- "submit",
807
- "taint",
808
- "text",
809
- "textarea",
810
- "top",
811
- "unescape",
812
- "untaint",
813
- "window",
814
-
815
- "onblur",
816
- "onclick",
817
- "onerror",
818
- "onfocus",
819
- "onkeydown",
820
- "onkeypress",
821
- "onkeyup",
822
- "onmouseover",
823
- "onload",
824
- "onmouseup",
825
- "onmousedown",
826
- "onsubmit"
827
- ]);
828
-
829
- // Set of already checked scopes
830
- const alreadyCheckedScopes = new Set();
831
-
832
- // get all global names
833
- for (const info of modulesWithInfo) {
834
- const superClassExpressions = [];
835
-
836
- // ignore symbols from moduleScope
837
- if (info.moduleScope) {
838
- alreadyCheckedScopes.add(info.moduleScope);
839
-
840
- // The super class expression in class scopes behaves weird
841
- // We store ranges of all super class expressions to make
842
- // renaming to work correctly
843
- for (const childScope of info.moduleScope.childScopes) {
844
- if (childScope.type !== "class") continue;
845
- if (!childScope.block.superClass) continue;
846
- superClassExpressions.push({
847
- range: childScope.block.superClass.range,
848
- variables: childScope.variables
849
- });
850
- }
851
- }
852
-
853
- // add global symbols
854
- if (info.globalScope) {
855
- for (const reference of info.globalScope.through) {
856
- const name = reference.identifier.name;
857
- if (
858
- /^__WEBPACK_MODULE_REFERENCE__\d+_([\da-f]+|ns)(_call)?(_strict)?__$/.test(
859
- name
860
- )
861
- ) {
862
- for (const expr of superClassExpressions) {
863
- if (
864
- expr.range[0] <= reference.identifier.range[0] &&
865
- expr.range[1] >= reference.identifier.range[1]
866
- ) {
867
- for (const variable of expr.variables) {
868
- allUsedNames.add(variable.name);
869
- }
870
- }
871
- }
872
- addScopeSymbols1(
873
- reference.from,
874
- allUsedNames,
875
- alreadyCheckedScopes
876
- );
877
- } else {
878
- allUsedNames.add(name);
879
- }
880
- }
881
- }
882
- }
883
-
884
- // generate names for symbols
885
- for (const info of modulesWithInfo) {
886
- switch (info.type) {
887
- case "concatenated": {
888
- const namespaceObjectName = this.findNewName(
889
- "namespaceObject",
890
- allUsedNames,
891
- null,
892
- info.module.readableIdentifier(requestShortener)
893
- );
894
- allUsedNames.add(namespaceObjectName);
895
- info.internalNames.set(namespaceObjectName, namespaceObjectName);
896
- info.exportMap.set(true, namespaceObjectName);
897
- for (const variable of info.moduleScope.variables) {
898
- const name = variable.name;
899
- if (allUsedNames.has(name)) {
900
- const references = getAllReferences(variable);
901
- const symbolsInReferences = new Set();
902
- const alreadyCheckedInnerScopes = new Set();
903
- for (const ref of references) {
904
- addScopeSymbols2(
905
- ref.from,
906
- symbolsInReferences,
907
- alreadyCheckedInnerScopes,
908
- alreadyCheckedScopes
909
- );
910
- }
911
- const newName = this.findNewName(
912
- name,
913
- allUsedNames,
914
- symbolsInReferences,
915
- info.module.readableIdentifier(requestShortener)
916
- );
917
- allUsedNames.add(newName);
918
- info.internalNames.set(name, newName);
919
- const source = info.source;
920
- const allIdentifiers = new Set(
921
- references.map(r => r.identifier).concat(variable.identifiers)
922
- );
923
- for (const identifier of allIdentifiers) {
924
- const r = identifier.range;
925
- const path = getPathInAst(info.ast, identifier);
926
- if (
927
- path &&
928
- path.length > 1 &&
929
- path[1].type === "Property" &&
930
- path[1].shorthand
931
- ) {
932
- source.insert(r[1], `: ${newName}`);
933
- } else {
934
- source.replace(r[0], r[1] - 1, newName);
935
- }
936
- }
937
- } else {
938
- allUsedNames.add(name);
939
- info.internalNames.set(name, name);
940
- }
941
- }
942
- break;
943
- }
944
- case "external": {
945
- const externalName = this.findNewName(
946
- "",
947
- allUsedNames,
948
- null,
949
- info.module.readableIdentifier(requestShortener)
950
- );
951
- allUsedNames.add(externalName);
952
- info.name = externalName;
953
- if (
954
- info.module.buildMeta.exportsType === "named" ||
955
- !info.module.buildMeta.exportsType
956
- ) {
957
- const externalNameInterop = this.findNewName(
958
- "namespaceObject",
959
- allUsedNames,
960
- null,
961
- info.module.readableIdentifier(requestShortener)
962
- );
963
- allUsedNames.add(externalNameInterop);
964
- info.interopNamespaceObjectName = externalNameInterop;
965
- }
966
- if (!info.module.buildMeta.exportsType) {
967
- const externalNameInterop = this.findNewName(
968
- "default",
969
- allUsedNames,
970
- null,
971
- info.module.readableIdentifier(requestShortener)
972
- );
973
- allUsedNames.add(externalNameInterop);
974
- info.interopDefaultAccessName = externalNameInterop;
975
- }
976
- break;
977
- }
978
- }
979
- }
980
-
981
- // Find and replace referenced to modules
982
- for (const info of modulesWithInfo) {
983
- if (info.type === "concatenated") {
984
- for (const reference of info.globalScope.through) {
985
- const name = reference.identifier.name;
986
- const match = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_strict)?__$/.exec(
987
- name
988
- );
989
- if (match) {
990
- const referencedModule = modulesWithInfo[+match[1]];
991
- let exportName;
992
- if (match[2] === "ns") {
993
- exportName = true;
994
- } else {
995
- const exportData = match[2];
996
- exportName = Buffer.from(exportData, "hex").toString("utf-8");
997
- }
998
- const asCall = !!match[3];
999
- const strictHarmonyModule = !!match[4];
1000
- const finalName = getFinalName(
1001
- referencedModule,
1002
- exportName,
1003
- moduleToInfoMap,
1004
- requestShortener,
1005
- asCall,
1006
- strictHarmonyModule
1007
- );
1008
- const r = reference.identifier.range;
1009
- const source = info.source;
1010
- source.replace(r[0], r[1] - 1, finalName);
1011
- }
1012
- }
1013
- }
1014
- }
1015
-
1016
- const result = new ConcatSource();
1017
-
1018
- // add harmony compatibility flag (must be first because of possible circular dependencies)
1019
- const usedExports = this.rootModule.usedExports;
1020
- if (usedExports === true) {
1021
- result.add(
1022
- runtimeTemplate.defineEsModuleFlagStatement({
1023
- exportsArgument: this.exportsArgument
1024
- })
1025
- );
1026
- }
1027
-
1028
- // define required namespace objects (must be before evaluation modules)
1029
- for (const info of modulesWithInfo) {
1030
- if (info.namespaceObjectSource) {
1031
- result.add(info.namespaceObjectSource);
1032
- }
1033
- }
1034
-
1035
- // evaluate modules in order
1036
- for (const info of modulesWithInfo) {
1037
- switch (info.type) {
1038
- case "concatenated":
1039
- result.add(
1040
- `\n// CONCATENATED MODULE: ${info.module.readableIdentifier(
1041
- requestShortener
1042
- )}\n`
1043
- );
1044
- result.add(info.source);
1045
- break;
1046
- case "external":
1047
- result.add(
1048
- `\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
1049
- requestShortener
1050
- )}\n`
1051
- );
1052
- result.add(
1053
- `var ${info.name} = __webpack_require__(${JSON.stringify(
1054
- info.module.id
1055
- )});\n`
1056
- );
1057
- if (info.interopNamespaceObjectUsed) {
1058
- if (info.module.buildMeta.exportsType === "named") {
1059
- result.add(
1060
- `var ${
1061
- info.interopNamespaceObjectName
1062
- } = /*#__PURE__*/Object.assign({ /* fake namespace object */ }, ${
1063
- info.name
1064
- }, { "default": ${info.name} });\n`
1065
- );
1066
- } else if (!info.module.buildMeta.exportsType) {
1067
- result.add(
1068
- `var ${
1069
- info.interopNamespaceObjectName
1070
- } = /*#__PURE__*/{ /* fake namespace object */ "default": ${
1071
- info.name
1072
- } };\n`
1073
- );
1074
- }
1075
- }
1076
- if (info.interopDefaultAccessUsed) {
1077
- result.add(
1078
- `var ${
1079
- info.interopDefaultAccessName
1080
- } = /*#__PURE__*/__webpack_require__.n(${info.name});\n`
1081
- );
1082
- }
1083
- break;
1084
- default:
1085
- throw new Error(`Unsupported concatenation entry type ${info.type}`);
1086
- }
1087
- }
1088
-
1089
- return result;
1090
- }
1091
-
1092
- findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
1093
- let name = oldName;
1094
-
1095
- if (name === "__WEBPACK_MODULE_DEFAULT_EXPORT__") name = "";
1096
-
1097
- // Remove uncool stuff
1098
- extraInfo = extraInfo.replace(
1099
- /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
1100
- ""
1101
- );
1102
-
1103
- const splittedInfo = extraInfo.split("/");
1104
- while (splittedInfo.length) {
1105
- name = splittedInfo.pop() + (name ? "_" + name : "");
1106
- const nameIdent = Template.toIdentifier(name);
1107
- if (
1108
- !usedNamed1.has(nameIdent) &&
1109
- (!usedNamed2 || !usedNamed2.has(nameIdent))
1110
- )
1111
- return nameIdent;
1112
- }
1113
-
1114
- let i = 0;
1115
- let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
1116
- while (
1117
- usedNamed1.has(nameWithNumber) ||
1118
- (usedNamed2 && usedNamed2.has(nameWithNumber))
1119
- ) {
1120
- i++;
1121
- nameWithNumber = Template.toIdentifier(`${name}_${i}`);
1122
- }
1123
- return nameWithNumber;
1124
- }
1125
-
1126
- updateHash(hash) {
1127
- for (const info of this._orderedConcatenationList) {
1128
- switch (info.type) {
1129
- case "concatenated":
1130
- info.module.updateHash(hash);
1131
- break;
1132
- case "external":
1133
- hash.update(`${info.module.id}`);
1134
- break;
1135
- }
1136
- }
1137
- super.updateHash(hash);
1138
- }
1139
- }
1140
-
1141
- class HarmonyImportSpecifierDependencyConcatenatedTemplate {
1142
- constructor(originalTemplate, modulesMap) {
1143
- this.originalTemplate = originalTemplate;
1144
- this.modulesMap = modulesMap;
1145
- }
1146
-
1147
- getHarmonyInitOrder(dep) {
1148
- const module = dep.module;
1149
- const info = this.modulesMap.get(module);
1150
- if (!info) {
1151
- return this.originalTemplate.getHarmonyInitOrder(dep);
1152
- }
1153
- return NaN;
1154
- }
1155
-
1156
- harmonyInit(dep, source, runtimeTemplate, dependencyTemplates) {
1157
- const module = dep.module;
1158
- const info = this.modulesMap.get(module);
1159
- if (!info) {
1160
- this.originalTemplate.harmonyInit(
1161
- dep,
1162
- source,
1163
- runtimeTemplate,
1164
- dependencyTemplates
1165
- );
1166
- return;
1167
- }
1168
- }
1169
-
1170
- apply(dep, source, runtime, dependencyTemplates) {
1171
- const module = dep.module;
1172
- const info = this.modulesMap.get(module);
1173
- if (!info) {
1174
- this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1175
- return;
1176
- }
1177
- let content;
1178
- const callFlag = dep.call ? "_call" : "";
1179
- const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
1180
- ? "_strict"
1181
- : "";
1182
- if (dep.id === null) {
1183
- content = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
1184
- } else if (dep.namespaceObjectAsContext) {
1185
- content = `__WEBPACK_MODULE_REFERENCE__${
1186
- info.index
1187
- }_ns${strictFlag}__[${JSON.stringify(dep.id)}]`;
1188
- } else {
1189
- const exportData = Buffer.from(dep.id, "utf-8").toString("hex");
1190
- content = `__WEBPACK_MODULE_REFERENCE__${
1191
- info.index
1192
- }_${exportData}${callFlag}${strictFlag}__`;
1193
- }
1194
- if (dep.shorthand) {
1195
- content = dep.name + ": " + content;
1196
- }
1197
- source.replace(dep.range[0], dep.range[1] - 1, content);
1198
- }
1199
- }
1200
-
1201
- class HarmonyImportSideEffectDependencyConcatenatedTemplate {
1202
- constructor(originalTemplate, modulesMap) {
1203
- this.originalTemplate = originalTemplate;
1204
- this.modulesMap = modulesMap;
1205
- }
1206
-
1207
- getHarmonyInitOrder(dep) {
1208
- const module = dep.module;
1209
- const info = this.modulesMap.get(module);
1210
- if (!info) {
1211
- return this.originalTemplate.getHarmonyInitOrder(dep);
1212
- }
1213
- return NaN;
1214
- }
1215
-
1216
- harmonyInit(dep, source, runtime, dependencyTemplates) {
1217
- const module = dep.module;
1218
- const info = this.modulesMap.get(module);
1219
- if (!info) {
1220
- this.originalTemplate.harmonyInit(
1221
- dep,
1222
- source,
1223
- runtime,
1224
- dependencyTemplates
1225
- );
1226
- return;
1227
- }
1228
- }
1229
-
1230
- apply(dep, source, runtime, dependencyTemplates) {
1231
- const module = dep.module;
1232
- const info = this.modulesMap.get(module);
1233
- if (!info) {
1234
- this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1235
- return;
1236
- }
1237
- }
1238
- }
1239
-
1240
- class HarmonyExportSpecifierDependencyConcatenatedTemplate {
1241
- constructor(originalTemplate, rootModule) {
1242
- this.originalTemplate = originalTemplate;
1243
- this.rootModule = rootModule;
1244
- }
1245
-
1246
- getHarmonyInitOrder(dep) {
1247
- if (dep.originModule === this.rootModule) {
1248
- return this.originalTemplate.getHarmonyInitOrder(dep);
1249
- }
1250
- return NaN;
1251
- }
1252
-
1253
- harmonyInit(dep, source, runtime, dependencyTemplates) {
1254
- if (dep.originModule === this.rootModule) {
1255
- this.originalTemplate.harmonyInit(
1256
- dep,
1257
- source,
1258
- runtime,
1259
- dependencyTemplates
1260
- );
1261
- return;
1262
- }
1263
- }
1264
-
1265
- apply(dep, source, runtime, dependencyTemplates) {
1266
- if (dep.originModule === this.rootModule) {
1267
- this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1268
- }
1269
- }
1270
- }
1271
-
1272
- class HarmonyExportExpressionDependencyConcatenatedTemplate {
1273
- constructor(originalTemplate, rootModule) {
1274
- this.originalTemplate = originalTemplate;
1275
- this.rootModule = rootModule;
1276
- }
1277
-
1278
- apply(dep, source, runtime, dependencyTemplates) {
1279
- let content =
1280
- "/* harmony default export */ var __WEBPACK_MODULE_DEFAULT_EXPORT__ = ";
1281
- if (dep.originModule === this.rootModule) {
1282
- const used = dep.originModule.isUsed("default");
1283
- const exportsName = dep.originModule.exportsArgument;
1284
- if (used) content += `${exportsName}[${JSON.stringify(used)}] = `;
1285
- }
1286
-
1287
- if (dep.range) {
1288
- source.replace(dep.rangeStatement[0], dep.range[0] - 1, content + "(");
1289
- source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");");
1290
- return;
1291
- }
1292
-
1293
- source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content);
1294
- }
1295
- }
1296
-
1297
- class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
1298
- constructor(originalTemplate, rootModule, modulesMap) {
1299
- this.originalTemplate = originalTemplate;
1300
- this.rootModule = rootModule;
1301
- this.modulesMap = modulesMap;
1302
- }
1303
-
1304
- getExports(dep) {
1305
- const importModule = dep.module;
1306
- if (dep.id) {
1307
- // export { named } from "module"
1308
- return [
1309
- {
1310
- name: dep.name,
1311
- id: dep.id,
1312
- module: importModule
1313
- }
1314
- ];
1315
- }
1316
- if (dep.name) {
1317
- // export * as abc from "module"
1318
- return [
1319
- {
1320
- name: dep.name,
1321
- id: true,
1322
- module: importModule
1323
- }
1324
- ];
1325
- }
1326
- // export * from "module"
1327
- return importModule.buildMeta.providedExports
1328
- .filter(exp => exp !== "default" && !dep.activeExports.has(exp))
1329
- .map(exp => {
1330
- return {
1331
- name: exp,
1332
- id: exp,
1333
- module: importModule
1334
- };
1335
- });
1336
- }
1337
-
1338
- getHarmonyInitOrder(dep) {
1339
- const module = dep.module;
1340
- const info = this.modulesMap.get(module);
1341
- if (!info) {
1342
- return this.originalTemplate.getHarmonyInitOrder(dep);
1343
- }
1344
- return NaN;
1345
- }
1346
-
1347
- harmonyInit(dep, source, runtime, dependencyTemplates) {
1348
- const module = dep.module;
1349
- const info = this.modulesMap.get(module);
1350
- if (!info) {
1351
- this.originalTemplate.harmonyInit(
1352
- dep,
1353
- source,
1354
- runtime,
1355
- dependencyTemplates
1356
- );
1357
- return;
1358
- }
1359
- }
1360
-
1361
- apply(dep, source, runtime, dependencyTemplates) {
1362
- if (dep.originModule === this.rootModule) {
1363
- if (this.modulesMap.get(dep.module)) {
1364
- const exportDefs = this.getExports(dep);
1365
- for (const def of exportDefs) {
1366
- const info = this.modulesMap.get(def.module);
1367
- const used = dep.originModule.isUsed(def.name);
1368
- if (!used) {
1369
- source.insert(
1370
- -1,
1371
- `/* unused concated harmony import ${dep.name} */\n`
1372
- );
1373
- }
1374
- let finalName;
1375
- const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
1376
- ? "_strict"
1377
- : "";
1378
- if (def.id === true) {
1379
- finalName = `__WEBPACK_MODULE_REFERENCE__${
1380
- info.index
1381
- }_ns${strictFlag}__`;
1382
- } else {
1383
- const exportData = Buffer.from(def.id, "utf-8").toString("hex");
1384
- finalName = `__WEBPACK_MODULE_REFERENCE__${
1385
- info.index
1386
- }_${exportData}${strictFlag}__`;
1387
- }
1388
- const exportsName = this.rootModule.exportsArgument;
1389
- const content = `/* concated harmony reexport */__webpack_require__.d(${exportsName}, ${JSON.stringify(
1390
- used
1391
- )}, function() { return ${finalName}; });\n`;
1392
- source.insert(-1, content);
1393
- }
1394
- } else {
1395
- this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1396
- }
1397
- }
1398
- }
1399
- }
1400
-
1401
- class HarmonyCompatibilityDependencyConcatenatedTemplate {
1402
- constructor(originalTemplate, rootModule, modulesMap) {
1403
- this.originalTemplate = originalTemplate;
1404
- this.rootModule = rootModule;
1405
- this.modulesMap = modulesMap;
1406
- }
1407
-
1408
- apply(dep, source, runtime, dependencyTemplates) {
1409
- // do nothing
1410
- }
1411
- }
1412
-
1413
- module.exports = ConcatenatedModule;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const Module = require("../Module");
8
+ const Template = require("../Template");
9
+ const Parser = require("../Parser");
10
+ const eslintScope = require("eslint-scope");
11
+ const { ConcatSource, ReplaceSource } = require("webpack-sources");
12
+ const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
13
+ const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
14
+ const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
15
+ const HarmonyExportSpecifierDependency = require("../dependencies/HarmonyExportSpecifierDependency");
16
+ const HarmonyExportExpressionDependency = require("../dependencies/HarmonyExportExpressionDependency");
17
+ const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
18
+ const HarmonyCompatibilityDependency = require("../dependencies/HarmonyCompatibilityDependency");
19
+ const createHash = require("../util/createHash");
20
+
21
+ const ensureNsObjSource = (
22
+ info,
23
+ moduleToInfoMap,
24
+ requestShortener,
25
+ strictHarmonyModule
26
+ ) => {
27
+ if (!info.hasNamespaceObject) {
28
+ info.hasNamespaceObject = true;
29
+ const name = info.exportMap.get(true);
30
+ const nsObj = [`var ${name} = {};`, `__webpack_require__.r(${name});`];
31
+ for (const exportName of info.module.buildMeta.providedExports) {
32
+ const finalName = getFinalName(
33
+ info,
34
+ exportName,
35
+ moduleToInfoMap,
36
+ requestShortener,
37
+ false,
38
+ strictHarmonyModule
39
+ );
40
+ nsObj.push(
41
+ `__webpack_require__.d(${name}, ${JSON.stringify(
42
+ exportName
43
+ )}, function() { return ${finalName}; });`
44
+ );
45
+ }
46
+ info.namespaceObjectSource = nsObj.join("\n") + "\n";
47
+ }
48
+ };
49
+
50
+ const getExternalImport = (
51
+ importedModule,
52
+ info,
53
+ exportName,
54
+ asCall,
55
+ strictHarmonyModule
56
+ ) => {
57
+ const used = importedModule.isUsed(exportName);
58
+ if (!used) return "/* unused reexport */undefined";
59
+ const comment =
60
+ used !== exportName ? ` ${Template.toNormalComment(exportName)}` : "";
61
+ switch (importedModule.buildMeta.exportsType) {
62
+ case "named":
63
+ if (exportName === "default") {
64
+ return info.name;
65
+ } else if (exportName === true) {
66
+ info.interopNamespaceObjectUsed = true;
67
+ return info.interopNamespaceObjectName;
68
+ } else {
69
+ break;
70
+ }
71
+ case "namespace":
72
+ if (exportName === true) {
73
+ return info.name;
74
+ } else {
75
+ break;
76
+ }
77
+ default:
78
+ if (strictHarmonyModule) {
79
+ if (exportName === "default") {
80
+ return info.name;
81
+ } else if (exportName === true) {
82
+ info.interopNamespaceObjectUsed = true;
83
+ return info.interopNamespaceObjectName;
84
+ } else {
85
+ return "/* non-default import from non-esm module */undefined";
86
+ }
87
+ } else {
88
+ if (exportName === "default") {
89
+ info.interopDefaultAccessUsed = true;
90
+ return asCall
91
+ ? `${info.interopDefaultAccessName}()`
92
+ : `${info.interopDefaultAccessName}.a`;
93
+ } else if (exportName === true) {
94
+ return info.name;
95
+ } else {
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ const reference = `${info.name}[${JSON.stringify(used)}${comment}]`;
101
+ if (asCall) return `Object(${reference})`;
102
+ return reference;
103
+ };
104
+
105
+ const getFinalName = (
106
+ info,
107
+ exportName,
108
+ moduleToInfoMap,
109
+ requestShortener,
110
+ asCall,
111
+ strictHarmonyModule
112
+ ) => {
113
+ switch (info.type) {
114
+ case "concatenated": {
115
+ const directExport = info.exportMap.get(exportName);
116
+ if (directExport) {
117
+ if (exportName === true) {
118
+ ensureNsObjSource(
119
+ info,
120
+ moduleToInfoMap,
121
+ requestShortener,
122
+ strictHarmonyModule
123
+ );
124
+ }
125
+ const name = info.internalNames.get(directExport);
126
+ if (!name) {
127
+ throw new Error(
128
+ `The export "${directExport}" in "${info.module.readableIdentifier(
129
+ requestShortener
130
+ )}" has no internal name`
131
+ );
132
+ }
133
+ return name;
134
+ }
135
+ const reexport = info.reexportMap.get(exportName);
136
+ if (reexport) {
137
+ const refInfo = moduleToInfoMap.get(reexport.module);
138
+ if (refInfo) {
139
+ // module is in the concatenation
140
+ return getFinalName(
141
+ refInfo,
142
+ reexport.exportName,
143
+ moduleToInfoMap,
144
+ requestShortener,
145
+ asCall,
146
+ strictHarmonyModule
147
+ );
148
+ }
149
+ }
150
+ const problem =
151
+ `Cannot get final name for export "${exportName}" in "${info.module.readableIdentifier(
152
+ requestShortener
153
+ )}"` +
154
+ ` (known exports: ${Array.from(info.exportMap.keys())
155
+ .filter(name => name !== true)
156
+ .join(" ")}, ` +
157
+ `known reexports: ${Array.from(info.reexportMap.keys()).join(" ")})`;
158
+ return `${Template.toNormalComment(problem)} undefined`;
159
+ }
160
+ case "external": {
161
+ const importedModule = info.module;
162
+ return getExternalImport(
163
+ importedModule,
164
+ info,
165
+ exportName,
166
+ asCall,
167
+ strictHarmonyModule
168
+ );
169
+ }
170
+ }
171
+ };
172
+
173
+ const addScopeSymbols1 = (s, nameSet, scopeSet) => {
174
+ let scope = s;
175
+ while (scope) {
176
+ if (scopeSet.has(scope)) break;
177
+ scopeSet.add(scope);
178
+ for (const variable of scope.variables) {
179
+ nameSet.add(variable.name);
180
+ }
181
+ scope = scope.upper;
182
+ }
183
+ };
184
+
185
+ const addScopeSymbols2 = (s, nameSet, scopeSet1, scopeSet2) => {
186
+ let scope = s;
187
+ while (scope) {
188
+ if (scopeSet1.has(scope)) break;
189
+ if (scopeSet2.has(scope)) break;
190
+ scopeSet1.add(scope);
191
+ for (const variable of scope.variables) {
192
+ nameSet.add(variable.name);
193
+ }
194
+ scope = scope.upper;
195
+ }
196
+ };
197
+
198
+ const getAllReferences = variable => {
199
+ let set = variable.references;
200
+ // Look for inner scope variables too (like in class Foo { t() { Foo } })
201
+ const identifiers = new Set(variable.identifiers);
202
+ for (const scope of variable.scope.childScopes) {
203
+ for (const innerVar of scope.variables) {
204
+ if (innerVar.identifiers.some(id => identifiers.has(id))) {
205
+ set = set.concat(innerVar.references);
206
+ break;
207
+ }
208
+ }
209
+ }
210
+ return set;
211
+ };
212
+
213
+ const getPathInAst = (ast, node) => {
214
+ if (ast === node) {
215
+ return [];
216
+ }
217
+
218
+ const nr = node.range;
219
+
220
+ const enterNode = n => {
221
+ if (!n) return undefined;
222
+ const r = n.range;
223
+ if (r) {
224
+ if (r[0] <= nr[0] && r[1] >= nr[1]) {
225
+ const path = getPathInAst(n, node);
226
+ if (path) {
227
+ path.push(n);
228
+ return path;
229
+ }
230
+ }
231
+ }
232
+ return undefined;
233
+ };
234
+
235
+ var i;
236
+ if (Array.isArray(ast)) {
237
+ for (i = 0; i < ast.length; i++) {
238
+ const enterResult = enterNode(ast[i]);
239
+ if (typeof enterResult !== "undefined") return enterResult;
240
+ }
241
+ } else if (ast && typeof ast === "object") {
242
+ const keys = Object.keys(ast);
243
+ for (i = 0; i < keys.length; i++) {
244
+ const value = ast[keys[i]];
245
+ if (Array.isArray(value)) {
246
+ const pathResult = getPathInAst(value, node);
247
+ if (typeof pathResult !== "undefined") return pathResult;
248
+ } else if (value && typeof value === "object") {
249
+ const enterResult = enterNode(value);
250
+ if (typeof enterResult !== "undefined") return enterResult;
251
+ }
252
+ }
253
+ }
254
+ };
255
+
256
+ class ConcatenatedModule extends Module {
257
+ constructor(rootModule, modules) {
258
+ super("javascript/esm", null);
259
+ super.setChunks(rootModule._chunks);
260
+
261
+ // Info from Factory
262
+ this.rootModule = rootModule;
263
+
264
+ // Info from Compilation
265
+ this.index = rootModule.index;
266
+ this.index2 = rootModule.index2;
267
+ this.depth = rootModule.depth;
268
+
269
+ // Info from Optimization
270
+ this.used = rootModule.used;
271
+ this.usedExports = rootModule.usedExports;
272
+
273
+ // Info from Build
274
+ this.buildInfo = {
275
+ strict: true,
276
+ cacheable: modules.every(m => m.buildInfo.cacheable),
277
+ moduleArgument: rootModule.buildInfo.moduleArgument,
278
+ exportsArgument: rootModule.buildInfo.exportsArgument,
279
+ fileDependencies: new Set(),
280
+ contextDependencies: new Set(),
281
+ assets: undefined
282
+ };
283
+ this.built = modules.some(m => m.built);
284
+ this.buildMeta = rootModule.buildMeta;
285
+
286
+ // Caching
287
+ this._numberOfConcatenatedModules = modules.length;
288
+
289
+ // Graph
290
+ const modulesSet = new Set(modules);
291
+ this.reasons = rootModule.reasons.filter(
292
+ reason =>
293
+ !(reason.dependency instanceof HarmonyImportDependency) ||
294
+ !modulesSet.has(reason.module)
295
+ );
296
+
297
+ this.dependencies = [];
298
+
299
+ this.warnings = [];
300
+ this.errors = [];
301
+ this._orderedConcatenationList = this._createOrderedConcatenationList(
302
+ rootModule,
303
+ modulesSet
304
+ );
305
+ for (const info of this._orderedConcatenationList) {
306
+ if (info.type === "concatenated") {
307
+ const m = info.module;
308
+
309
+ // populate dependencies
310
+ for (const d of m.dependencies.filter(
311
+ dep =>
312
+ !(dep instanceof HarmonyImportDependency) ||
313
+ !modulesSet.has(dep._module)
314
+ )) {
315
+ this.dependencies.push(d);
316
+ }
317
+ // populate file dependencies
318
+ if (m.buildInfo.fileDependencies) {
319
+ for (const file of m.buildInfo.fileDependencies) {
320
+ this.buildInfo.fileDependencies.add(file);
321
+ }
322
+ }
323
+ // populate context dependencies
324
+ if (m.buildInfo.contextDependencies) {
325
+ for (const context of m.buildInfo.contextDependencies) {
326
+ this.buildInfo.contextDependencies.add(context);
327
+ }
328
+ }
329
+ // populate warnings
330
+ for (const warning of m.warnings) {
331
+ this.warnings.push(warning);
332
+ }
333
+ // populate errors
334
+ for (const error of m.errors) {
335
+ this.errors.push(error);
336
+ }
337
+
338
+ if (m.buildInfo.assets) {
339
+ if (this.buildInfo.assets === undefined) {
340
+ this.buildInfo.assets = Object.create(null);
341
+ }
342
+ Object.assign(this.buildInfo.assets, m.buildInfo.assets);
343
+ }
344
+ }
345
+ }
346
+ this._identifier = this._createIdentifier();
347
+ }
348
+
349
+ get modules() {
350
+ return this._orderedConcatenationList
351
+ .filter(info => info.type === "concatenated")
352
+ .map(info => info.module);
353
+ }
354
+
355
+ identifier() {
356
+ return this._identifier;
357
+ }
358
+
359
+ readableIdentifier(requestShortener) {
360
+ return (
361
+ this.rootModule.readableIdentifier(requestShortener) +
362
+ ` + ${this._numberOfConcatenatedModules - 1} modules`
363
+ );
364
+ }
365
+
366
+ libIdent(options) {
367
+ return this.rootModule.libIdent(options);
368
+ }
369
+
370
+ nameForCondition() {
371
+ return this.rootModule.nameForCondition();
372
+ }
373
+
374
+ build(options, compilation, resolver, fs, callback) {
375
+ throw new Error("Cannot build this module. It should be already built.");
376
+ }
377
+
378
+ size() {
379
+ // Guess size from embedded modules
380
+ return this._orderedConcatenationList.reduce((sum, info) => {
381
+ switch (info.type) {
382
+ case "concatenated":
383
+ return sum + info.module.size();
384
+ case "external":
385
+ return sum + 5;
386
+ }
387
+ return sum;
388
+ }, 0);
389
+ }
390
+
391
+ _createOrderedConcatenationList(rootModule, modulesSet) {
392
+ const list = [];
393
+ const set = new Set();
394
+
395
+ const getConcatenatedImports = module => {
396
+ return module.dependencies
397
+ .filter(dep => dep instanceof HarmonyImportDependency)
398
+ .sort((a, b) => a.sourceOrder - b.sourceOrder)
399
+ .map(dep => () => {
400
+ const ref = dep.getReference();
401
+ return ref && ref.module;
402
+ });
403
+ };
404
+
405
+ const enterModule = getModule => {
406
+ const module = getModule();
407
+ if (!module) return;
408
+ if (set.has(module)) return;
409
+ set.add(module);
410
+ if (modulesSet.has(module)) {
411
+ const imports = getConcatenatedImports(module);
412
+ imports.forEach(enterModule);
413
+ list.push({
414
+ type: "concatenated",
415
+ module
416
+ });
417
+ } else {
418
+ list.push({
419
+ type: "external",
420
+ get module() {
421
+ // We need to use a getter here, because the module in the dependency
422
+ // could be replaced by some other process (i. e. also replaced with a
423
+ // concatenated module)
424
+ return getModule();
425
+ }
426
+ });
427
+ }
428
+ };
429
+
430
+ enterModule(() => rootModule);
431
+
432
+ return list;
433
+ }
434
+
435
+ _createIdentifier() {
436
+ let orderedConcatenationListIdentifiers = "";
437
+ for (let i = 0; i < this._orderedConcatenationList.length; i++) {
438
+ if (this._orderedConcatenationList[i].type === "concatenated") {
439
+ orderedConcatenationListIdentifiers += this._orderedConcatenationList[
440
+ i
441
+ ].module.identifier();
442
+ orderedConcatenationListIdentifiers += " ";
443
+ }
444
+ }
445
+ const hash = createHash("md4");
446
+ hash.update(orderedConcatenationListIdentifiers);
447
+ return this.rootModule.identifier() + " " + hash.digest("hex");
448
+ }
449
+
450
+ source(dependencyTemplates, runtimeTemplate) {
451
+ const requestShortener = runtimeTemplate.requestShortener;
452
+ // Metainfo for each module
453
+ const modulesWithInfo = this._orderedConcatenationList.map((info, idx) => {
454
+ switch (info.type) {
455
+ case "concatenated": {
456
+ const exportMap = new Map();
457
+ const reexportMap = new Map();
458
+ for (const dep of info.module.dependencies) {
459
+ if (dep instanceof HarmonyExportSpecifierDependency) {
460
+ if (!exportMap.has(dep.name)) {
461
+ exportMap.set(dep.name, dep.id);
462
+ }
463
+ } else if (dep instanceof HarmonyExportExpressionDependency) {
464
+ if (!exportMap.has("default")) {
465
+ exportMap.set("default", "__WEBPACK_MODULE_DEFAULT_EXPORT__");
466
+ }
467
+ } else if (
468
+ dep instanceof HarmonyExportImportedSpecifierDependency
469
+ ) {
470
+ const exportName = dep.name;
471
+ const importName = dep.id;
472
+ const importedModule = dep._module;
473
+ if (exportName && importName) {
474
+ if (!reexportMap.has(exportName)) {
475
+ reexportMap.set(exportName, {
476
+ module: importedModule,
477
+ exportName: importName,
478
+ dependency: dep
479
+ });
480
+ }
481
+ } else if (exportName) {
482
+ if (!reexportMap.has(exportName)) {
483
+ reexportMap.set(exportName, {
484
+ module: importedModule,
485
+ exportName: true,
486
+ dependency: dep
487
+ });
488
+ }
489
+ } else if (importedModule) {
490
+ for (const name of importedModule.buildMeta.providedExports) {
491
+ if (dep.activeExports.has(name) || name === "default") {
492
+ continue;
493
+ }
494
+ if (!reexportMap.has(name)) {
495
+ reexportMap.set(name, {
496
+ module: importedModule,
497
+ exportName: name,
498
+ dependency: dep
499
+ });
500
+ }
501
+ }
502
+ }
503
+ }
504
+ }
505
+ return {
506
+ type: "concatenated",
507
+ module: info.module,
508
+ index: idx,
509
+ ast: undefined,
510
+ internalSource: undefined,
511
+ source: undefined,
512
+ globalScope: undefined,
513
+ moduleScope: undefined,
514
+ internalNames: new Map(),
515
+ exportMap: exportMap,
516
+ reexportMap: reexportMap,
517
+ hasNamespaceObject: false,
518
+ namespaceObjectSource: null
519
+ };
520
+ }
521
+ case "external":
522
+ return {
523
+ type: "external",
524
+ module: info.module,
525
+ index: idx,
526
+ name: undefined,
527
+ interopNamespaceObjectUsed: false,
528
+ interopNamespaceObjectName: undefined,
529
+ interopDefaultAccessUsed: false,
530
+ interopDefaultAccessName: undefined
531
+ };
532
+ default:
533
+ throw new Error(`Unsupported concatenation entry type ${info.type}`);
534
+ }
535
+ });
536
+
537
+ // Create mapping from module to info
538
+ const moduleToInfoMap = new Map();
539
+ for (const m of modulesWithInfo) {
540
+ moduleToInfoMap.set(m.module, m);
541
+ }
542
+
543
+ // Configure template decorators for dependencies
544
+ const innerDependencyTemplates = new Map(dependencyTemplates);
545
+
546
+ innerDependencyTemplates.set(
547
+ HarmonyImportSpecifierDependency,
548
+ new HarmonyImportSpecifierDependencyConcatenatedTemplate(
549
+ dependencyTemplates.get(HarmonyImportSpecifierDependency),
550
+ moduleToInfoMap
551
+ )
552
+ );
553
+ innerDependencyTemplates.set(
554
+ HarmonyImportSideEffectDependency,
555
+ new HarmonyImportSideEffectDependencyConcatenatedTemplate(
556
+ dependencyTemplates.get(HarmonyImportSideEffectDependency),
557
+ moduleToInfoMap
558
+ )
559
+ );
560
+ innerDependencyTemplates.set(
561
+ HarmonyExportSpecifierDependency,
562
+ new HarmonyExportSpecifierDependencyConcatenatedTemplate(
563
+ dependencyTemplates.get(HarmonyExportSpecifierDependency),
564
+ this.rootModule
565
+ )
566
+ );
567
+ innerDependencyTemplates.set(
568
+ HarmonyExportExpressionDependency,
569
+ new HarmonyExportExpressionDependencyConcatenatedTemplate(
570
+ dependencyTemplates.get(HarmonyExportExpressionDependency),
571
+ this.rootModule
572
+ )
573
+ );
574
+ innerDependencyTemplates.set(
575
+ HarmonyExportImportedSpecifierDependency,
576
+ new HarmonyExportImportedSpecifierDependencyConcatenatedTemplate(
577
+ dependencyTemplates.get(HarmonyExportImportedSpecifierDependency),
578
+ this.rootModule,
579
+ moduleToInfoMap
580
+ )
581
+ );
582
+ innerDependencyTemplates.set(
583
+ HarmonyCompatibilityDependency,
584
+ new HarmonyCompatibilityDependencyConcatenatedTemplate(
585
+ dependencyTemplates.get(HarmonyCompatibilityDependency),
586
+ this.rootModule,
587
+ moduleToInfoMap
588
+ )
589
+ );
590
+
591
+ // Must use full identifier in our cache here to ensure that the source
592
+ // is updated should our dependencies list change.
593
+ innerDependencyTemplates.set(
594
+ "hash",
595
+ innerDependencyTemplates.get("hash") + this.identifier()
596
+ );
597
+
598
+ // Generate source code and analyse scopes
599
+ // Prepare a ReplaceSource for the final source
600
+ for (const info of modulesWithInfo) {
601
+ if (info.type === "concatenated") {
602
+ const m = info.module;
603
+ const source = m.source(innerDependencyTemplates, runtimeTemplate);
604
+ const code = source.source();
605
+ let ast;
606
+ try {
607
+ ast = Parser.parse(code, {
608
+ sourceType: "module"
609
+ });
610
+ } catch (err) {
611
+ if (
612
+ err.loc &&
613
+ typeof err.loc === "object" &&
614
+ typeof err.loc.line === "number"
615
+ ) {
616
+ const lineNumber = err.loc.line;
617
+ const lines = code.split("\n");
618
+ err.message +=
619
+ "\n| " +
620
+ lines
621
+ .slice(Math.max(0, lineNumber - 3), lineNumber + 2)
622
+ .join("\n| ");
623
+ }
624
+ throw err;
625
+ }
626
+ const scopeManager = eslintScope.analyze(ast, {
627
+ ecmaVersion: 6,
628
+ sourceType: "module",
629
+ optimistic: true,
630
+ ignoreEval: true,
631
+ impliedStrict: true
632
+ });
633
+ const globalScope = scopeManager.acquire(ast);
634
+ const moduleScope = globalScope.childScopes[0];
635
+ const resultSource = new ReplaceSource(source);
636
+ info.ast = ast;
637
+ info.internalSource = source;
638
+ info.source = resultSource;
639
+ info.globalScope = globalScope;
640
+ info.moduleScope = moduleScope;
641
+ }
642
+ }
643
+
644
+ // List of all used names to avoid conflicts
645
+ const allUsedNames = new Set([
646
+ "__WEBPACK_MODULE_DEFAULT_EXPORT__", // avoid using this internal name
647
+
648
+ "abstract",
649
+ "arguments",
650
+ "async",
651
+ "await",
652
+ "boolean",
653
+ "break",
654
+ "byte",
655
+ "case",
656
+ "catch",
657
+ "char",
658
+ "class",
659
+ "const",
660
+ "continue",
661
+ "debugger",
662
+ "default",
663
+ "delete",
664
+ "do",
665
+ "double",
666
+ "else",
667
+ "enum",
668
+ "eval",
669
+ "export",
670
+ "extends",
671
+ "false",
672
+ "final",
673
+ "finally",
674
+ "float",
675
+ "for",
676
+ "function",
677
+ "goto",
678
+ "if",
679
+ "implements",
680
+ "import",
681
+ "in",
682
+ "instanceof",
683
+ "int",
684
+ "interface",
685
+ "let",
686
+ "long",
687
+ "native",
688
+ "new",
689
+ "null",
690
+ "package",
691
+ "private",
692
+ "protected",
693
+ "public",
694
+ "return",
695
+ "short",
696
+ "static",
697
+ "super",
698
+ "switch",
699
+ "synchronized",
700
+ "this",
701
+ "throw",
702
+ "throws",
703
+ "transient",
704
+ "true",
705
+ "try",
706
+ "typeof",
707
+ "var",
708
+ "void",
709
+ "volatile",
710
+ "while",
711
+ "with",
712
+ "yield",
713
+
714
+ "module",
715
+ "__dirname",
716
+ "__filename",
717
+ "exports",
718
+
719
+ "Array",
720
+ "Date",
721
+ "eval",
722
+ "function",
723
+ "hasOwnProperty",
724
+ "Infinity",
725
+ "isFinite",
726
+ "isNaN",
727
+ "isPrototypeOf",
728
+ "length",
729
+ "Math",
730
+ "NaN",
731
+ "name",
732
+ "Number",
733
+ "Object",
734
+ "prototype",
735
+ "String",
736
+ "toString",
737
+ "undefined",
738
+ "valueOf",
739
+
740
+ "alert",
741
+ "all",
742
+ "anchor",
743
+ "anchors",
744
+ "area",
745
+ "assign",
746
+ "blur",
747
+ "button",
748
+ "checkbox",
749
+ "clearInterval",
750
+ "clearTimeout",
751
+ "clientInformation",
752
+ "close",
753
+ "closed",
754
+ "confirm",
755
+ "constructor",
756
+ "crypto",
757
+ "decodeURI",
758
+ "decodeURIComponent",
759
+ "defaultStatus",
760
+ "document",
761
+ "element",
762
+ "elements",
763
+ "embed",
764
+ "embeds",
765
+ "encodeURI",
766
+ "encodeURIComponent",
767
+ "escape",
768
+ "event",
769
+ "fileUpload",
770
+ "focus",
771
+ "form",
772
+ "forms",
773
+ "frame",
774
+ "innerHeight",
775
+ "innerWidth",
776
+ "layer",
777
+ "layers",
778
+ "link",
779
+ "location",
780
+ "mimeTypes",
781
+ "navigate",
782
+ "navigator",
783
+ "frames",
784
+ "frameRate",
785
+ "hidden",
786
+ "history",
787
+ "image",
788
+ "images",
789
+ "offscreenBuffering",
790
+ "open",
791
+ "opener",
792
+ "option",
793
+ "outerHeight",
794
+ "outerWidth",
795
+ "packages",
796
+ "pageXOffset",
797
+ "pageYOffset",
798
+ "parent",
799
+ "parseFloat",
800
+ "parseInt",
801
+ "password",
802
+ "pkcs11",
803
+ "plugin",
804
+ "prompt",
805
+ "propertyIsEnum",
806
+ "radio",
807
+ "reset",
808
+ "screenX",
809
+ "screenY",
810
+ "scroll",
811
+ "secure",
812
+ "select",
813
+ "self",
814
+ "setInterval",
815
+ "setTimeout",
816
+ "status",
817
+ "submit",
818
+ "taint",
819
+ "text",
820
+ "textarea",
821
+ "top",
822
+ "unescape",
823
+ "untaint",
824
+ "window",
825
+
826
+ "onblur",
827
+ "onclick",
828
+ "onerror",
829
+ "onfocus",
830
+ "onkeydown",
831
+ "onkeypress",
832
+ "onkeyup",
833
+ "onmouseover",
834
+ "onload",
835
+ "onmouseup",
836
+ "onmousedown",
837
+ "onsubmit"
838
+ ]);
839
+
840
+ // Set of already checked scopes
841
+ const alreadyCheckedScopes = new Set();
842
+
843
+ // get all global names
844
+ for (const info of modulesWithInfo) {
845
+ const superClassExpressions = [];
846
+
847
+ // ignore symbols from moduleScope
848
+ if (info.moduleScope) {
849
+ alreadyCheckedScopes.add(info.moduleScope);
850
+
851
+ // The super class expression in class scopes behaves weird
852
+ // We store ranges of all super class expressions to make
853
+ // renaming to work correctly
854
+ for (const childScope of info.moduleScope.childScopes) {
855
+ if (childScope.type !== "class") continue;
856
+ if (!childScope.block.superClass) continue;
857
+ superClassExpressions.push({
858
+ range: childScope.block.superClass.range,
859
+ variables: childScope.variables
860
+ });
861
+ }
862
+ }
863
+
864
+ // add global symbols
865
+ if (info.globalScope) {
866
+ for (const reference of info.globalScope.through) {
867
+ const name = reference.identifier.name;
868
+ if (
869
+ /^__WEBPACK_MODULE_REFERENCE__\d+_([\da-f]+|ns)(_call)?(_strict)?__$/.test(
870
+ name
871
+ )
872
+ ) {
873
+ for (const expr of superClassExpressions) {
874
+ if (
875
+ expr.range[0] <= reference.identifier.range[0] &&
876
+ expr.range[1] >= reference.identifier.range[1]
877
+ ) {
878
+ for (const variable of expr.variables) {
879
+ allUsedNames.add(variable.name);
880
+ }
881
+ }
882
+ }
883
+ addScopeSymbols1(
884
+ reference.from,
885
+ allUsedNames,
886
+ alreadyCheckedScopes
887
+ );
888
+ } else {
889
+ allUsedNames.add(name);
890
+ }
891
+ }
892
+ }
893
+ }
894
+
895
+ // generate names for symbols
896
+ for (const info of modulesWithInfo) {
897
+ switch (info.type) {
898
+ case "concatenated": {
899
+ const namespaceObjectName = this.findNewName(
900
+ "namespaceObject",
901
+ allUsedNames,
902
+ null,
903
+ info.module.readableIdentifier(requestShortener)
904
+ );
905
+ allUsedNames.add(namespaceObjectName);
906
+ info.internalNames.set(namespaceObjectName, namespaceObjectName);
907
+ info.exportMap.set(true, namespaceObjectName);
908
+ for (const variable of info.moduleScope.variables) {
909
+ const name = variable.name;
910
+ if (allUsedNames.has(name)) {
911
+ const references = getAllReferences(variable);
912
+ const symbolsInReferences = new Set();
913
+ const alreadyCheckedInnerScopes = new Set();
914
+ for (const ref of references) {
915
+ addScopeSymbols2(
916
+ ref.from,
917
+ symbolsInReferences,
918
+ alreadyCheckedInnerScopes,
919
+ alreadyCheckedScopes
920
+ );
921
+ }
922
+ const newName = this.findNewName(
923
+ name,
924
+ allUsedNames,
925
+ symbolsInReferences,
926
+ info.module.readableIdentifier(requestShortener)
927
+ );
928
+ allUsedNames.add(newName);
929
+ info.internalNames.set(name, newName);
930
+ const source = info.source;
931
+ const allIdentifiers = new Set(
932
+ references.map(r => r.identifier).concat(variable.identifiers)
933
+ );
934
+ for (const identifier of allIdentifiers) {
935
+ const r = identifier.range;
936
+ const path = getPathInAst(info.ast, identifier);
937
+ if (
938
+ path &&
939
+ path.length > 1 &&
940
+ path[1].type === "Property" &&
941
+ path[1].shorthand
942
+ ) {
943
+ source.insert(r[1], `: ${newName}`);
944
+ } else {
945
+ source.replace(r[0], r[1] - 1, newName);
946
+ }
947
+ }
948
+ } else {
949
+ allUsedNames.add(name);
950
+ info.internalNames.set(name, name);
951
+ }
952
+ }
953
+ break;
954
+ }
955
+ case "external": {
956
+ const externalName = this.findNewName(
957
+ "",
958
+ allUsedNames,
959
+ null,
960
+ info.module.readableIdentifier(requestShortener)
961
+ );
962
+ allUsedNames.add(externalName);
963
+ info.name = externalName;
964
+ if (
965
+ info.module.buildMeta.exportsType === "named" ||
966
+ !info.module.buildMeta.exportsType
967
+ ) {
968
+ const externalNameInterop = this.findNewName(
969
+ "namespaceObject",
970
+ allUsedNames,
971
+ null,
972
+ info.module.readableIdentifier(requestShortener)
973
+ );
974
+ allUsedNames.add(externalNameInterop);
975
+ info.interopNamespaceObjectName = externalNameInterop;
976
+ }
977
+ if (!info.module.buildMeta.exportsType) {
978
+ const externalNameInterop = this.findNewName(
979
+ "default",
980
+ allUsedNames,
981
+ null,
982
+ info.module.readableIdentifier(requestShortener)
983
+ );
984
+ allUsedNames.add(externalNameInterop);
985
+ info.interopDefaultAccessName = externalNameInterop;
986
+ }
987
+ break;
988
+ }
989
+ }
990
+ }
991
+
992
+ // Find and replace referenced to modules
993
+ for (const info of modulesWithInfo) {
994
+ if (info.type === "concatenated") {
995
+ for (const reference of info.globalScope.through) {
996
+ const name = reference.identifier.name;
997
+ const match = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_strict)?__$/.exec(
998
+ name
999
+ );
1000
+ if (match) {
1001
+ const referencedModule = modulesWithInfo[+match[1]];
1002
+ let exportName;
1003
+ if (match[2] === "ns") {
1004
+ exportName = true;
1005
+ } else {
1006
+ const exportData = match[2];
1007
+ exportName = Buffer.from(exportData, "hex").toString("utf-8");
1008
+ }
1009
+ const asCall = !!match[3];
1010
+ const strictHarmonyModule = !!match[4];
1011
+ const finalName = getFinalName(
1012
+ referencedModule,
1013
+ exportName,
1014
+ moduleToInfoMap,
1015
+ requestShortener,
1016
+ asCall,
1017
+ strictHarmonyModule
1018
+ );
1019
+ const r = reference.identifier.range;
1020
+ const source = info.source;
1021
+ source.replace(r[0], r[1] - 1, finalName);
1022
+ }
1023
+ }
1024
+ }
1025
+ }
1026
+
1027
+ const result = new ConcatSource();
1028
+
1029
+ // add harmony compatibility flag (must be first because of possible circular dependencies)
1030
+ const usedExports = this.rootModule.usedExports;
1031
+ if (usedExports === true) {
1032
+ result.add(
1033
+ runtimeTemplate.defineEsModuleFlagStatement({
1034
+ exportsArgument: this.exportsArgument
1035
+ })
1036
+ );
1037
+ }
1038
+
1039
+ // define required namespace objects (must be before evaluation modules)
1040
+ for (const info of modulesWithInfo) {
1041
+ if (info.namespaceObjectSource) {
1042
+ result.add(info.namespaceObjectSource);
1043
+ }
1044
+ }
1045
+
1046
+ // evaluate modules in order
1047
+ for (const info of modulesWithInfo) {
1048
+ switch (info.type) {
1049
+ case "concatenated":
1050
+ result.add(
1051
+ `\n// CONCATENATED MODULE: ${info.module.readableIdentifier(
1052
+ requestShortener
1053
+ )}\n`
1054
+ );
1055
+ result.add(info.source);
1056
+ break;
1057
+ case "external":
1058
+ result.add(
1059
+ `\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
1060
+ requestShortener
1061
+ )}\n`
1062
+ );
1063
+ result.add(
1064
+ `var ${info.name} = __webpack_require__(${JSON.stringify(
1065
+ info.module.id
1066
+ )});\n`
1067
+ );
1068
+ if (info.interopNamespaceObjectUsed) {
1069
+ if (info.module.buildMeta.exportsType === "named") {
1070
+ result.add(
1071
+ `var ${
1072
+ info.interopNamespaceObjectName
1073
+ } = /*#__PURE__*/__webpack_require__.t(${info.name}, 2);\n`
1074
+ );
1075
+ } else if (!info.module.buildMeta.exportsType) {
1076
+ result.add(
1077
+ `var ${
1078
+ info.interopNamespaceObjectName
1079
+ } = /*#__PURE__*/__webpack_require__.t(${info.name});\n`
1080
+ );
1081
+ }
1082
+ }
1083
+ if (info.interopDefaultAccessUsed) {
1084
+ result.add(
1085
+ `var ${
1086
+ info.interopDefaultAccessName
1087
+ } = /*#__PURE__*/__webpack_require__.n(${info.name});\n`
1088
+ );
1089
+ }
1090
+ break;
1091
+ default:
1092
+ throw new Error(`Unsupported concatenation entry type ${info.type}`);
1093
+ }
1094
+ }
1095
+
1096
+ return result;
1097
+ }
1098
+
1099
+ findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
1100
+ let name = oldName;
1101
+
1102
+ if (name === "__WEBPACK_MODULE_DEFAULT_EXPORT__") name = "";
1103
+
1104
+ // Remove uncool stuff
1105
+ extraInfo = extraInfo.replace(
1106
+ /\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
1107
+ ""
1108
+ );
1109
+
1110
+ const splittedInfo = extraInfo.split("/");
1111
+ while (splittedInfo.length) {
1112
+ name = splittedInfo.pop() + (name ? "_" + name : "");
1113
+ const nameIdent = Template.toIdentifier(name);
1114
+ if (
1115
+ !usedNamed1.has(nameIdent) &&
1116
+ (!usedNamed2 || !usedNamed2.has(nameIdent))
1117
+ )
1118
+ return nameIdent;
1119
+ }
1120
+
1121
+ let i = 0;
1122
+ let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
1123
+ while (
1124
+ usedNamed1.has(nameWithNumber) ||
1125
+ (usedNamed2 && usedNamed2.has(nameWithNumber))
1126
+ ) {
1127
+ i++;
1128
+ nameWithNumber = Template.toIdentifier(`${name}_${i}`);
1129
+ }
1130
+ return nameWithNumber;
1131
+ }
1132
+
1133
+ updateHash(hash) {
1134
+ for (const info of this._orderedConcatenationList) {
1135
+ switch (info.type) {
1136
+ case "concatenated":
1137
+ info.module.updateHash(hash);
1138
+ break;
1139
+ case "external":
1140
+ hash.update(`${info.module.id}`);
1141
+ break;
1142
+ }
1143
+ }
1144
+ super.updateHash(hash);
1145
+ }
1146
+ }
1147
+
1148
+ class HarmonyImportSpecifierDependencyConcatenatedTemplate {
1149
+ constructor(originalTemplate, modulesMap) {
1150
+ this.originalTemplate = originalTemplate;
1151
+ this.modulesMap = modulesMap;
1152
+ }
1153
+
1154
+ getHarmonyInitOrder(dep) {
1155
+ const module = dep._module;
1156
+ const info = this.modulesMap.get(module);
1157
+ if (!info) {
1158
+ return this.originalTemplate.getHarmonyInitOrder(dep);
1159
+ }
1160
+ return NaN;
1161
+ }
1162
+
1163
+ harmonyInit(dep, source, runtimeTemplate, dependencyTemplates) {
1164
+ const module = dep._module;
1165
+ const info = this.modulesMap.get(module);
1166
+ if (!info) {
1167
+ this.originalTemplate.harmonyInit(
1168
+ dep,
1169
+ source,
1170
+ runtimeTemplate,
1171
+ dependencyTemplates
1172
+ );
1173
+ return;
1174
+ }
1175
+ }
1176
+
1177
+ apply(dep, source, runtime, dependencyTemplates) {
1178
+ const module = dep._module;
1179
+ const info = this.modulesMap.get(module);
1180
+ if (!info) {
1181
+ this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1182
+ return;
1183
+ }
1184
+ let content;
1185
+ const callFlag = dep.call ? "_call" : "";
1186
+ const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
1187
+ ? "_strict"
1188
+ : "";
1189
+ if (dep._id === null) {
1190
+ content = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
1191
+ } else if (dep.namespaceObjectAsContext) {
1192
+ content = `__WEBPACK_MODULE_REFERENCE__${
1193
+ info.index
1194
+ }_ns${strictFlag}__[${JSON.stringify(dep._id)}]`;
1195
+ } else {
1196
+ const exportData = Buffer.from(dep._id, "utf-8").toString("hex");
1197
+ content = `__WEBPACK_MODULE_REFERENCE__${
1198
+ info.index
1199
+ }_${exportData}${callFlag}${strictFlag}__`;
1200
+ }
1201
+ if (dep.shorthand) {
1202
+ content = dep.name + ": " + content;
1203
+ }
1204
+ source.replace(dep.range[0], dep.range[1] - 1, content);
1205
+ }
1206
+ }
1207
+
1208
+ class HarmonyImportSideEffectDependencyConcatenatedTemplate {
1209
+ constructor(originalTemplate, modulesMap) {
1210
+ this.originalTemplate = originalTemplate;
1211
+ this.modulesMap = modulesMap;
1212
+ }
1213
+
1214
+ getHarmonyInitOrder(dep) {
1215
+ const module = dep._module;
1216
+ const info = this.modulesMap.get(module);
1217
+ if (!info) {
1218
+ return this.originalTemplate.getHarmonyInitOrder(dep);
1219
+ }
1220
+ return NaN;
1221
+ }
1222
+
1223
+ harmonyInit(dep, source, runtime, dependencyTemplates) {
1224
+ const module = dep._module;
1225
+ const info = this.modulesMap.get(module);
1226
+ if (!info) {
1227
+ this.originalTemplate.harmonyInit(
1228
+ dep,
1229
+ source,
1230
+ runtime,
1231
+ dependencyTemplates
1232
+ );
1233
+ return;
1234
+ }
1235
+ }
1236
+
1237
+ apply(dep, source, runtime, dependencyTemplates) {
1238
+ const module = dep._module;
1239
+ const info = this.modulesMap.get(module);
1240
+ if (!info) {
1241
+ this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1242
+ return;
1243
+ }
1244
+ }
1245
+ }
1246
+
1247
+ class HarmonyExportSpecifierDependencyConcatenatedTemplate {
1248
+ constructor(originalTemplate, rootModule) {
1249
+ this.originalTemplate = originalTemplate;
1250
+ this.rootModule = rootModule;
1251
+ }
1252
+
1253
+ getHarmonyInitOrder(dep) {
1254
+ if (dep.originModule === this.rootModule) {
1255
+ return this.originalTemplate.getHarmonyInitOrder(dep);
1256
+ }
1257
+ return NaN;
1258
+ }
1259
+
1260
+ harmonyInit(dep, source, runtime, dependencyTemplates) {
1261
+ if (dep.originModule === this.rootModule) {
1262
+ this.originalTemplate.harmonyInit(
1263
+ dep,
1264
+ source,
1265
+ runtime,
1266
+ dependencyTemplates
1267
+ );
1268
+ return;
1269
+ }
1270
+ }
1271
+
1272
+ apply(dep, source, runtime, dependencyTemplates) {
1273
+ if (dep.originModule === this.rootModule) {
1274
+ this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1275
+ }
1276
+ }
1277
+ }
1278
+
1279
+ class HarmonyExportExpressionDependencyConcatenatedTemplate {
1280
+ constructor(originalTemplate, rootModule) {
1281
+ this.originalTemplate = originalTemplate;
1282
+ this.rootModule = rootModule;
1283
+ }
1284
+
1285
+ apply(dep, source, runtime, dependencyTemplates) {
1286
+ let content =
1287
+ "/* harmony default export */ var __WEBPACK_MODULE_DEFAULT_EXPORT__ = ";
1288
+ if (dep.originModule === this.rootModule) {
1289
+ const used = dep.originModule.isUsed("default");
1290
+ const exportsName = dep.originModule.exportsArgument;
1291
+ if (used) content += `${exportsName}[${JSON.stringify(used)}] = `;
1292
+ }
1293
+
1294
+ if (dep.range) {
1295
+ source.replace(dep.rangeStatement[0], dep.range[0] - 1, content + "(");
1296
+ source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");");
1297
+ return;
1298
+ }
1299
+
1300
+ source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content);
1301
+ }
1302
+ }
1303
+
1304
+ class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
1305
+ constructor(originalTemplate, rootModule, modulesMap) {
1306
+ this.originalTemplate = originalTemplate;
1307
+ this.rootModule = rootModule;
1308
+ this.modulesMap = modulesMap;
1309
+ }
1310
+
1311
+ getExports(dep) {
1312
+ const importModule = dep._module;
1313
+ if (dep.id) {
1314
+ // export { named } from "module"
1315
+ return [
1316
+ {
1317
+ name: dep.name,
1318
+ id: dep.id,
1319
+ module: importModule
1320
+ }
1321
+ ];
1322
+ }
1323
+ if (dep.name) {
1324
+ // export * as abc from "module"
1325
+ return [
1326
+ {
1327
+ name: dep.name,
1328
+ id: true,
1329
+ module: importModule
1330
+ }
1331
+ ];
1332
+ }
1333
+ // export * from "module"
1334
+ return importModule.buildMeta.providedExports
1335
+ .filter(exp => exp !== "default" && !dep.activeExports.has(exp))
1336
+ .map(exp => {
1337
+ return {
1338
+ name: exp,
1339
+ id: exp,
1340
+ module: importModule
1341
+ };
1342
+ });
1343
+ }
1344
+
1345
+ getHarmonyInitOrder(dep) {
1346
+ const module = dep._module;
1347
+ const info = this.modulesMap.get(module);
1348
+ if (!info) {
1349
+ return this.originalTemplate.getHarmonyInitOrder(dep);
1350
+ }
1351
+ return NaN;
1352
+ }
1353
+
1354
+ harmonyInit(dep, source, runtime, dependencyTemplates) {
1355
+ const module = dep._module;
1356
+ const info = this.modulesMap.get(module);
1357
+ if (!info) {
1358
+ this.originalTemplate.harmonyInit(
1359
+ dep,
1360
+ source,
1361
+ runtime,
1362
+ dependencyTemplates
1363
+ );
1364
+ return;
1365
+ }
1366
+ }
1367
+
1368
+ apply(dep, source, runtime, dependencyTemplates) {
1369
+ if (dep.originModule === this.rootModule) {
1370
+ if (this.modulesMap.get(dep._module)) {
1371
+ const exportDefs = this.getExports(dep);
1372
+ for (const def of exportDefs) {
1373
+ const info = this.modulesMap.get(def.module);
1374
+ const used = dep.originModule.isUsed(def.name);
1375
+ if (!used) {
1376
+ source.insert(
1377
+ -1,
1378
+ `/* unused concated harmony import ${dep.name} */\n`
1379
+ );
1380
+ }
1381
+ let finalName;
1382
+ const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
1383
+ ? "_strict"
1384
+ : "";
1385
+ if (def.id === true) {
1386
+ finalName = `__WEBPACK_MODULE_REFERENCE__${
1387
+ info.index
1388
+ }_ns${strictFlag}__`;
1389
+ } else {
1390
+ const exportData = Buffer.from(def.id, "utf-8").toString("hex");
1391
+ finalName = `__WEBPACK_MODULE_REFERENCE__${
1392
+ info.index
1393
+ }_${exportData}${strictFlag}__`;
1394
+ }
1395
+ const exportsName = this.rootModule.exportsArgument;
1396
+ const content = `/* concated harmony reexport */__webpack_require__.d(${exportsName}, ${JSON.stringify(
1397
+ used
1398
+ )}, function() { return ${finalName}; });\n`;
1399
+ source.insert(-1, content);
1400
+ }
1401
+ } else {
1402
+ this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1403
+ }
1404
+ }
1405
+ }
1406
+ }
1407
+
1408
+ class HarmonyCompatibilityDependencyConcatenatedTemplate {
1409
+ constructor(originalTemplate, rootModule, modulesMap) {
1410
+ this.originalTemplate = originalTemplate;
1411
+ this.rootModule = rootModule;
1412
+ this.modulesMap = modulesMap;
1413
+ }
1414
+
1415
+ apply(dep, source, runtime, dependencyTemplates) {
1416
+ // do nothing
1417
+ }
1418
+ }
1419
+
1420
+ module.exports = ConcatenatedModule;