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,80 +1,78 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const Template = require("./Template");
8
- const Chunk = require("./Chunk");
9
- const Tapable = require("tapable").Tapable;
10
- const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
11
- const SyncHook = require("tapable").SyncHook;
12
-
13
- module.exports = class HotUpdateChunkTemplate extends Tapable {
14
- constructor(outputOptions) {
15
- super();
16
- this.outputOptions = outputOptions || {};
17
- this.hooks = {
18
- modules: new SyncWaterfallHook([
19
- "source",
20
- "modules",
21
- "removedModules",
22
- "moduleTemplate",
23
- "dependencyTemplates"
24
- ]),
25
- render: new SyncWaterfallHook([
26
- "source",
27
- "modules",
28
- "removedModules",
29
- "hash",
30
- "id",
31
- "moduleTemplate",
32
- "dependencyTemplates"
33
- ]),
34
- hash: new SyncHook(["hash"])
35
- };
36
- }
37
-
38
- render(
39
- id,
40
- modules,
41
- removedModules,
42
- hash,
43
- moduleTemplate,
44
- dependencyTemplates
45
- ) {
46
- const hotUpdateChunk = new Chunk();
47
- hotUpdateChunk.id = id;
48
- hotUpdateChunk.setModules(modules);
49
- hotUpdateChunk.removedModules = removedModules;
50
- const modulesSource = Template.renderChunkModules(
51
- hotUpdateChunk,
52
- () => true,
53
- moduleTemplate,
54
- dependencyTemplates
55
- );
56
- const core = this.hooks.modules.call(
57
- modulesSource,
58
- modules,
59
- removedModules,
60
- moduleTemplate,
61
- dependencyTemplates
62
- );
63
- const source = this.hooks.render.call(
64
- core,
65
- modules,
66
- removedModules,
67
- hash,
68
- id,
69
- moduleTemplate,
70
- dependencyTemplates
71
- );
72
- return source;
73
- }
74
-
75
- updateHash(hash) {
76
- hash.update("HotUpdateChunkTemplate");
77
- hash.update("1");
78
- this.hooks.hash.call(hash);
79
- }
80
- };
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const Template = require("./Template");
8
+ const Chunk = require("./Chunk");
9
+ const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
10
+
11
+ module.exports = class HotUpdateChunkTemplate extends Tapable {
12
+ constructor(outputOptions) {
13
+ super();
14
+ this.outputOptions = outputOptions || {};
15
+ this.hooks = {
16
+ modules: new SyncWaterfallHook([
17
+ "source",
18
+ "modules",
19
+ "removedModules",
20
+ "moduleTemplate",
21
+ "dependencyTemplates"
22
+ ]),
23
+ render: new SyncWaterfallHook([
24
+ "source",
25
+ "modules",
26
+ "removedModules",
27
+ "hash",
28
+ "id",
29
+ "moduleTemplate",
30
+ "dependencyTemplates"
31
+ ]),
32
+ hash: new SyncHook(["hash"])
33
+ };
34
+ }
35
+
36
+ render(
37
+ id,
38
+ modules,
39
+ removedModules,
40
+ hash,
41
+ moduleTemplate,
42
+ dependencyTemplates
43
+ ) {
44
+ const hotUpdateChunk = new Chunk();
45
+ hotUpdateChunk.id = id;
46
+ hotUpdateChunk.setModules(modules);
47
+ hotUpdateChunk.removedModules = removedModules;
48
+ const modulesSource = Template.renderChunkModules(
49
+ hotUpdateChunk,
50
+ m => typeof m.source === "function",
51
+ moduleTemplate,
52
+ dependencyTemplates
53
+ );
54
+ const core = this.hooks.modules.call(
55
+ modulesSource,
56
+ modules,
57
+ removedModules,
58
+ moduleTemplate,
59
+ dependencyTemplates
60
+ );
61
+ const source = this.hooks.render.call(
62
+ core,
63
+ modules,
64
+ removedModules,
65
+ hash,
66
+ id,
67
+ moduleTemplate,
68
+ dependencyTemplates
69
+ );
70
+ return source;
71
+ }
72
+
73
+ updateHash(hash) {
74
+ hash.update("HotUpdateChunkTemplate");
75
+ hash.update("1");
76
+ this.hooks.hash.call(hash);
77
+ }
78
+ };
@@ -1,229 +1,228 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const RawSource = require("webpack-sources").RawSource;
8
- const ReplaceSource = require("webpack-sources").ReplaceSource;
9
-
10
- // TODO: clean up this file
11
- // replace with newer constructs
12
-
13
- // TODO: remove DependencyVariables and replace them with something better
14
-
15
- class JavascriptGenerator {
16
- generate(module, dependencyTemplates, runtimeTemplate) {
17
- const originalSource = module.originalSource();
18
- if (!originalSource) {
19
- return new RawSource("throw new Error('No source available');");
20
- }
21
-
22
- const source = new ReplaceSource(originalSource);
23
-
24
- this.sourceBlock(
25
- module,
26
- module,
27
- [],
28
- dependencyTemplates,
29
- source,
30
- runtimeTemplate
31
- );
32
-
33
- return source;
34
- }
35
-
36
- sourceBlock(
37
- module,
38
- block,
39
- availableVars,
40
- dependencyTemplates,
41
- source,
42
- runtimeTemplate
43
- ) {
44
- for (const dependency of block.dependencies) {
45
- this.sourceDependency(
46
- dependency,
47
- dependencyTemplates,
48
- source,
49
- runtimeTemplate
50
- );
51
- }
52
-
53
- /**
54
- * Get the variables of all blocks that we need to inject.
55
- * These will contain the variable name and its expression.
56
- * The name will be added as a parameter in a IIFE the expression as its value.
57
- */
58
- const vars = block.variables.reduce((result, value) => {
59
- const variable = this.sourceVariables(
60
- value,
61
- availableVars,
62
- dependencyTemplates,
63
- runtimeTemplate
64
- );
65
-
66
- if (variable) {
67
- result.push(variable);
68
- }
69
-
70
- return result;
71
- }, []);
72
-
73
- /**
74
- * if we actually have variables
75
- * this is important as how #splitVariablesInUniqueNamedChunks works
76
- * it will always return an array in an array which would lead to a IIFE wrapper around
77
- * a module if we do this with an empty vars array.
78
- */
79
- if (vars.length > 0) {
80
- /**
81
- * Split all variables up into chunks of unique names.
82
- * e.g. imagine you have the following variable names that need to be injected:
83
- * [foo, bar, baz, foo, some, more]
84
- * we can not inject "foo" twice, therefore we just make two IIFEs like so:
85
- * (function(foo, bar, baz){
86
- * (function(foo, some, more){
87
- * ...
88
- * }(...));
89
- * }(...));
90
- *
91
- * "splitVariablesInUniqueNamedChunks" splits the variables shown above up to this:
92
- * [[foo, bar, baz], [foo, some, more]]
93
- */
94
- const injectionVariableChunks = this.splitVariablesInUniqueNamedChunks(
95
- vars
96
- );
97
-
98
- // create all the beginnings of IIFEs
99
- const functionWrapperStarts = injectionVariableChunks.map(
100
- variableChunk => {
101
- return this.variableInjectionFunctionWrapperStartCode(
102
- variableChunk.map(variable => variable.name)
103
- );
104
- }
105
- );
106
-
107
- // and all the ends
108
- const functionWrapperEnds = injectionVariableChunks.map(variableChunk => {
109
- return this.variableInjectionFunctionWrapperEndCode(
110
- module,
111
- variableChunk.map(variable => variable.expression),
112
- block
113
- );
114
- });
115
-
116
- // join them to one big string
117
- const varStartCode = functionWrapperStarts.join("");
118
-
119
- // reverse the ends first before joining them, as the last added must be the inner most
120
- const varEndCode = functionWrapperEnds.reverse().join("");
121
-
122
- // if we have anything, add it to the source
123
- if (varStartCode && varEndCode) {
124
- const start = block.range ? block.range[0] : -10;
125
- const end = block.range
126
- ? block.range[1]
127
- : module.originalSource().size() + 1;
128
- source.insert(start + 0.5, varStartCode);
129
- source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
130
- }
131
- }
132
-
133
- for (const childBlock of block.blocks) {
134
- this.sourceBlock(
135
- module,
136
- childBlock,
137
- availableVars.concat(vars),
138
- dependencyTemplates,
139
- source,
140
- runtimeTemplate
141
- );
142
- }
143
- }
144
-
145
- sourceDependency(dependency, dependencyTemplates, source, runtimeTemplate) {
146
- const template = dependencyTemplates.get(dependency.constructor);
147
- if (!template)
148
- throw new Error(
149
- "No template for dependency: " + dependency.constructor.name
150
- );
151
- template.apply(dependency, source, runtimeTemplate, dependencyTemplates);
152
- }
153
-
154
- sourceVariables(
155
- variable,
156
- availableVars,
157
- dependencyTemplates,
158
- runtimeTemplate
159
- ) {
160
- const name = variable.name;
161
- const expr = variable.expressionSource(
162
- dependencyTemplates,
163
- runtimeTemplate
164
- );
165
-
166
- if (
167
- availableVars.some(
168
- v => v.name === name && v.expression.source() === expr.source()
169
- )
170
- ) {
171
- return;
172
- }
173
- return {
174
- name: name,
175
- expression: expr
176
- };
177
- }
178
-
179
- /*
180
- * creates the start part of a IIFE around the module to inject a variable name
181
- * (function(...){ <- this part
182
- * }.call(...))
183
- */
184
- variableInjectionFunctionWrapperStartCode(varNames) {
185
- const args = varNames.join(", ");
186
- return `/* WEBPACK VAR INJECTION */(function(${args}) {`;
187
- }
188
-
189
- contextArgument(module, block) {
190
- if (this === block) {
191
- return module.exportsArgument;
192
- }
193
- return "this";
194
- }
195
-
196
- /*
197
- * creates the end part of a IIFE around the module to inject a variable name
198
- * (function(...){
199
- * }.call(...)) <- this part
200
- */
201
- variableInjectionFunctionWrapperEndCode(module, varExpressions, block) {
202
- const firstParam = this.contextArgument(module, block);
203
- const furtherParams = varExpressions.map(e => e.source()).join(", ");
204
- return `}.call(${firstParam}, ${furtherParams}))`;
205
- }
206
-
207
- splitVariablesInUniqueNamedChunks(vars) {
208
- const startState = [[]];
209
- return vars.reduce((chunks, variable) => {
210
- const current = chunks[chunks.length - 1];
211
- // check if variable with same name exists already
212
- // if so create a new chunk of variables.
213
- const variableNameAlreadyExists = current.some(
214
- v => v.name === variable.name
215
- );
216
-
217
- if (variableNameAlreadyExists) {
218
- // start new chunk with current variable
219
- chunks.push([variable]);
220
- } else {
221
- // else add it to current chunk
222
- current.push(variable);
223
- }
224
- return chunks;
225
- }, startState);
226
- }
227
- }
228
-
229
- module.exports = JavascriptGenerator;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const { RawSource, ReplaceSource } = require("webpack-sources");
8
+
9
+ // TODO: clean up this file
10
+ // replace with newer constructs
11
+
12
+ // TODO: remove DependencyVariables and replace them with something better
13
+
14
+ class JavascriptGenerator {
15
+ generate(module, dependencyTemplates, runtimeTemplate) {
16
+ const originalSource = module.originalSource();
17
+ if (!originalSource) {
18
+ return new RawSource("throw new Error('No source available');");
19
+ }
20
+
21
+ const source = new ReplaceSource(originalSource);
22
+
23
+ this.sourceBlock(
24
+ module,
25
+ module,
26
+ [],
27
+ dependencyTemplates,
28
+ source,
29
+ runtimeTemplate
30
+ );
31
+
32
+ return source;
33
+ }
34
+
35
+ sourceBlock(
36
+ module,
37
+ block,
38
+ availableVars,
39
+ dependencyTemplates,
40
+ source,
41
+ runtimeTemplate
42
+ ) {
43
+ for (const dependency of block.dependencies) {
44
+ this.sourceDependency(
45
+ dependency,
46
+ dependencyTemplates,
47
+ source,
48
+ runtimeTemplate
49
+ );
50
+ }
51
+
52
+ /**
53
+ * Get the variables of all blocks that we need to inject.
54
+ * These will contain the variable name and its expression.
55
+ * The name will be added as a parameter in a IIFE the expression as its value.
56
+ */
57
+ const vars = block.variables.reduce((result, value) => {
58
+ const variable = this.sourceVariables(
59
+ value,
60
+ availableVars,
61
+ dependencyTemplates,
62
+ runtimeTemplate
63
+ );
64
+
65
+ if (variable) {
66
+ result.push(variable);
67
+ }
68
+
69
+ return result;
70
+ }, []);
71
+
72
+ /**
73
+ * if we actually have variables
74
+ * this is important as how #splitVariablesInUniqueNamedChunks works
75
+ * it will always return an array in an array which would lead to a IIFE wrapper around
76
+ * a module if we do this with an empty vars array.
77
+ */
78
+ if (vars.length > 0) {
79
+ /**
80
+ * Split all variables up into chunks of unique names.
81
+ * e.g. imagine you have the following variable names that need to be injected:
82
+ * [foo, bar, baz, foo, some, more]
83
+ * we can not inject "foo" twice, therefore we just make two IIFEs like so:
84
+ * (function(foo, bar, baz){
85
+ * (function(foo, some, more){
86
+ *
87
+ * }(…));
88
+ * }());
89
+ *
90
+ * "splitVariablesInUniqueNamedChunks" splits the variables shown above up to this:
91
+ * [[foo, bar, baz], [foo, some, more]]
92
+ */
93
+ const injectionVariableChunks = this.splitVariablesInUniqueNamedChunks(
94
+ vars
95
+ );
96
+
97
+ // create all the beginnings of IIFEs
98
+ const functionWrapperStarts = injectionVariableChunks.map(
99
+ variableChunk => {
100
+ return this.variableInjectionFunctionWrapperStartCode(
101
+ variableChunk.map(variable => variable.name)
102
+ );
103
+ }
104
+ );
105
+
106
+ // and all the ends
107
+ const functionWrapperEnds = injectionVariableChunks.map(variableChunk => {
108
+ return this.variableInjectionFunctionWrapperEndCode(
109
+ module,
110
+ variableChunk.map(variable => variable.expression),
111
+ block
112
+ );
113
+ });
114
+
115
+ // join them to one big string
116
+ const varStartCode = functionWrapperStarts.join("");
117
+
118
+ // reverse the ends first before joining them, as the last added must be the inner most
119
+ const varEndCode = functionWrapperEnds.reverse().join("");
120
+
121
+ // if we have anything, add it to the source
122
+ if (varStartCode && varEndCode) {
123
+ const start = block.range ? block.range[0] : -10;
124
+ const end = block.range
125
+ ? block.range[1]
126
+ : module.originalSource().size() + 1;
127
+ source.insert(start + 0.5, varStartCode);
128
+ source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
129
+ }
130
+ }
131
+
132
+ for (const childBlock of block.blocks) {
133
+ this.sourceBlock(
134
+ module,
135
+ childBlock,
136
+ availableVars.concat(vars),
137
+ dependencyTemplates,
138
+ source,
139
+ runtimeTemplate
140
+ );
141
+ }
142
+ }
143
+
144
+ sourceDependency(dependency, dependencyTemplates, source, runtimeTemplate) {
145
+ const template = dependencyTemplates.get(dependency.constructor);
146
+ if (!template)
147
+ throw new Error(
148
+ "No template for dependency: " + dependency.constructor.name
149
+ );
150
+ template.apply(dependency, source, runtimeTemplate, dependencyTemplates);
151
+ }
152
+
153
+ sourceVariables(
154
+ variable,
155
+ availableVars,
156
+ dependencyTemplates,
157
+ runtimeTemplate
158
+ ) {
159
+ const name = variable.name;
160
+ const expr = variable.expressionSource(
161
+ dependencyTemplates,
162
+ runtimeTemplate
163
+ );
164
+
165
+ if (
166
+ availableVars.some(
167
+ v => v.name === name && v.expression.source() === expr.source()
168
+ )
169
+ ) {
170
+ return;
171
+ }
172
+ return {
173
+ name: name,
174
+ expression: expr
175
+ };
176
+ }
177
+
178
+ /*
179
+ * creates the start part of a IIFE around the module to inject a variable name
180
+ * (function(…){ <- this part
181
+ * }.call())
182
+ */
183
+ variableInjectionFunctionWrapperStartCode(varNames) {
184
+ const args = varNames.join(", ");
185
+ return `/* WEBPACK VAR INJECTION */(function(${args}) {`;
186
+ }
187
+
188
+ contextArgument(module, block) {
189
+ if (this === block) {
190
+ return module.exportsArgument;
191
+ }
192
+ return "this";
193
+ }
194
+
195
+ /*
196
+ * creates the end part of a IIFE around the module to inject a variable name
197
+ * (function(…){
198
+ * }.call()) <- this part
199
+ */
200
+ variableInjectionFunctionWrapperEndCode(module, varExpressions, block) {
201
+ const firstParam = this.contextArgument(module, block);
202
+ const furtherParams = varExpressions.map(e => e.source()).join(", ");
203
+ return `}.call(${firstParam}, ${furtherParams}))`;
204
+ }
205
+
206
+ splitVariablesInUniqueNamedChunks(vars) {
207
+ const startState = [[]];
208
+ return vars.reduce((chunks, variable) => {
209
+ const current = chunks[chunks.length - 1];
210
+ // check if variable with same name exists already
211
+ // if so create a new chunk of variables.
212
+ const variableNameAlreadyExists = current.some(
213
+ v => v.name === variable.name
214
+ );
215
+
216
+ if (variableNameAlreadyExists) {
217
+ // start new chunk with current variable
218
+ chunks.push([variable]);
219
+ } else {
220
+ // else add it to current chunk
221
+ current.push(variable);
222
+ }
223
+ return chunks;
224
+ }, startState);
225
+ }
226
+ }
227
+
228
+ module.exports = JavascriptGenerator;