esbuild
esbuild copied to clipboard
keep-names to only be applied when name is changed
I would like to request for --keep-names
to only be applied when the name is changed (e.g. via minification).
Currently, it applies even if the name is unchanged: https://hyrious.me/esbuild-repl/?version=0.15.10&mode=transform&input=function+name%28%29+%7B%7D&options=--keep-names
This improvement should have the benefit of reducing transformation size and also preserve as much of the original code when possible (which can help with https://github.com/evanw/esbuild/issues/1438).
I tried to have a stab at this because I was hoping it'd essentially be an extra if
.
However, I'm a bit thrown off by the fact that the __name
calls are introduced at parse time. Specifically, keepStmtSymbolName
creates an EIdentifier
from the provided ref
. It looks like that will get turned into the final name by the JS printer, but that's not available yet when parsing, so there's nothing to compare.
Disclaimer: I know my way around Go but it's my first time hacking at esbuild, so there's a good chance I'm wrong. 🤞🏻
I had script for Vue SFC compilation script that I used to run using tsx but I now get __name
error. Bumping this for the visibility and possible solution.
This bug seems to prevent tsx from working with puppeteer, bump for fix
bumping as well... unable to use puppeteer and tsx. Please fix.
This is also blocking us + would love to see this resolved 👍
I was able to resolve this for puppeteer by just creating my own function:
await page.evaluateOnNewDocument(() => (window.__name = (func) => func));
// .. All the other evaluates you need
^ If the above didn't work check out this solution: https://github.com/vuejs/core/issues/8303
I was able to resolve this for puppeteer but just creating my own function:
await page.evaluateOnNewDocument(() => (window.__name = (func) => func)); // .. All the other evaluates you need
The following worked for me:
await page.evaluate(() => {
(window as any).__name = (func: Function) => func;
});
await page.evaluate......
it works, thx very much!