From 0983f2c42012b2b97258d0cdcb07b6d43c904814 Mon Sep 17 00:00:00 2001 From: Adam Tanner <27502+admtnnr@users.noreply.github.com> Date: Wed, 22 May 2024 00:35:46 -0400 Subject: [PATCH] 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 --------- Co-authored-by: Jun Yang --- src/drop/drop.ts | 2 +- test/integration/drop/drop.spec.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/drop/drop.ts b/src/drop/drop.ts index f9ea608904..74b4e152fd 100644 --- a/src/drop/drop.ts +++ b/src/drop/drop.ts @@ -1,5 +1,5 @@ export abstract class Drop { - public liquidMethodMissing (key: string | number): Promise | string | undefined { + public liquidMethodMissing (key: string | number): Promise | any { return undefined } } diff --git a/test/integration/drop/drop.spec.ts b/test/integration/drop/drop.spec.ts index f4f874b481..bf299cefe8 100644 --- a/test/integration/drop/drop.spec.ts +++ b/test/integration/drop/drop.spec.ts @@ -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') + }) })