| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | function BasicEvaluatedExpression() { | 
					
						
							|  |  |  | 	this.range = null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = BasicEvaluatedExpression; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-22 16:32:42 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.isNull = function() { | 
					
						
							|  |  |  | 	return !!this.null; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.isString = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "string"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.isNumber = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "number"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.isBoolean = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "bool"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.isRegExp = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "regExp"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.isConditional = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "options"); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.isArray = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "items"); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-12-08 21:59:52 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.isConstArray = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "array"); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-11-08 16:00:39 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.isIdentifier = function() { | 
					
						
							|  |  |  | 	return Object.prototype.hasOwnProperty.call(this, "identifier"); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.isWrapped = function() { | 
					
						
							| 
									
										
										
										
											2015-02-28 07:51:15 +08:00
										 |  |  | 	return Object.prototype.hasOwnProperty.call(this, "prefix") || Object.prototype.hasOwnProperty.call(this, "postfix"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-09-13 17:17:57 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.asBool = function() { | 
					
						
							|  |  |  | 	if(this.isBoolean()) return this.bool; | 
					
						
							| 
									
										
										
										
											2014-12-22 16:32:42 +08:00
										 |  |  | 	else if(this.isNull()) return false; | 
					
						
							| 
									
										
										
										
											2013-09-13 17:17:57 +08:00
										 |  |  | 	else if(this.isString()) return !!this.string; | 
					
						
							|  |  |  | 	else if(this.isNumber()) return !!this.number; | 
					
						
							|  |  |  | 	else if(this.isRegExp()) return true; | 
					
						
							|  |  |  | 	else if(this.isArray()) return true; | 
					
						
							| 
									
										
										
										
											2013-12-08 21:59:52 +08:00
										 |  |  | 	else if(this.isConstArray()) return true; | 
					
						
							| 
									
										
										
										
											2013-09-13 17:17:57 +08:00
										 |  |  | 	else if(this.isWrapped()) return this.prefix || this.postfix ? true : undefined; | 
					
						
							|  |  |  | 	return undefined; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2014-12-22 16:32:42 +08:00
										 |  |  | 	if(value === null) return this.setNull(); | 
					
						
							| 
									
										
										
										
											2013-09-13 17:17:57 +08:00
										 |  |  | 	if(value instanceof RegExp) return this.setRegExp(value); | 
					
						
							| 
									
										
										
										
											2013-12-08 21:59:52 +08:00
										 |  |  | 	if(Array.isArray(value)) return this.setArray(value); | 
					
						
							| 
									
										
										
										
											2013-09-13 17:17:57 +08:00
										 |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.setString = function(str) { | 
					
						
							|  |  |  | 	if(str === null) | 
					
						
							|  |  |  | 		delete this.string; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.string = str; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-12-22 16:32:42 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.setNull = function(str) { | 
					
						
							|  |  |  | 	this.null = true; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.setNumber = function(num) { | 
					
						
							|  |  |  | 	if(num === null) | 
					
						
							|  |  |  | 		delete this.number; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.number = num; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.setBoolean = function(bool) { | 
					
						
							|  |  |  | 	if(bool === null) | 
					
						
							|  |  |  | 		delete this.bool; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.bool = bool; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.setRegExp = function(regExp) { | 
					
						
							|  |  |  | 	if(regExp === null) | 
					
						
							|  |  |  | 		delete this.regExp; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.regExp = regExp; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-11-08 16:00:39 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.setIdentifier = function(identifier) { | 
					
						
							|  |  |  | 	if(identifier === null) | 
					
						
							|  |  |  | 		delete this.identifier; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.identifier = identifier; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.setWrapped = function(prefix, postfix) { | 
					
						
							|  |  |  | 	this.prefix = prefix; | 
					
						
							|  |  |  | 	this.postfix = postfix; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.unsetWrapped = function() { | 
					
						
							|  |  |  | 	delete this.prefix; | 
					
						
							|  |  |  | 	delete this.postfix; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.setOptions = function(options) { | 
					
						
							|  |  |  | 	if(options === null) | 
					
						
							|  |  |  | 		delete this.options; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.options = options; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.setItems = function(items) { | 
					
						
							|  |  |  | 	if(items === null) | 
					
						
							|  |  |  | 		delete this.items; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.items = items; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-12-08 21:59:52 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.setArray = function(array) { | 
					
						
							|  |  |  | 	if(array === null) | 
					
						
							|  |  |  | 		delete this.array; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		this.array = array; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | BasicEvaluatedExpression.prototype.addOptions = function(options) { | 
					
						
							|  |  |  | 	if(!this.options) this.options = []; | 
					
						
							|  |  |  | 	options.forEach(function(item) { | 
					
						
							|  |  |  | 		this.options.push(item); | 
					
						
							|  |  |  | 	}, this); | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | BasicEvaluatedExpression.prototype.setRange = function(range) { | 
					
						
							|  |  |  | 	this.range = range; | 
					
						
							|  |  |  | 	return this; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |