toloframework
Version:
Javascript/HTML/CSS compiler for Firefox OS or nodewebkit apps using modules in the nodejs style.
64 lines (49 loc) • 2.18 kB
JavaScript
exports.__esModule = true;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError('Cannot call a class as a function');
}
}
function _inherits(subClass, superClass) {
if (typeof superClass !== 'function' && superClass !== null) {
throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _uglifyJs = require('uglify-js');
var compressor = _uglifyJs.Compressor();
var LocationFixer = (function (_TreeWalker) {
_inherits(LocationFixer, _TreeWalker);
function LocationFixer(path) {
_classCallCheck(this, LocationFixer);
_TreeWalker.call(this, function (node) {
node.start.file = node.end.file = path.hub.file.opts.filenameRelative;
});
}
return LocationFixer;
})(_uglifyJs.TreeWalker);
exports['default'] = function (_ref) {
var Plugin = _ref.Plugin;
var t = _ref.types;
return new Plugin('uglify', {
visitor: {
Program: function (ast) {
// Convert to UglifyJS AST
var uAST = _uglifyJs.AST_Node.from_mozilla_ast(ast);
// Fix locations (Babel doesn't insert `loc.source` into nodes for some reason)
uAST.walk(new LocationFixer(this));
// Compress
uAST.figure_out_scope();
uAST = uAST.transform(compressor);
// Mangle names
uAST.figure_out_scope();
uAST.compute_char_frequency();
uAST.mangle_names();
// Convert back to ESTree AST
var result = uAST.to_mozilla_ast();
return result;
}
}
});
};
module.exports = exports['default'];
;