From 78089419b1d8477e574c3e239869ce4b3f76dca4 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Wed, 8 Mar 2023 13:16:46 -0700 Subject: [PATCH] fix: avoid using variable in template (#46) --- .changeset/stale-years-stare.md | 5 +++++ src/components/vite.marko | 11 +++++------ src/server-entry-template.ts | 5 ++--- 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 .changeset/stale-years-stare.md diff --git a/.changeset/stale-years-stare.md b/.changeset/stale-years-stare.md new file mode 100644 index 0000000..2ef8427 --- /dev/null +++ b/.changeset/stale-years-stare.md @@ -0,0 +1,5 @@ +--- +"@marko/vite": patch +--- + +Avoid using $global in internal templates. diff --git a/src/components/vite.marko b/src/components/vite.marko index 9f8ad93..5237f52 100644 --- a/src/components/vite.marko +++ b/src/components/vite.marko @@ -21,14 +21,13 @@ static function renderAssets(slot) { return html; } -$ const $global = out.global; -$ if (!$global.___viteRenderAssets) { - $global.___viteInjectAttrs = $global.cspNonce - ? ` nonce="${$global.cspNonce.replace(/"/g, "'")}"` +$ if (!out.global.___viteRenderAssets) { + out.global.___viteInjectAttrs = out.global.cspNonce + ? ` nonce="${out.global.cspNonce.replace(/"/g, "'")}"` : ""; - $global.___viteRenderAssets = renderAssets; + out.global.___viteRenderAssets = renderAssets; } <__flush_here_and_after__> - $!{$global.___viteRenderAssets(input.slot)} + $!{out.global.___viteRenderAssets(input.slot)} diff --git a/src/server-entry-template.ts b/src/server-entry-template.ts index b78cd67..86e5a52 100644 --- a/src/server-entry-template.ts +++ b/src/server-entry-template.ts @@ -7,12 +7,11 @@ export default async (opts: { const fileNameStr = JSON.stringify(`./${path.basename(opts.fileName)}`); return `import template from ${fileNameStr}; export * from ${fileNameStr}; -$ const $global = out.global; ${ opts.runtimeId - ? `$ $global.runtimeId = ${JSON.stringify(opts.runtimeId)};\n` + ? `$ out.global.runtimeId = ${JSON.stringify(opts.runtimeId)};\n` : "" -}$ ($global.___viteEntries || ($global.___viteEntries = [])).push(${ +}$ (out.global.___viteEntries || (out.global.___viteEntries = [])).push(${ opts.entryData }); <_vite slot="head-prepend"/>