(ast, options)
| 1494 | var SPLICE_NEEDS_BRACKETS = jsp.array_to_hash([ "if", "while", "do", "for", "for-in", "with" ]); |
| 1495 | |
| 1496 | function 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) { |
no test coverage detected