Created
March 20, 2016 07:41
-
-
Save ThomasR/dd7060b10798a833d54d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var esprima = require('esprima'); | |
var esmangle = require('esmangle'); | |
var escodegen = require('escodegen'); | |
module.exports = code => { | |
let ast = esprima.parse(code); | |
let optimized = esmangle.optimize(ast, null); | |
optimized = ast; | |
esmangle.mangle(optimized, { | |
destructive: true, | |
distinguishFunctionExpressionScope: false | |
}); | |
return escodegen.generate(optimized, { | |
format: { | |
compact: true, | |
quotes: 'double', | |
semicolons: false, | |
renumber: true, | |
hexadecimal: true, | |
escapeless: true, | |
parentheses: false | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment