node.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var fs = require("fs");
  2. exports.FILES = [
  3. require.resolve("../lib/utils.js"),
  4. require.resolve("../lib/ast.js"),
  5. require.resolve("../lib/parse.js"),
  6. require.resolve("../lib/transform.js"),
  7. require.resolve("../lib/scope.js"),
  8. require.resolve("../lib/output.js"),
  9. require.resolve("../lib/compress.js"),
  10. require.resolve("../lib/sourcemap.js"),
  11. require.resolve("../lib/mozilla-ast.js"),
  12. require.resolve("../lib/propmangle.js"),
  13. require.resolve("../lib/minify.js"),
  14. require.resolve("./exports.js"),
  15. ];
  16. new Function("exports", function() {
  17. var code = exports.FILES.map(function(file) {
  18. return fs.readFileSync(file, "utf8");
  19. });
  20. code.push("exports.describe_ast = " + describe_ast.toString());
  21. return code.join("\n\n");
  22. }())(exports);
  23. function describe_ast() {
  24. var out = OutputStream({ beautify: true });
  25. function doitem(ctor) {
  26. out.print("AST_" + ctor.TYPE);
  27. var props = ctor.SELF_PROPS.filter(function(prop) {
  28. return !/^\$/.test(prop);
  29. });
  30. if (props.length > 0) {
  31. out.space();
  32. out.with_parens(function() {
  33. props.forEach(function(prop, i) {
  34. if (i) out.space();
  35. out.print(prop);
  36. });
  37. });
  38. }
  39. if (ctor.documentation) {
  40. out.space();
  41. out.print_string(ctor.documentation);
  42. }
  43. if (ctor.SUBCLASSES.length > 0) {
  44. out.space();
  45. out.with_block(function() {
  46. ctor.SUBCLASSES.sort(function(a, b) {
  47. return a.TYPE < b.TYPE ? -1 : 1;
  48. }).forEach(function(ctor, i) {
  49. out.indent();
  50. doitem(ctor);
  51. out.newline();
  52. });
  53. });
  54. }
  55. };
  56. doitem(AST_Node);
  57. return out + "\n";
  58. }
  59. function infer_options(options) {
  60. var result = exports.minify("", options);
  61. return result.error && result.error.defs;
  62. }
  63. exports.default_options = function() {
  64. var defs = infer_options({ 0: 0 });
  65. Object.keys(defs).forEach(function(component) {
  66. var options = {};
  67. options[component] = { 0: 0 };
  68. if (options = infer_options(options)) {
  69. defs[component] = options;
  70. }
  71. });
  72. return defs;
  73. };