UNPKG

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