Code coverage report for lib\ExternalModule.js

Statements: 84.62% (44 / 52)      Branches: 60% (12 / 20)      Functions: 66.67% (6 / 9)      Lines: 84.31% (43 / 51)      Ignored: none     

All files » lib\ » ExternalModule.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88        1 1 1 1   1 110 110 110 110   1   1   1   1 550     1 179     1       1 69 69     1 69 69 69 69                         65         65 65     3 3 1   3 3   1 1 1   1 1   69 40   29       1 134  
/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
var Module = require("./Module");
var OriginalSource = require("webpack-core/lib/OriginalSource");
var RawSource = require("webpack-core/lib/RawSource");
var WebpackMissingModule = require("./dependencies/WebpackMissingModule");
 
function ExternalModule(request, type) {
	Module.call(this);
	this.request = request;
	this.type = type;
	this.built = false;
}
module.exports = ExternalModule;
 
ExternalModule.prototype = Object.create(Module.prototype);
 
ExternalModule.prototype.external = true;
 
ExternalModule.prototype.identifier = function() {
	return "external " + JSON.stringify(this.request);
};
 
ExternalModule.prototype.readableIdentifier = function(requestShortener) {
	return "external " + JSON.stringify(this.request);
};
 
ExternalModule.prototype.needRebuild = function(fileTimestamps, contextTimestamps) {
	return false;
};
 
ExternalModule.prototype.build = function(options, compilation, resolver, fs, callback) {
	this.builtTime = new Date().getTime();
	callback();
};
 
ExternalModule.prototype.source = function(dependencyTemplates, outputOptions, requestShortener) {
	var str = "throw new Error('Externals not supported');";
	var request = this.request;
	if(typeof request === "object") request = request[this.type];
	switch(this.type) {
	case "this":
	case "window":
	case "global":
		if(Array.isArray(request)) {
			str = "(function() { module.exports = " + this.type + request.map(function(r) {
				return "[" + JSON.stringify(r) + "]";
			}).join("") + "; }());";
		} else
			str = "(function() { module.exports = " + this.type + "[" + JSON.stringify(request) + "]; }());";
		break;
	case "commonjs":
	case "commonjs2":
		Iif(Array.isArray(request)) {
			str = "module.exports = require(" + JSON.stringify(request[0]) + ")" + request.slice(1).map(function(r) {
				return "[" + JSON.stringify(r) + "]";
			}).join("") + ";";
		} else 
			str = "module.exports = require(" + JSON.stringify(request) + ");";
		break;
	case "amd":
	case "umd":
		str = "";
		if(this.optional) {
			str += "if(typeof __WEBPACK_EXTERNAL_MODULE_" + this.id + "__ === 'undefined') {" + WebpackMissingModule.moduleCode(request) + "}\n";
		}
		str += "module.exports = __WEBPACK_EXTERNAL_MODULE_" + this.id + "__;";
		break;
	default:
		str = "";
		Eif(this.optional) {
			str += "if(typeof " + request + " === 'undefined') {" + WebpackMissingModule.moduleCode(request) + "}\n";
		}
		str += "module.exports = " + request + ";";
		break;
	}
	if(this.useSourceMap) {
		return new OriginalSource(str, this.identifier());
	} else {
		return new RawSource(str);
	}
};
 
ExternalModule.prototype.size = function() {
	return 42;
};