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.
10291029The safest comments where to place copyright information (or other info that
10301030needs to be kept in the output) are comments attached to toplevel nodes.
10311031
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+
10321041### The ` unsafe ` ` compress ` option
10331042
10341043It 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) {
565565 scopes . push ( scope ) ;
566566 } while ( scope = scope . parent_scope ) ;
567567 } ) ;
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+ }
569575 for ( var i = 0 ; i < holes . length ; i ++ ) {
570576 name = base54 ( holes [ i ] ) ;
571577 if ( names . has ( name ) ) continue ;
Original file line number Diff line number Diff line change @@ -965,6 +965,20 @@ function_name_mangle: {
965965 expect_stdout: "function"
966966}
967967
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+
968982function_name_mangle_ie8: {
969983 options = {
970984 keep_fargs : false ,
You can’t perform that action at this time.
0 commit comments