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
This commit is contained in:
Lach
2025-09-09 15:17:36 +02:00
committed by GitHub
parent 79d8cfc3ed
commit 5781123157
@@ -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.`,