diff options
Diffstat (limited to 'node_modules/babel-plugin-uglify/dist')
| -rw-r--r-- | node_modules/babel-plugin-uglify/dist/index.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-uglify/dist/index.js b/node_modules/babel-plugin-uglify/dist/index.js new file mode 100644 index 00000000..9a0b29c6 --- /dev/null +++ b/node_modules/babel-plugin-uglify/dist/index.js @@ -0,0 +1,55 @@ +'use strict'; + +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 Program(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 + return uAST.to_mozilla_ast(); + } + } + }); +}; + +module.exports = exports['default'];
\ No newline at end of file |
