fix: map filter allow nil results in strict mode, fixes #647

This commit is contained in:
Harttle
2023-08-24 00:20:57 +08:00
parent 942944eae0
commit 45adbd7008
5 changed files with 16 additions and 5 deletions
+4 -1
View File
@@ -31,7 +31,10 @@ describe('filter', function () {
it('should render a simple filter', async function () {
expect(await toPromise(new Filter('upcase', (x: string) => x.toUpperCase(), [], liquid).render('foo', ctx))).toBe('FOO')
})
it('should reject promise when filter throws', async function () {
const filter = new Filter('foo', function * () { throw new Error('intended') }, [], liquid)
expect(toPromise(filter.render('foo', ctx))).rejects.toMatch('intended')
})
it('should render filters with argument', async function () {
const two = new NumberToken('2', 0, 1, undefined)
expect(await toPromise(new Filter('add', (a: number, b: number) => a + b, [two], liquid).render(3, ctx))).toBe(5)
+1 -1
View File
@@ -27,6 +27,6 @@ export class Filter {
if (isKeyValuePair(arg)) argv.push([arg[0], yield evalToken(arg[1], context)])
else argv.push(yield evalToken(arg, context))
}
return this.handler.apply({ context, liquid: this.liquid }, [value, ...argv])
return yield this.handler.apply({ context, liquid: this.liquid }, [value, ...argv])
}
}