diff options
Diffstat (limited to 'node_modules/babel-plugin-uglify')
| -rw-r--r-- | node_modules/babel-plugin-uglify/.babelrc | 3 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/.editorconfig | 12 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/.npmignore | 3 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/LICENSE | 22 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/README.md | 41 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/dist/index.js | 55 | ||||
| l--------- | node_modules/babel-plugin-uglify/node_modules/.bin/uglifyjs | 1 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/package.json | 28 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/test/fixtures/actual.js | 6 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/test/fixtures/expected.js | 7 | ||||
| -rw-r--r-- | node_modules/babel-plugin-uglify/test/index.js | 53 |
11 files changed, 231 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-uglify/.babelrc b/node_modules/babel-plugin-uglify/.babelrc new file mode 100644 index 00000000..4adbf344 --- /dev/null +++ b/node_modules/babel-plugin-uglify/.babelrc @@ -0,0 +1,3 @@ +{
+ "loose": "all"
+}
diff --git a/node_modules/babel-plugin-uglify/.editorconfig b/node_modules/babel-plugin-uglify/.editorconfig new file mode 100644 index 00000000..ae483a20 --- /dev/null +++ b/node_modules/babel-plugin-uglify/.editorconfig @@ -0,0 +1,12 @@ +root = true
+
+[*]
+charset = utf-8
+trim_trailing_whitespace = true
+indent_style = tab
+indent_size = 4
+insert_final_newline = true
+
+[*.{json,babelrc,eslintrc}]
+indent_style = space
+indent_size = 2
diff --git a/node_modules/babel-plugin-uglify/.npmignore b/node_modules/babel-plugin-uglify/.npmignore new file mode 100644 index 00000000..5b023555 --- /dev/null +++ b/node_modules/babel-plugin-uglify/.npmignore @@ -0,0 +1,3 @@ +node_modules +/src +*.log diff --git a/node_modules/babel-plugin-uglify/LICENSE b/node_modules/babel-plugin-uglify/LICENSE new file mode 100644 index 00000000..451219ec --- /dev/null +++ b/node_modules/babel-plugin-uglify/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Ingvar Stepanyan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/node_modules/babel-plugin-uglify/README.md b/node_modules/babel-plugin-uglify/README.md new file mode 100644 index 00000000..67ea232a --- /dev/null +++ b/node_modules/babel-plugin-uglify/README.md @@ -0,0 +1,41 @@ +# babel-plugin-uglify + +UglifyJS integration for Babel. + +It will allow you to integrate [UglifyJS minifier](https://github.com/mishoo/UglifyJS2) into Babel pipeline without a need for generating code from Babel and parsing back into UglifyJS just to minify it and generate back again. + +You can find a bit more detailed article on this [in my blog](https://rreverser.com/using-mozilla-ast-with-uglifyjs/). + +## Installation + +```sh +$ npm install babel-plugin-uglify --save-dev +``` + +## Usage + +Note that plugin should be **always** runned after any ES6 transformers (use `:after` suffix as shown below), as UglifyJS doesn't understand ES6 at all, and thus will just break if you have anything left untransformed. + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["uglify:after"] +} +``` + +### Via CLI + +```sh +$ babel --plugins uglify:after script.js +``` + +### Via Node API + +```javascript +require('babel').transform('code', { + plugins: ['uglify:after'] +}); +``` 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 diff --git a/node_modules/babel-plugin-uglify/node_modules/.bin/uglifyjs b/node_modules/babel-plugin-uglify/node_modules/.bin/uglifyjs new file mode 120000 index 00000000..aaaeee8a --- /dev/null +++ b/node_modules/babel-plugin-uglify/node_modules/.bin/uglifyjs @@ -0,0 +1 @@ +../../../uglify-js/bin/uglifyjs
\ No newline at end of file diff --git a/node_modules/babel-plugin-uglify/package.json b/node_modules/babel-plugin-uglify/package.json new file mode 100644 index 00000000..70b3d202 --- /dev/null +++ b/node_modules/babel-plugin-uglify/package.json @@ -0,0 +1,28 @@ +{ + "name": "babel-plugin-uglify", + "version": "1.0.2", + "description": "UglifyJS integration for Babel", + "repository": "RReverser/babel-plugin-uglify", + "license": "MIT", + "main": "dist/index.js", + "dependencies": { + "uglify-js": "^2.4.24" + }, + "devDependencies": { + "babel": "^5.8.19", + "chalk": "^1.1.0", + "clear": "0.0.1", + "diff": "^1.4.0", + "watch": "^0.16.0" + }, + "scripts": { + "release": "babel src --out-dir dist", + "test": "node test", + "watch": "node test --watch" + }, + "keywords": [ + "babel-plugin", + "uglify", + "minify" + ] +} diff --git a/node_modules/babel-plugin-uglify/test/fixtures/actual.js b/node_modules/babel-plugin-uglify/test/fixtures/actual.js new file mode 100644 index 00000000..6f5503c3 --- /dev/null +++ b/node_modules/babel-plugin-uglify/test/fixtures/actual.js @@ -0,0 +1,6 @@ +export function doSmth(hiThere) {
+ hiThere();
+ if (false) {
+ console.log('dead code');
+ }
+};
diff --git a/node_modules/babel-plugin-uglify/test/fixtures/expected.js b/node_modules/babel-plugin-uglify/test/fixtures/expected.js new file mode 100644 index 00000000..8c8c7a5a --- /dev/null +++ b/node_modules/babel-plugin-uglify/test/fixtures/expected.js @@ -0,0 +1,7 @@ +'use strict'; + +function doSmth(t) { + t(); +} + +exports.__esModule = !0, exports.doSmth = doSmth; diff --git a/node_modules/babel-plugin-uglify/test/index.js b/node_modules/babel-plugin-uglify/test/index.js new file mode 100644 index 00000000..127e3938 --- /dev/null +++ b/node_modules/babel-plugin-uglify/test/index.js @@ -0,0 +1,53 @@ +var assert = require('assert');
+var babel = require('babel');
+var chalk = require('chalk');
+var clear = require('clear');
+var diff = require('diff');
+var fs = require('fs');
+
+require('babel/register')(JSON.parse(fs.readFileSync(__dirname + '/../.babelrc')));
+
+var pluginPath = require.resolve('../src');
+
+function runTest() {
+ var output = babel.transformFileSync(__dirname + '/fixtures/actual.js', {
+ optional: ['runtime'],
+ plugins: [pluginPath + ':after'],
+ filenameRelative: 'test/fixtures/actual.js'
+ });
+
+ var expected = fs.readFileSync(__dirname + '/fixtures/expected.js', 'utf-8');
+
+ function normalizeLines(str) {
+ return str.trimRight().replace(/\r\n/g, '\n');
+ }
+
+ diff.diffLines(normalizeLines(output.code), normalizeLines(expected))
+ .forEach(function (part) {
+ var value = part.value;
+ if (part.added) {
+ value = chalk.green(part.value);
+ } else if (part.removed) {
+ value = chalk.red(part.value);
+ }
+ process.stdout.write(value);
+ });
+
+ console.log();
+}
+
+if (process.argv.indexOf('--watch') >= 0) {
+ require('watch').watchTree(__dirname + '/..', function () {
+ delete require.cache[pluginPath];
+ clear();
+ console.log('Press Ctrl+C to stop watching...');
+ console.log('================================');
+ try {
+ runTest();
+ } catch (e) {
+ console.error(chalk.magenta(e.stack));
+ }
+ });
+} else {
+ runTest();
+}
|
