From 0f4916bc5a93f5e744e4246336c68f2e89774272 Mon Sep 17 00:00:00 2001 From: Harttle Date: Mon, 12 Dec 2022 19:40:37 +0800 Subject: [PATCH] fix: support `Context` as `evalValue` parameter, #568 --- src/liquid.ts | 8 ++++---- src/template/tag.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/liquid.ts b/src/liquid.ts index 2b21b5f5f9..0e306d8880 100644 --- a/src/liquid.ts +++ b/src/liquid.ts @@ -76,15 +76,15 @@ export class Liquid { return this.renderToNodeStream(templates, scope, renderOptions) } - public _evalValue (str: string, scope?: object): IterableIterator { + public _evalValue (str: string, scope?: object | Context): IterableIterator { const value = new Value(str, this) - const ctx = new Context(scope, this.options) + const ctx = scope instanceof Context ? scope : new Context(scope, this.options) return value.value(ctx, false) } - public async evalValue (str: string, scope?: object): Promise { + public async evalValue (str: string, scope?: object | Context): Promise { return toPromise(this._evalValue(str, scope)) } - public evalValueSync (str: string, scope?: object): any { + public evalValueSync (str: string, scope?: object | Context): any { return toValueSync(this._evalValue(str, scope)) } diff --git a/src/template/tag.ts b/src/template/tag.ts index 1515b2a2c5..b74ccdb1a7 100644 --- a/src/template/tag.ts +++ b/src/template/tag.ts @@ -9,7 +9,7 @@ export type TagRenderReturn = Generator | Promise implements Template { public name: string - protected liquid: Liquid + public liquid: Liquid public constructor (token: TagToken, remainTokens: TopLevelToken[], liquid: Liquid) { super(token)