mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
Implement lenientIf option (resolve #265; default off)
See description of the option in liquid-options.ts.
This commit is contained in:
committed by
Jun Yang
parent
c920ebb282
commit
768fb79e32
@@ -4,6 +4,7 @@ import { FilterMap } from '../template/filter/filter-map'
|
||||
import { Filter } from './filter/filter'
|
||||
import { Context } from '../context/context'
|
||||
import { ValueToken } from '../tokens/value-token'
|
||||
import { assert } from '../util/assert'
|
||||
|
||||
export class Value {
|
||||
public readonly filters: Filter[] = []
|
||||
@@ -18,7 +19,10 @@ export class Value {
|
||||
this.filters = tokenizer.readFilters().map(({ name, args }) => new Filter(name, this.filterMap.get(name), args))
|
||||
}
|
||||
public * value (ctx: Context) {
|
||||
let val = yield evalToken(this.initial, ctx)
|
||||
assert(ctx, () => 'unable to evaluate: context not defined')
|
||||
const lenient = ctx.opts.lenientIf && this.filters.length > 0 && this.filters[0].name == "default"
|
||||
|
||||
let val = yield evalToken(this.initial, ctx, lenient)
|
||||
for (const filter of this.filters) {
|
||||
val = yield filter.render(val, ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user