MCPcopy
hub / github.com/mishoo/UglifyJS-old / gen_code

Function gen_code

lib/process.js:1496–1988  ·  view source on GitHub ↗
(ast, options)

Source from the content-addressed store, hash-verified

1494var SPLICE_NEEDS_BRACKETS = jsp.array_to_hash([ "if", "while", "do", "for", "for-in", "with" ]);
1495
1496function gen_code(ast, options) {
1497 options = defaults(options, {
1498 indent_start : 0,
1499 indent_level : 4,
1500 quote_keys : false,
1501 space_colon : false,
1502 beautify : false,
1503 ascii_only : false,
1504 inline_script: false
1505 });
1506 var beautify = !!options.beautify;
1507 var indentation = 0,
1508 newline = beautify ? "\n" : "",
1509 space = beautify ? " " : "";
1510
1511 function encode_string(str) {
1512 var ret = make_string(str, options.ascii_only);
1513 if (options.inline_script)
1514 ret = ret.replace(/<\x2fscript([>\/\t\n\f\r ])/gi, "<\\/script$1");
1515 return ret;
1516 };
1517
1518 function make_name(name) {
1519 name = name.toString();
1520 if (options.ascii_only)
1521 name = to_ascii(name);
1522 return name;
1523 };
1524
1525 function indent(line) {
1526 if (line == null)
1527 line = "";
1528 if (beautify)
1529 line = repeat_string(" ", options.indent_start + indentation * options.indent_level) + line;
1530 return line;
1531 };
1532
1533 function with_indent(cont, incr) {
1534 if (incr == null) incr = 1;
1535 indentation += incr;
1536 try { return cont.apply(null, slice(arguments, 1)); }
1537 finally { indentation -= incr; }
1538 };
1539
1540 function last_char(str) {
1541 str = str.toString();
1542 return str.charAt(str.length - 1);
1543 };
1544
1545 function first_char(str) {
1546 return str.toString().charAt(0);
1547 };
1548
1549 function add_spaces(a) {
1550 if (beautify)
1551 return a.join(" ");
1552 var b = [];
1553 for (var i = 0; i < a.length; ++i) {

Callers 3

best_ofFunction · 0.85
warn_unreachableFunction · 0.85
make_real_ifFunction · 0.85

Calls 15

defaultsFunction · 0.85
ast_walkerFunction · 0.85
make_block_statementsFunction · 0.85
indentFunction · 0.85
add_commasFunction · 0.85
make_blockFunction · 0.85
add_spacesFunction · 0.85
parenthesizeFunction · 0.85
make_switch_blockFunction · 0.85
make_nameFunction · 0.85
needs_parensFunction · 0.85
make_thenFunction · 0.85

Tested by

no test coverage detected