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:
@@ -0,0 +1,23 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user