mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
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]>
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
export abstract class Drop {
|
export abstract class Drop {
|
||||||
public liquidMethodMissing (key: string | number): Promise<string | undefined> | string | undefined {
|
public liquidMethodMissing (key: string | number): Promise<any> | any {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,4 +83,20 @@ describe('drop/drop', function () {
|
|||||||
const html = await liquid.parseAndRender(tpl, { address, customer })
|
const html = await liquid.parseAndRender(tpl, { address, customer })
|
||||||
expect(html).toBe('test')
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user