webpack 2.4.0 → 2.6.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.
- package/README.md +9 -1
- package/lib/BannerPlugin.js +30 -8
- package/lib/Compilation.js +14 -14
- package/lib/Compiler.js +29 -24
- package/lib/ContextModule.js +133 -33
- package/lib/DelegatedModule.js +3 -1
- package/lib/ExternalModule.js +1 -1
- package/lib/HotModuleReplacement.runtime.js +3 -1
- package/lib/IgnorePlugin.js +2 -2
- package/lib/JsonpMainTemplatePlugin.js +5 -3
- package/lib/LibManifestPlugin.js +1 -1
- package/lib/NormalModule.js +1 -1
- package/lib/Parser.js +37 -22
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +1 -1
- package/lib/Stats.js +2 -1
- package/lib/Template.js +5 -0
- package/lib/WebpackOptionsApply.js +3 -3
- package/lib/WebpackOptionsDefaulter.js +1 -0
- package/lib/dependencies/DepBlockHelpers.js +1 -1
- package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportContextDependency.js +0 -1
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportEagerContextDependency.js +22 -0
- package/lib/dependencies/ImportEagerDependency.js +46 -0
- package/lib/dependencies/ImportLazyContextDependency.js +22 -0
- package/lib/dependencies/ImportLazyOnceContextDependency.js +22 -0
- package/lib/dependencies/ImportParserPlugin.js +37 -6
- package/lib/dependencies/ImportPlugin.js +15 -3
- package/lib/formatLocation.js +44 -27
- package/lib/node/NodeSourcePlugin.js +72 -70
- package/lib/optimize/CommonsChunkPlugin.js +1 -1
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +4 -2
- package/package.json +6 -4
- package/schemas/webpackOptionsSchema.json +12 -0
package/lib/LibManifestPlugin.js
CHANGED
@@ -46,7 +46,7 @@ class LibManifestPlugin {
|
|
46
46
|
return obj;
|
47
47
|
}, {})
|
48
48
|
};
|
49
|
-
const content = new Buffer(JSON.stringify(manifest
|
49
|
+
const content = new Buffer(JSON.stringify(manifest), "utf8"); //eslint-disable-line
|
50
50
|
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
|
51
51
|
if(err) return callback(err);
|
52
52
|
compiler.outputFileSystem.writeFile(targetPath, content, callback);
|
package/lib/NormalModule.js
CHANGED
@@ -257,7 +257,7 @@ class NormalModule extends Module {
|
|
257
257
|
}
|
258
258
|
|
259
259
|
build(options, compilation, resolver, fs, callback) {
|
260
|
-
this.buildTimestamp =
|
260
|
+
this.buildTimestamp = Date.now();
|
261
261
|
this.built = true;
|
262
262
|
this._source = null;
|
263
263
|
this.error = null;
|
package/lib/Parser.js
CHANGED
@@ -636,11 +636,16 @@ class Parser extends Tapable {
|
|
636
636
|
}
|
637
637
|
|
638
638
|
walkFunctionDeclaration(statement) {
|
639
|
+
statement.params.forEach(param => {
|
640
|
+
this.walkPattern(param);
|
641
|
+
});
|
639
642
|
this.inScope(statement.params, function() {
|
640
|
-
if(statement.body.type === "BlockStatement")
|
643
|
+
if(statement.body.type === "BlockStatement") {
|
644
|
+
this.prewalkStatement(statement.body);
|
641
645
|
this.walkStatement(statement.body);
|
642
|
-
else
|
646
|
+
} else {
|
643
647
|
this.walkExpression(statement.body);
|
648
|
+
}
|
644
649
|
}.bind(this));
|
645
650
|
}
|
646
651
|
|
@@ -795,24 +800,15 @@ class Parser extends Tapable {
|
|
795
800
|
switch(declarator.type) {
|
796
801
|
case "VariableDeclarator":
|
797
802
|
{
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
const idx = this.scope.definitions.indexOf(declarator.id.name);
|
804
|
-
if(idx >= 0) this.scope.definitions.splice(idx, 1);
|
805
|
-
}
|
806
|
-
} else {
|
807
|
-
this.enterPattern(declarator.id, (name, decl) => {
|
808
|
-
if(!this.applyPluginsBailResult1("var-" + declarator.kind + " " + name, decl)) {
|
809
|
-
if(!this.applyPluginsBailResult1("var " + name, decl)) {
|
810
|
-
this.scope.renames["$" + name] = undefined;
|
803
|
+
this.enterPattern(declarator.id, (name, decl) => {
|
804
|
+
if(!this.applyPluginsBailResult1("var-" + declarator.kind + " " + name, decl)) {
|
805
|
+
if(!this.applyPluginsBailResult1("var " + name, decl)) {
|
806
|
+
this.scope.renames["$" + name] = undefined;
|
807
|
+
if(this.scope.definitions.indexOf(name) < 0)
|
811
808
|
this.scope.definitions.push(name);
|
812
|
-
}
|
813
809
|
}
|
814
|
-
}
|
815
|
-
}
|
810
|
+
}
|
811
|
+
});
|
816
812
|
break;
|
817
813
|
}
|
818
814
|
}
|
@@ -825,7 +821,14 @@ class Parser extends Tapable {
|
|
825
821
|
case "VariableDeclarator":
|
826
822
|
{
|
827
823
|
const renameIdentifier = declarator.init && this.getRenameIdentifier(declarator.init);
|
828
|
-
if(
|
824
|
+
if(renameIdentifier && declarator.id.type === "Identifier" && this.applyPluginsBailResult1("can-rename " + renameIdentifier, declarator.init)) {
|
825
|
+
// renaming with "var a = b;"
|
826
|
+
if(!this.applyPluginsBailResult1("rename " + renameIdentifier, declarator.init)) {
|
827
|
+
this.scope.renames["$" + declarator.id.name] = this.scope.renames["$" + renameIdentifier] || renameIdentifier;
|
828
|
+
const idx = this.scope.definitions.indexOf(declarator.id.name);
|
829
|
+
if(idx >= 0) this.scope.definitions.splice(idx, 1);
|
830
|
+
}
|
831
|
+
} else {
|
829
832
|
this.walkPattern(declarator.id);
|
830
833
|
if(declarator.init)
|
831
834
|
this.walkExpression(declarator.init);
|
@@ -843,6 +846,11 @@ class Parser extends Tapable {
|
|
843
846
|
this["walk" + pattern.type](pattern);
|
844
847
|
}
|
845
848
|
|
849
|
+
walkAssignmentPattern(pattern) {
|
850
|
+
this.walkExpression(pattern.right);
|
851
|
+
this.walkPattern(pattern.left);
|
852
|
+
}
|
853
|
+
|
846
854
|
walkObjectPattern(pattern) {
|
847
855
|
for(let i = 0, len = pattern.properties.length; i < len; i++) {
|
848
856
|
const prop = pattern.properties[i];
|
@@ -910,6 +918,9 @@ class Parser extends Tapable {
|
|
910
918
|
}
|
911
919
|
|
912
920
|
walkFunctionExpression(expression) {
|
921
|
+
expression.params.forEach(param => {
|
922
|
+
this.walkPattern(param);
|
923
|
+
});
|
913
924
|
this.inScope(expression.params, function() {
|
914
925
|
if(expression.body.type === "BlockStatement") {
|
915
926
|
this.prewalkStatement(expression.body);
|
@@ -921,6 +932,9 @@ class Parser extends Tapable {
|
|
921
932
|
}
|
922
933
|
|
923
934
|
walkArrowFunctionExpression(expression) {
|
935
|
+
expression.params.forEach(param => {
|
936
|
+
this.walkPattern(param);
|
937
|
+
});
|
924
938
|
this.inScope(expression.params, function() {
|
925
939
|
if(expression.body.type === "BlockStatement") {
|
926
940
|
this.prewalkStatement(expression.body);
|
@@ -991,8 +1005,10 @@ class Parser extends Tapable {
|
|
991
1005
|
}
|
992
1006
|
} else {
|
993
1007
|
this.walkExpression(expression.right);
|
994
|
-
this.
|
995
|
-
this.
|
1008
|
+
this.walkPattern(expression.left);
|
1009
|
+
this.enterPattern(expression.left, (name, decl) => {
|
1010
|
+
this.scope.renames["$" + name] = undefined;
|
1011
|
+
});
|
996
1012
|
}
|
997
1013
|
}
|
998
1014
|
|
@@ -1189,7 +1205,6 @@ class Parser extends Tapable {
|
|
1189
1205
|
|
1190
1206
|
enterAssignmentPattern(pattern, onIdent) {
|
1191
1207
|
this.enterPattern(pattern.left, onIdent);
|
1192
|
-
this.walkExpression(pattern.right);
|
1193
1208
|
}
|
1194
1209
|
|
1195
1210
|
evaluateExpression(expression) {
|
package/lib/ProgressPlugin.js
CHANGED
@@ -157,9 +157,9 @@ class ProgressPlugin {
|
|
157
157
|
state = state.replace(/^\d+\/\d+\s+/, "");
|
158
158
|
if(percentage === 0) {
|
159
159
|
lastState = null;
|
160
|
-
lastStateTime =
|
160
|
+
lastStateTime = Date.now();
|
161
161
|
} else if(state !== lastState || percentage === 1) {
|
162
|
-
const now =
|
162
|
+
const now = Date.now();
|
163
163
|
if(lastState) {
|
164
164
|
const stateMsg = `${now - lastStateTime}ms ${lastState}`;
|
165
165
|
goToLineStart(stateMsg);
|
package/lib/RawModule.js
CHANGED
package/lib/Stats.js
CHANGED
@@ -95,6 +95,7 @@ class Stats {
|
|
95
95
|
const showProvidedExports = optionOrFallback(options.providedExports, !forToString);
|
96
96
|
const showChildren = optionOrFallback(options.children, true);
|
97
97
|
const showSource = optionOrFallback(options.source, !forToString);
|
98
|
+
const showModuleTrace = optionOrFallback(options.moduleTrace, true);
|
98
99
|
const showErrors = optionOrFallback(options.errors, true);
|
99
100
|
const showErrorDetails = optionOrFallback(options.errorDetails, !forToString);
|
100
101
|
const showWarnings = optionOrFallback(options.warnings, true);
|
@@ -164,7 +165,7 @@ class Stats {
|
|
164
165
|
text += e.message;
|
165
166
|
if(showErrorDetails && e.details) text += `\n${e.details}`;
|
166
167
|
if(showErrorDetails && e.missing) text += e.missing.map(item => `\n[${item}]`).join("");
|
167
|
-
if(e.dependencies && e.origin) {
|
168
|
+
if(showModuleTrace && e.dependencies && e.origin) {
|
168
169
|
text += `\n @ ${e.origin.readableIdentifier(requestShortener)}`;
|
169
170
|
e.dependencies.forEach(dep => {
|
170
171
|
if(!dep.loc) return;
|
package/lib/Template.js
CHANGED
@@ -26,6 +26,11 @@ module.exports = class Template extends Tapable {
|
|
26
26
|
return str.replace(/^[^a-zA-Z$_]/, "_").replace(/[^a-zA-Z0-9$_]/g, "_");
|
27
27
|
}
|
28
28
|
|
29
|
+
static toPath(str) {
|
30
|
+
if(typeof str !== "string") return "";
|
31
|
+
return str.replace(/[^a-zA-Z0-9_!§$()=\-\^°]+/g, "-").replace(/^-|-$/, "");
|
32
|
+
}
|
33
|
+
|
29
34
|
// map number to a single character a-z, A-Z or <_ + number> if number is too big
|
30
35
|
static numberToIdentifer(n) {
|
31
36
|
// lower case
|
@@ -206,9 +206,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
206
206
|
noSources = options.devtool.indexOf("nosources") >= 0;
|
207
207
|
legacy = options.devtool.indexOf("@") >= 0;
|
208
208
|
modern = options.devtool.indexOf("#") >= 0;
|
209
|
-
comment = legacy && modern ? "\n/*\n//@
|
210
|
-
legacy ? "\n/*\n//@
|
211
|
-
modern ? "\n//#
|
209
|
+
comment = legacy && modern ? "\n/*\n//@ source" + "MappingURL=[url]\n//# source" + "MappingURL=[url]\n*/" :
|
210
|
+
legacy ? "\n/*\n//@ source" + "MappingURL=[url]\n*/" :
|
211
|
+
modern ? "\n//# source" + "MappingURL=[url]" :
|
212
212
|
null;
|
213
213
|
let Plugin = evalWrapped ? EvalSourceMapDevToolPlugin : SourceMapDevToolPlugin;
|
214
214
|
compiler.apply(new Plugin({
|
@@ -60,6 +60,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
60
60
|
this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js");
|
61
61
|
this.set("output.hotUpdateMainFilename", "[hash].hot-update.json");
|
62
62
|
this.set("output.crossOriginLoading", false);
|
63
|
+
this.set("output.chunkLoadTimeout", 120000);
|
63
64
|
this.set("output.hashFunction", "md5");
|
64
65
|
this.set("output.hashDigest", "hex");
|
65
66
|
this.set("output.hashDigestLength", 20);
|
@@ -22,7 +22,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
|
|
22
22
|
if(usedExports && !Array.isArray(usedExports)) {
|
23
23
|
const exportName = dep.originModule.exportsArgument || "exports";
|
24
24
|
const content = `Object.defineProperty(${exportName}, \"__esModule\", { value: true });\n`;
|
25
|
-
source.insert(-
|
25
|
+
source.insert(-10, content);
|
26
26
|
}
|
27
27
|
}
|
28
28
|
};
|
@@ -45,7 +45,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
45
45
|
} else {
|
46
46
|
const immutable = statement.declaration && isImmutableStatement(statement.declaration);
|
47
47
|
const hoisted = statement.declaration && isHoistedStatement(statement.declaration);
|
48
|
-
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -
|
48
|
+
dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -2 : (statement.range[1] + 0.5), immutable);
|
49
49
|
}
|
50
50
|
dep.loc = Object.create(statement.loc);
|
51
51
|
dep.loc.index = idx;
|
@@ -44,7 +44,7 @@ ImportDependency.Template = class ImportDependencyTemplate {
|
|
44
44
|
|
45
45
|
if(dep.module) {
|
46
46
|
const stringifiedId = JSON.stringify(dep.module.id);
|
47
|
-
return `Promise
|
47
|
+
return `new Promise(function(resolve) { resolve(__webpack_require__(${comment}${stringifiedId})); })`;
|
48
48
|
}
|
49
49
|
|
50
50
|
return webpackMissingPromiseModule(dep.request);
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportEagerContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "eager";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context eager";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportEagerContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportEagerContextDependency;
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ModuleDependency = require("./ModuleDependency");
|
7
|
+
const webpackMissingPromiseModule = require("./WebpackMissingModule").promise;
|
8
|
+
|
9
|
+
class ImportEagerDependency extends ModuleDependency {
|
10
|
+
constructor(request, range) {
|
11
|
+
super(request);
|
12
|
+
this.range = range;
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import()";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportEagerDependency.Template = class ImportEagerDependencyTemplate {
|
21
|
+
apply(dep, source, outputOptions, requestShortener) {
|
22
|
+
const comment = this.getOptionalComment(outputOptions.pathinfo, requestShortener.shorten(dep.request));
|
23
|
+
|
24
|
+
const content = this.getContent(dep, comment);
|
25
|
+
source.replace(dep.range[0], dep.range[1] - 1, content);
|
26
|
+
}
|
27
|
+
|
28
|
+
getOptionalComment(pathinfo, shortenedRequest) {
|
29
|
+
if(!pathinfo) {
|
30
|
+
return "";
|
31
|
+
}
|
32
|
+
|
33
|
+
return `/*! ${shortenedRequest} */ `;
|
34
|
+
}
|
35
|
+
|
36
|
+
getContent(dep, comment) {
|
37
|
+
if(dep.module) {
|
38
|
+
const stringifiedId = JSON.stringify(dep.module.id);
|
39
|
+
return `new Promise(function(resolve) { resolve(__webpack_require__(${comment}${stringifiedId})); })`;
|
40
|
+
}
|
41
|
+
|
42
|
+
return webpackMissingPromiseModule(dep.request);
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
module.exports = ImportEagerDependency;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportLazyContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "lazy";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context lazy";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportLazyContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportLazyContextDependency;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const ImportContextDependency = require("./ImportContextDependency");
|
7
|
+
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
8
|
+
|
9
|
+
class ImportLazyOnceContextDependency extends ImportContextDependency {
|
10
|
+
constructor(request, recursive, regExp, range, valueRange, chunkName) {
|
11
|
+
super(request, recursive, regExp, range, valueRange, chunkName);
|
12
|
+
this.async = "lazy-once";
|
13
|
+
}
|
14
|
+
|
15
|
+
get type() {
|
16
|
+
return "import() context lazy-once";
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportLazyOnceContextDependency.Template = ContextDependencyTemplateAsRequireCall;
|
21
|
+
|
22
|
+
module.exports = ImportLazyOnceContextDependency;
|
@@ -4,9 +4,13 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const
|
7
|
+
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
|
8
|
+
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
|
9
|
+
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
|
8
10
|
const ImportDependenciesBlock = require("./ImportDependenciesBlock");
|
11
|
+
const ImportEagerDependency = require("./ImportEagerDependency");
|
9
12
|
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
13
|
+
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
10
14
|
|
11
15
|
class ImportParserPlugin {
|
12
16
|
constructor(options) {
|
@@ -23,22 +27,49 @@ class ImportParserPlugin {
|
|
23
27
|
const param = parser.evaluateExpression(expr.arguments[0]);
|
24
28
|
|
25
29
|
let chunkName = null;
|
30
|
+
let mode = "lazy";
|
26
31
|
|
27
32
|
const importOptions = parser.getCommentOptions(expr.range);
|
28
33
|
if(importOptions) {
|
29
34
|
if(typeof importOptions.webpackChunkName !== "undefined") {
|
30
35
|
if(typeof importOptions.webpackChunkName !== "string")
|
31
|
-
|
32
|
-
|
36
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`));
|
37
|
+
else
|
38
|
+
chunkName = importOptions.webpackChunkName;
|
39
|
+
}
|
40
|
+
if(typeof importOptions.webpackMode !== "undefined") {
|
41
|
+
if(typeof importOptions.webpackMode !== "string")
|
42
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected a string, but received: ${importOptions.webpackMode}.`));
|
43
|
+
else
|
44
|
+
mode = importOptions.webpackMode;
|
33
45
|
}
|
34
46
|
}
|
35
47
|
|
36
48
|
if(param.isString()) {
|
37
|
-
|
38
|
-
|
49
|
+
if(mode !== "lazy" && mode !== "eager") {
|
50
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy' or 'eager', but received: ${mode}.`));
|
51
|
+
}
|
52
|
+
|
53
|
+
if(mode === "eager") {
|
54
|
+
const dep = new ImportEagerDependency(param.string, expr.range);
|
55
|
+
parser.state.current.addDependency(dep);
|
56
|
+
} else {
|
57
|
+
const depBlock = new ImportDependenciesBlock(param.string, expr.range, chunkName, parser.state.module, expr.loc);
|
58
|
+
parser.state.current.addBlock(depBlock);
|
59
|
+
}
|
39
60
|
return true;
|
40
61
|
} else {
|
41
|
-
|
62
|
+
if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager") {
|
63
|
+
parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once' or 'eager', but received: ${mode}.`));
|
64
|
+
}
|
65
|
+
|
66
|
+
let Dep = ImportLazyContextDependency;
|
67
|
+
if(mode === "eager") {
|
68
|
+
Dep = ImportEagerContextDependency;
|
69
|
+
} else if(mode === "lazy-once") {
|
70
|
+
Dep = ImportLazyOnceContextDependency;
|
71
|
+
}
|
72
|
+
const dep = ContextDependencyHelpers.create(Dep, expr.range, param, expr, options, chunkName);
|
42
73
|
if(!dep) return;
|
43
74
|
dep.loc = expr.loc;
|
44
75
|
dep.optional = !!parser.scope.inTry;
|
@@ -5,7 +5,10 @@
|
|
5
5
|
"use strict";
|
6
6
|
|
7
7
|
const ImportDependency = require("./ImportDependency");
|
8
|
-
const
|
8
|
+
const ImportEagerDependency = require("./ImportEagerDependency");
|
9
|
+
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
|
10
|
+
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
|
11
|
+
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
|
9
12
|
const ImportParserPlugin = require("./ImportParserPlugin");
|
10
13
|
|
11
14
|
class ImportPlugin {
|
@@ -22,8 +25,17 @@ class ImportPlugin {
|
|
22
25
|
compilation.dependencyFactories.set(ImportDependency, normalModuleFactory);
|
23
26
|
compilation.dependencyTemplates.set(ImportDependency, new ImportDependency.Template());
|
24
27
|
|
25
|
-
compilation.dependencyFactories.set(
|
26
|
-
compilation.dependencyTemplates.set(
|
28
|
+
compilation.dependencyFactories.set(ImportEagerDependency, normalModuleFactory);
|
29
|
+
compilation.dependencyTemplates.set(ImportEagerDependency, new ImportEagerDependency.Template());
|
30
|
+
|
31
|
+
compilation.dependencyFactories.set(ImportEagerContextDependency, contextModuleFactory);
|
32
|
+
compilation.dependencyTemplates.set(ImportEagerContextDependency, new ImportEagerContextDependency.Template());
|
33
|
+
|
34
|
+
compilation.dependencyFactories.set(ImportLazyOnceContextDependency, contextModuleFactory);
|
35
|
+
compilation.dependencyTemplates.set(ImportLazyOnceContextDependency, new ImportLazyOnceContextDependency.Template());
|
36
|
+
|
37
|
+
compilation.dependencyFactories.set(ImportLazyContextDependency, contextModuleFactory);
|
38
|
+
compilation.dependencyTemplates.set(ImportLazyContextDependency, new ImportLazyContextDependency.Template());
|
27
39
|
|
28
40
|
params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
|
29
41
|
|
package/lib/formatLocation.js
CHANGED
@@ -2,36 +2,53 @@
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
3
|
Author Tobias Koppers @sokra
|
4
4
|
*/
|
5
|
-
module.exports = function formatLocation(loc) {
|
6
|
-
if(typeof loc === "string")
|
7
|
-
return loc;
|
8
|
-
if(typeof loc === "number")
|
9
|
-
return loc + "";
|
10
|
-
if(loc && typeof loc === "object") {
|
11
|
-
if(loc.start && loc.end) {
|
12
|
-
if(typeof loc.start.line === "number" && typeof loc.end.line === "number" && typeof loc.end.column === "number" && loc.start.line === loc.end.line)
|
13
|
-
return formatPosition(loc.start) + "-" + loc.end.column;
|
14
|
-
return formatPosition(loc.start) + "-" + formatPosition(loc.end);
|
15
|
-
}
|
16
|
-
if(loc.start)
|
17
|
-
return formatPosition(loc.start);
|
18
|
-
return formatPosition(loc);
|
19
|
-
}
|
20
|
-
return "";
|
21
5
|
|
22
|
-
|
23
|
-
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const formatPosition = (pos) => {
|
9
|
+
if(pos === null)
|
10
|
+
return "";
|
11
|
+
const typeOfPos = typeof pos;
|
12
|
+
switch(typeOfPos) {
|
13
|
+
case "string":
|
24
14
|
return pos;
|
25
|
-
|
26
|
-
return pos
|
27
|
-
|
15
|
+
case "number":
|
16
|
+
return `${pos}`;
|
17
|
+
case "object":
|
28
18
|
if(typeof pos.line === "number" && typeof pos.column === "number")
|
29
|
-
return pos.line
|
30
|
-
if(typeof pos.line === "number")
|
31
|
-
return pos.line
|
32
|
-
if(typeof pos.index === "number")
|
33
|
-
return
|
34
|
-
|
19
|
+
return `${pos.line}:${pos.column}`;
|
20
|
+
else if(typeof pos.line === "number")
|
21
|
+
return `${pos.line}:?`;
|
22
|
+
else if(typeof pos.index === "number")
|
23
|
+
return `+${pos.index}`;
|
24
|
+
else
|
25
|
+
return "";
|
26
|
+
default:
|
27
|
+
return "";
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
const formatLocation = (loc) => {
|
32
|
+
if(loc === null)
|
35
33
|
return "";
|
34
|
+
const typeOfLoc = typeof loc;
|
35
|
+
switch(typeOfLoc) {
|
36
|
+
case "string":
|
37
|
+
return loc;
|
38
|
+
case "number":
|
39
|
+
return `${loc}`;
|
40
|
+
case "object":
|
41
|
+
if(loc.start && loc.end) {
|
42
|
+
if(typeof loc.start.line === "number" && typeof loc.end.line === "number" && typeof loc.end.column === "number" && loc.start.line === loc.end.line)
|
43
|
+
return `${formatPosition(loc.start)}-${loc.end.column}`;
|
44
|
+
return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
|
45
|
+
}
|
46
|
+
if(loc.start)
|
47
|
+
return formatPosition(loc.start);
|
48
|
+
return formatPosition(loc);
|
49
|
+
default:
|
50
|
+
return "";
|
36
51
|
}
|
37
52
|
};
|
53
|
+
|
54
|
+
module.exports = formatLocation;
|