2

I have a scenario where I want to expose certain properties to other API's on the page, but internally keep those property names mangled. Uglify's "keep_quoted" option seems like it should do what I want, but instead it prevents every instance of anything that's quoted at least once from being mangled

For example, if in my src I had:

const myID = 1;
const myObj = {
  'myID': myID
};

I would expect Uglify to output the following:

const a=1;const b={'myID':a};

But instead it gives me:

const myID=1;const b={'myID':myID};

The 'myID' is prevented from being mangled EVERYWHERE just because it was quoted in one place.

I'm big enough and ugly enough to remember to add quotes around my propertyNames wherever I need to them to be exported. How can I get Uglify to mangle the ones that I chose not to add quotes to?

Jeff Boyes
  • 31
  • 5
  • Hello future people! I found that the behaviour that I want is what Terser does, using the same flags I was trying in Uglify. – Jeff Boyes Oct 04 '18 at 09:16
  • What flags are you using? I get the same output from Terser and Uglify. When using keep_quoted, both the quoted and the non-quoted properties that match them are not mangled, rather than only the quoted one being mangled. – Daniel Crabtree Oct 24 '18 at 04:43
  • Yeah, that was a mistake. A very simple example behaved the way I wanted, but when I used something more like my actually code the behaviour of terser matched uglifyjs. I now think the correct answer is that it really doesn't matter because the minified code is going to be gzipped anyway and the difference in size will be only a few bytes. – Jeff Boyes Nov 10 '18 at 11:27

0 Answers0