Skip to content

Commit

Permalink
Allows variables that evaluate to falsy to be returned (#23)
Browse files Browse the repository at this point in the history
The current code skips particular scopes that have a variable defined
when the variable is falsy. This is no good as legitimate values such
as empty string and boolean 'false' are then skipped and end up being
set to undefined.
  • Loading branch information
rcrichton authored Nov 22, 2021
1 parent 44bfed3 commit 28e5acc
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/shim/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,14 +527,23 @@ const pm = Object.freeze({
/* General variable access */
variables: Object.freeze({
get(name) {
return (
(scope.local[Has](name) && scope.local[name]) ||
(scope.data[Has](name) && scope.data[name]) ||
(scope.environment[Has](name) && scope.environment[name]) ||
(scope.collection[Has](name) && scope.collection[name]) ||
(scope.global[Has](name) && scope.global[name]) ||
undef
);
if (scope.local[Has](name)) {
return scope.local[name];
}
if (scope.data[Has](name)) {
return scope.data[name];
}
if (scope.environment[Has](name)) {
return scope.environment[name];
}
if (scope.collection[Has](name)) {
return scope.collection[name];
}
if (scope.global[Has](name)) {
return scope.global[name];
}

return undef;
},
set(name, value) {
requireRequest();
Expand Down

0 comments on commit 28e5acc

Please sign in to comment.