feat: promise in expression & nested property, #533 #276

This commit is contained in:
Harttle
2022-08-27 23:19:16 +08:00
committed by Harttle
parent 0997530bab
commit bbf00f37bf
19 changed files with 256 additions and 20537 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
import { evalToken } from '../../render/expression'
import { _evalToken } from '../../render/expression'
import { Context } from '../../context/context'
import { identify } from '../../util/underscore'
import { FilterImplOptions } from './filter-impl-options'
@@ -17,11 +17,11 @@ export class Filter {
this.args = args
this.liquid = liquid
}
public render (value: any, context: Context) {
public * render (value: any, context: Context): IterableIterator<unknown> {
const argv: any[] = []
for (const arg of this.args as FilterArg[]) {
if (isKeyValuePair(arg)) argv.push([arg[0], evalToken(arg[1], context)])
else argv.push(evalToken(arg, context))
if (isKeyValuePair(arg)) argv.push([arg[0], yield _evalToken(arg[1], context)])
else argv.push(yield _evalToken(arg, context))
}
return this.impl.apply({ context, liquid: this.liquid }, [value, ...argv])
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { evalToken } from '../../render/expression'
import { _evalToken } from '../../render/expression'
import { Context } from '../../context/context'
import { Tokenizer } from '../../parser/tokenizer'
@@ -25,7 +25,7 @@ export class Hash {
* render (ctx: Context): Generator<unknown, HashValue, unknown> {
const hash = {}
for (const key of Object.keys(this.hash)) {
hash[key] = this.hash[key] === undefined ? true : yield evalToken(this.hash[key], ctx)
hash[key] = this.hash[key] === undefined ? true : yield _evalToken(this.hash[key], ctx)
}
return hash
}