Sha256: 74033432e8223eab10b9e6270efac340eaec9323a5dd6beb494b7f9a39ff5a3c

Contents?: true

Size: 1.78 KB

Versions: 62

Compression:

Stored size: 1.78 KB

Contents

/*
	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") {
			if(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") {
			if(expression.test.type !== "Literal")
				this.state.current.addDependency(new ConstDependency(bool + "", param.range));
			return bool;
		}
	});
	compiler.parser.plugin("evaluate Identifier __resourceQuery", function(expr) {
		if(!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) {
		if(!this.state.module) return;
		this.state.current.addVariable("__resourceQuery", JSON.stringify(this.state.module.splitQuery(this.state.module.resource)[1]));
		return true;
	});
};

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
smock-0.1.268 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.267 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.266 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.265 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.264 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.263 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.262 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.261 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.260 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.259 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.258 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.256 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.255 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.254 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.253 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.252 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.251 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.250 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.249 node_modules/webpack/lib/ConstPlugin.js
smock-0.1.247 node_modules/webpack/lib/ConstPlugin.js