Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept truthy/falsy value for not #5112

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/BasicEvaluatedExpression.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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");
}
})