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 properties builtins option supports array #1455

Open
cuixiping opened this issue Oct 12, 2023 · 0 comments
Open

Feature Request: mangle properties builtins option supports array #1455

cuixiping opened this issue Oct 12, 2023 · 0 comments

Comments

@cuixiping
Copy link

Bug report or Feature request?

Feature request

I want to mangle all non-builtin properties and a few built-in properties, and reserve most of built-in properties.
Currently I have no easy way to config the option, since I have to list every property names which need mangle or list every ones which need to be reserved.
It will be much easier to set option if there is a list with a few built-in properties to be reserved.

For example, I have 10 non-builtin property names and 10 builtin property names. My purpose is mangle the all 10 non-builtin property names and 1 builtin property names. An expected easier option is like this:

 mangle: {
    properties: {
      builtins: ['value'],  // only mangle this one builtin and all non-builtin property names
    },
  },

instead of current

 mangle: {
    properties: {
      builtins: true,
      reserved: ['width', 'height', 'target', 'name', 'id', 'style', 'parent', 'self', 'top'],  // all reserved builtins
    },
  },

or

 mangle: {
    properties: {
      builtins: true,
      regex: /^(value|foo|bar|hello|world|example|github|terser)$/,   // all non-builtin and a few builtins
    },
  },

Version

Latest

Complete CLI command or minify() options used

{
  module: true,
  compress: {},
  mangle: {
    properties: {
      builtins: ['value'],  // only boolean value is supported, so this is equals to `true`
    },
  },
  output: {
    beautify: true,
  },
  parse: {},
  rename: {},
}

terser input

class A {
  // non-builtin property names
  foo = 'foo';
  bar = 'bar';
  hello = 'hello';
  world = 'world';
  // builtin property names
  target = 1;
  width = 3;
  height = 4;
  value = 2;
}
new A();

terser output or error

new class {
    l="foo";
    o="bar";
    e="hello";
    a="world";
    h=1;
    r=3;
    t=4;
    w=2;
};

Expected result

new class {
    l="foo";   // non-builtin, mangled
    o="bar";   // non-builtin, mangled
    e="hello";   // non-builtin, mangled
    a="world";   // non-builtin, mangled

    target=1;     // builtin, reserved
    width=3;     // builtin, reserved
    height=4;     // builtin, reserved

    h=2;     // builtin, mangled
};
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