Skip to content

Commit 0983f2c

Browse files
admtnnrharttle
andauthored
fix: allow liquidMethodMissing to return any supported value type (#698)
* fix: allow liquidMethodMissing to return any supported value type * Update src/drop/drop.ts Co-authored-by: Jun Yang <[email protected]> --------- Co-authored-by: Jun Yang <[email protected]>
1 parent 12001b6 commit 0983f2c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/drop/drop.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export abstract class Drop {
2-
public liquidMethodMissing (key: string | number): Promise<string | undefined> | string | undefined {
2+
public liquidMethodMissing (key: string | number): Promise<any> | any {
33
return undefined
44
}
55
}

test/integration/drop/drop.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,20 @@ describe('drop/drop', function () {
8383
const html = await liquid.parseAndRender(tpl, { address, customer })
8484
expect(html).toBe('test')
8585
})
86+
it('should support returning supported value types from liquidMethodMissing', async function () {
87+
class DynamicTypeDrop extends Drop {
88+
liquidMethodMissing (key: string) {
89+
switch (key) {
90+
case 'number': return 42
91+
case 'string': return 'foo'
92+
case 'boolean': return true
93+
case 'array': return [1, 2, 3]
94+
case 'object': return { foo: 'bar' }
95+
case 'drop': return new CustomDrop()
96+
}
97+
}
98+
}
99+
const html = await liquid.parseAndRender(`{{obj.number}} {{obj.string}} {{obj.boolean}} {{obj.array | first}} {{obj.object.foo}} {{obj.drop.getName}}`, { obj: new DynamicTypeDrop() })
100+
expect(html).toBe('42 foo true 1 bar GET NAME')
101+
})
86102
})

0 commit comments

Comments
 (0)