File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1029,6 +1029,15 @@ discarded by the compressor as not referenced.
1029
1029
The safest comments where to place copyright information (or other info that
1030
1030
needs to be kept in the output) are comments attached to toplevel nodes.
1031
1031
1032
+ ### Specify preferred mangled name in comment annotations
1033
+
1034
+ ` /*@mangleTo:X*/ ` or ` /*@mangleTo:X*/ ` comments allow you to choose the name.
1035
+
1036
+ ``` javascript
1037
+ (function (one /* #mangleTo:H*/ , two /* #mangleTo:i*/ ) { /* ..*/ })(1 , 2 );
1038
+ // results (function(H,i){ /*..*/ )(1,2);
1039
+ ```
1040
+
1032
1041
### The ` unsafe ` ` compress ` option
1033
1042
1034
1043
It enables some transformations that * might* break code logic in certain
Original file line number Diff line number Diff line change @@ -565,7 +565,13 @@ function next_mangled_name(def, options) {
565
565
scopes . push ( scope ) ;
566
566
} while ( scope = scope . parent_scope ) ;
567
567
} ) ;
568
- var name ;
568
+ var comment = def . orig [ 0 ] . start . comments_after [ 0 ] ?. value ;
569
+ var preferredName = comment && / [ @ # ] m a n g l e T o : ( .* ) / . exec ( comment ) ;
570
+ var name = preferredName && preferredName [ 1 ] ;
571
+ if ( name && ! names . has ( name ) ) {
572
+ in_use . set ( name , true ) ;
573
+ return name ;
574
+ }
569
575
for ( var i = 0 ; i < holes . length ; i ++ ) {
570
576
name = base54 ( holes [ i ] ) ;
571
577
if ( names . has ( name ) ) continue ;
Original file line number Diff line number Diff line change @@ -965,6 +965,20 @@ function_name_mangle: {
965
965
expect_stdout: "function"
966
966
}
967
967
968
+ function_name_mangle_from_preferred_comment: {
969
+ options = {
970
+ keep_fargs : false ,
971
+ }
972
+ mangle = { }
973
+ input: {
974
+ ( function ( one /*#mangleTo:W*/ , two ) {
975
+ console . log ( one , two ) ;
976
+ } ) ( 1 , 2 ) ;
977
+ }
978
+ expect_exact: "(function(W,o){console.log(W,o)})(1,2);"
979
+ expect_stdout: "1 2"
980
+ }
981
+
968
982
function_name_mangle_ie8: {
969
983
options = {
970
984
keep_fargs : false ,
You can’t perform that action at this time.
0 commit comments