From e295c4720df3cd7a6e9e2bde61862857a3eff01e Mon Sep 17 00:00:00 2001 From: dpiercey Date: Fri, 10 Nov 2023 14:58:20 -0700 Subject: [PATCH] fix: issue with multiple flags --- .changeset/yellow-bobcats-scream.md | 5 +++++ src/plugins/build-ssr.ts | 4 ++++ src/plugins/build-web.ts | 4 ++++ 3 files changed, 13 insertions(+) create mode 100644 .changeset/yellow-bobcats-scream.md diff --git a/.changeset/yellow-bobcats-scream.md b/.changeset/yellow-bobcats-scream.md new file mode 100644 index 0000000..ea4b031 --- /dev/null +++ b/.changeset/yellow-bobcats-scream.md @@ -0,0 +1,5 @@ +--- +"arc-vite": patch +--- + +Fix issue when there are multiple flags. diff --git a/src/plugins/build-ssr.ts b/src/plugins/build-ssr.ts index 941257a..28772c2 100644 --- a/src/plugins/build-ssr.ts +++ b/src/plugins/build-ssr.ts @@ -136,6 +136,7 @@ function partsToString(parts, base, injectAttrs) { let code = ""; let matchCode = ""; + let matchCodeSep = ""; let i = 0; for (const { flags, value } of adaptiveMatches.alternates) { @@ -145,9 +146,12 @@ function partsToString(parts, base, injectAttrs) { )};\n`; matchCode += + matchCodeSep + flags.map((flag) => `f.${flag}`).join("&&") + "?" + adaptedImportId; + + matchCodeSep = ":"; } const defaultId = `_${indexToId(i)}`; diff --git a/src/plugins/build-web.ts b/src/plugins/build-web.ts index 428a2ab..f84608e 100644 --- a/src/plugins/build-web.ts +++ b/src/plugins/build-web.ts @@ -424,12 +424,16 @@ export function pluginBuildWeb({ const defaultFlaggedAssets = flaggedAssetsForEntry .sort(compareFlaggedObject) .pop()!; + let matchCodeSep = ""; + manifestCode += `case ${JSON.stringify(entryName)}:return `; for (const { flags, manifest } of flaggedAssetsForEntry) { manifestCode += + matchCodeSep + flags.map((flag) => `f.${flag}`).join("&&") + "?" + JSON.stringify(manifest); + matchCodeSep = ":"; } manifestCode += `:${JSON.stringify(defaultFlaggedAssets.manifest)}`;