accept truthy/falsy value for not

fix #5100
This commit is contained in:
Tobias Koppers 2017-06-20 15:58:24 +02:00
parent bf4ec9c26e
commit 8e4c8423b5
3 changed files with 20 additions and 0 deletions

View File

@ -55,6 +55,14 @@ class BasicEvaluatedExpression {
return Object.prototype.hasOwnProperty.call(this, "quasis");
}
isTruthy() {
return this.truthy;
}
isFalsy() {
return this.falsy;
}
asBool() {
if(this.truthy) return true;
else if(this.falsy) return false;

View File

@ -242,6 +242,10 @@ class Parser extends Tapable {
if(!argument) return;
if(argument.isBoolean()) {
return new BasicEvaluatedExpression().setBoolean(!argument.bool).setRange(expr.range);
} else if(argument.isTruthy()) {
return new BasicEvaluatedExpression().setBoolean(false).setRange(expr.range);
} else if(argument.isFalsy()) {
return new BasicEvaluatedExpression().setBoolean(true).setRange(expr.range);
} else if(argument.isString()) {
return new BasicEvaluatedExpression().setBoolean(!argument.string).setRange(expr.range);
} else if(argument.isNumber()) {

View File

@ -98,3 +98,11 @@ it("should not explode on recursive statements", function() {
wurst; // <- is recursivly defined in config
}).should.throw("suppe is not defined");
});
it("should evaluate composed expressions (issue 5100)", function() {
if(!module.hot && process.env.DEFINED_NESTED_KEY_STRING === "string") {
// ok
} else {
require("fail");
}
})