Skip to content

Commit

Permalink
accept truthy/falsy value for not
Browse files Browse the repository at this point in the history
fix #5100
  • Loading branch information
sokra committed Jun 20, 2017
1 parent bf4ec9c commit 8e4c842
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/BasicEvaluatedExpression.js
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions lib/Parser.js
Expand Up @@ -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()) {
Expand Down
8 changes: 8 additions & 0 deletions test/configCases/plugins/define-plugin/index.js
Expand Up @@ -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");
}
})

0 comments on commit 8e4c842

Please sign in to comment.