You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The key detail is that in class Test, the private properties are mangled to two-letter names. They could instead be one-letter names.
Description
JavaScript's private properties and methods effectively act in a separate namespace to all other properties. They cannot be accessed by string, and they cannot be accessed by any derived or super classes.
Therefore it should always be safe to rename the first private property of a class to a single-letter name like #a. It is impossible for this to have a name collision with anything other than another private property in the same class, and UglifyJS can see all of those in the source.
In our case we have a large and complex codebase which ends up mangling properties to three-letter names. UglifyJS then continues to mangle private properties with three-letter names instead of using shorter one-letter names again. The repro demonstrates this by using enough object properties to push mangled names to two letters, then demonstrates that private properties/methods continue using the same length names instead of taking advantage of the fact they are in a separate namespace and so can use shorter names.
The output code is perfectly valid, just sub-optimal - I'm posting this basically as a feature request, as hopefully it may be a straightforward change to make and a nice win for property mangling code that heavily uses private properties. (It's also ideal if lots of classes use the same private property names like #a as these will also be compressed more effectively.)
The text was updated successfully, but these errors were encountered:
This is a case of sub-optimal but correct code, which the template says is not a bug, so I guess this is a feature request.
Uglify version (
uglifyjs -V
) 3.19.3JavaScript input
It's quite long so expand the below:
input.js
Command:
uglifyjs input.js --compress --mangle-props --beautify --output output.js
JavaScript output or error produced.
output.js
The key detail is that in
class Test
, the private properties are mangled to two-letter names. They could instead be one-letter names.Description
JavaScript's private properties and methods effectively act in a separate namespace to all other properties. They cannot be accessed by string, and they cannot be accessed by any derived or super classes.
Therefore it should always be safe to rename the first private property of a class to a single-letter name like
#a
. It is impossible for this to have a name collision with anything other than another private property in the same class, and UglifyJS can see all of those in the source.In our case we have a large and complex codebase which ends up mangling properties to three-letter names. UglifyJS then continues to mangle private properties with three-letter names instead of using shorter one-letter names again. The repro demonstrates this by using enough object properties to push mangled names to two letters, then demonstrates that private properties/methods continue using the same length names instead of taking advantage of the fact they are in a separate namespace and so can use shorter names.
The output code is perfectly valid, just sub-optimal - I'm posting this basically as a feature request, as hopefully it may be a straightforward change to make and a nice win for property mangling code that heavily uses private properties. (It's also ideal if lots of classes use the same private property names like
#a
as these will also be compressed more effectively.)The text was updated successfully, but these errors were encountered: