webpack 4.1.0 → 4.4.0

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