@@ -7,19 +7,24 @@ import type { BundleOptions } from './schemas.js';
77import type { BuildOutput } from './types.js' ;
88
99const GLOBAL_PROXY_SHIM = `
10- const createProxy = (name) => {
10+ let __ODC_BUNDLER_ERROR_CONTEXT;
11+ const __createProxy = (name) => {
12+ const formatErrorMessage = (method, propertyName, targetName) => {
13+ const contextName = __ODC_BUNDLER_ERROR_CONTEXT ?? 'UNKNOWN'
14+ return "Cannot " + method + " property '" + propertyName + "' of object '" + targetName + "' in global scope of context '" + contextName + "'"
15+ }
1116 return new Proxy({ name }, {
1217 get(target, property) {
13- throw new Error("Cannot get property '" + property.toString() + "' of object '" + target.name + "' in global scope");
18+ throw new Error(formatErrorMessage(' get', property.toString(), target.name))
1419 },
1520 set(target, property) {
16- throw new Error("Cannot set property '" + property.toString() + "' of object '" + target.name + "' in global scope");
21+ throw new Error(formatErrorMessage(' set', property.toString(), target.name))
1722 }
1823 });
1924 };
20- const document = globalThis.document ?? createProxy ('document');
21- const self = globalThis.self ?? createProxy ('self');
22- const window = globalThis.window ?? createProxy ('window');
25+ const document = globalThis.document ?? __createProxy ('document');
26+ const self = globalThis.self ?? __createProxy ('self');
27+ const window = globalThis.window ?? __createProxy ('window');
2328` ;
2429
2530/**
@@ -43,7 +48,9 @@ export async function createBundle(output: BuildOutput, options: { minify: boole
4348 const result = await esbuild . transform ( bundle , {
4449 charset : 'ascii' ,
4550 format : 'esm' ,
46- minify : options . minify ,
51+ minifyIdentifiers : false ,
52+ minifySyntax : options . minify ,
53+ minifyWhitespace : options . minify ,
4754 platform : 'browser' ,
4855 target : 'es2022' ,
4956 treeShaking : true
0 commit comments