wallet-core/node_modules/webpack/lib/DelegatedModule.js

93 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-05-03 15:35:00 +02:00
/*
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");
2017-08-14 05:01:11 +02:00
const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
2017-05-03 15:35:00 +02:00
class DelegatedModule extends Module {
2017-08-14 05:01:11 +02:00
constructor(sourceRequest, data, type, userRequest, originalRequest) {
2017-05-03 15:35:00 +02:00
super();
this.sourceRequest = sourceRequest;
this.request = data.id;
this.meta = data.meta;
this.type = type;
2017-08-14 05:01:11 +02:00
this.originalRequest = originalRequest;
2017-05-03 15:35:00 +02:00
this.userRequest = userRequest;
this.built = false;
this.delegated = true;
this.delegateData = data;
}
2017-08-14 05:01:11 +02:00
libIdent(options) {
return typeof this.originalRequest === "string" ? this.originalRequest : this.originalRequest.libIdent(options);
}
2017-05-03 15:35:00 +02:00
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;
2017-05-24 15:10:37 +02:00
this.builtTime = Date.now();
2017-08-14 05:01:11 +02:00
this.cacheable = true;
2017-05-03 15:35:00 +02:00
this.dependencies.length = 0;
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
2017-08-14 05:01:11 +02:00
this.addDependency(new DelegatedExportsDependency(this, this.delegateData.exports || true));
2017-05-03 15:35:00 +02:00
callback();
}
unbuild() {
this.built = false;
super.unbuild();
}
source() {
const sourceModule = this.dependencies[0].module;
let str;
if(!sourceModule) {
str = WebpackMissingModule.moduleCode(this.sourceRequest);
} else {
2017-08-14 05:01:11 +02:00
str = `module.exports = (__webpack_require__(${JSON.stringify(sourceModule.id)}))`;
2017-05-03 15:35:00 +02:00
switch(this.type) {
case "require":
str += `(${JSON.stringify(this.request)})`;
break;
case "object":
str += `[${JSON.stringify(this.request)}]`;
break;
}
2017-05-24 15:10:37 +02:00
str += ";";
2017-05-03 15:35:00 +02:00
}
if(this.useSourceMap) {
return new OriginalSource(str, this.identifier());
} else {
return new RawSource(str);
}
}
size() {
return 42;
}
}
module.exports = DelegatedModule;