From b115077e122a7b90e7972d58174d68aea8edd7bf Mon Sep 17 00:00:00 2001 From: Jun Yang Date: Wed, 16 Nov 2022 19:44:06 +0800 Subject: [PATCH] refactor: remove use of internal `Context` class in `evalValue` argument BREAKING CHANGE: `evalValue` won't support `Context` as second argument anymore. --- src/liquid.ts | 12 ++++++------ test/e2e/eval-value.ts | 12 +----------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/liquid.ts b/src/liquid.ts index c0e1a69800..bae6164543 100644 --- a/src/liquid.ts +++ b/src/liquid.ts @@ -90,16 +90,16 @@ export class Liquid { return this.renderToNodeStream(templates, scope, renderOptions) } - public _evalValue (str: string, scopeOrContext?: object | Context): IterableIterator { + public _evalValue (str: string, scope?: object): IterableIterator { const value = new Value(str, this) - const ctx = scopeOrContext instanceof Context ? scopeOrContext : new Context(scopeOrContext, this.options) + const ctx = new Context(scope, this.options) return value.value(ctx, false) } - public async evalValue (str: string, scopeOrContext?: object | Context): Promise { - return toPromise(this._evalValue(str, scopeOrContext)) + public async evalValue (str: string, scope?: object): Promise { + return toPromise(this._evalValue(str, scope)) } - public evalValueSync (str: string, scopeOrContext?: object | Context): any { - return toValueSync(this._evalValue(str, scopeOrContext)) + public evalValueSync (str: string, scope?: object): any { + return toValueSync(this._evalValue(str, scope)) } public registerFilter (name: string, filter: FilterImplOptions) { diff --git a/test/e2e/eval-value.ts b/test/e2e/eval-value.ts index aa6579788a..388a018ea6 100644 --- a/test/e2e/eval-value.ts +++ b/test/e2e/eval-value.ts @@ -1,5 +1,5 @@ import { expect } from 'chai' -import { Context, Liquid } from '../..' +import { Liquid } from '../..' describe('#evalValue()', function () { var engine: Liquid @@ -19,14 +19,4 @@ describe('#evalValue()', function () { const val = await engine.evalValue('foo') expect(val).to.equal('FOO') }) - - it('should support passing Context', async function () { - const val = await engine.evalValue('a > b', new Context({ a: 1, b: 2 })) - expect(val).to.equal(false) - }) - - it('should respect options in passed in Context', async function () { - const val = await engine.evalValue('foo', new Context({}, { globals: { foo: 'BAR' } } as any)) - expect(val).to.equal('BAR') - }) })