webpack 2.2.0-rc.6 → 2.2.1

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 (68) hide show
  1. package/README.md +39 -63
  2. package/bin/webpack.js +3 -3
  3. package/buildin/harmony-module.js +0 -6
  4. package/buildin/module.js +0 -2
  5. package/lib/APIPlugin.js +2 -8
  6. package/lib/AsyncDependenciesBlock.js +46 -55
  7. package/lib/ChunkTemplate.js +25 -26
  8. package/lib/CompatibilityPlugin.js +49 -46
  9. package/lib/Compilation.js +279 -138
  10. package/lib/Compiler.js +5 -2
  11. package/lib/ConstPlugin.js +2 -6
  12. package/lib/DefinePlugin.js +9 -27
  13. package/lib/EnvironmentPlugin.js +25 -9
  14. package/lib/EvalDevToolModulePlugin.js +15 -10
  15. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +1 -1
  16. package/lib/EvalSourceMapDevToolPlugin.js +24 -18
  17. package/lib/ExtendedAPIPlugin.js +1 -6
  18. package/lib/FlagDependencyExportsPlugin.js +72 -79
  19. package/lib/FlagInitialModulesAsUsedPlugin.js +17 -13
  20. package/lib/FunctionModulePlugin.js +17 -11
  21. package/lib/HotModuleReplacementPlugin.js +3 -13
  22. package/lib/HotUpdateChunkTemplate.js +21 -22
  23. package/lib/JsonpTemplatePlugin.js +15 -11
  24. package/lib/LibManifestPlugin.js +1 -1
  25. package/lib/LoaderTargetPlugin.js +14 -10
  26. package/lib/MainTemplate.js +193 -191
  27. package/lib/MultiWatching.js +16 -14
  28. package/lib/NoEmitOnErrorsPlugin.js +14 -11
  29. package/lib/NodeStuffPlugin.js +6 -30
  30. package/lib/NormalModuleFactory.js +2 -2
  31. package/lib/NormalModuleReplacementPlugin.js +36 -31
  32. package/lib/Parser.js +11 -8
  33. package/lib/ParserHelpers.js +19 -5
  34. package/lib/ProvidePlugin.js +2 -6
  35. package/lib/RequestShortener.js +49 -47
  36. package/lib/RequireJsStuffPlugin.js +5 -20
  37. package/lib/RuleSet.js +28 -20
  38. package/lib/SourceMapDevToolPlugin.js +1 -1
  39. package/lib/Template.js +133 -132
  40. package/lib/compareLocations.js +9 -8
  41. package/lib/dependencies/AMDPlugin.js +111 -115
  42. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +157 -154
  43. package/lib/dependencies/CommonJsPlugin.js +81 -85
  44. package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +73 -75
  45. package/lib/dependencies/ContextDependencyTemplateAsId.js +21 -18
  46. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +23 -29
  47. package/lib/dependencies/CriticalDependencyWarning.js +13 -8
  48. package/lib/dependencies/{HarmonyCompatiblilityDependency.js → HarmonyCompatibilityDependency.js} +3 -3
  49. package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
  50. package/lib/dependencies/HarmonyModulesPlugin.js +51 -49
  51. package/lib/dependencies/ImportParserPlugin.js +31 -28
  52. package/lib/dependencies/ImportPlugin.js +28 -24
  53. package/lib/dependencies/LocalModule.js +17 -13
  54. package/lib/dependencies/ModuleDependencyTemplateAsId.js +15 -17
  55. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +15 -17
  56. package/lib/dependencies/RequireContextPlugin.js +59 -57
  57. package/lib/dependencies/RequireEnsurePlugin.js +22 -26
  58. package/lib/dependencies/RequireIncludePlugin.js +18 -23
  59. package/lib/dependencies/RequireResolveDependencyParserPlugin.js +59 -56
  60. package/lib/dependencies/SystemPlugin.js +34 -36
  61. package/lib/dependencies/WebpackMissingModule.js +10 -18
  62. package/lib/node/NodeTargetPlugin.js +8 -5
  63. package/lib/node/NodeWatchFileSystem.js +54 -53
  64. package/lib/optimize/CommonsChunkPlugin.js +163 -166
  65. package/lib/optimize/RemoveParentModulesPlugin.js +36 -27
  66. package/lib/validateSchema.js +18 -18
  67. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +22 -20
  68. package/package.json +13 -7
