mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
24 lines
509 B
TypeScript
24 lines
509 B
TypeScript
import { toValue } from '../util/underscore'
|
|
import { Context } from '../context/context'
|
|
import { parseLiteral } from '../parser/literal'
|
|
|
|
export class Value {
|
|
private str: string
|
|
|
|
public constructor (str: string) {
|
|
this.str = str
|
|
}
|
|
|
|
public evaluate (ctx: Context) {
|
|
const literalValue = parseLiteral(this.str)
|
|
if (literalValue !== undefined) {
|
|
return literalValue
|
|
}
|
|
return ctx.get(this.str)
|
|
}
|
|
|
|
public value (ctx: Context) {
|
|
return toValue(this.evaluate(ctx))
|
|
}
|
|
}
|