aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/DelegatedModule.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/webpack/lib/DelegatedModule.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/webpack/lib/DelegatedModule.js')
-rw-r--r--node_modules/webpack/lib/DelegatedModule.js212
1 files changed, 114 insertions, 98 deletions
diff --git a/node_modules/webpack/lib/DelegatedModule.js b/node_modules/webpack/lib/DelegatedModule.js
index 4046d03d5..170ceca7a 100644
--- a/node_modules/webpack/lib/DelegatedModule.js
+++ b/node_modules/webpack/lib/DelegatedModule.js
@@ -1,98 +1,114 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Tobias Koppers @sokra
-*/
-"use strict";
-
-const Module = require("./Module");
-const OriginalSource = require("webpack-sources").OriginalSource;
-const RawSource = require("webpack-sources").RawSource;
-const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
-const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
-const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
-
-class DelegatedModule extends Module {
- constructor(sourceRequest, data, type, userRequest, originalRequest) {
- super();
- this.sourceRequest = sourceRequest;
- this.request = data.id;
- this.meta = data.meta;
- this.type = type;
- this.originalRequest = originalRequest;
- this.userRequest = userRequest;
- this.built = false;
- this.delegated = true;
- this.delegateData = data;
- }
-
- libIdent(options) {
- return typeof this.originalRequest === "string" ? this.originalRequest : this.originalRequest.libIdent(options);
- }
-
- identifier() {
- return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
- }
-
- readableIdentifier() {
- return `delegated ${this.userRequest} from ${this.sourceRequest}`;
- }
-
- needRebuild() {
- return false;
- }
-
- build(options, compilation, resolver, fs, callback) {
- this.built = true;
- this.builtTime = Date.now();
- this.cacheable = true;
- this.dependencies.length = 0;
- this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
- this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true));
- callback();
- }
-
- unbuild() {
- this.built = false;
- super.unbuild();
- }
-
- source() {
- const sourceModule = this.dependencies[0].module;
- let str;
-
- if(!sourceModule) {
- str = WebpackMissingModule.moduleCode(this.sourceRequest);
- } else {
- str = `module.exports = (__webpack_require__(${JSON.stringify(sourceModule.id)}))`;
-
- switch(this.type) {
- case "require":
- str += `(${JSON.stringify(this.request)})`;
- break;
- case "object":
- str += `[${JSON.stringify(this.request)}]`;
- break;
- }
-
- str += ";";
- }
-
- if(this.useSourceMap) {
- return new OriginalSource(str, this.identifier());
- } else {
- return new RawSource(str);
- }
- }
-
- size() {
- return 42;
- }
-
- updateHash(hash) {
- hash.update(this.type);
- hash.update(JSON.stringify(this.request));
- super.updateHash(hash);
- }
-}
-
-module.exports = DelegatedModule;
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+"use strict";
+
+const { OriginalSource, RawSource } = require("webpack-sources");
+
+const Module = require("./Module");
+const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
+const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
+const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
+
+/** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
+/** @typedef {import("./util/createHash").Hash} Hash */
+
+class DelegatedModule extends Module {
+ constructor(sourceRequest, data, type, userRequest, originalRequest) {
+ super("javascript/dynamic", null);
+
+ // Info from Factory
+ this.sourceRequest = sourceRequest;
+ this.request = data.id;
+ this.type = type;
+ this.userRequest = userRequest;
+ this.originalRequest = originalRequest;
+ this.delegateData = data;
+
+ // Build info
+ this.delegatedSourceDependency = undefined;
+ }
+
+ libIdent(options) {
+ return typeof this.originalRequest === "string"
+ ? this.originalRequest
+ : this.originalRequest.libIdent(options);
+ }
+
+ identifier() {
+ return `delegated ${JSON.stringify(this.request)} from ${
+ this.sourceRequest
+ }`;
+ }
+
+ readableIdentifier() {
+ return `delegated ${this.userRequest} from ${this.sourceRequest}`;
+ }
+
+ needRebuild() {
+ return false;
+ }
+
+ build(options, compilation, resolver, fs, callback) {
+ this.built = true;
+ this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
+ this.buildInfo = {};
+ this.delegatedSourceDependency = new DelegatedSourceDependency(
+ this.sourceRequest
+ );
+ this.addDependency(this.delegatedSourceDependency);
+ this.addDependency(
+ new DelegatedExportsDependency(this, this.delegateData.exports || true)
+ );
+ callback();
+ }
+
+ source(depTemplates, runtime) {
+ const dep = /** @type {DelegatedSourceDependency} */ (this.dependencies[0]);
+ const sourceModule = dep.module;
+ let str;
+
+ if (!sourceModule) {
+ str = WebpackMissingModule.moduleCode(this.sourceRequest);
+ } else {
+ str = `module.exports = (${runtime.moduleExports({
+ module: sourceModule,
+ request: dep.request
+ })})`;
+
+ switch (this.type) {
+ case "require":
+ str += `(${JSON.stringify(this.request)})`;
+ break;
+ case "object":
+ str += `[${JSON.stringify(this.request)}]`;
+ break;
+ }
+
+ str += ";";
+ }
+
+ if (this.useSourceMap) {
+ return new OriginalSource(str, this.identifier());
+ } else {
+ return new RawSource(str);
+ }
+ }
+
+ size() {
+ return 42;
+ }
+
+ /**
+ * @param {Hash} hash the hash used to track dependencies
+ * @returns {void}
+ */
+ updateHash(hash) {
+ hash.update(this.type);
+ hash.update(JSON.stringify(this.request));
+ super.updateHash(hash);
+ }
+}
+
+module.exports = DelegatedModule;