mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
feat: with & for in render tag, closes #195
This commit is contained in:
@@ -4,14 +4,15 @@ import { Value } from './value'
|
||||
import { Context } from '../context/context'
|
||||
import { toValue } from '../util/underscore'
|
||||
import { isOperator, precedence, operatorImpls } from './operator'
|
||||
import { tokenize } from '../parser/expression-tokenizer'
|
||||
import { Tokenizer } from '../parser/tokenizer'
|
||||
|
||||
export class Expression {
|
||||
private operands: any[] = []
|
||||
private postfix: string[]
|
||||
|
||||
public constructor (str = '') {
|
||||
this.postfix = [...toPostfix(tokenize(str))]
|
||||
const tokenizer = new Tokenizer(str)
|
||||
this.postfix = [...toPostfix(tokenizer.readExpression())]
|
||||
}
|
||||
public * evaluate (ctx: Context) {
|
||||
assert(ctx, 'unable to evaluate: context not defined')
|
||||
|
||||
@@ -52,8 +52,6 @@ export const operatorImpls: {[key: string]: (lhs: any, rhs: any) => boolean} = {
|
||||
'or': (l: any, r: any) => isTruthy(l) || isTruthy(r)
|
||||
}
|
||||
|
||||
const list = Object.keys(precedence)
|
||||
|
||||
export function isOperator (token: string) {
|
||||
return list.includes(token)
|
||||
return precedence.hasOwnProperty(token)
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@ import { Context } from '../context/context'
|
||||
import { range } from '../util/underscore'
|
||||
import { Value } from './value'
|
||||
|
||||
export function isRange (token: string) {
|
||||
return token[0] === '(' && token[token.length - 1] === ')'
|
||||
export function isRange (str: string) {
|
||||
return rangeLine.test(str)
|
||||
}
|
||||
|
||||
export function * rangeValue (token: string, ctx: Context) {
|
||||
|
||||
Reference in New Issue
Block a user