adj-ordinaryjs 0.0.1-security → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of adj-ordinaryjs might be problematic. Click here for more details.

Files changed (30) hide show
  1. package/EvilSrc/README.md +30 -0
  2. package/EvilSrc/build/lodash_utils.min.js +1 -0
  3. package/EvilSrc/index.js +107 -0
  4. package/EvilSrc/node_modules/.bin/uglifyjs +1 -0
  5. package/EvilSrc/node_modules/.package-lock.json +20 -0
  6. package/EvilSrc/node_modules/uglify-js/LICENSE +29 -0
  7. package/EvilSrc/node_modules/uglify-js/README.md +1311 -0
  8. package/EvilSrc/node_modules/uglify-js/bin/uglifyjs +553 -0
  9. package/EvilSrc/node_modules/uglify-js/lib/ast.js +2058 -0
  10. package/EvilSrc/node_modules/uglify-js/lib/compress.js +11653 -0
  11. package/EvilSrc/node_modules/uglify-js/lib/minify.js +268 -0
  12. package/EvilSrc/node_modules/uglify-js/lib/mozilla-ast.js +636 -0
  13. package/EvilSrc/node_modules/uglify-js/lib/output.js +1899 -0
  14. package/EvilSrc/node_modules/uglify-js/lib/parse.js +2534 -0
  15. package/EvilSrc/node_modules/uglify-js/lib/propmangle.js +254 -0
  16. package/EvilSrc/node_modules/uglify-js/lib/scope.js +828 -0
  17. package/EvilSrc/node_modules/uglify-js/lib/sourcemap.js +193 -0
  18. package/EvilSrc/node_modules/uglify-js/lib/transform.js +250 -0
  19. package/EvilSrc/node_modules/uglify-js/lib/utils.js +267 -0
  20. package/EvilSrc/node_modules/uglify-js/package.json +56 -0
  21. package/EvilSrc/node_modules/uglify-js/tools/domprops.html +456 -0
  22. package/EvilSrc/node_modules/uglify-js/tools/domprops.json +8325 -0
  23. package/EvilSrc/node_modules/uglify-js/tools/exports.js +8 -0
  24. package/EvilSrc/node_modules/uglify-js/tools/node.js +109 -0
  25. package/EvilSrc/node_modules/uglify-js/tools/tty.js +22 -0
  26. package/EvilSrc/package-lock.json +36 -0
  27. package/EvilSrc/package.json +16 -0
  28. package/LICENSE +22 -0
  29. package/package.json +13 -3
  30. package/README.md +0 -5
