Closure Compiler doesn't rename certain object properties no matter what

34 views
Skip to first unread message

williamist

unread,
Nov 6, 2024, 12:38:08 PM11/6/24
to Closure Compiler Discuss
Hello. I've been liking using Closure Compiler so far, but I've run into a bit of an interesting occurrence where certain property names just don't get renamed, even if they are only referenced with dot notation.

Here's an example: (I'm using the property names "title" and "hint" here since those are the ones my actual code uses, there may be more, I'm not sure)

var test_object = {
  not_title: "hello, this is my not title!",
  title: "hello, this is my title!",
  not_hint: "hello, this is my not hint!",
  hint: "hello, this is my hint!"
};

console.log(test_object);

It minifies into the following output (on ADVANCED mode):

'use strict';console.log({h:"hello, this is my not title!",title:"hello, this is my title!",g:"hello, this is my not hint!",hint:"hello, this is my hint!"});

As you can see, the properties named "title" and "hint" are not renamed, even though they should be (and the ones named "not_title" and "not_hint" are).

If anyone has any insight as to why this happens, and how I can get these properties to be renamed, that would be very helpful.

Thanks.

Stanimir Mladenov

unread,
Nov 7, 2024, 3:15:34 AM11/7/24
to Closure Compiler Discuss
Closure compiler works with externs to prevent the renaming of third party libraries or browser build in api names.

"title" is in those externs and that is the reason the compiler doesn't rename it.
"not_title" is not a popular name and is out of any externs, so it gets renamed.

The best approach to make your properties renamed is to use unpopular or prefixed/suffixed with specifics to the usage. Like "test_title" and "test_hint".
Reply all
Reply to author
Forward
0 new messages