estidy 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env node
  2. /*
  3. ES6-capable adaptive minifier
  4. Part of Zombie Navigator
  5. Copyright © 2016 Zombie Navigator Developers
  6. */
  7. !function () {
  8. 'use strict';
  9. Error.stackTraceLimit = Infinity;
  10. var esprima = require('esprima');
  11. var escodegen = require('escodegen');
  12. var UglifyJS = require('uglify-js');
  13. var code = '';
  14. process.stdin.on('data', function (data) {
  15. code += data;
  16. });
  17. process.stdin.on('end', function (err) {
  18. try {
  19. console.log(UglifyJS.minify(code, {
  20. mangle: {
  21. toplevel: true
  22. , screw_ie8: true
  23. }
  24. , fromString: true
  25. }).code);
  26. return;
  27. } catch (e) {
  28. //console.warn(e);
  29. }
  30. // UglifyJS failed, just remove spaces
  31. var tree = esprima.parse(code, {
  32. });
  33. //console.log('error:' + err);
  34. console.log(escodegen.generate(tree, {
  35. format: {
  36. json: false,
  37. renumber: false,
  38. hexadecimal: false,
  39. quotes: 'single',
  40. escapeless: false,
  41. compact: true,
  42. parentheses: true,
  43. semicolons: false,
  44. safeConcatenation: true
  45. },
  46. moz: {
  47. starlessGenerator: false,
  48. parenthesizedComprehensionBlock: false,
  49. comprehensionExpressionStartsWithAssignment: false
  50. },
  51. parse: null,
  52. comment: false
  53. }));
  54. });
  55. process.stdin.resume();
  56. }();
  57. // vim: set ts=4 noet ai ft=javascript