@@ -2,15 +2,19 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- function LoaderTargetPlugin(target) {
6
- this.target = target;
5
+ "use strict";
6
+
7
+ class LoaderTargetPlugin {
8
+ constructor(target) {
9
+ this.target = target;
10
+ }
11
+
12
+ apply(compiler) {
13
+ let target = this.target;
14
+ compiler.plugin("compilation", (compilation) => {
15
+ compilation.plugin("normal-module-loader", (loaderContext) => loaderContext.target = target);
16
+ });
17
+ }
7
18
  }
19
+
8
20
  module.exports = LoaderTargetPlugin;
9
- LoaderTargetPlugin.prototype.apply = function(compiler) {
10
- var target = this.target;
11
- compiler.plugin("compilation", function(compilation) {
12
- compilation.plugin("normal-module-loader", function(loaderContext) {
13
- loaderContext.target = target;
14
- });
15
- });
16
- };
@@ -2,10 +2,12 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var ConcatSource = require("webpack-sources").ConcatSource;
6
- var OriginalSource = require("webpack-sources").OriginalSource;
7
- var PrefixSource = require("webpack-sources").PrefixSource;
8
- var Template = require("./Template");
5
+ "use strict";
6
+
7
+ const ConcatSource = require("webpack-sources").ConcatSource;
8
+ const OriginalSource = require("webpack-sources").OriginalSource;
9
+ const PrefixSource = require("webpack-sources").PrefixSource;
10
+ const Template = require("./Template");
9
11
 
10
12
  // require function shortcuts:
11
13
  // __webpack_require__.s = the module id of the entry point
@@ -21,214 +23,214 @@ var Template = require("./Template");
21
23
  // __webpack_require__.oe = the uncatched error handler for the webpack runtime
22
24
  // __webpack_require__.nc = the script nonce
23
25
 
24
- function MainTemplate(outputOptions) {
25
- Template.call(this, outputOptions);
26
- this.plugin("startup", function(source, chunk, hash) {
27
- var buf = [];
28
- if(chunk.entryModule) {
29
- buf.push("// Load entry module and return exports");
30
- buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id)) +
31
- "(" + this.requireFn + ".s = " + JSON.stringify(chunk.entryModule.id) + ");");
32
- }
33
- return this.asString(buf);
34
- });
35
- this.plugin("render", function(bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) {
36
- var source = new ConcatSource();
37
- source.add("/******/ (function(modules) { // webpackBootstrap\n");
38
- source.add(new PrefixSource("/******/", bootstrapSource));
39
- source.add("/******/ })\n");
40
- source.add("/************************************************************************/\n");
41
- source.add("/******/ (");
42
- var modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
43
- source.add(this.applyPluginsWaterfall("modules", modules, chunk, hash, moduleTemplate, dependencyTemplates));
44
- source.add(")");
45
- return source;
46
- });
47
- this.plugin("local-vars", function(source, chunk, hash) {
48
- return this.asString([
49
- source,
50
- "// The module cache",
51
- "var installedModules = {};"
52
- ]);
53
- });
54
- this.plugin("require", function(source, chunk, hash) {
55
- return this.asString([
56
- source,
57
- "// Check if module is in cache",
58
- "if(installedModules[moduleId])",
59
- this.indent("return installedModules[moduleId].exports;"),
60
- "",
61
- "// Create a new module (and put it into the cache)",
62
- "var module = installedModules[moduleId] = {",
63
- this.indent(this.applyPluginsWaterfall("module-obj", "", chunk, hash, "moduleId")),
64
- "};",
65
- "",
66
- this.asString(outputOptions.strictModuleExceptionHandling ? [
67
- "// Execute the module function",
68
- "var threw = true;",
69
- "try {",
70
- this.indent([
26
+ module.exports = class MainTemplate extends Template {
27
+ constructor(outputOptions) {
28
+ super(outputOptions);
29
+ this.plugin("startup", (source, chunk, hash) => {
30
+ let buf = [];
31
+ if(chunk.entryModule) {
32
+ buf.push("// Load entry module and return exports");
33
+ buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, JSON.stringify(chunk.entryModule.id)) +
34
+ "(" + this.requireFn + ".s = " + JSON.stringify(chunk.entryModule.id) + ");");
35
+ }
36
+ return this.asString(buf);
37
+ });
38
+ this.plugin("render", (bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
39
+ let source = new ConcatSource();
40
+ source.add("/******/ (function(modules) { // webpackBootstrap\n");
41
+ source.add(new PrefixSource("/******/", bootstrapSource));
42
+ source.add("/******/ })\n");
43
+ source.add("/************************************************************************/\n");
44
+ source.add("/******/ (");
45
+ let modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
46
+ source.add(this.applyPluginsWaterfall("modules", modules, chunk, hash, moduleTemplate, dependencyTemplates));
47
+ source.add(")");
48
+ return source;
49
+ });
50
+ this.plugin("local-vars", (source, chunk, hash) => {
51
+ return this.asString([
52
+ source,
53
+ "// The module cache",
54
+ "var installedModules = {};"
55
+ ]);
56
+ });
57
+ this.plugin("require", (source, chunk, hash) => {
58
+ return this.asString([
59
+ source,
60
+ "// Check if module is in cache",
61
+ "if(installedModules[moduleId])",
62
+ this.indent("return installedModules[moduleId].exports;"),
63
+ "",
64
+ "// Create a new module (and put it into the cache)",
65
+ "var module = installedModules[moduleId] = {",
66
+ this.indent(this.applyPluginsWaterfall("module-obj", "", chunk, hash, "moduleId")),
67
+ "};",
68
+ "",
69
+ this.asString(outputOptions.strictModuleExceptionHandling ? [
70
+ "// Execute the module function",
71
+ "var threw = true;",
72
+ "try {",
73
+ this.indent([
74
+ "modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
75
+ "threw = false;"
76
+ ]),
77
+ "} finally {",
78
+ this.indent([
79
+ "if(threw) delete installedModules[moduleId];"
80
+ ]),
81
+ "}"
82
+ ] : [
83
+ "// Execute the module function",
71
84
  "modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
72
- "threw = false;"
73
85
  ]),
74
- "} finally {",
86
+ "",
87
+ "// Flag the module as loaded",
88
+ "module.l = true;",
89
+ "",
90
+ "// Return the exports of the module",
91
+ "return module.exports;"
92
+ ]);
93
+ });
94
+ this.plugin("module-obj", (source, chunk, hash, varModuleId) => {
95
+ return this.asString([
96
+ "i: moduleId,",
97
+ "l: false,",
98
+ "exports: {}"
99
+ ]);
100
+ });
101
+ this.plugin("require-extensions", (source, chunk, hash) => {
102
+ let buf = [];
103
+ if(chunk.chunks.length > 0) {
104
+ buf.push("// This file contains only the entry chunk.");
105
+ buf.push("// The chunk loading function for additional chunks");
106
+ buf.push(this.requireFn + ".e = function requireEnsure(chunkId) {");
107
+ buf.push(this.indent(this.applyPluginsWaterfall("require-ensure", "throw new Error('Not chunk loading available');", chunk, hash, "chunkId")));
108
+ buf.push("};");
109
+ }
110
+ buf.push("");
111
+ buf.push("// expose the modules object (__webpack_modules__)");
112
+ buf.push(this.requireFn + ".m = modules;");
113
+
114
+ buf.push("");
115
+ buf.push("// expose the module cache");
116
+ buf.push(this.requireFn + ".c = installedModules;");
117
+
118
+ buf.push("");
119
+ buf.push("// identity function for calling harmony imports with the correct context");
120
+ buf.push(this.requireFn + ".i = function(value) { return value; };");
121
+
122
+ buf.push("");
123
+ buf.push("// define getter function for harmony exports");
124
+ buf.push(this.requireFn + ".d = function(exports, name, getter) {");
125
+ buf.push(this.indent([
126
+ "if(!" + this.requireFn + ".o(exports, name)) {",
75
127
  this.indent([
76
- "if(threw) delete installedModules[moduleId];"
128
+ "Object.defineProperty(exports, name, {",
129
+ this.indent([
130
+ "configurable: false,",
131
+ "enumerable: true,",
132
+ "get: getter"
133
+ ]),
134
+ "});"
77
135
  ]),
78
136
  "}"
79
- ] : [
80
- "// Execute the module function",
81
- "modules[moduleId].call(module.exports, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
82
- ]),
83
- "",
84
- "// Flag the module as loaded",
85
- "module.l = true;",
86
- "",
87
- "// Return the exports of the module",
88
- "return module.exports;"
89
- ]);
90
- });
91
- this.plugin("module-obj", function(source, chunk, hash, varModuleId) {
92
- return this.asString([
93
- "i: moduleId,",
94
- "l: false,",
95
- "exports: {}"
96
- ]);
97
- });
98
- this.plugin("require-extensions", function(source, chunk, hash) {
99
- var buf = [];
100
- if(chunk.chunks.length > 0) {
101
- buf.push("// This file contains only the entry chunk.");
102
- buf.push("// The chunk loading function for additional chunks");
103
- buf.push(this.requireFn + ".e = function requireEnsure(chunkId) {");
104
- buf.push(this.indent(this.applyPluginsWaterfall("require-ensure", "throw new Error('Not chunk loading available');", chunk, hash, "chunkId")));
137
+ ]));
105
138
  buf.push("};");
106
- }
107
- buf.push("");
108
- buf.push("// expose the modules object (__webpack_modules__)");
109
- buf.push(this.requireFn + ".m = modules;");
110
139
 
111
- buf.push("");
112
- buf.push("// expose the module cache");
113
- buf.push(this.requireFn + ".c = installedModules;");
114
-
115
- buf.push("");
116
- buf.push("// identity function for calling harmony imports with the correct context");
117
- buf.push(this.requireFn + ".i = function(value) { return value; };");
118
-
119
- buf.push("");
120
- buf.push("// define getter function for harmony exports");
121
- buf.push(this.requireFn + ".d = function(exports, name, getter) {");
122
- buf.push(this.indent([
123
- "if(!" + this.requireFn + ".o(exports, name)) {",
124
- this.indent([
125
- "Object.defineProperty(exports, name, {",
140
+ buf.push("");
141
+ buf.push("// getDefaultExport function for compatibility with non-harmony modules");
142
+ buf.push(this.requireFn + ".n = function(module) {");
143
+ buf.push(this.indent([
144
+ "var getter = module && module.__esModule ?",
126
145
  this.indent([
127
- "configurable: false,",
128
- "enumerable: true,",
129
- "get: getter"
146
+ "function getDefault() { return module['default']; } :",
147
+ "function getModuleExports() { return module; };"
130
148
  ]),
131
- "});"
132
- ]),
133
- "}"
134
- ]));
135
- buf.push("};");
149
+ this.requireFn + ".d(getter, 'a', getter);",
150
+ "return getter;"
151
+ ]));
152
+ buf.push("};");
136
153
 
137
- buf.push("");
138
- buf.push("// getDefaultExport function for compatibility with non-harmony modules");
139
- buf.push(this.requireFn + ".n = function(module) {");
140
- buf.push(this.indent([
141
- "var getter = module && module.__esModule ?",
142
- this.indent([
143
- "function getDefault() { return module['default']; } :",
144
- "function getModuleExports() { return module; };"
145
- ]),
146
- this.requireFn + ".d(getter, 'a', getter);",
147
- "return getter;"
148
- ]));
149
- buf.push("};");
154
+ buf.push("");
155
+ buf.push("// Object.prototype.hasOwnProperty.call");
156
+ buf.push(this.requireFn + ".o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };");
157
+
158
+ let publicPath = this.getPublicPath({
159
+ hash: hash
160
+ });
161
+ buf.push("");
162
+ buf.push("// __webpack_public_path__");
163
+ buf.push(this.requireFn + ".p = " + JSON.stringify(publicPath) + ";");
164
+ return this.asString(buf);
165
+ });
150
166
 
151
- buf.push("");
152
- buf.push("// Object.prototype.hasOwnProperty.call");
153
- buf.push(this.requireFn + ".o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };");
167
+ this.requireFn = "__webpack_require__";
168
+ }
154
169
 
155
- var publicPath = this.getPublicPath({
156
- hash: hash
157
- });
170
+ render(hash, chunk, moduleTemplate, dependencyTemplates) {
171
+ let buf = [];
172
+ buf.push(this.applyPluginsWaterfall("bootstrap", "", chunk, hash, moduleTemplate, dependencyTemplates));
173
+ buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
174
+ buf.push("");
175
+ buf.push("// The require function");
176
+ buf.push("function " + this.requireFn + "(moduleId) {");
177
+ buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
178
+ buf.push("}");
179
+ buf.push("");
180
+ buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
158
181
  buf.push("");
159
- buf.push("// __webpack_public_path__");
160
- buf.push(this.requireFn + ".p = " + JSON.stringify(publicPath) + ";");
161
- return this.asString(buf);
162
- });
163
- }
164
- module.exports = MainTemplate;
165
-
166
- MainTemplate.prototype = Object.create(Template.prototype);
167
- MainTemplate.prototype.constructor = MainTemplate;
168
- MainTemplate.prototype.requireFn = "__webpack_require__";
169
- MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
170
- var buf = [];
171
- buf.push(this.applyPluginsWaterfall("bootstrap", "", chunk, hash, moduleTemplate, dependencyTemplates));
172
- buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
173
- buf.push("");
174
- buf.push("// The require function");
175
- buf.push("function " + this.requireFn + "(moduleId) {");
176
- buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
177
- buf.push("}");
178
- buf.push("");
179
- buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
180
- buf.push("");
181
- buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
182
- var source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", "webpack/bootstrap " + hash), chunk, hash, moduleTemplate, dependencyTemplates);
183
- if(chunk.hasEntryModule()) {
184
- source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
182
+ buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
183
+ let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", "webpack/bootstrap " + hash), chunk, hash, moduleTemplate, dependencyTemplates);
184
+ if(chunk.hasEntryModule()) {
185
+ source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
186
+ }
187
+ if(!source) throw new Error("Compiler error: MainTemplate plugin 'render' should return something");
188
+ chunk.rendered = true;
189
+ return new ConcatSource(source, ";");
185
190
  }
186
- if(!source) throw new Error("Compiler error: MainTemplate plugin 'render' should return something");
187
- chunk.rendered = true;
188
- return new ConcatSource(source, ";");
189
- };
190
191
 
