Code coverage report for lib\ConstPlugin.js

Statements: 94.29% (33 / 35)      Branches: 66.67% (8 / 12)      Functions: 100% (7 / 7)      Lines: 100% (33 / 33)      Ignored: none     

All files » lib\ » ConstPlugin.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        1 1   1   1   1   1 484 496 496   484 7261 7261 7261 160 160 160     484 810 810 810 30 30 30     484 30 30 30 30 30   484 10 10 10    
/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
var ConstDependency = require("./dependencies/ConstDependency");
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
 
var NullFactory = require("./NullFactory");
 
function ConstPlugin() {
}
module.exports = ConstPlugin;
 
ConstPlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation, params) {
		compilation.dependencyFactories.set(ConstDependency, new NullFactory());
		compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
	});
	compiler.parser.plugin("statement if", function(statement) {
		var param = this.evaluateExpression(statement.test);
		var bool = param.asBool();
		if(typeof bool === "boolean") {
			Eif(statement.test.type !== "Literal")
				this.state.current.addDependency(new ConstDependency(bool + "", param.range));
			return bool;
		}
	});
	compiler.parser.plugin("expression ?:", function(expression) {
		var param = this.evaluateExpression(expression.test);
		var bool = param.asBool();
		if(typeof bool === "boolean") {
			Eif(expression.test.type !== "Literal")
				this.state.current.addDependency(new ConstDependency(bool + "", param.range));
			return bool;
		}
	});
	compiler.parser.plugin("evaluate Identifier __resourceQuery", function(expr) {
		Iif(!this.state.module) return;
		var res = new BasicEvaluatedExpression();
		res.setString(this.state.module.splitQuery(this.state.module.resource)[1]);
		res.setRange(expr.range);
		return res;
	});
	compiler.parser.plugin("expression __resourceQuery", function(expr) {
		Iif(!this.state.module) return;
		this.state.current.addVariable("__resourceQuery", JSON.stringify(this.state.module.splitQuery(this.state.module.resource)[1]));
		return true;
	});
};