feat(vite): error when using Deno global in the browser (#3305)
Related https://github.com/denoland/fresh/issues/3296
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type { PluginObj, types } from "@babel/core";
|
||||
|
||||
export function denoGlobal({ types: t }: { types: typeof types }): PluginObj {
|
||||
return {
|
||||
name: "fresh-deno-global",
|
||||
visitor: {
|
||||
Identifier(path) {
|
||||
if (path.node.name === "Deno") {
|
||||
// Ignore `Deno.env.get()` calls. Those will be inlined.
|
||||
if (
|
||||
t.isMemberExpression(path.parent) &&
|
||||
path.parent.object === path.node &&
|
||||
t.isIdentifier(path.parent.property) &&
|
||||
path.parent.property.name === "env" &&
|
||||
t.isMemberExpression(path.parentPath?.parent) &&
|
||||
t.isIdentifier(path.parentPath?.parent.property) &&
|
||||
path.parentPath?.parent.property.name === "get"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw path.buildCodeFrameError(
|
||||
`The Deno.* global cannot be used in the browser.`,
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user