@@ -70,10 +70,15 @@ exports.init = function(grunt) {
70
70
topLevel = topLevel . wrap_enclose ( argParamList ) ;
71
71
}
72
72
73
+ var topLevelCache = null ;
74
+ if ( options . nameCache ) {
75
+ topLevelCache = UglifyJS . readNameCache ( options . nameCache , 'vars' ) ;
76
+ }
77
+
73
78
// Need to call this before we mangle or compress,
74
79
// and call after any compression or ast altering
75
80
if ( options . expression === false ) {
76
- topLevel . figure_out_scope ( { screw_ie8 : options . screwIE8 } ) ;
81
+ topLevel . figure_out_scope ( { screw_ie8 : options . screwIE8 , cache : topLevelCache } ) ;
77
82
}
78
83
79
84
if ( options . compress !== false ) {
@@ -87,7 +92,45 @@ exports.init = function(grunt) {
87
92
topLevel = topLevel . transform ( compressor ) ;
88
93
89
94
// Need to figure out scope again after source being altered
90
- topLevel . figure_out_scope ( { screw_ie8 : options . screwIE8 } ) ;
95
+ if ( options . expression === false ) {
96
+ topLevel . figure_out_scope ( { screw_ie8 : options . screwIE8 , cache : topLevelCache } ) ;
97
+ }
98
+ }
99
+
100
+ var mangleExclusions = { vars : [ ] , props : [ ] } ;
101
+ if ( options . reserveDOMProperties ) {
102
+ mangleExclusions = UglifyJS . readDefaultReservedFile ( ) ;
103
+ }
104
+
105
+ if ( options . exceptionsFiles ) {
106
+ try {
107
+ options . exceptionsFiles . forEach ( function ( filename ) {
108
+ mangleExclusions = UglifyJS . readReservedFile ( filename , mangleExclusions ) ;
109
+ } ) ;
110
+ } catch ( ex ) {
111
+ grunt . warn ( ex ) ;
112
+ }
113
+ }
114
+
115
+ var cache = null ;
116
+ if ( options . nameCache ) {
117
+ cache = UglifyJS . readNameCache ( options . nameCache , 'props' ) ;
118
+ }
119
+
120
+ if ( options . mangleProperties === true ) {
121
+ topLevel = UglifyJS . mangle_properties ( topLevel , {
122
+ reserved : mangleExclusions ? mangleExclusions . props : null ,
123
+ cache : cache
124
+ } ) ;
125
+
126
+ if ( options . nameCache ) {
127
+ UglifyJS . writeNameCache ( options . nameCache , 'props' , cache ) ;
128
+ }
129
+
130
+ // Need to figure out scope again since topLevel has been altered
131
+ if ( options . expression === false ) {
132
+ topLevel . figure_out_scope ( { screw_ie8 : options . screwIE8 , cache : topLevelCache } ) ;
133
+ }
91
134
}
92
135
93
136
if ( options . mangle !== false ) {
@@ -97,9 +140,20 @@ exports.init = function(grunt) {
97
140
// // compute_char_frequency optimizes names for compression
98
141
// topLevel.compute_char_frequency(options.mangle);
99
142
143
+ options . mangle . cache = topLevelCache ;
144
+
145
+ options . mangle . except = options . mangle . except ? options . mangle . except : [ ] ;
146
+ if ( mangleExclusions . vars ) {
147
+ mangleExclusions . vars . forEach ( function ( name ) {
148
+ UglifyJS . push_uniq ( options . mangle . except , name ) ;
149
+ } ) ;
150
+ }
151
+
100
152
// Requires previous call to figure_out_scope
101
153
// and should always be called after compressor transform
102
154
topLevel . mangle_names ( options . mangle ) ;
155
+
156
+ UglifyJS . writeNameCache ( options . nameCache , 'vars' , options . mangle . cache ) ;
103
157
}
104
158
105
159
if ( options . sourceMap && options . sourceMapIncludeSources ) {
0 commit comments