191
- MainTemplate.prototype.renderRequireFunctionForModule = function(hash, chunk, varModuleId) {
192
- return this.applyPluginsWaterfall("module-require", this.requireFn, chunk, hash, varModuleId);
193
- };
192
+ renderRequireFunctionForModule(hash, chunk, varModuleId) {
193
+ return this.applyPluginsWaterfall("module-require", this.requireFn, chunk, hash, varModuleId);
194
+ }
194
195
 
195
- MainTemplate.prototype.renderAddModule = function(hash, chunk, varModuleId, varModule) {
196
- return this.applyPluginsWaterfall("add-module", "modules[" + varModuleId + "] = " + varModule + ";", chunk, hash, varModuleId, varModule);
197
- };
196
+ renderAddModule(hash, chunk, varModuleId, varModule) {
197
+ return this.applyPluginsWaterfall("add-module", "modules[" + varModuleId + "] = " + varModule + ";", chunk, hash, varModuleId, varModule);
198
+ }
198
199
 
199
- MainTemplate.prototype.renderCurrentHashCode = function(hash, length) {
200
- length = length || Infinity;
201
- return this.applyPluginsWaterfall("current-hash", JSON.stringify(hash.substr(0, length)), length);
202
- };
200
+ renderCurrentHashCode(hash, length) {
201
+ length = length || Infinity;
202
+ return this.applyPluginsWaterfall("current-hash", JSON.stringify(hash.substr(0, length)), length);
203
+ }
203
204
 
