Skip to content

Commit

Permalink
fix: allow liquidMethodMissing to return any supported value type (#698)
Browse files Browse the repository at this point in the history
* fix: allow liquidMethodMissing to return any supported value type

* Update src/drop/drop.ts

Co-authored-by: Jun Yang <harttleharttle@gmail.com>

---------

Co-authored-by: Jun Yang <harttleharttle@gmail.com>
  • Loading branch information
admtnnr and harttle committed May 22, 2024
1 parent 12001b6 commit 0983f2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/drop/drop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export abstract class Drop {
public liquidMethodMissing (key: string | number): Promise<string | undefined> | string | undefined {
public liquidMethodMissing (key: string | number): Promise<any> | any {
return undefined
}
}
16 changes: 16 additions & 0 deletions test/integration/drop/drop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,20 @@ describe('drop/drop', function () {
const html = await liquid.parseAndRender(tpl, { address, customer })
expect(html).toBe('test')
})
it('should support returning supported value types from liquidMethodMissing', async function () {
class DynamicTypeDrop extends Drop {
liquidMethodMissing (key: string) {
switch (key) {
case 'number': return 42
case 'string': return 'foo'
case 'boolean': return true
case 'array': return [1, 2, 3]
case 'object': return { foo: 'bar' }
case 'drop': return new CustomDrop()
}
}
}
const html = await liquid.parseAndRender(`{{obj.number}} {{obj.string}} {{obj.boolean}} {{obj.array | first}} {{obj.object.foo}} {{obj.drop.getName}}`, { obj: new DynamicTypeDrop() })
expect(html).toBe('42 foo true 1 bar GET NAME')
})
})

0 comments on commit 0983f2c

Please sign in to comment.