Permalink
Browse files

Add toplevel mangle option

fixes #31
  • Loading branch information...
1 parent f0401a3 commit 8a21ea449ecc3fc81c4dace9bcf2b6d89a8cbfa0 @gpbmike committed Feb 6, 2016
Showing with 19 additions and 4 deletions.
  1. +11 −3 api/index.js
  2. +2 −1 app/scripts/options/uglify.js
  3. +6 −0 app/templates/options/uglify.hbs
View
@@ -51,7 +51,10 @@ api.post('/javascript/', function (req, res) {
return;
}
- var options = {};
+ var mangleKeys = ['toplevel'];
+
+ var compressOptions = {};
+ var mangleOptions = {};
Object.keys(req.body.options).forEach(function (key) {
var value = req.body.options[key];
@@ -64,13 +67,18 @@ api.post('/javascript/', function (req, res) {
if (value === '') {
value = null;
}
- options[key] = value;
+ if (~mangleKeys.indexOf(key)) {
+ mangleOptions[key] = value;
+ } else {
+ compressOptions[key] = value;
+ }
});
try {
res.json(UglifyJS.minify(req.body.code, {
fromString: true,
- compress: options
+ compress: compressOptions,
+ mangle: mangleOptions,
}));
} catch (error) {
// users don't need to see filestructure of server
@@ -27,7 +27,8 @@ var defaults = Ember.Object.create();
'hoist_vars',
'pure_getters',
'drop_console',
- 'keep_fargs'
+ 'keep_fargs',
+ 'toplevel'
].forEach(function (option) {
defaults.set(option, false);
});
@@ -131,3 +131,9 @@
{{input class="form-control" placeholder="comma separated list" value=compressOptions.javascript.options.pure_funcs_cs}}
<p class="help-block">default null. You can pass an array of names and UglifyJS will assume that those functions do not produce side effects. <span class="text-danger">DANGER: will not check if the name is redefined in scope.</span> An example case here, for instance var q = Math.floor(a/b). If variable q is not used elsewhere, UglifyJS will drop it, but will still keep the Math.floor(a/b), not knowing what it does. You can pass pure_funcs: [ 'Math.floor' ] to let it know that this function won't produce any side effect, in which case the whole statement would get discarded. The current implementation adds some overhead (compression will be slower).</p>
</div>
+<div class="checkbox">
+ <label>
+ {{input type="checkbox" checked=compressOptions.javascript.options.toplevel}}
+ <code>toplevel</code> &mdash; mangle names declared in the toplevel scope
+ </label>
+</div>

0 comments on commit 8a21ea4

Please sign in to comment.