feat: renderSync, parseAndRenderSync and renderFileSync, see #48

This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 8028f82499
commit 7fb01ad69a
66 changed files with 896 additions and 272 deletions
+12 -4
View File
@@ -5,11 +5,15 @@ import { parseLiteral } from '../parser/literal'
export class Value {
private str: string
public constructor (str: string = '') {
public constructor (str: string) {
this.str = str
}
public evaluate (ctx: Context) {
public async evaluate (ctx: Context) {
return this.evaluateSync(ctx)
}
public evaluateSync (ctx: Context) {
const literalValue = parseLiteral(this.str)
if (literalValue !== undefined) {
return literalValue
@@ -17,7 +21,11 @@ export class Value {
return ctx.get(this.str)
}
public value (ctx: Context) {
return toValue(this.evaluate(ctx))
public async value (ctx: Context) {
return toValue(await this.evaluate(ctx))
}
public valueSync (ctx: Context) {
return toValue(this.evaluateSync(ctx))
}
}