Skip to content

Commit ea77dde

Browse files
committedJan 13, 2016
Merge pull request #375 from jrhite/master
add handling of mangle_properties regex option in uglifyjs
2 parents 63279df + 8578547 commit ea77dde

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed
 

‎Gruntfile.js

+10
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ module.exports = function(grunt) {
327327
nameCache: 'tmp/uglify_name_cache.json'
328328
}
329329
},
330+
mangleprops_withRegex: {
331+
files: {
332+
'tmp/mangleprops_withRegex.js': ['test/fixtures/src/mangleprops_withRegex.js']
333+
},
334+
options: {
335+
mangleProperties: {
336+
regex: /^[^#].*/
337+
}
338+
}
339+
},
330340
quotes_single: {
331341
files: {
332342
'tmp/quotes_single.js': ['test/fixtures/src/quotes.js']

‎docs/uglify-options.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ Default: `false`
135135
Pass this flag if you don't care about full compliance with Internet Explorer 6-8 quirks.
136136

137137
## mangleProperties
138-
Type: `Boolean`
138+
Type: `Boolean` `Object`
139139
Default: `false`
140140

141-
Use this flag to turn on object property name mangling.
141+
Turn on or off property mangling with default options. If an `Object` is specified, it is passed directly to `ast.mangle_properties()` (mimicking command line behavior). [View all options here](https://github.com/mishoo/UglifyJS2#mangler-options).
142142

143143
## reserveDOMProperties
144144
Type: `Boolean`

‎tasks/lib/uglify.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ exports.init = function(grunt) {
117117
cache = UglifyJS.readNameCache(options.nameCache, 'props');
118118
}
119119

120-
if (options.mangleProperties === true) {
121-
topLevel = UglifyJS.mangle_properties(topLevel, {
122-
reserved: mangleExclusions ? mangleExclusions.props : null,
123-
cache: cache
124-
});
120+
if (typeof(options.mangleProperties) !== 'undefined' && options.mangleProperties !== false) {
121+
// if options.mangleProperties is a boolean (true) convert it into an object
122+
if (typeof options.mangleProperties !== 'object') {
123+
options.mangleProperties = {};
124+
}
125+
126+
options.mangleProperties.reserved = mangleExclusions ? mangleExclusions.props : null;
127+
options.mangleProperties.cache = cache;
128+
129+
topLevel = UglifyJS.mangle_properties(topLevel, options.mangleProperties);
125130

126131
if (options.nameCache) {
127132
UglifyJS.writeNameCache(options.nameCache, 'props', cache);
@@ -257,7 +262,7 @@ exports.init = function(grunt) {
257262
if (!_.isUndefined(options.preserveComments)) {
258263
outputOptions.comments = options.preserveComments;
259264
}
260-
265+
261266
return outputOptions;
262267
};
263268

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var anObject={a:"val","#key2":"val2"};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var anObject = {
2+
key1: 'val',
3+
'#key2': 'val2'
4+
};

‎test/uglify_test.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ exports.contrib_uglify = {
5656
'mangleprops_withExceptAndExceptionsFiles.js',
5757
'mangleprops_withNameCacheFile1.js',
5858
'mangleprops_withNameCacheFile2.js',
59+
'mangleprops_withRegex.js',
5960
'uglify_name_cache.json',
6061
'quotes_single.js',
6162
'quotes_double.js',

0 commit comments

Comments
 (0)
Please sign in to comment.