204
- MainTemplate.prototype.entryPointInChildren = function(chunk) {
205
- function checkChildren(chunk, alreadyCheckedChunks) {
206
- return chunk.chunks.some(function(child) {
207
- if(alreadyCheckedChunks.indexOf(child) >= 0) return;
208
- alreadyCheckedChunks.push(child);
209
- return child.hasEntryModule() || checkChildren(child, alreadyCheckedChunks);
210
- });
205
+ entryPointInChildren(chunk) {
206
+ let checkChildren = (chunk, alreadyCheckedChunks) => {
207
+ return chunk.chunks.some((child) => {
208
+ if(alreadyCheckedChunks.indexOf(child) >= 0) return;
209
+ alreadyCheckedChunks.push(child);
210
+ return child.hasEntryModule() || checkChildren(child, alreadyCheckedChunks);
211
+ });
212
+ };
213
+ return checkChildren(chunk, []);
211
214
  }
212
- return checkChildren(chunk, []);
213
- };
214
215
 
215
- MainTemplate.prototype.getPublicPath = function(options) {
216
- return this.applyPluginsWaterfall("asset-path", this.outputOptions.publicPath || "", options);
217
- };
216
+ getPublicPath(options) {
217
+ return this.applyPluginsWaterfall("asset-path", this.outputOptions.publicPath || "", options);
218
+ }
218
219
 
219
- MainTemplate.prototype.updateHash = function(hash) {
220
- hash.update("maintemplate");
221
- hash.update("3");
222
- hash.update(this.outputOptions.publicPath + "");
223
- this.applyPlugins("hash", hash);
224
- };
220
+ updateHash(hash) {
221
+ hash.update("maintemplate");
222
+ hash.update("3");
223
+ hash.update(this.outputOptions.publicPath + "");
224
+ this.applyPlugins("hash", hash);
225
+ }
225
226
 
226
- MainTemplate.prototype.updateHashForChunk = function(hash, chunk) {
227
- this.updateHash(hash);
228
- this.applyPlugins("hash-for-chunk", hash, chunk);
229
- };
227
+ updateHashForChunk(hash, chunk) {
228
+ this.updateHash(hash);
229
+ this.applyPlugins("hash-for-chunk", hash, chunk);
230
+ }
230
231
 
231
- MainTemplate.prototype.useChunkHash = function(chunk) {
232
- var paths = this.applyPluginsWaterfall("global-hash-paths", []);
233
- return !this.applyPluginsBailResult("global-hash", chunk, paths);
232
+ useChunkHash(chunk) {
233
+ let paths = this.applyPluginsWaterfall("global-hash-paths", []);
234
+ return !this.applyPluginsBailResult("global-hash", chunk, paths);
235
+ }
234
236
  };
@@ -2,22 +2,24 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var async = require("async");
5
+ "use strict";
6
6
 
7
- function MultiWatching(watchings) {
8
- this.watchings = watchings;
9
- }
7
+ const async = require("async");
8
+
9
+ class MultiWatching {
10
+ constructor(watchings) {
11
+ this.watchings = watchings;
12
+ }
10
13
 
11
- MultiWatching.prototype.invalidate = function() {
12
- this.watchings.forEach(function(watching) {
13
- watching.invalidate();
14
- });
15
- };
14
+ invalidate() {
15
+ this.watchings.forEach((watching) => watching.invalidate());
16
+ }
16
17
 
17
- MultiWatching.prototype.close = function(callback) {
18
- async.forEach(this.watchings, function(watching, finishedCallback) {
19
- watching.close(finishedCallback);
20
- }, callback);
21
- };
18
+ close(callback) {
19
+ async.forEach(this.watchings, (watching, finishedCallback) => {
20
+ watching.close(finishedCallback);
21
+ }, callback);
22
+ }
23
+ }
22
24
 
23
25
  module.exports = MultiWatching;
@@ -2,18 +2,21 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- function NoEmitOnErrorsPlugin() {}
5
+ "use strict";
6
6
 
7
- module.exports = NoEmitOnErrorsPlugin;
8
- NoEmitOnErrorsPlugin.prototype.apply = function(compiler) {
9
- compiler.plugin("should-emit", function(compilation) {
10
- if(compilation.errors.length > 0)
11
- return false;
12
- });
13
- compiler.plugin("compilation", function(compilation) {
14
- compilation.plugin("should-record", function() {
7
+ class NoEmitOnErrorsPlugin {
8
+ apply(compiler) {
9
+ compiler.plugin("should-emit", (compilation) => {
15
10
  if(compilation.errors.length > 0)
16
11
  return false;
17
12
  });
18
- });
19
- };
13
+ compiler.plugin("compilation", (compilation) => {
14
+ compilation.plugin("should-record", () => {
15
+ if(compilation.errors.length > 0)
16
+ return false;
17
+ });
18
+ });
19
+ }
20
+ }
21
+
22
+ module.exports = NoEmitOnErrorsPlugin;
@@ -5,7 +5,6 @@
5
5
  var path = require("path");
6
6
  var ParserHelpers = require("./ParserHelpers");
7
7
  var ConstDependency = require("./dependencies/ConstDependency");
8
- var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9
8
 
10
9
  var NullFactory = require("./NullFactory");
11
10
 
@@ -51,12 +50,9 @@ NodeStuffPlugin.prototype.apply = function(compiler) {
51
50
  }
52
51
  parser.plugin("evaluate Identifier __filename", function(expr) {
53
52
  if(!this.state.module) return;
54
- var res = new BasicEvaluatedExpression();
55
53
  var resource = this.state.module.resource;
56
54
  var i = resource.indexOf("?");
57
- res.setString(i < 0 ? resource : resource.substr(0, i));
58
- res.setRange(expr.range);
59
- return res;
55
+ return ParserHelpers.evaluateToString(i < 0 ? resource : resource.substr(0, i))(expr);
60
56
  });
61
57
  if(localOptions.__dirname === "mock") {
62
58
  setConstant("__dirname", "/");
@@ -67,42 +63,22 @@ NodeStuffPlugin.prototype.apply = function(compiler) {
67
63
  }
68
64
  parser.plugin("evaluate Identifier __dirname", function(expr) {
69
65
  if(!this.state.module) return;
70
- var res = new BasicEvaluatedExpression();
71
- res.setString(this.state.module.context);
72
- res.setRange(expr.range);
73
- return res;
74
- });
75
- parser.plugin("expression require.main", function(expr) {
76
- var dep = new ConstDependency("__webpack_require__.c[__webpack_require__.s]", expr.range);
77
- dep.loc = expr.loc;
78
- this.state.current.addDependency(dep);
79
- return true;
66
+ return ParserHelpers.evaluateToString(this.state.module.context)(expr);
80
67
  });
68
+ parser.plugin("expression require.main", ParserHelpers.toConstantDependency("__webpack_require__.c[__webpack_require__.s]"));
81
69
  parser.plugin(
82
70
  "expression require.extensions",
83
71
  ParserHelpers.expressionIsUnsupported("require.extensions is not supported by webpack. Use a loader instead.")
84
72
  );
85
- parser.plugin("expression module.loaded", function(expr) {
86
- var dep = new ConstDependency("module.l", expr.range);
87
- dep.loc = expr.loc;
88
- this.state.current.addDependency(dep);
89
- return true;
90
- });
91
- parser.plugin("expression module.id", function(expr) {
92
- var dep = new ConstDependency("module.i", expr.range);
93
- dep.loc = expr.loc;
94
- this.state.current.addDependency(dep);
95
- return true;
96
- });
73
+ parser.plugin("expression module.loaded", ParserHelpers.toConstantDependency("module.l"));
74
+ parser.plugin("expression module.id", ParserHelpers.toConstantDependency("module.i"));
97
75
  parser.plugin("expression module.exports", function() {
98
76
  var module = this.state.module;
99
77
  var isHarmony = module.meta && module.meta.harmonyModule;
100
78
  if(!isHarmony)
101
79
  return true;
102
80
  });
103
- parser.plugin("evaluate Identifier module.hot", function(expr) {
104
- return new BasicEvaluatedExpression().setBoolean(false).setRange(expr.range);
105
- });
81
+ parser.plugin("evaluate Identifier module.hot", ParserHelpers.evaluateToBoolean(false));
106
82
  parser.plugin("expression module", function() {
107
83
  var module = this.state.module;
108
84
  var isHarmony = module.meta && module.meta.harmonyModule;
@@ -16,8 +16,8 @@ function loaderToIdent(data) {
16
16
  return data.loader + "?" + data.options;
17
17
  if(typeof data.options !== "object")
18
18
  throw new Error("loader options must be string or object");
19
- if(data.options.ident)
20
- return data.loader + "??" + data.options.ident;
19
+ if(data.ident)
20
+ return data.loader + "??" + data.ident;
21
21
  return data.loader + "?" + JSON.stringify(data.options);
22
22
  }
23
23