mirror of https://github.com/webpack/webpack.git
				
				
				
			
							parent
							
								
									cc930801b5
								
							
						
					
					
						commit
						4fef1312c5
					
				|  | @ -7,6 +7,9 @@ function BasicEvaluatedExpression() { | |||
| } | ||||
| module.exports = BasicEvaluatedExpression; | ||||
| 
 | ||||
| BasicEvaluatedExpression.prototype.isNull = function() { | ||||
| 	return !!this.null; | ||||
| }; | ||||
| BasicEvaluatedExpression.prototype.isString = function() { | ||||
| 	return Object.prototype.hasOwnProperty.call(this, "string"); | ||||
| }; | ||||
|  | @ -36,6 +39,7 @@ BasicEvaluatedExpression.prototype.isWrapped = function() { | |||
| }; | ||||
| BasicEvaluatedExpression.prototype.asBool = function() { | ||||
| 	if(this.isBoolean()) return this.bool; | ||||
| 	else if(this.isNull()) return false; | ||||
| 	else if(this.isString()) return !!this.string; | ||||
| 	else if(this.isNumber()) return !!this.number; | ||||
| 	else if(this.isRegExp()) return true; | ||||
|  | @ -48,6 +52,7 @@ BasicEvaluatedExpression.prototype.set = function(value) { | |||
| 	if(typeof value === "string") return this.setString(value); | ||||
| 	if(typeof value === "number") return this.setNumber(value); | ||||
| 	if(typeof value === "boolean") return this.setBoolean(value); | ||||
| 	if(value === null) return this.setNull(); | ||||
| 	if(value instanceof RegExp) return this.setRegExp(value); | ||||
| 	if(Array.isArray(value)) return this.setArray(value); | ||||
| 	return this; | ||||
|  | @ -59,6 +64,10 @@ BasicEvaluatedExpression.prototype.setString = function(str) { | |||
| 		this.string = str; | ||||
| 	return this; | ||||
| }; | ||||
| BasicEvaluatedExpression.prototype.setNull = function(str) { | ||||
| 	this.null = true; | ||||
| 	return this; | ||||
| }; | ||||
| BasicEvaluatedExpression.prototype.setNumber = function(num) { | ||||
| 	if(num === null) | ||||
| 		delete this.number; | ||||
|  |  | |||
|  | @ -33,6 +33,8 @@ Parser.prototype.initializeEvaluating = function() { | |||
| 		case "boolean": | ||||
| 			return new BasicEvaluatedExpression().setBoolean(expr.value).setRange(expr.range); | ||||
| 		} | ||||
| 		if(expr.value === null) | ||||
| 			return new BasicEvaluatedExpression().setNull().setRange(expr.range); | ||||
| 		if(expr.value instanceof RegExp) | ||||
| 			return new BasicEvaluatedExpression().setRegExp(expr.value).setRange(expr.range); | ||||
| 	}); | ||||
|  |  | |||
|  | @ -5,6 +5,12 @@ it("should define DEBUG", function() { | |||
| 	var y = DEBUG ? require("fail") : require("./a"); | ||||
| }); | ||||
| 
 | ||||
| it("should evaluate null", function() { | ||||
| 	var y = null ? require("fail") : require("./a"); | ||||
| 	if(null) | ||||
| 		require("fail"); | ||||
| }); | ||||
| 
 | ||||
| it("should short-circut evaluating", function() { | ||||
| 	var expr; | ||||
| 	var a = DEBUG && expr ? require("fail") : require("./a"); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue