-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathuglifier.js
49 lines (42 loc) · 1.18 KB
/
uglifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Set source-map.js sourceMap to uglify.js MOZ_SourceMap
MOZ_SourceMap = sourceMap;
function comments(option) {
if (Object.prototype.toString.call(option) === '[object Array]') {
return new RegExp(option[0], option[1]);
} else if (option == "jsdoc") {
return function(node, comment) {
if (comment.type == "comment2") {
return /@preserve|@license|@cc_on/i.test(comment.value);
} else {
return false;
}
};
} else {
return option;
}
}
function regexOption(options) {
if (typeof options === 'object' && options.regex) {
return new RegExp(options.regex[0], options.regex[1]);
} else {
return null;
}
}
function uglifier(options) {
var source = options.source;
options.output.comments = comments(options.output.comments);
if (options.mangle) {
if (options.mangle.properties) {
options.mangle.properties.regex = regexOption(options.mangle.properties);
}
}
delete options.source;
var inputFilename = '0'
if (options.sourceMap) {
inputFilename = options.sourceMap.input;
delete options.sourceMap.input;
}
var inputs = {};
inputs[inputFilename] = source;
return UglifyJS.minify(inputs, options);
}