mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
refactor: rewrite expression evaluation, fix #130
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { parseValue } from '../../render/syntax'
|
||||
import { Expression } from '../../render/expression'
|
||||
import { Context } from '../../context/context'
|
||||
import { isArray } from '../../util/underscore'
|
||||
import { FilterImplOptions } from './filter-impl-options'
|
||||
@@ -24,8 +24,8 @@ export class Filter {
|
||||
public render (value: any, context: Context) {
|
||||
const argv: any[] = []
|
||||
for (const arg of this.args) {
|
||||
if (isKeyValuePair(arg)) argv.push([arg[0], parseValue(arg[1], context)])
|
||||
else argv.push(parseValue(arg, context))
|
||||
if (isKeyValuePair(arg)) argv.push([arg[0], new Expression(arg[1]).evaluate(context)])
|
||||
else argv.push(new Expression(arg).evaluate(context))
|
||||
}
|
||||
return this.impl.apply({ context }, [value, ...argv])
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { hashCapture } from '../../parser/lexical'
|
||||
import { parseValue } from '../../render/syntax'
|
||||
import { Expression } from '../../render/expression'
|
||||
import { Context } from '../../context/context'
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ export class Hash {
|
||||
while ((match = hashCapture.exec(markup))) {
|
||||
const k = match[1]
|
||||
const v = match[2]
|
||||
instance[k] = await parseValue(v, ctx)
|
||||
instance[k] = new Expression(v).evaluate(ctx)
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { parseExp } from '../render/syntax'
|
||||
import { Expression } from '../render/expression'
|
||||
import { FilterArgs, Filter } from './filter/filter'
|
||||
import { Context } from '../context/context'
|
||||
|
||||
@@ -48,7 +48,7 @@ export class Value {
|
||||
this.filters.push(new Filter(name, args, this.strictFilters))
|
||||
}
|
||||
public value (ctx: Context) {
|
||||
let val = parseExp(this.initial, ctx)
|
||||
let val = new Expression(this.initial).evaluate(ctx)
|
||||
for (const filter of this.filters) {
|
||||
val = filter.render(val, ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user