Comparing version 0.1.0 to 0.1.1
@@ -35,17 +35,32 @@ "use strict"; | ||
if (options.Constants && contains(options.Constants, name)) { | ||
const value = options.Constants[name]; | ||
if (options.Constants) { | ||
let constValue = undefined; | ||
if (typeof value === 'function') { | ||
return (0, _.makeConstEval)((0, _util.bindFunction)(value, options.Constants)); | ||
if (contains(options.Constants, name)) { | ||
constValue = options.Constants[name]; | ||
} else if (contains(options.Constants, _.ValueLookup)) { | ||
constValue = options.Constants[_.ValueLookup](name); | ||
} | ||
return (0, _.makeConstEval)(value); | ||
if (constValue !== undefined) { | ||
if (typeof constValue === 'function') { | ||
return (0, _.makeConstEval)((0, _util.bindFunction)(constValue, options.Constants)); | ||
} | ||
return (0, _.makeConstEval)(constValue); | ||
} | ||
} | ||
const get = options.NoProtoAccess ? _util.ownPropGetter : (0, _util.makeProtoPropGetter)(options); | ||
return context => { | ||
let value = get(context, name); | ||
const evaluator = context => { | ||
const value = get(context, name); | ||
if (value === undefined && contains(context, _.ValueLookup)) { | ||
value = context[_.ValueLookup](name); | ||
} | ||
if (options.NoUndefinedVars && value === undefined) { | ||
throw new ReferenceError((0, _Error.UndefinedIdentifier)(name)); | ||
} | ||
if (typeof value === 'function') { | ||
@@ -57,16 +72,4 @@ return (0, _util.bindFunction)(value, context); | ||
}; | ||
if (options.NoUndefinedVars) { | ||
return (context, stack) => { | ||
if (!contains(context, name)) { | ||
throw new ReferenceError((0, _Error.UndefinedIdentifier)(name)); | ||
} | ||
return evaluator(context, stack); | ||
}; | ||
} | ||
return evaluator; | ||
}; | ||
exports.Identifier = Identifier; |
@@ -11,3 +11,3 @@ "use strict"; | ||
exports.evalConst = evalConst; | ||
exports.AsyncValue = exports.ConstValue = void 0; | ||
exports.ValueLookup = exports.AsyncValue = exports.ConstValue = void 0; | ||
const ConstValue = Symbol('const'); | ||
@@ -17,2 +17,4 @@ exports.ConstValue = ConstValue; | ||
exports.AsyncValue = AsyncValue; | ||
const ValueLookup = Symbol('lookup'); | ||
exports.ValueLookup = ValueLookup; | ||
@@ -19,0 +21,0 @@ function mark(attrib, evaluator) { |
{ | ||
"name": "numenor", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Customizable, safe evaluator of JavaScript-like expressions.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120639
3074