You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

4 years ago
  1. var fs = require("fs");
  2. exports.FILES = [
  3. "../lib/utils.js",
  4. "../lib/ast.js",
  5. "../lib/parse.js",
  6. "../lib/transform.js",
  7. "../lib/scope.js",
  8. "../lib/output.js",
  9. "../lib/compress.js",
  10. "../lib/sourcemap.js",
  11. "../lib/mozilla-ast.js",
  12. "../lib/propmangle.js",
  13. "../lib/minify.js",
  14. "./exports.js",
  15. ].map(function(file) {
  16. return require.resolve(file);
  17. });
  18. new Function("MOZ_SourceMap", "exports", function() {
  19. var code = exports.FILES.map(function(file) {
  20. return fs.readFileSync(file, "utf8");
  21. });
  22. code.push("exports.describe_ast = " + describe_ast.toString());
  23. return code.join("\n\n");
  24. }())(require("source-map"), exports);
  25. function describe_ast() {
  26. var out = OutputStream({ beautify: true });
  27. function doitem(ctor) {
  28. out.print("AST_" + ctor.TYPE);
  29. var props = ctor.SELF_PROPS.filter(function(prop) {
  30. return !/^\$/.test(prop);
  31. });
  32. if (props.length > 0) {
  33. out.space();
  34. out.with_parens(function() {
  35. props.forEach(function(prop, i) {
  36. if (i) out.space();
  37. out.print(prop);
  38. });
  39. });
  40. }
  41. if (ctor.documentation) {
  42. out.space();
  43. out.print_string(ctor.documentation);
  44. }
  45. if (ctor.SUBCLASSES.length > 0) {
  46. out.space();
  47. out.with_block(function() {
  48. ctor.SUBCLASSES.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 = {};
  65. Object.keys(infer_options({ 0: 0 })).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. };