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

Option to Exclude Built-in Objects from Mangle Process #1473

Open
kyaido opened this issue Nov 17, 2023 · 2 comments
Open

Option to Exclude Built-in Objects from Mangle Process #1473

kyaido opened this issue Nov 17, 2023 · 2 comments

Comments

@kyaido
Copy link

kyaido commented Nov 17, 2023

Bug report or Feature request?

Feature request

Version (complete output of terser -V or specific git commit)

https://try.terser.org/

I would like to inquire if there's a possibility to exclude built-in objects from the mangling process.
Currently, when declaring a variable with the same name as a built-in object, such as Symbol, and then using that built-in object, both the user-defined variable and the usage of the built-in object get mangled.

Here's a snippet that reproduces the issue, which you can also replicate using the Terser REPL:

terser input

console.log(Symbol);
const Symbol = 'Symbol';
console.log(Symbol);

terser output or error

console.log(o);const o="Symbol";console.log(o); // => o is not defined

However, the desired outcome is to keep the built-in object Symbol intact while only mangling the user-defined variable name:

Expected result

console.log(Symbol);const o="Symbol";console.log(o);

Is there an existing option or workaround to achieve this behavior? If not, could this be considered for a future enhancement?

@fabiosantoscode
Copy link
Collaborator

fabiosantoscode commented Nov 17, 2023

With const I don't think this reproduces a problem, because Terser's output is going to crash the same way as the input:

ReferenceError: can't access lexical declaration 'Symbol' before initialization

Maybe your example was a bit more contrived before you made it a minimal repro?

edit: I had an example with var that I thought was a reproduction, but it was a false alarm. I made a mistake while using the browser console

@fabiosantoscode
Copy link
Collaborator

What's the source issue you're trying to solve? Is this related to concatenating files?

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

No branches or pull requests

2 participants