From f25f5cd6bd9ac70e900784238078f5dee794675b Mon Sep 17 00:00:00 2001 From: Jacob Hull Date: Thu, 21 Mar 2024 14:56:02 -0700 Subject: [PATCH] fix(lookup): don't parse nested array elements as string templates When parsing nested arrays in the lookup function, pass all values through the lookup parser instead of just object types and handling the rest as if they are string templates. Signed-off-by: Jacob Hull --- lib/chain.js | 4 +--- test/unit/chain.js | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/chain.js b/lib/chain.js index 144c4a9..702792d 100644 --- a/lib/chain.js +++ b/lib/chain.js @@ -100,9 +100,7 @@ module.exports = class SetupChain { // remap array values with lookup result if (Array.isArray(value)) { out[key] = value.map((val) => { - if (typeOf(val) === 'object') return this.lookup(val) - const resolved = this[lookup](this.parse(val)) - return resolved + return this.lookup(val) }) continue } diff --git a/test/unit/chain.js b/test/unit/chain.js index 4ec9372..e82d511 100644 --- a/test/unit/chain.js +++ b/test/unit/chain.js @@ -101,6 +101,12 @@ test('chain', async (t) => { t.same(chain.lookup(lookup), expected, 'can populate an array') } + { + const expected = {position: [11, 2]} + const lookup = {position: [11, 2]} + t.same(chain.lookup(lookup), expected, 'array values parse number literals') + } + { const expected = {key: 11, values: [2, 10, {foo: 3}]} const lookup = {key: '#g', values: ['#b.c', '#f', {foo: '#b.d.e'}]}