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

Is it possible to obfuscate the same string with the property when obfuscating the property? #2574

Closed
masx200 opened this issue Sep 27, 2022 · 3 comments

Comments

@masx200
Copy link

masx200 commented Sep 27, 2022

Is it possible to obfuscate the same string with the property when obfuscating the property?

version
0.15.9

 npx -y esbuild test.js --mangle-props=_$ --mangle-quoted

input

export default createclass([
    {
        key: "__walk__",
        value: function () {
            console.log(this.__collapse__);
        },
    },
    {
        key: "__collapse__",
        value: function () {
            console.log(this["__walk__"]);
        },
    },
]);
export function createclass(entries) {
    Object.assign(
        constructor.prototype,
        Object.fromEntries(entries.map(({ key, value }) => [key, value]))
    );
    function constructor() {};
   return constructor
}

output

export default createclass([
  {
    key: "__walk__",
    value: function() {
      console.log(this.a);
    }
  },
  {
    key: "__collapse__",
    value: function() {
      console.log(this.b);
    }
  }
]);
export function createclass(entries) {
  Object.assign(
    constructor.prototype,
    Object.fromEntries(entries.map(({ key, value }) => [key, value]))
  );
  function constructor() {
  }
  return constructor;
}

Expected result

export default createclass([
  {
    key: "l",
    value: function () {
      console.log(this.t);
    },
  },
  {
    key: "t",
    value: function () {
      console.log(this.l);
    },
  },
]);
export function createclass(e) {
  function t() {}
  return (
    Object.assign(
      t.prototype,
      Object.fromEntries(e.map(({ key: e, value: t }) => [e, t]))
    ),
    t
  );
}
@evanw
Copy link
Owner

evanw commented Sep 27, 2022

No, that’s not possible with esbuild.

@evanw
Copy link
Owner

evanw commented Sep 29, 2022

Closing as by design. Property mangling in esbuild is a static analysis and requires you to use the properties statically, not dynamically. It's also intentionally designed to work similarly to other tools in the ecosystem.

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2022
@evanw
Copy link
Owner

evanw commented Jun 5, 2023

I'm reopening this because Terser has since added a way to do this: prefixing a string literal with a /* @__KEY__ */ comment. More information here: terser/terser#1365. It seems reasonable to do this in esbuild as well.

@evanw evanw reopened this Jun 5, 2023
@evanw evanw closed this as completed in b2176c8 Jun 10, 2023
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