-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.js
121 lines (121 loc) · 3.95 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Generated by CoffeeScript 2.0.0-beta7
void function () {
var $0, cache$, counter, fuzz, fuzzAndRoundtrip, generate, knownOpts, nonstandardParsers, nopt, optAliases, options, parsers, path, recur;
path = require('path');
nopt = require('nopt');
cache$ = require('./index');
generate = cache$.generate;
fuzz = cache$.fuzz;
fuzzAndRoundtrip = cache$.fuzzAndRoundtrip;
knownOpts = {
acorn: Boolean,
es6: Boolean,
esprima: Boolean,
help: Boolean,
iterations: Number,
'max-depth': Number,
reflect: Boolean,
reflectjs: Boolean,
zeparser: Boolean,
uglifyjs: Boolean,
version: Boolean
};
optAliases = {
n: '--iterations',
d: '--max-depth'
};
options = nopt(knownOpts, optAliases, process.argv, 2);
if (null != options.esprima)
options.esprima;
else
options.esprima = true;
if (null != options.acorn)
options.acorn;
else
options.acorn = true;
if (null != options.reflect)
options.reflect;
else
options.reflect = 'undefined' !== typeof Reflect && null != Reflect && 'function' === typeof Reflect.parse;
if (null != options.iterations)
options.iterations;
else
options.iterations = 1 / 0;
if (null != options['max-depth'])
options['max-depth'];
else
options['max-depth'] = 7;
options.maxDepth = options['max-depth'];
parsers = [];
nonstandardParsers = [];
if (options.esprima)
try {
parsers.push(require('esprima'));
} catch (e$) {
}
if (options.acorn)
try {
parsers.push(require('acorn'));
} catch (e$1) {
}
if (options.reflectjs)
try {
parsers.push(require('reflect'));
} catch (e$2) {
}
if (options.reflect)
try {
parsers.push(Reflect);
} catch (e$3) {
}
if (options.uglifyjs)
try {
nonstandardParsers.push(require('uglify-js'));
} catch (e$4) {
}
if (options.zeparser)
try {
nonstandardParsers.push(require('zeparser').ZeParser);
} catch (e$5) {
}
if (options.help) {
$0 = process.argv[0] === 'node' ? process.argv[1] : process.argv[0];
$0 = path.basename($0);
console.log('\n Usage: ' + $0 + ' OPT*\n\n -n, --iterations NUM use at most NUM programs; default: unlimited\n -d, --max-depth NUM create ASTs with a height no greater than NUM; default: 8\n --acorn enable marijnh/acorn parser; default: on\n --es6 allow ECMAScript 6 features in generated programs\n --esprima enable ariya/esprima parser; default: on\n --help display this help message and exit\n --reflect enable Reflect.parse parser; default: on if it exists\n --reflectjs enable zaach/reflect.js parser\n --uglifyjs enable limited support for mishoo/UglifyJS2\n --version display the version number and exit\n --zeparser enable limited support for qfox/ZeParser\n');
process.exit(0);
}
if (options.version) {
console.log(require('../package.json').version);
process.exit(0);
}
process.on('SIGINT', function () {
process.stdout.write(' \n');
return process.exit(0);
});
counter = 0;
(recur = function () {
var ast, cache$1, err, js, message, name, program, stack;
if (counter < options.iterations) {
process.stdout.write('\b\b\b\b\b\b\b\b\b\b\b\b\b\b' + ++counter);
try {
program = generate({ maxDepth: options.maxDepth });
fuzzAndRoundtrip(program, parsers);
if (nonstandardParsers.length)
fuzz(program, nonstandardParsers);
} catch (e$6) {
err = e$6;
cache$1 = err;
stack = cache$1.stack;
ast = cache$1.ast;
js = cache$1.js;
name = cache$1.name;
message = cache$1.message;
console.error('\b\b\b\b\b\b\b\b\b\b\b\b\b' + name + ': ' + message + '\n\n' + stack + '\n\n' + js + '\n\n' + ast);
process.exit(1);
}
setImmediate(recur);
} else {
process.stdout.write('\n');
}
})();
}.call(this);