1 | var fs = require("fs");
|
2 |
|
3 | exports.FILES = [
|
4 | require.resolve("../lib/utils.js"),
|
5 | require.resolve("../lib/ast.js"),
|
6 | require.resolve("../lib/transform.js"),
|
7 | require.resolve("../lib/parse.js"),
|
8 | require.resolve("../lib/scope.js"),
|
9 | require.resolve("../lib/compress.js"),
|
10 | require.resolve("../lib/output.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 |
|
18 | new 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 |
|
26 | function to_comment(value) {
|
27 | if (typeof value != "string") value = JSON.stringify(value, function(key, value) {
|
28 | return typeof value == "function" ? "<[ " + value + " ]>" : value;
|
29 | }, 2);
|
30 | return "// " + value.replace(/\n/g, "\n// ");
|
31 | }
|
32 |
|
33 | if (+process.env["UGLIFY_BUG_REPORT"]) exports.minify = function(files, options) {
|
34 | if (typeof options == "undefined") options = "<<undefined>>";
|
35 | var code = [
|
36 | "// UGLIFY_BUG_REPORT",
|
37 | to_comment(options),
|
38 | ];
|
39 | if (typeof files == "string") {
|
40 | code.push("");
|
41 | code.push("//-------------------------------------------------------------")
|
42 | code.push("// INPUT CODE", files);
|
43 | } else for (var name in files) {
|
44 | code.push("");
|
45 | code.push("//-------------------------------------------------------------")
|
46 | code.push(to_comment(name), files[name]);
|
47 | }
|
48 | if (options.sourceMap && options.sourceMap.url) {
|
49 | code.push("");
|
50 | code.push("//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9");
|
51 | }
|
52 | var result = { code: code.join("\n") };
|
53 | if (options.sourceMap) result.map = '{"version":3,"sources":[],"names":[],"mappings":""}';
|
54 | return result;
|
55 | };
|
56 |
|
57 | function describe_ast() {
|
58 | var out = OutputStream({ beautify: true });
|
59 | doitem(AST_Node);
|
60 | return out.get() + "\n";
|
61 |
|
62 | function doitem(ctor) {
|
63 | out.print("AST_" + ctor.TYPE);
|
64 | var props = ctor.SELF_PROPS.filter(function(prop) {
|
65 | return !/^\$/.test(prop);
|
66 | });
|
67 | if (props.length > 0) {
|
68 | out.space();
|
69 | out.with_parens(function() {
|
70 | props.forEach(function(prop, i) {
|
71 | if (i) out.space();
|
72 | out.print(prop);
|
73 | });
|
74 | });
|
75 | }
|
76 | if (ctor.documentation) {
|
77 | out.space();
|
78 | out.print_string(ctor.documentation);
|
79 | }
|
80 | if (ctor.SUBCLASSES.length > 0) {
|
81 | out.space();
|
82 | out.with_block(function() {
|
83 | ctor.SUBCLASSES.sort(function(a, b) {
|
84 | return a.TYPE < b.TYPE ? -1 : 1;
|
85 | }).forEach(function(ctor, i) {
|
86 | out.indent();
|
87 | doitem(ctor);
|
88 | out.newline();
|
89 | });
|
90 | });
|
91 | }
|
92 | }
|
93 | }
|
94 |
|
95 | function infer_options(options) {
|
96 | var result = exports.minify("", options);
|
97 | return result.error && result.error.defs;
|
98 | }
|
99 |
|
100 | exports.default_options = function() {
|
101 | var defs = infer_options({ 0: 0 });
|
102 | Object.keys(defs).forEach(function(component) {
|
103 | var options = {};
|
104 | options[component] = { 0: 0 };
|
105 | if (options = infer_options(options)) {
|
106 | defs[component] = options;
|
107 | }
|
108 | });
|
109 | return defs;
|
110 | };
|