Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: allow liquidMethodMissing to return any supported value type #698

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | undefined> | any | undefined {
admtnnr marked this conversation as resolved.
Show resolved Hide resolved
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')
})
})
Loading