Skip to content

Commit

Permalink
refactor: remove use of internal Context class in evalValue argument
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `evalValue` won't support `Context` as second argument anymore.
  • Loading branch information
harttle committed Nov 27, 2022
1 parent bb58d3e commit b115077
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ export class Liquid {
return this.renderToNodeStream(templates, scope, renderOptions)
}

public _evalValue (str: string, scopeOrContext?: object | Context): IterableIterator<any> {
public _evalValue (str: string, scope?: object): IterableIterator<any> {
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<any> {
return toPromise(this._evalValue(str, scopeOrContext))
public async evalValue (str: string, scope?: object): Promise<any> {
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) {
Expand Down
12 changes: 1 addition & 11 deletions test/e2e/eval-value.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai'
import { Context, Liquid } from '../..'
import { Liquid } from '../..'

describe('#evalValue()', function () {
var engine: Liquid
Expand All @@ -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')
})
})

0 comments on commit b115077

Please sign in to comment.