refactor: rewrite expression evaluation, fix #130

This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 538610e169
commit 76019e9e18
31 changed files with 407 additions and 246 deletions
+3 -3
View File
@@ -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])
}
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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)
}