From 45a8070d0d232de0aad9edb0f2771fd47fd32ca9 Mon Sep 17 00:00:00 2001 From: macdonst Date: Thu, 30 Nov 2023 15:57:55 -0500 Subject: [PATCH] Automatically join arrays Signed-off-by: macdonst --- lib/transcode.mjs | 5 ++++- test/enhance.test.mjs | 4 ++-- test/fixtures/templates/my-pre.mjs | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/transcode.mjs b/lib/transcode.mjs index 254da93..f2f043f 100644 --- a/lib/transcode.mjs +++ b/lib/transcode.mjs @@ -7,6 +7,9 @@ export function encode(value) { else if (typeof value == 'number' ) { return value } + else if (Array.isArray(value) && value.every(i => typeof i === "string") ) { + return value.join('') + } else { const id = `__b_${place++}` map[id] = value @@ -18,4 +21,4 @@ export function decode(value) { return value.startsWith('__b_') ? map[value] : value -} \ No newline at end of file +} diff --git a/test/enhance.test.mjs b/test/enhance.test.mjs index f9bf04e..7cd24ae 100644 --- a/test/enhance.test.mjs +++ b/test/enhance.test.mjs @@ -115,8 +115,8 @@ test('Passing state through multiple levels', t => { ` const expected = ` - - + +
test
diff --git a/test/fixtures/templates/my-pre.mjs b/test/fixtures/templates/my-pre.mjs index 4820dd1..fa9333d 100644 --- a/test/fixtures/templates/my-pre.mjs +++ b/test/fixtures/templates/my-pre.mjs @@ -1,4 +1,4 @@ export default function MyMoreContent({ html, state }) { - const { items=[] } = state?.attrs - return html`
${items[0]}
` + const { items='' } = state?.attrs + return html`
${items}
` }