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

Feature Request: Mangle string literals by regex #990

Open
Slimevine opened this issue May 14, 2021 · 0 comments
Open

Feature Request: Mangle string literals by regex #990

Slimevine opened this issue May 14, 2021 · 0 comments

Comments

@Slimevine
Copy link

Slimevine commented May 14, 2021

Bug report or Feature request? Feature Request

Use case:
A codebase may have string literals that are used for internal / computing purposes only and are never displayed to the end-user. For example, internal custom event names that are lengthy but never go outside the app's scope or string literals that are used to name/reference things within a library/custom data object.

A significant reduction in size could be achieved by mangling these literals, similar to the way properties can be mangled.

Of course, in this case, only matching by regex would make sense. One could prefix/suffix these literals with something and use a regex to match it. E.g. '__myEventName'

Proposed API:

terser({
    mangle: {
      literals: {
        regex: /^__/,
      },
    },
  });

Example:

'__myEventName' becomes 'aBx'
'__windowActive' becomes 'aBy'
'__menu' becomes 'aBz'

What would it take to implement something like this? Could the existing property mangling functionality be extended for this use case?

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

2 participants