Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep-names to only be applied when name is changed #2605

Open
privatenumber opened this issue Oct 11, 2022 · 9 comments
Open

keep-names to only be applied when name is changed #2605

privatenumber opened this issue Oct 11, 2022 · 9 comments

Comments

@privatenumber
Copy link
Contributor

privatenumber commented Oct 11, 2022

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 #1438).

@timdp
Copy link

timdp commented Apr 5, 2023

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. 🤞🏻

@jd-solanki
Copy link

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.

@pixelpax
Copy link

This bug seems to prevent tsx from working with puppeteer, bump for fix

@jackspirou
Copy link

jackspirou commented Feb 28, 2024

bumping as well... unable to use puppeteer and tsx. Please fix.

@connorgiles
Copy link

This is also blocking us + would love to see this resolved 👍

@jim-alexander
Copy link

jim-alexander commented Apr 12, 2024

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

@cjgvalent
Copy link

^ If the above didn't work check out this solution: vuejs/core#8303

@DOCS-kdu3
Copy link

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;
  });

@pdsuwwz
Copy link

pdsuwwz commented Jul 18, 2024

await page.evaluate......

it works, thx very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests