mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 20:30:39 -07:00
eslint
This commit is contained in:
+40
-40
@@ -1,55 +1,55 @@
|
||||
const operators = require('./operators.js');
|
||||
const lexical = require('./lexical.js');
|
||||
const assert = require('../src/util/assert.js');
|
||||
const operators = require('./operators.js')
|
||||
const lexical = require('./lexical.js')
|
||||
const assert = require('../src/util/assert.js')
|
||||
|
||||
function evalExp(exp, scope) {
|
||||
assert(scope, 'unable to evalExp: scope undefined');
|
||||
var operatorREs = lexical.operators,
|
||||
match;
|
||||
for (var i = 0; i < operatorREs.length; i++) {
|
||||
var operatorRE = operatorREs[i];
|
||||
var expRE = new RegExp(`^(${lexical.quoteBalanced.source})(${operatorRE.source})(${lexical.quoteBalanced.source})$`);
|
||||
if (match = exp.match(expRE)) {
|
||||
var l = evalExp(match[1], scope);
|
||||
var op = operators[match[2].trim()];
|
||||
var r = evalExp(match[3], scope);
|
||||
return op(l, r);
|
||||
}
|
||||
function evalExp (exp, scope) {
|
||||
assert(scope, 'unable to evalExp: scope undefined')
|
||||
var operatorREs = lexical.operators
|
||||
var match
|
||||
for (var i = 0; i < operatorREs.length; i++) {
|
||||
var operatorRE = operatorREs[i]
|
||||
var expRE = new RegExp(`^(${lexical.quoteBalanced.source})(${operatorRE.source})(${lexical.quoteBalanced.source})$`)
|
||||
if ((match = exp.match(expRE))) {
|
||||
var l = evalExp(match[1], scope)
|
||||
var op = operators[match[2].trim()]
|
||||
var r = evalExp(match[3], scope)
|
||||
return op(l, r)
|
||||
}
|
||||
}
|
||||
|
||||
if (match = exp.match(lexical.rangeLine)) {
|
||||
var low = evalValue(match[1], scope),
|
||||
high = evalValue(match[2], scope);
|
||||
var range = [];
|
||||
for (var j = low; j <= high; j++) {
|
||||
range.push(j);
|
||||
}
|
||||
return range;
|
||||
if ((match = exp.match(lexical.rangeLine))) {
|
||||
var low = evalValue(match[1], scope)
|
||||
var high = evalValue(match[2], scope)
|
||||
var range = []
|
||||
for (var j = low; j <= high; j++) {
|
||||
range.push(j)
|
||||
}
|
||||
return range
|
||||
}
|
||||
|
||||
return evalValue(exp, scope);
|
||||
return evalValue(exp, scope)
|
||||
}
|
||||
|
||||
function evalValue(str, scope) {
|
||||
str = str && str.trim();
|
||||
if (!str) return undefined;
|
||||
function evalValue (str, scope) {
|
||||
str = str && str.trim()
|
||||
if (!str) return undefined
|
||||
|
||||
if (lexical.isLiteral(str)) {
|
||||
return lexical.parseLiteral(str);
|
||||
}
|
||||
if (lexical.isVariable(str)) {
|
||||
return scope.get(str);
|
||||
}
|
||||
if (lexical.isLiteral(str)) {
|
||||
return lexical.parseLiteral(str)
|
||||
}
|
||||
if (lexical.isVariable(str)) {
|
||||
return scope.get(str)
|
||||
}
|
||||
}
|
||||
|
||||
function isTruthy(val) {
|
||||
return !isFalsy(val);
|
||||
function isTruthy (val) {
|
||||
return !isFalsy(val)
|
||||
}
|
||||
|
||||
function isFalsy(val) {
|
||||
return false === val || undefined === val || null === val;;
|
||||
function isFalsy (val) {
|
||||
return val === false || undefined === val || val === null
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
evalExp, evalValue, isTruthy, isFalsy
|
||||
};
|
||||
evalExp, evalValue, isTruthy, isFalsy
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user