diff options
| author | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:10:37 +0200 |
|---|---|---|
| committer | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:11:17 +0200 |
| commit | 7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch) | |
| tree | 70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/webpack/lib/dependencies | |
| parent | aca1143cb9eed16cf37f04e475e4257418dd18ac (diff) | |
fix build issues and add typedoc
Diffstat (limited to 'node_modules/webpack/lib/dependencies')
11 files changed, 168 insertions, 14 deletions
diff --git a/node_modules/webpack/lib/dependencies/DepBlockHelpers.js b/node_modules/webpack/lib/dependencies/DepBlockHelpers.js index aef63fded..d4a4014ec 100644 --- a/node_modules/webpack/lib/dependencies/DepBlockHelpers.js +++ b/node_modules/webpack/lib/dependencies/DepBlockHelpers.js @@ -33,7 +33,7 @@ DepBlockHelpers.getDepBlockPromise = function(depBlock, outputOptions, requestSh "])";
}
}
- return "Promise.resolve()";
+ return "new Promise(function(resolve) { resolve(); })";
};
function asComment(str) {
diff --git a/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js b/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js index 8016dac80..9407499dc 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js +++ b/node_modules/webpack/lib/dependencies/HarmonyCompatibilityDependency.js @@ -22,7 +22,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate if(usedExports && !Array.isArray(usedExports)) {
const exportName = dep.originModule.exportsArgument || "exports";
const content = `Object.defineProperty(${exportName}, \"__esModule\", { value: true });\n`;
- source.insert(-1, content);
+ source.insert(-10, content);
}
}
};
diff --git a/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js b/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js index 3edf6e642..d6f37fce1 100644 --- a/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/HarmonyExportDependencyParserPlugin.js @@ -45,7 +45,7 @@ module.exports = class HarmonyExportDependencyParserPlugin { } else {
const immutable = statement.declaration && isImmutableStatement(statement.declaration);
const hoisted = statement.declaration && isHoistedStatement(statement.declaration);
- dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -0.5 : (statement.range[1] + 0.5), immutable);
+ dep = new HarmonyExportSpecifierDependency(parser.state.module, id, name, !immutable || hoisted ? -2 : (statement.range[1] + 0.5), immutable);
}
dep.loc = Object.create(statement.loc);
dep.loc.index = idx;
diff --git a/node_modules/webpack/lib/dependencies/ImportContextDependency.js b/node_modules/webpack/lib/dependencies/ImportContextDependency.js index 7b688d5d9..252bc75a0 100644 --- a/node_modules/webpack/lib/dependencies/ImportContextDependency.js +++ b/node_modules/webpack/lib/dependencies/ImportContextDependency.js @@ -12,7 +12,6 @@ class ImportContextDependency extends ContextDependency { super(request, recursive, regExp);
this.range = range;
this.valueRange = valueRange;
- this.async = true;
this.chunkName = chunkName;
}
diff --git a/node_modules/webpack/lib/dependencies/ImportDependency.js b/node_modules/webpack/lib/dependencies/ImportDependency.js index 8858ba20b..4c2667756 100644 --- a/node_modules/webpack/lib/dependencies/ImportDependency.js +++ b/node_modules/webpack/lib/dependencies/ImportDependency.js @@ -44,7 +44,7 @@ ImportDependency.Template = class ImportDependencyTemplate { if(dep.module) {
const stringifiedId = JSON.stringify(dep.module.id);
- return `Promise.resolve(__webpack_require__(${comment}${stringifiedId}))`;
+ return `new Promise(function(resolve) { resolve(__webpack_require__(${comment}${stringifiedId})); })`;
}
return webpackMissingPromiseModule(dep.request);
diff --git a/node_modules/webpack/lib/dependencies/ImportEagerContextDependency.js b/node_modules/webpack/lib/dependencies/ImportEagerContextDependency.js new file mode 100644 index 000000000..a4b7388bc --- /dev/null +++ b/node_modules/webpack/lib/dependencies/ImportEagerContextDependency.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 ImportEagerContextDependency extends ImportContextDependency {
+ constructor(request, recursive, regExp, range, valueRange, chunkName) {
+ super(request, recursive, regExp, range, valueRange, chunkName);
+ this.async = "eager";
+ }
+
+ get type() {
+ return "import() context eager";
+ }
+}
+
+ImportEagerContextDependency.Template = ContextDependencyTemplateAsRequireCall;
+
+module.exports = ImportEagerContextDependency;
diff --git a/node_modules/webpack/lib/dependencies/ImportEagerDependency.js b/node_modules/webpack/lib/dependencies/ImportEagerDependency.js new file mode 100644 index 000000000..9e1c2ace1 --- /dev/null +++ b/node_modules/webpack/lib/dependencies/ImportEagerDependency.js @@ -0,0 +1,46 @@ +/*
+ 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 ImportEagerDependency extends ModuleDependency {
+ constructor(request, range) {
+ super(request);
+ this.range = range;
+ }
+
+ get type() {
+ return "import()";
+ }
+}
+
+ImportEagerDependency.Template = class ImportEagerDependencyTemplate {
+ 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 `new Promise(function(resolve) { resolve(__webpack_require__(${comment}${stringifiedId})); })`;
+ }
+
+ return webpackMissingPromiseModule(dep.request);
+ }
+};
+
+module.exports = ImportEagerDependency;
diff --git a/node_modules/webpack/lib/dependencies/ImportLazyContextDependency.js b/node_modules/webpack/lib/dependencies/ImportLazyContextDependency.js new file mode 100644 index 000000000..b6f9187c9 --- /dev/null +++ b/node_modules/webpack/lib/dependencies/ImportLazyContextDependency.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 ImportLazyContextDependency extends ImportContextDependency {
+ constructor(request, recursive, regExp, range, valueRange, chunkName) {
+ super(request, recursive, regExp, range, valueRange, chunkName);
+ this.async = "lazy";
+ }
+
+ get type() {
+ return "import() context lazy";
+ }
+}
+
+ImportLazyContextDependency.Template = ContextDependencyTemplateAsRequireCall;
+
+module.exports = ImportLazyContextDependency;
diff --git a/node_modules/webpack/lib/dependencies/ImportLazyOnceContextDependency.js b/node_modules/webpack/lib/dependencies/ImportLazyOnceContextDependency.js new file mode 100644 index 000000000..607ac3f2d --- /dev/null +++ b/node_modules/webpack/lib/dependencies/ImportLazyOnceContextDependency.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 ImportLazyOnceContextDependency extends ImportContextDependency {
+ constructor(request, recursive, regExp, range, valueRange, chunkName) {
+ super(request, recursive, regExp, range, valueRange, chunkName);
+ this.async = "lazy-once";
+ }
+
+ get type() {
+ return "import() context lazy-once";
+ }
+}
+
+ImportLazyOnceContextDependency.Template = ContextDependencyTemplateAsRequireCall;
+
+module.exports = ImportLazyOnceContextDependency;
diff --git a/node_modules/webpack/lib/dependencies/ImportParserPlugin.js b/node_modules/webpack/lib/dependencies/ImportParserPlugin.js index 73972ebee..d97355dc7 100644 --- a/node_modules/webpack/lib/dependencies/ImportParserPlugin.js +++ b/node_modules/webpack/lib/dependencies/ImportParserPlugin.js @@ -4,9 +4,13 @@ */
"use strict";
-const ImportContextDependency = require("./ImportContextDependency");
+const ImportEagerContextDependency = require("./ImportEagerContextDependency");
+const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
+const ImportLazyContextDependency = require("./ImportLazyContextDependency");
const ImportDependenciesBlock = require("./ImportDependenciesBlock");
+const ImportEagerDependency = require("./ImportEagerDependency");
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
+const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
class ImportParserPlugin {
constructor(options) {
@@ -23,22 +27,49 @@ class ImportParserPlugin { const param = parser.evaluateExpression(expr.arguments[0]);
let chunkName = null;
+ let mode = "lazy";
const importOptions = parser.getCommentOptions(expr.range);
if(importOptions) {
if(typeof importOptions.webpackChunkName !== "undefined") {
if(typeof importOptions.webpackChunkName !== "string")
- throw new Error(`\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`);
- chunkName = importOptions.webpackChunkName;
+ parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`));
+ else
+ chunkName = importOptions.webpackChunkName;
+ }
+ if(typeof importOptions.webpackMode !== "undefined") {
+ if(typeof importOptions.webpackMode !== "string")
+ parser.state.module.warnings.push(new UnsupportedFeatureWarning(parser.state.module, `\`webpackMode\` expected a string, but received: ${importOptions.webpackMode}.`));
+ else
+ mode = importOptions.webpackMode;
}
}
if(param.isString()) {
- const depBlock = new ImportDependenciesBlock(param.string, expr.range, chunkName, parser.state.module, expr.loc);
- parser.state.current.addBlock(depBlock);
+ 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 === "eager") {
+ const dep = new ImportEagerDependency(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 {
- const dep = ContextDependencyHelpers.create(ImportContextDependency, expr.range, param, expr, options, chunkName);
+ 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}.`));
+ }
+
+ let Dep = ImportLazyContextDependency;
+ if(mode === "eager") {
+ Dep = ImportEagerContextDependency;
+ } else if(mode === "lazy-once") {
+ Dep = ImportLazyOnceContextDependency;
+ }
+ const dep = ContextDependencyHelpers.create(Dep, expr.range, param, expr, options, chunkName);
if(!dep) return;
dep.loc = expr.loc;
dep.optional = !!parser.scope.inTry;
diff --git a/node_modules/webpack/lib/dependencies/ImportPlugin.js b/node_modules/webpack/lib/dependencies/ImportPlugin.js index 487b97455..4905df183 100644 --- a/node_modules/webpack/lib/dependencies/ImportPlugin.js +++ b/node_modules/webpack/lib/dependencies/ImportPlugin.js @@ -5,7 +5,10 @@ "use strict";
const ImportDependency = require("./ImportDependency");
-const ImportContextDependency = require("./ImportContextDependency");
+const ImportEagerDependency = require("./ImportEagerDependency");
+const ImportEagerContextDependency = require("./ImportEagerContextDependency");
+const ImportLazyOnceContextDependency = require("./ImportLazyOnceContextDependency");
+const ImportLazyContextDependency = require("./ImportLazyContextDependency");
const ImportParserPlugin = require("./ImportParserPlugin");
class ImportPlugin {
@@ -22,8 +25,17 @@ class ImportPlugin { compilation.dependencyFactories.set(ImportDependency, normalModuleFactory);
compilation.dependencyTemplates.set(ImportDependency, new ImportDependency.Template());
- compilation.dependencyFactories.set(ImportContextDependency, contextModuleFactory);
- compilation.dependencyTemplates.set(ImportContextDependency, new ImportContextDependency.Template());
+ compilation.dependencyFactories.set(ImportEagerDependency, normalModuleFactory);
+ compilation.dependencyTemplates.set(ImportEagerDependency, new ImportEagerDependency.Template());
+
+ compilation.dependencyFactories.set(ImportEagerContextDependency, contextModuleFactory);
+ compilation.dependencyTemplates.set(ImportEagerContextDependency, new ImportEagerContextDependency.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) => {
|