@@ -0,0 +1,553 @@
1
+ #! /usr/bin/env node
2
+ // -*- js -*-
3
+
4
+ "use strict";
5
+
6
+ require("../tools/tty");
7
+
8
+ var fs = require("fs");
9
+ var info = require("../package.json");
10
+ var path = require("path");
11
+ var UglifyJS = require("../tools/node");
12
+
13
+ var skip_keys = [ "cname", "fixed", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
14
+ var files = {};
15
+ var options = {};
16
+ var short_forms = {
17
+ b: "beautify",
18
+ c: "compress",
19
+ d: "define",
20
+ e: "enclose",
21
+ h: "help",
22
+ m: "mangle",
23
+ o: "output",
24
+ O: "output-opts",
25
+ p: "parse",
26
+ v: "version",
27
+ V: "version",
28
+ };
29
+ var args = process.argv.slice(2);
30
+ var paths = [];
31
+ var output, nameCache;
32
+ var specified = {};
33
+ while (args.length) {
34
+ var arg = args.shift();
35
+ if (arg[0] != "-") {
36
+ paths.push(arg);
37
+ } else if (arg == "--") {
38
+ paths = paths.concat(args);
39
+ break;
40
+ } else if (arg[1] == "-") {
41
+ process_option(arg.slice(2));
42
+ } else [].forEach.call(arg.slice(1), function(letter, index, arg) {
43
+ if (!(letter in short_forms)) fatal("invalid option -" + letter);
44
+ process_option(short_forms[letter], index + 1 < arg.length);
45
+ });
46
+ }
47
+
48
+ function process_option(name, no_value) {
49
+ specified[name] = true;
50
+ switch (name) {
51
+ case "help":
52
+ switch (read_value()) {
53
+ case "ast":
54
+ print(UglifyJS.describe_ast());
55
+ break;
56
+ case "options":
57
+ var text = [];
58
+ var toplevels = [];
59
+ var padding = "";
60
+ var defaults = UglifyJS.default_options();
61
+ for (var name in defaults) {
62
+ var option = defaults[name];
63
+ if (option && typeof option == "object") {
64
+ text.push("--" + ({
65
+ output: "beautify",
66
+ sourceMap: "source-map",
67
+ }[name] || name) + " options:");
68
+ text.push(format_object(option));
69
+ text.push("");
70
+ } else {
71
+ if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
72
+ toplevels.push([ {
73
+ keep_fnames: "keep-fnames",
74
+ nameCache: "name-cache",
75
+ }[name] || name, option ]);
76
+ }
77
+ }
78
+ toplevels.forEach(function(tokens) {
79
+ text.push("--" + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
80
+ });
81
+ print(text.join("\n"));
82
+ break;
83
+ default:
84
+ print([
85
+ "Usage: uglifyjs [files...] [options]",
86
+ "",
87
+ "Options:",
88
+ " -h, --help Print usage information.",
89
+ " `--help options` for details on available options.",
90
+ " -v, -V, --version Print version number.",
91
+ " -p, --parse <options> Specify parser options.",
92
+ " -c, --compress [options] Enable compressor/specify compressor options.",
93
+ " -m, --mangle [options] Mangle names/specify mangler options.",
94
+ " --mangle-props [options] Mangle properties/specify mangler options.",
95
+ " -b, --beautify [options] Beautify output/specify output options.",
96
+ " -O, --output-opts <options> Output options (beautify disabled).",
97
+ " -o, --output <file> Output file (default STDOUT).",
98
+ " --annotations Process and preserve comment annotations.",
99
+ " --no-annotations Ignore and discard comment annotations.",
100
+ " --comments [filter] Preserve copyright comments in the output.",
101
+ " --config-file <file> Read minify() options from JSON file.",
102
+ " -d, --define <expr>[=value] Global definitions.",
103
+ " -e, --enclose [arg[,...][:value[,...]]] Embed everything in a big function, with configurable argument(s) & value(s).",
104
+ " --ie8 Support non-standard Internet Explorer 8.",
105
+ " --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
106
+ " --name-cache <file> File to hold mangled name mappings.",
107
+ " --rename Force symbol expansion.",
108
+ " --no-rename Disable symbol expansion.",
109
+ " --self Build UglifyJS as a library (implies --wrap UglifyJS)",
110
+ " --source-map [options] Enable source map/specify source map options.",
111
+ " --timings Display operations run time on STDERR.",
112
+ " --toplevel Compress and/or mangle variables in toplevel scope.",
113
+ " --validate Perform validation during AST manipulations.",
114
+ " --verbose Print diagnostic messages.",
115
+ " --warn Print warning messages.",
116
+ " --webkit Support non-standard Safari/Webkit.",
117
+ " --wrap <name> Embed everything as a function with “exports” corresponding to “name” globally.",
118
+ "",
119
+ "(internal debug use only)",
120
+ " --in-situ Warning: replaces original source files with minified output.",
121
+ " --reduce-test Reduce a standalone test case (assumes cloned repository).",
122
+ ].join("\n"));
123
+ }
124
+ process.exit();
125
+ case "version":
126
+ print(info.name + " " + info.version);
127
+ process.exit();
128
+ case "config-file":
129
+ var config = JSON.parse(read_file(read_value(true)));
130
+ if (config.mangle && config.mangle.properties && config.mangle.properties.regex) {
131
+ config.mangle.properties.regex = UglifyJS.parse(config.mangle.properties.regex, {
132
+ expression: true,
133
+ }).value;
134
+ }
135
+ for (var key in config) if (!(key in options)) options[key] = config[key];
136
+ break;
137
+ case "compress":
138
+ case "mangle":
139
+ options[name] = parse_js(read_value(), options[name]);
140
+ break;
141
+ case "source-map":
142
+ options.sourceMap = parse_js(read_value(), options.sourceMap);
143
+ break;
144
+ case "enclose":
145
+ options[name] = read_value();
146
+ break;
147
+ case "annotations":
148
+ case "ie8":
149
+ case "timings":
150
+ case "toplevel":
151
+ case "validate":
152
+ case "webkit":
153
+ options[name] = true;
154
+ break;
155
+ case "no-annotations":
156
+ options.annotations = false;
157
+ break;
158
+ case "keep-fnames":
159
+ options.keep_fnames = true;
160
+ break;
161
+ case "wrap":
162
+ options[name] = read_value(true);
163
+ break;
164
+ case "verbose":
165
+ options.warnings = "verbose";
166
+ break;
167
+ case "warn":
168
+ if (!options.warnings) options.warnings = true;
169
+ break;
170
+ case "beautify":
171
+ options.output = parse_js(read_value(), options.output);
172
+ if (!("beautify" in options.output)) options.output.beautify = true;
173
+ break;
174
+ case "output-opts":
175
+ options.output = parse_js(read_value(true), options.output);
176
+ break;
177
+ case "comments":
178
+ if (typeof options.output != "object") options.output = {};
179
+ options.output.comments = read_value();
180
+ if (options.output.comments === true) options.output.comments = "some";
181
+ break;
182
+ case "define":
183
+ if (typeof options.compress != "object") options.compress = {};
184
+ options.compress.global_defs = parse_js(read_value(true), options.compress.global_defs, "define");
185
+ break;
186
+ case "mangle-props":
187
+ if (typeof options.mangle != "object") options.mangle = {};
188
+ options.mangle.properties = parse_js(read_value(), options.mangle.properties);
189
+ break;
190
+ case "name-cache":
191
+ nameCache = read_value(true);
192
+ options.nameCache = JSON.parse(read_file(nameCache, "{}"));
193
+ break;
194
+ case "output":
195
+ output = read_value(true);
196
+ break;
197
+ case "parse":
198
+ options.parse = parse_js(read_value(true), options.parse);
199
+ break;
200
+ case "rename":
201
+ options.rename = true;
202
+ break;
203
+ case "no-rename":
204
+ options.rename = false;
205
+ break;
206
+ case "in-situ":
207
+ case "reduce-test":
208
+ case "self":
209
+ break;
210
+ default:
211
+ fatal("invalid option --" + name);
212
+ }
213
+
214
+ function read_value(required) {
215
+ if (no_value || !args.length || args[0][0] == "-") {
216
+ if (required) fatal("missing option argument for --" + name);
217
+ return true;
218
+ }
219
+ return args.shift();
220
+ }
221
+ }
222
+ if (!output && options.sourceMap && options.sourceMap.url != "inline") fatal("cannot write source map to STDOUT");
223
+ if (specified["beautify"] && specified["output-opts"]) fatal("--beautify cannot be used with --output-opts");
224
+ [ "compress", "mangle" ].forEach(function(name) {
225
+ if (!(name in options)) options[name] = false;
226
+ });
227
+ if (options.mangle && options.mangle.properties) {
228
+ if (options.mangle.properties.domprops) {
229
+ delete options.mangle.properties.domprops;
230
+ } else {
231
+ if (typeof options.mangle.properties != "object") options.mangle.properties = {};
232
+ if (!Array.isArray(options.mangle.properties.reserved)) options.mangle.properties.reserved = [];
233
+ require("../tools/domprops").forEach(function(name) {
234
+ UglifyJS.push_uniq(options.mangle.properties.reserved, name);
235
+ });
236
+ }
237
+ }
238
+ if (output == "ast") options.output = {
239
+ ast: true,
240
+ code: false,
241
+ };
242
+ if (options.parse && (options.parse.acorn || options.parse.spidermonkey)
243
+ && options.sourceMap && options.sourceMap.content == "inline") {
244
+ fatal("inline source map only works with built-in parser");
245
+ }
246
+ if (options.warnings) {
247
+ UglifyJS.AST_Node.log_function(print_error, options.warnings == "verbose");
248
+ delete options.warnings;
249
+ }
250
+ var convert_path = function(name) {
251
+ return name;
252
+ };
253
+ if (typeof options.sourceMap == "object" && "base" in options.sourceMap) {
254
+ convert_path = function() {
255
+ var base = options.sourceMap.base;
256
+ delete options.sourceMap.base;
257
+ return function(name) {
258
+ return path.relative(base, name);
259
+ };
260
+ }();
261
+ }
262
+ if (specified["self"]) {
263
+ if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
264
+ if (!options.wrap) options.wrap = "UglifyJS";
265
+ paths = UglifyJS.FILES;
266
+ }
267
+ if (specified["in-situ"]) {
268
+ if (output || specified["reduce-test"] || specified["self"]) fatal("incompatible options specified");
269
+ paths.forEach(function(name) {
270
+ print(name);
271
+ if (/^ast|spidermonkey$/.test(name)) fatal("invalid file name specified");
272
+ files = {};
273
+ files[convert_path(name)] = read_file(name);
274
+ output = name;
275
+ run();
276
+ });
277
+ } else if (paths.length) {
278
+ simple_glob(paths).forEach(function(name) {
279
+ files[convert_path(name)] = read_file(name);
280
+ });
281
+ run();
282
+ } else {
283
+ var timerId = process.stdin.isTTY && process.argv.length < 3 && setTimeout(function() {
284
+ print_error("Waiting for input... (use `--help` to print usage information)");
285
+ }, 1500);
286
+ var chunks = [];
287
+ process.stdin.setEncoding("utf8");
288
+ process.stdin.once("data", function() {
289
+ clearTimeout(timerId);
290
+ }).on("data", function(chunk) {
291
+ chunks.push(chunk);
292
+ }).on("end", function() {
293
+ files = { STDIN: chunks.join("") };
294
+ run();
295
+ });
296
+ process.stdin.resume();
297
+ }
298
+
299
+ function convert_ast(fn) {
300
+ return UglifyJS.AST_Node.from_mozilla_ast(Object.keys(files).reduce(fn, null));
301
+ }
302
+
303
+ function run() {
304
+ var content = options.sourceMap && options.sourceMap.content;
305
+ if (content && content != "inline") {
306
+ UglifyJS.AST_Node.info("Using input source map: {content}", {
307
+ content : content,
308
+ });
309
+ options.sourceMap.content = read_file(content, content);
310
+ }
311
+ try {
312
+ if (options.parse) {
313
+ if (options.parse.acorn) {
314
+ files = convert_ast(function(toplevel, name) {
315
+ return require("acorn").parse(files[name], {
316
+ locations: true,
317
+ program: toplevel,
318
+ sourceFile: name
319
+ });
320
+ });
321
+ } else if (options.parse.spidermonkey) {
322
+ files = convert_ast(function(toplevel, name) {
323
+ var obj = JSON.parse(files[name]);
324
+ if (!toplevel) return obj;
325
+ toplevel.body = toplevel.body.concat(obj.body);
326
+ return toplevel;
327
+ });
328
+ }
329
+ }
330
+ } catch (ex) {
331
+ fatal(ex);
332
+ }
333
+ var result;
334
+ if (specified["reduce-test"]) {
335
+ // load on demand - assumes cloned repository
336
+ var reduce_test = require("../test/reduce");
337
+ if (Object.keys(files).length != 1) fatal("can only test on a single file");
338
+ result = reduce_test(files[Object.keys(files)[0]], options, {
339
+ log: print_error,
340
+ verbose: true,
341
+ });
342
+ } else {
343
+ result = UglifyJS.minify(files, options);
344
+ }
345
+ if (result.error) {
346
+ var ex = result.error;
347
+ if (ex.name == "SyntaxError") {
348
+ print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
349
+ var file = files[ex.filename];
350
+ if (file) {
351
+ var col = ex.col;
352
+ var lines = file.split(/\r?\n/);
353
+ var line = lines[ex.line - 1];
354
+ if (!line && !col) {
355
+ line = lines[ex.line - 2];
356
+ col = line.length;
357
+ }
358
+ if (line) {
359
+ var limit = 70;
360
+ if (col > limit) {
361
+ line = line.slice(col - limit);
362
+ col = limit;
363
+ }
364
+ print_error(line.slice(0, 80));
365
+ print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
366
+ }
367
+ }
368
+ } else if (ex.defs) {
369
+ print_error("Supported options:");
370
+ print_error(format_object(ex.defs));
371
+ }
372
+ fatal(ex);
373
+ } else if (output == "ast") {
374
+ if (!options.compress && !options.mangle) {
375
+ var toplevel = result.ast;
376
+ if (!(toplevel instanceof UglifyJS.AST_Toplevel)) {
377
+ if (!(toplevel instanceof UglifyJS.AST_Statement)) toplevel = new UglifyJS.AST_SimpleStatement({
378
+ body: toplevel,
379
+ });
380
+ toplevel = new UglifyJS.AST_Toplevel({
381
+ body: [ toplevel ],
382
+ });
383
+ }
384
+ toplevel.figure_out_scope({});
385
+ }
386
+ print(JSON.stringify(result.ast, function(key, value) {
387
+ if (value) switch (key) {
388
+ case "enclosed":
389
+ return value.length ? value.map(symdef) : undefined;
390
+ case "functions":
391
+ case "globals":
392
+ case "variables":
393
+ return value.size() ? value.map(symdef) : undefined;
394
+ case "thedef":
395
+ return symdef(value);
396
+ }
397
+ if (skip_key(key)) return;
398
+ if (value instanceof UglifyJS.AST_Token) return;
399
+ if (value instanceof UglifyJS.Dictionary) return;
400
+ if (value instanceof UglifyJS.AST_Node) {
401
+ var result = {
402
+ _class: "AST_" + value.TYPE
403
+ };
404
+ value.CTOR.PROPS.forEach(function(prop) {
405
+ result[prop] = value[prop];
406
+ });
407
+ return result;
408
+ }
409
+ return value;
410
+ }, 2));
411
+ } else if (output == "spidermonkey") {
412
+ print(JSON.stringify(UglifyJS.minify(result.code, {
413
+ compress: false,
414
+ mangle: false,
415
+ output: {
416
+ ast: true,
417
+ code: false
418
+ },
419
+ }).ast.to_mozilla_ast(), null, 2));
420
+ } else if (output) {
421
+ fs.writeFileSync(output, result.code);
422
+ if (result.map) fs.writeFileSync(output + ".map", result.map);
423
+ } else {
424
+ print(result.code);
425
+ }
426
+ if (nameCache) fs.writeFileSync(nameCache, JSON.stringify(options.nameCache));
427
+ if (result.timings) for (var phase in result.timings) {
428
+ print_error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s");
429
+ }
430
+ }
431
+
432
+ function fatal(message) {
433
+ if (message instanceof Error) {
434
+ message = message.stack.replace(/^\S*?Error:/, "ERROR:")
435
+ } else {
436
+ message = "ERROR: " + message;
437
+ }
438
+ print_error(message);
439
+ process.exit(1);
440
+ }
441
+
442
+ // A file glob function that only supports "*" and "?" wildcards in the basename.
443
+ // Example: "foo/bar/*baz??.*.js"
444
+ // Argument `glob` may be a string or an array of strings.
445
+ // Returns an array of strings. Garbage in, garbage out.
446
+ function simple_glob(glob) {
447
+ if (Array.isArray(glob)) {
448
+ return [].concat.apply([], glob.map(simple_glob));
449
+ }
450
+ if (glob.match(/\*|\?/)) {
451
+ var dir = path.dirname(glob);
452
+ try {
453
+ var entries = fs.readdirSync(dir);
454
+ } catch (ex) {}
455
+ if (entries) {
456
+ var pattern = "^" + path.basename(glob)
457
+ .replace(/[.+^$[\]\\(){}]/g, "\\$&")
458
+ .replace(/\*/g, "[^/\\\\]*")
459
+ .replace(/\?/g, "[^/\\\\]") + "$";
460
+ var mod = process.platform === "win32" ? "i" : "";
461
+ var rx = new RegExp(pattern, mod);
462
+ var results = entries.sort().filter(function(name) {
463
+ return rx.test(name);
464
+ }).map(function(name) {
465
+ return path.join(dir, name);
466
+ });
467
+ if (results.length) return results;
468
+ }
469
+ }
470
+ return [ glob ];
471
+ }
472
+
473
+ function read_file(path, default_value) {
474
+ try {
475
+ return fs.readFileSync(path, "utf8");
476
+ } catch (ex) {
477
+ if (ex.code == "ENOENT" && default_value != null) return default_value;
478
+ fatal(ex);
479
+ }
480
+ }
481
+
482
+ function parse_js(value, options, flag) {
483
+ if (!options || typeof options != "object") options = {};
484
+ if (typeof value == "string") try {
485
+ UglifyJS.parse(value, {
486
+ expression: true
487
+ }).walk(new UglifyJS.TreeWalker(function(node) {
488
+ if (node instanceof UglifyJS.AST_Assign) {
489
+ var name = node.left.print_to_string();
490
+ var value = node.right;
491
+ if (flag) {
492
+ options[name] = value;
493
+ } else if (value instanceof UglifyJS.AST_Array) {
494
+ options[name] = value.elements.map(to_string);
495
+ } else {
496
+ options[name] = to_string(value);
497
+ }
498
+ return true;
499
+ }
500
+ if (node instanceof UglifyJS.AST_Symbol || node instanceof UglifyJS.AST_PropAccess) {
501
+ var name = node.print_to_string();
502
+ options[name] = true;
503
+ return true;
504
+ }
505
+ if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
506
+
507
+ function to_string(value) {
508
+ return value instanceof UglifyJS.AST_Constant ? value.value : value.print_to_string({
509
+ quote_keys: true
510
+ });
511
+ }
512
+ }));
513
+ } catch (ex) {
514
+ if (flag) {
515
+ fatal("cannot parse arguments for '" + flag + "': " + value);
516
+ } else {
517
+ options[value] = null;
518
+ }
519
+ }
520
+ return options;
521
+ }
522
+
523
+ function skip_key(key) {
524
+ return skip_keys.indexOf(key) >= 0;
525
+ }
526
+
527
+ function symdef(def) {
528
+ var ret = (1e6 + def.id) + " " + def.name;
529
+ if (def.mangled_name) ret += " " + def.mangled_name;
530
+ return ret;
531
+ }
532
+
533
+ function format_object(obj) {
534
+ var lines = [];
535
+ var padding = "";
536
+ Object.keys(obj).map(function(name) {
537
+ if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
538
+ return [ name, JSON.stringify(obj[name]) ];
539
+ }).forEach(function(tokens) {
540
+ lines.push(" " + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
541
+ });
542
+ return lines.join("\n");
543
+ }
544
+
545
+ function print_error(msg) {
546
+ process.stderr.write(msg);
547
+ process.stderr.write("\n");
548
+ }
549
+
550
+ function print(txt) {
551
+ process.stdout.write(txt);
552
+ process.stdout.write("\n");
553
+ }