2013-01-31 01:49:25 +08:00
|
|
|
/*
|
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
|
*/
|
2013-03-26 23:54:41 +08:00
|
|
|
var ConcatSource = require("webpack-core/lib/ConcatSource");
|
2013-01-31 01:49:25 +08:00
|
|
|
|
2013-10-16 04:00:28 +08:00
|
|
|
function SetVarMainTemplateDecorator(mainTemplate, varExpression, copyObject) {
|
2013-01-31 01:49:25 +08:00
|
|
|
this.mainTemplate = mainTemplate;
|
|
|
|
|
this.varExpression = varExpression;
|
2013-10-16 04:00:28 +08:00
|
|
|
this.copyObject = copyObject;
|
2013-01-31 01:49:25 +08:00
|
|
|
}
|
2013-03-11 21:51:23 +08:00
|
|
|
module.exports = SetVarMainTemplateDecorator;
|
|
|
|
|
SetVarMainTemplateDecorator.prototype.render = function(hash, chunk, moduleTemplate, dependencyTemplates) {
|
2013-01-31 01:49:25 +08:00
|
|
|
var source = this.mainTemplate.render(hash, chunk, moduleTemplate, dependencyTemplates);
|
2013-10-16 04:00:28 +08:00
|
|
|
if(this.copyObject) {
|
|
|
|
|
return new ConcatSource("(function(e, a) { for(var i in a) e[i] = a[i]; }(" +
|
|
|
|
|
this.varExpression + ", ", source, "))");
|
|
|
|
|
} else {
|
|
|
|
|
var prefix = this.varExpression + " =\n";
|
|
|
|
|
return new ConcatSource(prefix, source);
|
|
|
|
|
}
|
2013-01-31 01:49:25 +08:00
|
|
|
};
|
2013-03-11 21:51:23 +08:00
|
|
|
SetVarMainTemplateDecorator.prototype.updateHash = function(hash) {
|
2013-01-31 01:49:25 +08:00
|
|
|
hash.update("set var");
|
2014-02-11 15:53:32 +08:00
|
|
|
hash.update(this.varExpression + "");
|
|
|
|
|
hash.update(this.copyObject + "");
|
2013-01-31 01:49:25 +08:00
|
|
|
this.mainTemplate.updateHash(hash);
|
|
|
|
|
};
|