From 57811231571db1072e8ec0812f31252ac1cb1d2a Mon Sep 17 00:00:00 2001 From: Lach Date: Tue, 9 Sep 2025 15:17:36 +0200 Subject: [PATCH] fix(vite): allow optional property access to Deno global (#3370) Ideally, those expressions should be replaced with undefined for better code optimizations, yet I haven't figured it out the best way for this. Fixes: https://github.com/denoland/fresh/issues/3296#issuecomment-3270452525 --- packages/plugin-vite/src/plugins/patches/deno_global.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/plugin-vite/src/plugins/patches/deno_global.ts b/packages/plugin-vite/src/plugins/patches/deno_global.ts index 19e3ed5f..297382b1 100644 --- a/packages/plugin-vite/src/plugins/patches/deno_global.ts +++ b/packages/plugin-vite/src/plugins/patches/deno_global.ts @@ -18,6 +18,13 @@ export function denoGlobal({ types: t }: { types: typeof types }): PluginObj { ) { return; } + // Ignore `Deno?.thing` expression. Those will result in undefined, and that might be used for shims. + if ( + t.isOptionalMemberExpression(path.parent) && + path.parent.object === path.node + ) { + return; + } throw path.buildCodeFrameError( `The Deno.* global cannot be used in the browser.`,