aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/dependencies
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/webpack/lib/dependencies')
-rw-r--r--node_modules/webpack/lib/dependencies/AMDPlugin.js4
-rw-r--r--node_modules/webpack/lib/dependencies/CommonJsPlugin.js3
-rw-r--r--node_modules/webpack/lib/dependencies/DelegatedExportsDependency.js33
-rw-r--r--node_modules/webpack/lib/dependencies/DepBlockHelpers.js35
-rw-r--r--node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js2
-rw-r--r--node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js19
-rw-r--r--node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js8
-rw-r--r--node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js20
-rw-r--r--node_modules/webpack/lib/dependencies/ImportParserPlugin.js15
-rw-r--r--node_modules/webpack/lib/dependencies/ImportPlugin.js10
-rw-r--r--node_modules/webpack/lib/dependencies/ImportWeakContextDependency.js22
-rw-r--r--node_modules/webpack/lib/dependencies/ImportWeakDependency.js47
-rw-r--r--node_modules/webpack/lib/dependencies/RequireContextDependency.js6
-rw-r--r--node_modules/webpack/lib/dependencies/RequireContextDependencyParserPlugin.js10
-rw-r--r--node_modules/webpack/lib/dependencies/RequireContextPlugin.js31
-rw-r--r--node_modules/webpack/lib/dependencies/RequireEnsureDependenciesBlock.js8
-rw-r--r--node_modules/webpack/lib/dependencies/RequireResolveDependencyParserPlugin.js2
17 files changed, 219 insertions, 56 deletions
diff --git a/node_modules/webpack/lib/dependencies/AMDPlugin.js b/node_modules/webpack/lib/dependencies/AMDPlugin.js
index d1d5cf09e..944241c23 100644
--- a/node_modules/webpack/lib/dependencies/AMDPlugin.js
+++ b/node_modules/webpack/lib/dependencies/AMDPlugin.js
@@ -82,8 +82,8 @@ class AMDPlugin {
parser.state.current.addVariable("__webpack_amd_options__", JSON.stringify(amdOptions)));
parser.plugin("evaluate typeof define.amd", ParserHelpers.evaluateToString(typeof amdOptions));
parser.plugin("evaluate typeof require.amd", ParserHelpers.evaluateToString(typeof amdOptions));
- parser.plugin("evaluate Identifier define.amd", ParserHelpers.evaluateToBoolean(true));
- parser.plugin("evaluate Identifier require.amd", ParserHelpers.evaluateToBoolean(true));
+ parser.plugin("evaluate Identifier define.amd", ParserHelpers.evaluateToIdentifier("define.amd", true));
+ parser.plugin("evaluate Identifier require.amd", ParserHelpers.evaluateToIdentifier("require.amd", true));
parser.plugin("typeof define", ParserHelpers.toConstantDependency(JSON.stringify("function")));
parser.plugin("evaluate typeof define", ParserHelpers.evaluateToString("function"));
parser.plugin("can-rename define", ParserHelpers.approve);
diff --git a/node_modules/webpack/lib/dependencies/CommonJsPlugin.js b/node_modules/webpack/lib/dependencies/CommonJsPlugin.js
index e514fd99e..218cddb3d 100644
--- a/node_modules/webpack/lib/dependencies/CommonJsPlugin.js
+++ b/node_modules/webpack/lib/dependencies/CommonJsPlugin.js
@@ -54,8 +54,9 @@ class CommonJsPlugin {
const requireExpressions = ["require", "require.resolve", "require.resolveWeak"];
for(let expression of requireExpressions) {
- parser.plugin(`typeof ${expression}`, ParserHelpers.toConstantDependency("function"));
+ parser.plugin(`typeof ${expression}`, ParserHelpers.toConstantDependency(JSON.stringify("function")));
parser.plugin(`evaluate typeof ${expression}`, ParserHelpers.evaluateToString("function"));
+ parser.plugin(`evaluate Identifier ${expression}`, ParserHelpers.evaluateToIdentifier(expression, true));
}
parser.plugin("evaluate typeof module", ParserHelpers.evaluateToString("object"));
diff --git a/node_modules/webpack/lib/dependencies/DelegatedExportsDependency.js b/node_modules/webpack/lib/dependencies/DelegatedExportsDependency.js
new file mode 100644
index 000000000..ad36acbe4
--- /dev/null
+++ b/node_modules/webpack/lib/dependencies/DelegatedExportsDependency.js
@@ -0,0 +1,33 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+const NullDependency = require("./NullDependency");
+
+class DelegatedExportsDependency extends NullDependency {
+ constructor(originModule, exports) {
+ super();
+ this.originModule = originModule;
+ this.exports = exports;
+ }
+
+ get type() {
+ return "delegated exports";
+ }
+
+ getReference() {
+ return {
+ module: this.originModule,
+ importedNames: true
+ };
+ }
+
+ getExports() {
+ return {
+ exports: this.exports
+ };
+ }
+}
+
+module.exports = DelegatedExportsDependency;
diff --git a/node_modules/webpack/lib/dependencies/DepBlockHelpers.js b/node_modules/webpack/lib/dependencies/DepBlockHelpers.js
index d4a4014ec..c1e48a3a5 100644
--- a/node_modules/webpack/lib/dependencies/DepBlockHelpers.js
+++ b/node_modules/webpack/lib/dependencies/DepBlockHelpers.js
@@ -2,10 +2,12 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
-var DepBlockHelpers = exports;
+"use strict";
-DepBlockHelpers.getLoadDepBlockWrapper = function(depBlock, outputOptions, requestShortener, name) {
- var promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
+const DepBlockHelpers = exports;
+
+DepBlockHelpers.getLoadDepBlockWrapper = (depBlock, outputOptions, requestShortener, name) => {
+ const promiseCode = DepBlockHelpers.getDepBlockPromise(depBlock, outputOptions, requestShortener, name);
return [
promiseCode + ".then(",
").catch(",
@@ -13,24 +15,19 @@ DepBlockHelpers.getLoadDepBlockWrapper = function(depBlock, outputOptions, reque
];
};
-DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestShortener, name) {
+DepBlockHelpers.getDepBlockPromise = (depBlock, outputOptions, requestShortener, name) => {
if(depBlock.chunks) {
- var chunks = depBlock.chunks.filter(function(chunk) {
- return !chunk.hasRuntime() && chunk.id !== null;
- });
+ const chunks = depBlock.chunks.filter(chunk => !chunk.hasRuntime() && chunk.id !== null);
+ const pathChunkCheck = outputOptions.pathinfo && depBlock.chunkName;
+ const shortChunkName = requestShortener.shorten(depBlock.chunkName);
+ const chunkReason = asComment(depBlock.chunkReason);
+ const requireChunkId = chunk => "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
+ name = asComment(name);
if(chunks.length === 1) {
- var chunk = chunks[0];
- return "__webpack_require__.e" + asComment(name) + "(" + JSON.stringify(chunk.id) + "" +
- (outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
- asComment(depBlock.chunkReason) + ")";
+ const chunkId = JSON.stringify(chunks[0].id);
+ return `__webpack_require__.e${name}(${chunkId}${pathChunkCheck ? "/*! " + shortChunkName + " */" : ""}${chunkReason})`;
} else if(chunks.length > 0) {
- return "Promise.all" + asComment(name) + "(" +
- (outputOptions.pathinfo && depBlock.chunkName ? "/*! " + requestShortener.shorten(depBlock.chunkName) + " */" : "") +
- "[" +
- chunks.map(function(chunk) {
- return "__webpack_require__.e(" + JSON.stringify(chunk.id) + ")";
- }).join(", ") +
- "])";
+ return `Promise.all${name}(${pathChunkCheck ? "/*! " + shortChunkName + " */" : ""}[${chunks.map(requireChunkId).join(", ")}])`;
}
}
return "new Promise(function(resolve) { resolve(); })";
@@ -38,5 +35,5 @@ DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestSh
function asComment(str) {
if(!str) return "";
- return "/* " + str + " */";
+ return `/* ${str} */`;
}
diff --git a/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js b/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js
index 9407499dc..8bd7bb708 100644
--- a/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js
+++ b/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js
@@ -21,7 +21,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
const usedExports = dep.originModule.usedExports;
if(usedExports && !Array.isArray(usedExports)) {
const exportName = dep.originModule.exportsArgument || "exports";
- const content = `Object.defineProperty(${exportName}, \"__esModule\", { value: true });\n`;
+ const content = `Object.defineProperty(${exportName}, "__esModule", { value: true });\n`;
source.insert(-10, content);
}
}
diff --git a/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js
index 973383551..d756688d2 100644
--- a/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js
+++ b/node_modules/webpack/lib/dependencies/HarmonyImportDependencyParserPlugin.js
@@ -13,6 +13,7 @@ const HarmonyModulesHelpers = require("./HarmonyModulesHelpers");
module.exports = class HarmonyImportDependencyParserPlugin {
constructor(moduleOptions) {
this.strictExportPresence = moduleOptions.strictExportPresence;
+ this.strictThisContextOnImports = moduleOptions.strictThisContextOnImports;
}
apply(parser) {
@@ -52,6 +53,24 @@ module.exports = class HarmonyImportDependencyParserPlugin {
parser.state.current.addDependency(dep);
return true;
});
+ if(this.strictThisContextOnImports) {
+ // only in case when we strictly follow the spec we need a special case here
+ parser.plugin("call imported var.*", (expr) => {
+ const name = expr.callee.object.name;
+ const settings = parser.state.harmonySpecifier[`$${name}`];
+ if(settings[2] !== null)
+ return false;
+ const dep = new HarmonyImportSpecifierDependency(settings[0], settings[1], expr.callee.property.name || expr.callee.property.value, name, expr.callee.range, this.strictExportPresence);
+ dep.shorthand = parser.scope.inShorthand;
+ dep.directImport = false;
+ dep.namespaceObjectAsContext = true;
+ dep.loc = expr.callee.loc;
+ parser.state.current.addDependency(dep);
+ if(expr.arguments)
+ parser.walkExpressions(expr.arguments);
+ return true;
+ });
+ }
parser.plugin("call imported var", (expr) => {
const args = expr.arguments;
const fullExpr = expr;
diff --git a/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js b/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
index 01290b962..083019291 100644
--- a/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
+++ b/node_modules/webpack/lib/dependencies/HarmonyImportSpecifierDependency.js
@@ -14,6 +14,10 @@ class HarmonyImportSpecifierDependency extends NullDependency {
this.name = name;
this.range = range;
this.strictExportPresence = strictExportPresence;
+ this.namespaceObjectAsContext = false;
+ this.callArgs = undefined;
+ this.call = undefined;
+ this.directImport = undefined;
}
get type() {
@@ -24,7 +28,7 @@ class HarmonyImportSpecifierDependency extends NullDependency {
if(!this.importDependency.module) return null;
return {
module: this.importDependency.module,
- importedNames: this.id ? [this.id] : true
+ importedNames: this.id && !this.namespaceObjectAsContext ? [this.id] : true
};
}
@@ -93,7 +97,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
}
if(dep.call && dep.id) {
- return `${shortHandPrefix}__webpack_require__.i(${importedVar}${importedVarSuffix})`;
+ return `${shortHandPrefix}Object(${importedVar}${importedVarSuffix})`;
}
return `${shortHandPrefix}${importedVar}${importedVarSuffix}`;
diff --git a/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js b/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js
index cd3b63115..1f3387fe1 100644
--- a/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js
+++ b/node_modules/webpack/lib/dependencies/HarmonyModulesHelpers.js
@@ -8,12 +8,12 @@ class HarmonyModulesHelpers {
static getModuleVar(state, request) {
if(!state.harmonyModules) state.harmonyModules = [];
- var idx = state.harmonyModules.indexOf(request);
+ let idx = state.harmonyModules.indexOf(request);
if(idx < 0) {
idx = state.harmonyModules.length;
state.harmonyModules.push(request);
}
- return "__WEBPACK_IMPORTED_MODULE_" + idx + "_" + request.replace(/[^A-Za-z0-9_]/g, "_").replace(/__+/g, "_") + "__";
+ return `__WEBPACK_IMPORTED_MODULE_${idx}_${request.replace(/[^A-Za-z0-9_]/g, "_").replace(/__+/g, "_")}__`;
}
static getNewModuleVar(state, request) {
@@ -31,17 +31,17 @@ class HarmonyModulesHelpers {
// checks if an harmony dependency is active in a module according to
// precedence rules.
static isActive(module, depInQuestion) {
- var desc = depInQuestion.describeHarmonyExport();
+ const desc = depInQuestion.describeHarmonyExport();
if(!desc.exportedName) return true;
- var before = true;
- for(var i = 0; i < module.dependencies.length; i++) {
- var dep = module.dependencies[i];
+ let before = true;
+ for(const moduleDependency of module.dependencies) {
+ const dep = moduleDependency;
if(dep === depInQuestion) {
before = false;
continue;
}
if(!dep.describeHarmonyExport) continue;
- var d = dep.describeHarmonyExport();
+ const d = dep.describeHarmonyExport();
if(!d || !d.exportedName) continue;
if(d.exportedName === desc.exportedName) {
if(d.precedence < desc.precedence) {
@@ -58,7 +58,7 @@ class HarmonyModulesHelpers {
// get a list of named exports defined in a module
// doesn't include * reexports.
static getActiveExports(module, currentDependency) {
- var desc = currentDependency && currentDependency.describeHarmonyExport();
+ const desc = currentDependency && currentDependency.describeHarmonyExport();
var currentIndex = currentDependency ? module.dependencies.indexOf(currentDependency) : -1;
return module.dependencies.map((dep, idx) => {
return {
@@ -66,9 +66,9 @@ class HarmonyModulesHelpers {
idx: idx
};
}).reduce((arr, data) => {
- var dep = data.dep;
+ const dep = data.dep;
if(!dep.describeHarmonyExport) return arr;
- var d = dep.describeHarmonyExport();
+ const d = dep.describeHarmonyExport();
if(!d) return arr;
if(!desc || (d.precedence < desc.precedence) || (d.precedence === desc.precedence && data.idx < currentIndex)) {
var names = [].concat(d.exportedName);
diff --git a/node_modules/webpack/lib/dependencies/ImportParserPlugin.js b/node_modules/webpack/lib/dependencies/ImportParserPlugin.js
index d97355dc7..a775571b2 100644
--- a/node_modules/webpack/lib/dependencies/ImportParserPlugin.js
+++ b/node_modules/webpack/lib/dependencies/ImportParserPlugin.js
@@ -5,6 +5,8 @@
"use strict";
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
+const ImportWeakDependency = require("./ImportWeakDependency");
+const ImportWeakContextDependency = require("./ImportWeakContextDependency");
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
const ImportDependenciesBlock = require("./ImportDependenciesBlock");
@@ -46,26 +48,31 @@ class ImportParserPlugin {
}
if(param.isString()) {
- if(mode !== "lazy" && mode !== "eager") {
- parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy' or 'eager', but received: ${mode}.`));
+ if(mode !== "lazy" && mode !== "eager" && mode !== "weak") {
+ parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}.`));
}
if(mode === "eager") {
const dep = new ImportEagerDependency(param.string, expr.range);
parser.state.current.addDependency(dep);
+ } else if(mode === "weak") {
+ const dep = new ImportWeakDependency(param.string, expr.range);
+ parser.state.current.addDependency(dep);
} else {
const depBlock = new ImportDependenciesBlock(param.string, expr.range, chunkName, parser.state.module, expr.loc);
parser.state.current.addBlock(depBlock);
}
return true;
} else {
- if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager") {
- parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once' or 'eager', but received: ${mode}.`));
+ if(mode !== "lazy" && mode !== "lazy-once" && mode !== "eager" && mode !== "weak") {
+ parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`));
}
let Dep = ImportLazyContextDependency;
if(mode === "eager") {
Dep = ImportEagerContextDependency;
+ } else if(mode === "weak") {
+ Dep = ImportWeakContextDependency;
} else if(mode === "lazy-once") {
Dep = ImportLazyOnceContextDependency;
}
diff --git a/node_modules/webpack/lib/dependencies/ImportPlugin.js b/node_modules/webpack/lib/dependencies/ImportPlugin.js
index 4905df183..27118bbcf 100644
--- a/node_modules/webpack/lib/dependencies/ImportPlugin.js
+++ b/node_modules/webpack/lib/dependencies/ImportPlugin.js
@@ -6,7 +6,9 @@
const ImportDependency = require("./ImportDependency");
const ImportEagerDependency = require("./ImportEagerDependency");
+const ImportWeakDependency = require("./ImportWeakDependency");
const ImportEagerContextDependency = require("./ImportEagerContextDependency");
+const ImportWeakContextDependency = require("./ImportWeakContextDependency");
const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
const ImportLazyContextDependency = require("./ImportLazyContextDependency");
const ImportParserPlugin = require("./ImportParserPlugin");
@@ -28,16 +30,22 @@ class ImportPlugin {
compilation.dependencyFactories.set(ImportEagerDependency, normalModuleFactory);
compilation.dependencyTemplates.set(ImportEagerDependency, new ImportEagerDependency.Template());
+ compilation.dependencyFactories.set(ImportWeakDependency, normalModuleFactory);
+ compilation.dependencyTemplates.set(ImportWeakDependency, new ImportWeakDependency.Template());
+
compilation.dependencyFactories.set(ImportEagerContextDependency, contextModuleFactory);
compilation.dependencyTemplates.set(ImportEagerContextDependency, new ImportEagerContextDependency.Template());
+ compilation.dependencyFactories.set(ImportWeakContextDependency, contextModuleFactory);
+ compilation.dependencyTemplates.set(ImportWeakContextDependency, new ImportWeakContextDependency.Template());
+
compilation.dependencyFactories.set(ImportLazyOnceContextDependency, contextModuleFactory);
compilation.dependencyTemplates.set(ImportLazyOnceContextDependency, new ImportLazyOnceContextDependency.Template());
compilation.dependencyFactories.set(ImportLazyContextDependency, contextModuleFactory);
compilation.dependencyTemplates.set(ImportLazyContextDependency, new ImportLazyContextDependency.Template());
- params.normalModuleFactory.plugin("parser", (parser, parserOptions) => {
+ normalModuleFactory.plugin("parser", (parser, parserOptions) => {
if(typeof parserOptions.import !== "undefined" && !parserOptions.import)
return;
diff --git a/node_modules/webpack/lib/dependencies/ImportWeakContextDependency.js b/node_modules/webpack/lib/dependencies/ImportWeakContextDependency.js
new file mode 100644
index 000000000..f6c19613e
--- /dev/null
+++ b/node_modules/webpack/lib/dependencies/ImportWeakContextDependency.js
@@ -0,0 +1,22 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+const ImportContextDependency = require("./ImportContextDependency");
+const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
+
+class ImportWeakContextDependency extends ImportContextDependency {
+ constructor(request, recursive, regExp, range, valueRange, chunkName) {
+ super(request, recursive, regExp, range, valueRange, chunkName);
+ this.async = "async-weak";
+ }
+
+ get type() {
+ return "import() context weak";
+ }
+}
+
+ImportWeakContextDependency.Template = ContextDependencyTemplateAsRequireCall;
+
+module.exports = ImportWeakContextDependency;
diff --git a/node_modules/webpack/lib/dependencies/ImportWeakDependency.js b/node_modules/webpack/lib/dependencies/ImportWeakDependency.js
new file mode 100644
index 000000000..ccad2d92c
--- /dev/null
+++ b/node_modules/webpack/lib/dependencies/ImportWeakDependency.js
@@ -0,0 +1,47 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+const ModuleDependency = require("./ModuleDependency");
+const webpackMissingPromiseModule = require("./WebpackMissingModule").promise;
+
+class ImportWeakDependency extends ModuleDependency {
+ constructor(request, range) {
+ super(request);
+ this.range = range;
+ this.weak = true;
+ }
+
+ get type() {
+ return "import() weak";
+ }
+}
+
+ImportWeakDependency.Template = class ImportDependencyTemplate {
+ apply(dep, source, outputOptions, requestShortener) {
+ const comment = this.getOptionalComment(outputOptions.pathinfo, requestShortener.shorten(dep.request));
+
+ const content = this.getContent(dep, comment);
+ source.replace(dep.range[0], dep.range[1] - 1, content);
+ }
+
+ getOptionalComment(pathinfo, shortenedRequest) {
+ if(!pathinfo) {
+ return "";
+ }
+
+ return `/*! ${shortenedRequest} */ `;
+ }
+
+ getContent(dep, comment) {
+ if(dep.module) {
+ const stringifiedId = JSON.stringify(dep.module.id);
+ return `Promise.resolve(${comment}${stringifiedId}).then(function(id) { if(!__webpack_require__.m[id]) throw new Error("Module '" + id + "' is not available (weak dependency)"); return __webpack_require__(id); })`;
+ }
+
+ return webpackMissingPromiseModule(dep.request);
+ }
+};
+
+module.exports = ImportWeakDependency;
diff --git a/node_modules/webpack/lib/dependencies/RequireContextDependency.js b/node_modules/webpack/lib/dependencies/RequireContextDependency.js
index c0f6bdc75..e37b1b54c 100644
--- a/node_modules/webpack/lib/dependencies/RequireContextDependency.js
+++ b/node_modules/webpack/lib/dependencies/RequireContextDependency.js
@@ -7,9 +7,13 @@ const ContextDependency = require("./ContextDependency");
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
class RequireContextDependency extends ContextDependency {
- constructor(request, recursive, regExp, range) {
+ constructor(request, recursive, regExp, asyncMode, range) {
super(request, recursive, regExp);
this.range = range;
+
+ if(asyncMode) {
+ this.async = asyncMode;
+ }
}
get type() {
diff --git a/node_modules/webpack/lib/dependencies/RequireContextDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/RequireContextDependencyParserPlugin.js
index 8587fba8d..04a8b25b9 100644
--- a/node_modules/webpack/lib/dependencies/RequireContextDependencyParserPlugin.js
+++ b/node_modules/webpack/lib/dependencies/RequireContextDependencyParserPlugin.js
@@ -11,7 +11,15 @@ module.exports = class RequireContextDependencyParserPlugin {
parser.plugin("call require.context", expr => {
let regExp = /^\.\/.*$/;
let recursive = true;
+ let asyncMode;
switch(expr.arguments.length) {
+ case 4:
+ {
+ const asyncModeExpr = parser.evaluateExpression(expr.arguments[3]);
+ if(!asyncModeExpr.isString()) return;
+ asyncMode = asyncModeExpr.string;
+ }
+ // falls through
case 3:
{
const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
@@ -30,7 +38,7 @@ module.exports = class RequireContextDependencyParserPlugin {
{
const requestExpr = parser.evaluateExpression(expr.arguments[0]);
if(!requestExpr.isString()) return;
- const dep = new RequireContextDependency(requestExpr.string, recursive, regExp, expr.range);
+ const dep = new RequireContextDependency(requestExpr.string, recursive, regExp, asyncMode, expr.range);
dep.loc = expr.loc;
dep.optional = parser.scope.inTry;
parser.state.current.addDependency(dep);
diff --git a/node_modules/webpack/lib/dependencies/RequireContextPlugin.js b/node_modules/webpack/lib/dependencies/RequireContextPlugin.js
index 57acda586..3e08729d3 100644
--- a/node_modules/webpack/lib/dependencies/RequireContextPlugin.js
+++ b/node_modules/webpack/lib/dependencies/RequireContextPlugin.js
@@ -10,18 +10,17 @@ const ContextElementDependency = require("./ContextElementDependency");
const RequireContextDependencyParserPlugin = require("./RequireContextDependencyParserPlugin");
class RequireContextPlugin {
- constructor(modulesDirectories, extensions) {
+ constructor(modulesDirectories, extensions, mainFiles) {
if(!Array.isArray(modulesDirectories))
throw new Error("modulesDirectories must be an array");
if(!Array.isArray(extensions))
throw new Error("extensions must be an array");
this.modulesDirectories = modulesDirectories;
this.extensions = extensions;
+ this.mainFiles = mainFiles;
}
apply(compiler) {
- const modulesDirectories = this.modulesDirectories;
- const extensions = this.extensions;
compiler.plugin("compilation", (compilation, params) => {
const contextModuleFactory = params.contextModuleFactory;
const normalModuleFactory = params.normalModuleFactory;
@@ -43,7 +42,7 @@ class RequireContextPlugin {
if(items.length === 0) return callback(null, items);
callback(null, items.map((obj) => {
- return extensions.filter((ext) => {
+ return this.extensions.filter((ext) => {
const l = obj.request.length;
return l > ext.length && obj.request.substr(l - ext.length, l) === ext;
}).map((ext) => {
@@ -60,8 +59,28 @@ class RequireContextPlugin {
if(items.length === 0) return callback(null, items);
callback(null, items.map((obj) => {
- for(let i = 0; i < modulesDirectories.length; i++) {
- const dir = modulesDirectories[i];
+ return this.mainFiles.filter((mainFile) => {
+ const l = obj.request.length;
+ return l > mainFile.length + 1 && obj.request.substr(l - mainFile.length - 1, l) === "/" + mainFile;
+ }).map((mainFile) => {
+ const l = obj.request.length;
+ return [{
+ context: obj.context,
+ request: obj.request.substr(0, l - mainFile.length)
+ }, {
+ context: obj.context,
+ request: obj.request.substr(0, l - mainFile.length - 1)
+ }];
+ }).reduce((a, b) => a.concat(b), []).concat(obj);
+ }).reduce((a, b) => a.concat(b), []));
+ });
+
+ params.contextModuleFactory.plugin("alternatives", (items, callback) => {
+ if(items.length === 0) return callback(null, items);
+
+ callback(null, items.map((obj) => {
+ for(let i = 0; i < this.modulesDirectories.length; i++) {
+ const dir = this.modulesDirectories[i];
const idx = obj.request.indexOf("./" + dir + "/");
if(idx === 0) {
obj.request = obj.request.slice(dir.length + 3);
diff --git a/node_modules/webpack/lib/dependencies/RequireEnsureDependenciesBlock.js b/node_modules/webpack/lib/dependencies/RequireEnsureDependenciesBlock.js
index 4b3a378e9..4d72b07ab 100644
--- a/node_modules/webpack/lib/dependencies/RequireEnsureDependenciesBlock.js
+++ b/node_modules/webpack/lib/dependencies/RequireEnsureDependenciesBlock.js
@@ -11,14 +11,8 @@ module.exports = class RequireEnsureDependenciesBlock extends AsyncDependenciesB
super(chunkName, module, loc);
this.expr = expr;
const successBodyRange = successExpression && successExpression.body && successExpression.body.range;
- const errorBodyRange = errorExpression && errorExpression.body && errorExpression.body.range;
- this.range = null;
if(successBodyRange) {
- if(errorBodyRange) {
- this.range = [successBodyRange[0] + 1, errorBodyRange[1] - 1];
- } else {
- this.range = [successBodyRange[0] + 1, successBodyRange[1] - 1];
- }
+ this.range = [successBodyRange[0] + 1, successBodyRange[1] - 1];
}
this.chunkNameRange = chunkNameRange;
const dep = new RequireEnsureDependency(this);
diff --git a/node_modules/webpack/lib/dependencies/RequireResolveDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/RequireResolveDependencyParserPlugin.js
index 09dd60788..85451cf95 100644
--- a/node_modules/webpack/lib/dependencies/RequireResolveDependencyParserPlugin.js
+++ b/node_modules/webpack/lib/dependencies/RequireResolveDependencyParserPlugin.js
@@ -62,7 +62,7 @@ class RequireResolveDependencyParserPlugin {
if(!dep) return;
dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry;
- dep.weak = weak;
+ dep.async = weak ? "weak" : false;
parser.state.current.addDependency(dep);
return true;
});