1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 |
|
5 | function _classCallCheck(instance, Constructor) {
|
6 | if (!(instance instanceof Constructor)) {
|
7 | throw new TypeError('Cannot call a class as a function');
|
8 | }
|
9 | }
|
10 |
|
11 | function _inherits(subClass, superClass) {
|
12 | if (typeof superClass !== 'function' && superClass !== null) {
|
13 | throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
|
14 | }
|
15 | 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; }
|
16 |
|
17 | var _uglifyJs = require('uglify-js');
|
18 |
|
19 | var compressor = _uglifyJs.Compressor();
|
20 |
|
21 | var LocationFixer = (function (_TreeWalker) {
|
22 | _inherits(LocationFixer, _TreeWalker);
|
23 |
|
24 | function LocationFixer(path) {
|
25 | _classCallCheck(this, LocationFixer);
|
26 |
|
27 | _TreeWalker.call(this, function (node) {
|
28 | node.start.file = node.end.file = path.hub.file.opts.filenameRelative;
|
29 | });
|
30 | }
|
31 |
|
32 | return LocationFixer;
|
33 | })(_uglifyJs.TreeWalker);
|
34 |
|
35 | exports['default'] = function (_ref) {
|
36 | var Plugin = _ref.Plugin;
|
37 | var t = _ref.types;
|
38 | return new Plugin('uglify', {
|
39 | visitor: {
|
40 | Program: function (ast) {
|
41 |
|
42 | var uAST = _uglifyJs.AST_Node.from_mozilla_ast(ast);
|
43 |
|
44 | uAST.walk(new LocationFixer(this));
|
45 |
|
46 |
|
47 | uAST.figure_out_scope();
|
48 | uAST = uAST.transform(compressor);
|
49 |
|
50 |
|
51 | uAST.figure_out_scope();
|
52 | uAST.compute_char_frequency();
|
53 | uAST.mangle_names();
|
54 |
|
55 |
|
56 | var result = uAST.to_mozilla_ast();
|
57 | return result;
|
58 | }
|
59 | }
|
60 | });
|
61 | };
|
62 |
|
63 | module.exports = exports['default'];
|