/usr/share/doc/coffeescript/html/nodes.html is in coffeescript-doc 1.9.3~dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 | <!DOCTYPE html>
<html>
<head>
<title>nodes.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="browser.html">
browser.coffee
</a>
<a class="source" href="cake.html">
cake.coffee
</a>
<a class="source" href="coffee-script.html">
coffee-script.coffee
</a>
<a class="source" href="command.html">
command.coffee
</a>
<a class="source" href="grammar.html">
grammar.coffee
</a>
<a class="source" href="helpers.html">
helpers.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
<a class="source" href="lexer.html">
lexer.coffee
</a>
<a class="source" href="nodes.html">
nodes.coffee
</a>
<a class="source" href="optparse.html">
optparse.coffee
</a>
<a class="source" href="register.html">
register.coffee
</a>
<a class="source" href="repl.html">
repl.coffee
</a>
<a class="source" href="rewriter.html">
rewriter.coffee
</a>
<a class="source" href="scope.html">
scope.litcoffee
</a>
<a class="source" href="sourcemap.html">
sourcemap.litcoffee
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>nodes.coffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<p><code>nodes.coffee</code> contains all of the node classes for the syntax tree. Most
nodes are created as the result of actions in the <a href="grammar.html">grammar</a>,
but some are created by other nodes as a method of code generation. To convert
the syntax tree into a string of JavaScript code, call <code>compile()</code> on the root.</p>
</div>
<div class="content"><div class='highlight'><pre>
Error.stackTraceLimit = Infinity
{Scope} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./scope'</span>
{RESERVED, STRICT_PROSCRIBED} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./lexer'</span></pre></div></div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<p>Import the helpers we plan to use.</p>
</div>
<div class="content"><div class='highlight'><pre>{compact, flatten, extend, merge, del, starts, ends, some,
addLocationDataFn, locationDataToString, throwSyntaxError} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./helpers'</span></pre></div></div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>Functions required by parser</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.extend = extend
<span class="hljs-built_in">exports</span>.addLocationDataFn = addLocationDataFn</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>Constant functions for nodes that don’t need customization.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">YES</span> = -></span> <span class="hljs-literal">yes</span>
<span class="hljs-function"><span class="hljs-title">NO</span> = -></span> <span class="hljs-literal">no</span>
<span class="hljs-function"><span class="hljs-title">THIS</span> = -></span> <span class="hljs-keyword">this</span>
<span class="hljs-function"><span class="hljs-title">NEGATE</span> = -></span> <span class="hljs-property">@negated</span> = <span class="hljs-keyword">not</span> <span class="hljs-property">@negated</span>; <span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<h3 id="codefragment">CodeFragment</h3>
</div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<p>The various nodes defined below all compile to a collection of <strong>CodeFragment</strong> objects.
A CodeFragments is a block of generated code, and the location in the source file where the code
came from. CodeFragments can be assembled together into working code just by catting together
all the CodeFragments’ <code>code</code> snippets, in order.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.CodeFragment = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CodeFragment</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(parent, code)</span> -></span>
<span class="hljs-property">@code</span> = <span class="hljs-string">"<span class="hljs-subst">#{code}</span>"</span>
<span class="hljs-property">@locationData</span> = parent?.locationData
<span class="hljs-property">@type</span> = parent?.constructor?.name <span class="hljs-keyword">or</span> <span class="hljs-string">'unknown'</span>
<span class="hljs-attribute">toString</span>:<span class="hljs-function"> -></span>
<span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@code</span>}</span><span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@locationData</span> <span class="hljs-keyword">then</span> <span class="hljs-string">": "</span> + locationDataToString(<span class="hljs-property">@locationData</span>) <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>}</span>"</span></pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">¶</a>
</div>
<p>Convert an array of CodeFragments into a string.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">fragmentsToText</span> = <span class="hljs-params">(fragments)</span> -></span>
(fragment.code <span class="hljs-keyword">for</span> fragment <span class="hljs-keyword">in</span> fragments).join(<span class="hljs-string">''</span>)</pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">¶</a>
</div>
<h3 id="base">Base</h3>
</div>
</li>
<li id="section-9">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">¶</a>
</div>
<p>The <strong>Base</strong> is the abstract base class for all nodes in the syntax tree.
Each subclass implements the <code>compileNode</code> method, which performs the
code generation for that node. To compile a node to JavaScript,
call <code>compile</code> on it, which wraps <code>compileNode</code> in some generic extra smarts,
to know when the generated code needs to be wrapped up in a closure.
An options hash is passed and cloned throughout, containing information about
the environment from higher in the tree (such as if a returned value is
being requested by the surrounding function), information about the current
scope, and indentation level.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Base = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">compile</span>: <span class="hljs-function"><span class="hljs-params">(o, lvl)</span> -></span>
fragmentsToText <span class="hljs-property">@compileToFragments</span> o, lvl</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">¶</a>
</div>
<p>Common logic for determining whether to wrap this node in a closure before
compiling it, or to compile directly. We need to wrap if this node is a
<em>statement</em>, and it’s not a <em>pureStatement</em>, and we’re not at
the top level of a block (which would be unnecessary), and we haven’t
already been asked to return the result (because statements know how to
return results).</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o, lvl)</span> -></span>
o = extend {}, o
o.level = lvl <span class="hljs-keyword">if</span> lvl
node = <span class="hljs-property">@unfoldSoak</span>(o) <span class="hljs-keyword">or</span> <span class="hljs-keyword">this</span>
node.tab = o.indent
<span class="hljs-keyword">if</span> o.level <span class="hljs-keyword">is</span> LEVEL_TOP <span class="hljs-keyword">or</span> <span class="hljs-keyword">not</span> node.isStatement(o)
node.compileNode o
<span class="hljs-keyword">else</span>
node.compileClosure o</pre></div></div>
</li>
<li id="section-11">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">¶</a>
</div>
<p>Statements converted into expressions via closure-wrapping share a scope
object with their parent closure, to preserve the expected lexical scope.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileClosure</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> jumpNode = <span class="hljs-property">@jumps</span>()
jumpNode.error <span class="hljs-string">'cannot use a pure statement in an expression'</span>
o.sharedScope = <span class="hljs-literal">yes</span>
func = <span class="hljs-keyword">new</span> Code [], Block.wrap [<span class="hljs-keyword">this</span>]
args = []
<span class="hljs-keyword">if</span> (argumentsNode = <span class="hljs-property">@contains</span> isLiteralArguments) <span class="hljs-keyword">or</span> <span class="hljs-property">@contains</span> isLiteralThis
args = [<span class="hljs-keyword">new</span> Literal <span class="hljs-string">'this'</span>]
<span class="hljs-keyword">if</span> argumentsNode
meth = <span class="hljs-string">'apply'</span>
args.push <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'arguments'</span>
<span class="hljs-keyword">else</span>
meth = <span class="hljs-string">'call'</span>
func = <span class="hljs-keyword">new</span> Value func, [<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal meth]
parts = (<span class="hljs-keyword">new</span> Call func, args).compileNode o
<span class="hljs-keyword">if</span> func.isGenerator <span class="hljs-keyword">or</span> func.base?.isGenerator
parts.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"(yield* "</span>
parts.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">")"</span>
parts</pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">¶</a>
</div>
<p>If the code generation wishes to use the result of a complex expression
in multiple places, ensure that the expression is only ever evaluated once,
by assigning it to a temporary variable. Pass a level to precompile.</p>
<p>If <code>level</code> is passed, then returns <code>[val, ref]</code>, where <code>val</code> is the compiled value, and <code>ref</code>
is the compiled reference. If <code>level</code> is not passed, this returns <code>[val, ref]</code> where
the two values are raw nodes which have not been compiled.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">cache</span>: <span class="hljs-function"><span class="hljs-params">(o, level, isComplex)</span> -></span>
complex = <span class="hljs-keyword">if</span> isComplex? <span class="hljs-keyword">then</span> isComplex <span class="hljs-keyword">this</span> <span class="hljs-keyword">else</span> <span class="hljs-property">@isComplex</span>()
<span class="hljs-keyword">if</span> complex
ref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'ref'</span>
sub = <span class="hljs-keyword">new</span> Assign ref, <span class="hljs-keyword">this</span>
<span class="hljs-keyword">if</span> level <span class="hljs-keyword">then</span> [sub.compileToFragments(o, level), [<span class="hljs-property">@makeCode</span>(ref.value)]] <span class="hljs-keyword">else</span> [sub, ref]
<span class="hljs-keyword">else</span>
ref = <span class="hljs-keyword">if</span> level <span class="hljs-keyword">then</span> <span class="hljs-property">@compileToFragments</span> o, level <span class="hljs-keyword">else</span> <span class="hljs-keyword">this</span>
[ref, ref]
<span class="hljs-attribute">cacheToCodeFragments</span>: <span class="hljs-function"><span class="hljs-params">(cacheValues)</span> -></span>
[fragmentsToText(cacheValues[<span class="hljs-number">0</span>]), fragmentsToText(cacheValues[<span class="hljs-number">1</span>])]</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">¶</a>
</div>
<p>Construct a node that returns the current node’s result.
Note that this is overridden for smarter behavior for
many statement nodes (e.g. If, For)…</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">makeReturn</span>: <span class="hljs-function"><span class="hljs-params">(res)</span> -></span>
me = <span class="hljs-property">@unwrapAll</span>()
<span class="hljs-keyword">if</span> res
<span class="hljs-keyword">new</span> Call <span class="hljs-keyword">new</span> Literal(<span class="hljs-string">"<span class="hljs-subst">#{res}</span>.push"</span>), [me]
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">new</span> Return me</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">¶</a>
</div>
<p>Does this node, or any of its children, contain a node of a certain kind?
Recursively traverses down the <em>children</em> nodes and returns the first one
that verifies <code>pred</code>. Otherwise return undefined. <code>contains</code> does not cross
scope boundaries.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">contains</span>: <span class="hljs-function"><span class="hljs-params">(pred)</span> -></span>
node = <span class="hljs-literal">undefined</span>
<span class="hljs-property">@traverseChildren</span> <span class="hljs-literal">no</span>, <span class="hljs-function"><span class="hljs-params">(n)</span> -></span>
<span class="hljs-keyword">if</span> pred n
node = n
<span class="hljs-keyword">return</span> <span class="hljs-literal">no</span>
node</pre></div></div>
</li>
<li id="section-15">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">¶</a>
</div>
<p>Pull out the last non-comment node of a node list.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">lastNonComment</span>: <span class="hljs-function"><span class="hljs-params">(list)</span> -></span>
i = list.length
<span class="hljs-keyword">return</span> list[i] <span class="hljs-keyword">while</span> i-- <span class="hljs-keyword">when</span> list[i] <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Comment
<span class="hljs-literal">null</span></pre></div></div>
</li>
<li id="section-16">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">¶</a>
</div>
<p><code>toString</code> representation of the node, for inspecting the parse tree.
This is what <code>coffee --nodes</code> prints out.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">toString</span>: <span class="hljs-function"><span class="hljs-params">(idt = <span class="hljs-string">''</span>, name = <span class="hljs-property">@constructor</span>.name)</span> -></span>
tree = <span class="hljs-string">'\n'</span> + idt + name
tree += <span class="hljs-string">'?'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@soak</span>
<span class="hljs-property">@eachChild</span> <span class="hljs-function"><span class="hljs-params">(node)</span> -></span> tree += node.toString idt + TAB
tree</pre></div></div>
</li>
<li id="section-17">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">¶</a>
</div>
<p>Passes each child to a function, breaking when the function returns <code>false</code>.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">eachChild</span>: <span class="hljs-function"><span class="hljs-params">(func)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@children</span>
<span class="hljs-keyword">for</span> attr <span class="hljs-keyword">in</span> <span class="hljs-property">@children</span> <span class="hljs-keyword">when</span> @[attr]
<span class="hljs-keyword">for</span> child <span class="hljs-keyword">in</span> flatten [@[attr]]
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">if</span> func(child) <span class="hljs-keyword">is</span> <span class="hljs-literal">false</span>
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">traverseChildren</span>: <span class="hljs-function"><span class="hljs-params">(crossScope, func)</span> -></span>
<span class="hljs-property">@eachChild</span> <span class="hljs-function"><span class="hljs-params">(child)</span> -></span>
recur = func(child)
child.traverseChildren(crossScope, func) <span class="hljs-keyword">unless</span> recur <span class="hljs-keyword">is</span> <span class="hljs-literal">no</span>
<span class="hljs-attribute">invert</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">new</span> Op <span class="hljs-string">'!'</span>, <span class="hljs-keyword">this</span>
<span class="hljs-attribute">unwrapAll</span>:<span class="hljs-function"> -></span>
node = <span class="hljs-keyword">this</span>
<span class="hljs-keyword">continue</span> <span class="hljs-keyword">until</span> node <span class="hljs-keyword">is</span> node = node.unwrap()
node</pre></div></div>
</li>
<li id="section-18">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">¶</a>
</div>
<p>Default implementations of the common node properties and methods. Nodes
will override these with custom logic, if needed.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">children</span>: []
isStatement : NO
jumps : NO
isComplex : YES
isChainable : NO
isAssignable : NO
unwrap : THIS
unfoldSoak : NO</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">¶</a>
</div>
<p>Is this node used to assign a certain variable?</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">assigns</span>: NO</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">¶</a>
</div>
<p>For this node and all descendents, set the location data to <code>locationData</code>
if the location data is not already set.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">updateLocationDataIfMissing</span>: <span class="hljs-function"><span class="hljs-params">(locationData)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@locationData</span>
<span class="hljs-property">@locationData</span> = locationData
<span class="hljs-property">@eachChild</span> <span class="hljs-function"><span class="hljs-params">(child)</span> -></span>
child.updateLocationDataIfMissing locationData</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">¶</a>
</div>
<p>Throw a SyntaxError associated with this node’s location.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">error</span>: <span class="hljs-function"><span class="hljs-params">(message)</span> -></span>
throwSyntaxError message, <span class="hljs-property">@locationData</span>
<span class="hljs-attribute">makeCode</span>: <span class="hljs-function"><span class="hljs-params">(code)</span> -></span>
<span class="hljs-keyword">new</span> CodeFragment <span class="hljs-keyword">this</span>, code
<span class="hljs-attribute">wrapInBraces</span>: <span class="hljs-function"><span class="hljs-params">(fragments)</span> -></span>
[].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">'('</span>), fragments, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">')'</span>)</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">¶</a>
</div>
<p><code>fragmentsList</code> is an array of arrays of fragments. Each array in fragmentsList will be
concatonated together, with <code>joinStr</code> added in between each, to produce a final flat array
of fragments.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">joinFragmentArrays</span>: <span class="hljs-function"><span class="hljs-params">(fragmentsList, joinStr)</span> -></span>
answer = []
<span class="hljs-keyword">for</span> fragments,i <span class="hljs-keyword">in</span> fragmentsList
<span class="hljs-keyword">if</span> i <span class="hljs-keyword">then</span> answer.push <span class="hljs-property">@makeCode</span> joinStr
answer = answer.concat fragments
answer</pre></div></div>
</li>
<li id="section-23">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">¶</a>
</div>
<h3 id="block">Block</h3>
</div>
</li>
<li id="section-24">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">¶</a>
</div>
<p>The block is the list of expressions that forms the body of an
indented block of code — the implementation of a function, a clause in an
<code>if</code>, <code>switch</code>, or <code>try</code>, and so on…</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Block = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Block</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(nodes)</span> -></span>
<span class="hljs-property">@expressions</span> = compact flatten nodes <span class="hljs-keyword">or</span> []
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expressions'</span>]</pre></div></div>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">¶</a>
</div>
<p>Tack an expression on to the end of this expression list.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">push</span>: <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
<span class="hljs-property">@expressions</span>.push node
<span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-26">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-26">¶</a>
</div>
<p>Remove and return the last expression of this expression list.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">pop</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@expressions</span>.pop()</pre></div></div>
</li>
<li id="section-27">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-27">¶</a>
</div>
<p>Add an expression at the beginning of this expression list.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">unshift</span>: <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
<span class="hljs-property">@expressions</span>.unshift node
<span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-28">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-28">¶</a>
</div>
<p>If this Block consists of just a single node, unwrap it by pulling
it back out.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">unwrap</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@expressions</span>.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@expressions</span>[<span class="hljs-number">0</span>] <span class="hljs-keyword">else</span> <span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-29">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-29">¶</a>
</div>
<p>Is this an empty block of code?</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">isEmpty</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">not</span> <span class="hljs-property">@expressions</span>.length
<span class="hljs-attribute">isStatement</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">for</span> exp <span class="hljs-keyword">in</span> <span class="hljs-property">@expressions</span> <span class="hljs-keyword">when</span> exp.isStatement o
<span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span>
<span class="hljs-literal">no</span>
<span class="hljs-attribute">jumps</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">for</span> exp <span class="hljs-keyword">in</span> <span class="hljs-property">@expressions</span>
<span class="hljs-keyword">return</span> jumpNode <span class="hljs-keyword">if</span> jumpNode = exp.jumps o</pre></div></div>
</li>
<li id="section-30">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-30">¶</a>
</div>
<p>A Block node does not return its entire body, rather it
ensures that the final expression is returned.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">makeReturn</span>: <span class="hljs-function"><span class="hljs-params">(res)</span> -></span>
len = <span class="hljs-property">@expressions</span>.length
<span class="hljs-keyword">while</span> len--
expr = <span class="hljs-property">@expressions</span>[len]
<span class="hljs-keyword">if</span> expr <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Comment
<span class="hljs-property">@expressions</span>[len] = expr.makeReturn res
<span class="hljs-property">@expressions</span>.splice(len, <span class="hljs-number">1</span>) <span class="hljs-keyword">if</span> expr <span class="hljs-keyword">instanceof</span> Return <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> expr.expression
<span class="hljs-keyword">break</span>
<span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-31">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-31">¶</a>
</div>
<p>A <strong>Block</strong> is the only node that can serve as the root.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o = {}, level)</span> -></span>
<span class="hljs-keyword">if</span> o.scope <span class="hljs-keyword">then</span> <span class="hljs-keyword">super</span> o, level <span class="hljs-keyword">else</span> <span class="hljs-property">@compileRoot</span> o</pre></div></div>
</li>
<li id="section-32">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-32">¶</a>
</div>
<p>Compile all expressions within the <strong>Block</strong> body. If we need to
return the result, and it’s an expression, simply return it. If it’s a
statement, ask the statement to do so.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@tab</span> = o.indent
top = o.level <span class="hljs-keyword">is</span> LEVEL_TOP
compiledNodes = []
<span class="hljs-keyword">for</span> node, index <span class="hljs-keyword">in</span> <span class="hljs-property">@expressions</span>
node = node.unwrapAll()
node = (node.unfoldSoak(o) <span class="hljs-keyword">or</span> node)
<span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Block</pre></div></div>
</li>
<li id="section-33">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-33">¶</a>
</div>
<p>This is a nested block. We don’t do anything special here like enclose
it in a new scope; we just compile the statements in this block along with
our own</p>
</div>
<div class="content"><div class='highlight'><pre> compiledNodes.push node.compileNode o
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> top
node.front = <span class="hljs-literal">true</span>
fragments = node.compileToFragments o
<span class="hljs-keyword">unless</span> node.isStatement o
fragments.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>"</span>
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">";"</span>
compiledNodes.push fragments
<span class="hljs-keyword">else</span>
compiledNodes.push node.compileToFragments o, LEVEL_LIST
<span class="hljs-keyword">if</span> top
<span class="hljs-keyword">if</span> <span class="hljs-property">@spaced</span>
<span class="hljs-keyword">return</span> [].concat <span class="hljs-property">@joinFragmentArrays</span>(compiledNodes, <span class="hljs-string">'\n\n'</span>), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>)
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@joinFragmentArrays</span>(compiledNodes, <span class="hljs-string">'\n'</span>)
<span class="hljs-keyword">if</span> compiledNodes.length
answer = <span class="hljs-property">@joinFragmentArrays</span>(compiledNodes, <span class="hljs-string">', '</span>)
<span class="hljs-keyword">else</span>
answer = [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"void 0"</span>]
<span class="hljs-keyword">if</span> compiledNodes.length > <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> o.level >= LEVEL_LIST <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> answer <span class="hljs-keyword">else</span> answer</pre></div></div>
</li>
<li id="section-34">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-34">¶</a>
</div>
<p>If we happen to be the top-level <strong>Block</strong>, wrap everything in
a safety closure, unless requested not to.
It would be better not to generate them in the first place, but for now,
clean up obvious double-parentheses.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileRoot</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
o.indent = <span class="hljs-keyword">if</span> o.bare <span class="hljs-keyword">then</span> <span class="hljs-string">''</span> <span class="hljs-keyword">else</span> TAB
o.level = LEVEL_TOP
<span class="hljs-property">@spaced</span> = <span class="hljs-literal">yes</span>
o.scope = <span class="hljs-keyword">new</span> Scope <span class="hljs-literal">null</span>, <span class="hljs-keyword">this</span>, <span class="hljs-literal">null</span>, o.referencedVars ? []</pre></div></div>
</li>
<li id="section-35">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-35">¶</a>
</div>
<p>Mark given local variables in the root scope as parameters so they don’t
end up being declared on this block.</p>
</div>
<div class="content"><div class='highlight'><pre> o.scope.parameter name <span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> o.locals <span class="hljs-keyword">or</span> []
prelude = []
<span class="hljs-keyword">unless</span> o.bare
preludeExps = <span class="hljs-keyword">for</span> exp, i <span class="hljs-keyword">in</span> <span class="hljs-property">@expressions</span>
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> exp.unwrap() <span class="hljs-keyword">instanceof</span> Comment
exp
rest = <span class="hljs-property">@expressions</span>[preludeExps.length...]
<span class="hljs-property">@expressions</span> = preludeExps
<span class="hljs-keyword">if</span> preludeExps.length
prelude = <span class="hljs-property">@compileNode</span> merge(o, <span class="hljs-attribute">indent</span>: <span class="hljs-string">''</span>)
prelude.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n"</span>
<span class="hljs-property">@expressions</span> = rest
fragments = <span class="hljs-property">@compileWithDeclarations</span> o
<span class="hljs-keyword">return</span> fragments <span class="hljs-keyword">if</span> o.bare
[].concat prelude, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"(function() {\n"</span>), fragments, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n}).call(this);\n"</span>)</pre></div></div>
</li>
<li id="section-36">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-36">¶</a>
</div>
<p>Compile the expressions body for the contents of a function, with
declarations of all inner variables pushed up to the top.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileWithDeclarations</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
fragments = []
post = []
<span class="hljs-keyword">for</span> exp, i <span class="hljs-keyword">in</span> <span class="hljs-property">@expressions</span>
exp = exp.unwrap()
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> exp <span class="hljs-keyword">instanceof</span> Comment <span class="hljs-keyword">or</span> exp <span class="hljs-keyword">instanceof</span> Literal
o = merge(o, <span class="hljs-attribute">level</span>: LEVEL_TOP)
<span class="hljs-keyword">if</span> i
rest = <span class="hljs-property">@expressions</span>.splice i, <span class="hljs-number">9e9</span>
[spaced, <span class="hljs-property">@spaced</span>] = [<span class="hljs-property">@spaced</span>, <span class="hljs-literal">no</span>]
[fragments, <span class="hljs-property">@spaced</span>] = [<span class="hljs-property">@compileNode</span>(o), spaced]
<span class="hljs-property">@expressions</span> = rest
post = <span class="hljs-property">@compileNode</span> o
{scope} = o
<span class="hljs-keyword">if</span> scope.expressions <span class="hljs-keyword">is</span> <span class="hljs-keyword">this</span>
declars = o.scope.hasDeclarations()
assigns = scope.hasAssignments
<span class="hljs-keyword">if</span> declars <span class="hljs-keyword">or</span> assigns
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">if</span> i
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>var "</span>
<span class="hljs-keyword">if</span> declars
fragments.push <span class="hljs-property">@makeCode</span> scope.declaredVariables().join(<span class="hljs-string">', '</span>)
<span class="hljs-keyword">if</span> assigns
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">",\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span> + TAB}</span>"</span> <span class="hljs-keyword">if</span> declars
fragments.push <span class="hljs-property">@makeCode</span> scope.assignedVariables().join(<span class="hljs-string">",\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span> + TAB}</span>"</span>)
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">";\n<span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@spaced</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>}</span>"</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> fragments.length <span class="hljs-keyword">and</span> post.length
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n"</span>
fragments.concat post</pre></div></div>
</li>
<li id="section-37">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-37">¶</a>
</div>
<p>Wrap up the given nodes as a <strong>Block</strong>, unless it already happens
to be one.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@wrap</span>: <span class="hljs-function"><span class="hljs-params">(nodes)</span> -></span>
<span class="hljs-keyword">return</span> nodes[<span class="hljs-number">0</span>] <span class="hljs-keyword">if</span> nodes.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> nodes[<span class="hljs-number">0</span>] <span class="hljs-keyword">instanceof</span> Block
<span class="hljs-keyword">new</span> Block nodes</pre></div></div>
</li>
<li id="section-38">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-38">¶</a>
</div>
<h3 id="literal">Literal</h3>
</div>
</li>
<li id="section-39">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-39">¶</a>
</div>
<p>Literals are static values that can be passed through directly into
JavaScript without translation, such as: strings, numbers,
<code>true</code>, <code>false</code>, <code>null</code>…</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Literal = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Literal</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@value</span>)</span> -></span>
<span class="hljs-attribute">makeReturn</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@isStatement</span>() <span class="hljs-keyword">then</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">else</span> <span class="hljs-keyword">super</span>
<span class="hljs-attribute">isAssignable</span>:<span class="hljs-function"> -></span>
IDENTIFIER.test <span class="hljs-property">@value</span>
<span class="hljs-attribute">isStatement</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@value</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'break'</span>, <span class="hljs-string">'continue'</span>, <span class="hljs-string">'debugger'</span>]
<span class="hljs-attribute">isComplex</span>: NO
<span class="hljs-attribute">assigns</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
name <span class="hljs-keyword">is</span> <span class="hljs-property">@value</span>
<span class="hljs-attribute">jumps</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@value</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'break'</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> (o?.<span class="hljs-keyword">loop</span> <span class="hljs-keyword">or</span> o?.block)
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@value</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'continue'</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> o?.<span class="hljs-keyword">loop</span>
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
code = <span class="hljs-keyword">if</span> <span class="hljs-property">@value</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'this'</span>
<span class="hljs-keyword">if</span> o.scope.method?.bound <span class="hljs-keyword">then</span> o.scope.method.context <span class="hljs-keyword">else</span> <span class="hljs-property">@value</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@value</span>.reserved
<span class="hljs-string">"\"<span class="hljs-subst">#{<span class="hljs-property">@value</span>}</span>\""</span>
<span class="hljs-keyword">else</span>
<span class="hljs-property">@value</span>
answer = <span class="hljs-keyword">if</span> <span class="hljs-property">@isStatement</span>() <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{code}</span>;"</span> <span class="hljs-keyword">else</span> code
[<span class="hljs-property">@makeCode</span> answer]
<span class="hljs-attribute">toString</span>:<span class="hljs-function"> -></span>
<span class="hljs-string">' "'</span> + <span class="hljs-property">@value</span> + <span class="hljs-string">'"'</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">exports</span>.<span class="hljs-title">Undefined</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">isAssignable</span>: NO
<span class="hljs-attribute">isComplex</span>: NO
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[<span class="hljs-property">@makeCode</span> <span class="hljs-keyword">if</span> o.level >= LEVEL_ACCESS <span class="hljs-keyword">then</span> <span class="hljs-string">'(void 0)'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'void 0'</span>]
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">exports</span>.<span class="hljs-title">Null</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">isAssignable</span>: NO
<span class="hljs-attribute">isComplex</span>: NO
<span class="hljs-attribute">compileNode</span>:<span class="hljs-function"> -></span> [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"null"</span>]
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">exports</span>.<span class="hljs-title">Bool</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">isAssignable</span>: NO
<span class="hljs-attribute">isComplex</span>: NO
<span class="hljs-attribute">compileNode</span>:<span class="hljs-function"> -></span> [<span class="hljs-property">@makeCode</span> <span class="hljs-property">@val</span>]
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@val</span>)</span> -></span></pre></div></div>
</li>
<li id="section-40">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-40">¶</a>
</div>
<h3 id="return">Return</h3>
</div>
</li>
<li id="section-41">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-41">¶</a>
</div>
<p>A <code>return</code> is a <em>pureStatement</em> — wrapping it in a closure wouldn’t
make sense.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Return = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Return</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@expression</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expression'</span>]
<span class="hljs-attribute">isStatement</span>: YES
<span class="hljs-attribute">makeReturn</span>: THIS
<span class="hljs-attribute">jumps</span>: THIS
<span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o, level)</span> -></span>
expr = <span class="hljs-property">@expression</span>?.makeReturn()
<span class="hljs-keyword">if</span> expr <span class="hljs-keyword">and</span> expr <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Return <span class="hljs-keyword">then</span> expr.compileToFragments o, level <span class="hljs-keyword">else</span> <span class="hljs-keyword">super</span> o, level
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
answer = []
exprIsYieldReturn = <span class="hljs-property">@expression</span>?.isYieldReturn?()</pre></div></div>
</li>
<li id="section-42">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-42">¶</a>
</div>
<p>TODO: If we call expression.compile() here twice, we’ll sometimes get back different results!</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> exprIsYieldReturn
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-property">@tab</span> + <span class="hljs-string">"return<span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@expression</span> <span class="hljs-keyword">then</span> <span class="hljs-string">" "</span> <span class="hljs-keyword">else</span> <span class="hljs-string">""</span>}</span>"</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@expression</span>
answer = answer.concat <span class="hljs-property">@expression</span>.compileToFragments o, LEVEL_PAREN
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">";"</span> <span class="hljs-keyword">unless</span> exprIsYieldReturn
<span class="hljs-keyword">return</span> answer</pre></div></div>
</li>
<li id="section-43">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-43">¶</a>
</div>
<h3 id="value">Value</h3>
</div>
</li>
<li id="section-44">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-44">¶</a>
</div>
<p>A value, variable or literal or parenthesized, indexed or dotted into,
or vanilla.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Value = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Value</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(base, props, tag)</span> -></span>
<span class="hljs-keyword">return</span> base <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> props <span class="hljs-keyword">and</span> base <span class="hljs-keyword">instanceof</span> Value
<span class="hljs-property">@base</span> = base
<span class="hljs-property">@properties</span> = props <span class="hljs-keyword">or</span> []
@[tag] = <span class="hljs-literal">true</span> <span class="hljs-keyword">if</span> tag
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'base'</span>, <span class="hljs-string">'properties'</span>]</pre></div></div>
</li>
<li id="section-45">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-45">¶</a>
</div>
<p>Add a property (or <em>properties</em> ) <code>Access</code> to the list.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">add</span>: <span class="hljs-function"><span class="hljs-params">(props)</span> -></span>
<span class="hljs-property">@properties</span> = <span class="hljs-property">@properties</span>.concat props
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">hasProperties</span>:<span class="hljs-function"> -></span>
!!<span class="hljs-property">@properties</span>.length
<span class="hljs-attribute">bareLiteral</span>: <span class="hljs-function"><span class="hljs-params">(type)</span> -></span>
<span class="hljs-keyword">not</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">and</span> <span class="hljs-property">@base</span> <span class="hljs-keyword">instanceof</span> type</pre></div></div>
</li>
<li id="section-46">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-46">¶</a>
</div>
<p>Some boolean checks for the benefit of other nodes.</p>
</div>
<div class="content"><div class='highlight'><pre> isArray :<span class="hljs-function"> -></span> <span class="hljs-property">@bareLiteral</span>(Arr)
isRange :<span class="hljs-function"> -></span> <span class="hljs-property">@bareLiteral</span>(Range)
isComplex :<span class="hljs-function"> -></span> <span class="hljs-property">@hasProperties</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@base</span>.isComplex()
isAssignable :<span class="hljs-function"> -></span> <span class="hljs-property">@hasProperties</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@base</span>.isAssignable()
isSimpleNumber :<span class="hljs-function"> -></span> <span class="hljs-property">@bareLiteral</span>(Literal) <span class="hljs-keyword">and</span> SIMPLENUM.test <span class="hljs-property">@base</span>.value
isString :<span class="hljs-function"> -></span> <span class="hljs-property">@bareLiteral</span>(Literal) <span class="hljs-keyword">and</span> IS_STRING.test <span class="hljs-property">@base</span>.value
isRegex :<span class="hljs-function"> -></span> <span class="hljs-property">@bareLiteral</span>(Literal) <span class="hljs-keyword">and</span> IS_REGEX.test <span class="hljs-property">@base</span>.value
isAtomic :<span class="hljs-function"> -></span>
<span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> <span class="hljs-property">@properties</span>.concat <span class="hljs-property">@base</span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">no</span> <span class="hljs-keyword">if</span> node.soak <span class="hljs-keyword">or</span> node <span class="hljs-keyword">instanceof</span> Call
<span class="hljs-literal">yes</span>
isNotCallable :<span class="hljs-function"> -></span> <span class="hljs-property">@isSimpleNumber</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@isString</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@isRegex</span>() <span class="hljs-keyword">or</span>
<span class="hljs-property">@isArray</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@isRange</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@isSplice</span>() <span class="hljs-keyword">or</span> <span class="hljs-property">@isObject</span>()
isStatement : <span class="hljs-function"><span class="hljs-params">(o)</span> -></span> <span class="hljs-keyword">not</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">and</span> <span class="hljs-property">@base</span>.isStatement o
assigns : <span class="hljs-function"><span class="hljs-params">(name)</span> -></span> <span class="hljs-keyword">not</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">and</span> <span class="hljs-property">@base</span>.assigns name
jumps : <span class="hljs-function"><span class="hljs-params">(o)</span> -></span> <span class="hljs-keyword">not</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">and</span> <span class="hljs-property">@base</span>.jumps o
<span class="hljs-attribute">isObject</span>: <span class="hljs-function"><span class="hljs-params">(onlyGenerated)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">no</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@properties</span>.length
(<span class="hljs-property">@base</span> <span class="hljs-keyword">instanceof</span> Obj) <span class="hljs-keyword">and</span> (<span class="hljs-keyword">not</span> onlyGenerated <span class="hljs-keyword">or</span> <span class="hljs-property">@base</span>.generated)
<span class="hljs-attribute">isSplice</span>:<span class="hljs-function"> -></span>
[..., lastProp] = <span class="hljs-property">@properties</span>
lastProp <span class="hljs-keyword">instanceof</span> Slice
<span class="hljs-attribute">looksStatic</span>: <span class="hljs-function"><span class="hljs-params">(className)</span> -></span>
<span class="hljs-property">@base</span>.value <span class="hljs-keyword">is</span> className <span class="hljs-keyword">and</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span>
<span class="hljs-property">@properties</span>[<span class="hljs-number">0</span>].name?.value <span class="hljs-keyword">isnt</span> <span class="hljs-string">'prototype'</span></pre></div></div>
</li>
<li id="section-47">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-47">¶</a>
</div>
<p>The value can be unwrapped as its inner node, if there are no attached
properties.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">unwrap</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@properties</span>.length <span class="hljs-keyword">then</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">else</span> <span class="hljs-property">@base</span></pre></div></div>
</li>
<li id="section-48">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-48">¶</a>
</div>
<p>A reference has base part (<code>this</code> value) and name part.
We cache them separately for compiling complex expressions.
<code>a()[b()] ?= c</code> -> <code>(_base = a())[_name = b()] ? _base[_name] = c</code></p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">cacheReference</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[..., name] = <span class="hljs-property">@properties</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@properties</span>.length < <span class="hljs-number">2</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@base</span>.isComplex() <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> name?.isComplex()
<span class="hljs-keyword">return</span> [<span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>] <span class="hljs-comment"># `a` `a.b`</span>
base = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@base</span>, <span class="hljs-property">@properties</span>[...-<span class="hljs-number">1</span>]
<span class="hljs-keyword">if</span> base.isComplex() <span class="hljs-comment"># `a().b`</span>
bref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'base'</span>
base = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">new</span> Assign bref, base
<span class="hljs-keyword">return</span> [base, bref] <span class="hljs-keyword">unless</span> name <span class="hljs-comment"># `a()`</span>
<span class="hljs-keyword">if</span> name.isComplex() <span class="hljs-comment"># `a[b()]`</span>
nref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'name'</span>
name = <span class="hljs-keyword">new</span> Index <span class="hljs-keyword">new</span> Assign nref, name.index
nref = <span class="hljs-keyword">new</span> Index nref
[base.add(name), <span class="hljs-keyword">new</span> Value(bref <span class="hljs-keyword">or</span> base.base, [nref <span class="hljs-keyword">or</span> name])]</pre></div></div>
</li>
<li id="section-49">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-49">¶</a>
</div>
<p>We compile a value to JavaScript by compiling and joining each property.
Things get much more interesting if the chain of properties has <em>soak</em>
operators <code>?.</code> interspersed. Then we have to take care not to accidentally
evaluate anything twice when building the soak chain.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@base</span>.front = <span class="hljs-property">@front</span>
props = <span class="hljs-property">@properties</span>
fragments = <span class="hljs-property">@base</span>.compileToFragments o, (<span class="hljs-keyword">if</span> props.length <span class="hljs-keyword">then</span> LEVEL_ACCESS <span class="hljs-keyword">else</span> <span class="hljs-literal">null</span>)
<span class="hljs-keyword">if</span> (<span class="hljs-property">@base</span> <span class="hljs-keyword">instanceof</span> Parens <span class="hljs-keyword">or</span> props.length) <span class="hljs-keyword">and</span> SIMPLENUM.test fragmentsToText fragments
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">'.'</span>
<span class="hljs-keyword">for</span> prop <span class="hljs-keyword">in</span> props
fragments.push (prop.compileToFragments o)...
fragments</pre></div></div>
</li>
<li id="section-50">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-50">¶</a>
</div>
<p>Unfold a soak into an <code>If</code>: <code>a?.b</code> -> <code>a.b if a?</code></p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">unfoldSoak</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@unfoldedSoak</span> ?= <span class="hljs-keyword">do</span><span class="hljs-function"> =></span>
<span class="hljs-keyword">if</span> ifn = <span class="hljs-property">@base</span>.unfoldSoak o
ifn.body.properties.push <span class="hljs-property">@properties</span>...
<span class="hljs-keyword">return</span> ifn
<span class="hljs-keyword">for</span> prop, i <span class="hljs-keyword">in</span> <span class="hljs-property">@properties</span> <span class="hljs-keyword">when</span> prop.soak
prop.soak = <span class="hljs-literal">off</span>
fst = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@base</span>, <span class="hljs-property">@properties</span>[...i]
snd = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@base</span>, <span class="hljs-property">@properties</span>[i..]
<span class="hljs-keyword">if</span> fst.isComplex()
ref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'ref'</span>
fst = <span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">new</span> Assign ref, fst
snd.base = ref
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> If <span class="hljs-keyword">new</span> Existence(fst), snd, <span class="hljs-attribute">soak</span>: <span class="hljs-literal">on</span>
<span class="hljs-literal">no</span></pre></div></div>
</li>
<li id="section-51">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-51">¶</a>
</div>
<h3 id="comment">Comment</h3>
</div>
</li>
<li id="section-52">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-52">¶</a>
</div>
<p>CoffeeScript passes through block comments as JavaScript block comments
at the same position.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Comment = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Comment</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@comment</span>)</span> -></span>
<span class="hljs-attribute">isStatement</span>: YES
<span class="hljs-attribute">makeReturn</span>: THIS
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o, level)</span> -></span>
comment = <span class="hljs-property">@comment</span>.replace <span class="hljs-regexp">/^(\s*)#(?=\s)/gm</span>, <span class="hljs-string">"$1 *"</span>
code = <span class="hljs-string">"/*<span class="hljs-subst">#{multident comment, <span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">in</span> comment <span class="hljs-keyword">then</span> <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>}</span> */"</span>
code = o.indent + code <span class="hljs-keyword">if</span> (level <span class="hljs-keyword">or</span> o.level) <span class="hljs-keyword">is</span> LEVEL_TOP
[<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>), <span class="hljs-property">@makeCode</span>(code)]</pre></div></div>
</li>
<li id="section-53">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-53">¶</a>
</div>
<h3 id="call">Call</h3>
</div>
</li>
<li id="section-54">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-54">¶</a>
</div>
<p>Node for a function invocation. Takes care of converting <code>super()</code> calls into
calls against the prototype’s function of the same name.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Call = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Call</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(variable, <span class="hljs-property">@args</span> = [], <span class="hljs-property">@soak</span>)</span> -></span>
<span class="hljs-property">@isNew</span> = <span class="hljs-literal">false</span>
<span class="hljs-property">@isSuper</span> = variable <span class="hljs-keyword">is</span> <span class="hljs-string">'super'</span>
<span class="hljs-property">@variable</span> = <span class="hljs-keyword">if</span> <span class="hljs-property">@isSuper</span> <span class="hljs-keyword">then</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">else</span> variable
<span class="hljs-keyword">if</span> variable <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> variable.isNotCallable()
variable.error <span class="hljs-string">"literal is not a function"</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'variable'</span>, <span class="hljs-string">'args'</span>]</pre></div></div>
</li>
<li id="section-55">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-55">¶</a>
</div>
<p>Tag this invocation as creating a new instance.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">newInstance</span>:<span class="hljs-function"> -></span>
base = <span class="hljs-property">@variable</span>?.base <span class="hljs-keyword">or</span> <span class="hljs-property">@variable</span>
<span class="hljs-keyword">if</span> base <span class="hljs-keyword">instanceof</span> Call <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> base.isNew
base.newInstance()
<span class="hljs-keyword">else</span>
<span class="hljs-property">@isNew</span> = <span class="hljs-literal">true</span>
<span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-56">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-56">¶</a>
</div>
<p>Grab the reference to the superclass’s implementation of the current
method.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">superReference</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
method = o.scope.namedMethod()
<span class="hljs-keyword">if</span> method?.klass
{klass, name, variable} = method
<span class="hljs-keyword">if</span> klass.isComplex()
bref = <span class="hljs-keyword">new</span> Literal o.scope.parent.freeVariable <span class="hljs-string">'base'</span>
base = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">new</span> Assign bref, klass
variable.base = base
variable.properties.splice <span class="hljs-number">0</span>, klass.properties.length
<span class="hljs-keyword">if</span> name.isComplex() <span class="hljs-keyword">or</span> (name <span class="hljs-keyword">instanceof</span> Index <span class="hljs-keyword">and</span> name.index.isAssignable())
nref = <span class="hljs-keyword">new</span> Literal o.scope.parent.freeVariable <span class="hljs-string">'name'</span>
name = <span class="hljs-keyword">new</span> Index <span class="hljs-keyword">new</span> Assign nref, name.index
variable.properties.pop()
variable.properties.push name
accesses = [<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'__super__'</span>]
accesses.push <span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'constructor'</span> <span class="hljs-keyword">if</span> method.static
accesses.push <span class="hljs-keyword">if</span> nref? <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Index nref <span class="hljs-keyword">else</span> name
(<span class="hljs-keyword">new</span> Value bref ? klass, accesses).compile o
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> method?.ctor
<span class="hljs-string">"<span class="hljs-subst">#{method.name}</span>.__super__.constructor"</span>
<span class="hljs-keyword">else</span>
<span class="hljs-property">@error</span> <span class="hljs-string">'cannot call super outside of an instance method.'</span></pre></div></div>
</li>
<li id="section-57">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-57">¶</a>
</div>
<p>The appropriate <code>this</code> value for a <code>super</code> call.</p>
</div>
<div class="content"><div class='highlight'><pre> superThis : <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
method = o.scope.method
(method <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> method.klass <span class="hljs-keyword">and</span> method.context) <span class="hljs-keyword">or</span> <span class="hljs-string">"this"</span></pre></div></div>
</li>
<li id="section-58">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-58">¶</a>
</div>
<p>Soaked chained invocations unfold into if/else ternary structures.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">unfoldSoak</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@soak</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>
<span class="hljs-keyword">return</span> ifn <span class="hljs-keyword">if</span> ifn = unfoldSoak o, <span class="hljs-keyword">this</span>, <span class="hljs-string">'variable'</span>
[left, rite] = <span class="hljs-keyword">new</span> Value(<span class="hljs-property">@variable</span>).cacheReference o
<span class="hljs-keyword">else</span>
left = <span class="hljs-keyword">new</span> Literal <span class="hljs-property">@superReference</span> o
rite = <span class="hljs-keyword">new</span> Value left
rite = <span class="hljs-keyword">new</span> Call rite, <span class="hljs-property">@args</span>
rite.isNew = <span class="hljs-property">@isNew</span>
left = <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"typeof <span class="hljs-subst">#{ left.compile o }</span> === \"function\""</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> If left, <span class="hljs-keyword">new</span> Value(rite), <span class="hljs-attribute">soak</span>: <span class="hljs-literal">yes</span>
call = <span class="hljs-keyword">this</span>
list = []
<span class="hljs-keyword">loop</span>
<span class="hljs-keyword">if</span> call.variable <span class="hljs-keyword">instanceof</span> Call
list.push call
call = call.variable
<span class="hljs-keyword">continue</span>
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> call.variable <span class="hljs-keyword">instanceof</span> Value
list.push call
<span class="hljs-keyword">break</span> <span class="hljs-keyword">unless</span> (call = call.variable.base) <span class="hljs-keyword">instanceof</span> Call
<span class="hljs-keyword">for</span> call <span class="hljs-keyword">in</span> list.reverse()
<span class="hljs-keyword">if</span> ifn
<span class="hljs-keyword">if</span> call.variable <span class="hljs-keyword">instanceof</span> Call
call.variable = ifn
<span class="hljs-keyword">else</span>
call.variable.base = ifn
ifn = unfoldSoak o, call, <span class="hljs-string">'variable'</span>
ifn</pre></div></div>
</li>
<li id="section-59">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-59">¶</a>
</div>
<p>Compile a vanilla function call.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@variable</span>?.front = <span class="hljs-property">@front</span>
compiledArray = Splat.compileSplattedArray o, <span class="hljs-property">@args</span>, <span class="hljs-literal">true</span>
<span class="hljs-keyword">if</span> compiledArray.length
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileSplat</span> o, compiledArray
compiledArgs = []
<span class="hljs-keyword">for</span> arg, argIndex <span class="hljs-keyword">in</span> <span class="hljs-property">@args</span>
<span class="hljs-keyword">if</span> argIndex <span class="hljs-keyword">then</span> compiledArgs.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">", "</span>
compiledArgs.push (arg.compileToFragments o, LEVEL_LIST)...
fragments = []
<span class="hljs-keyword">if</span> <span class="hljs-property">@isSuper</span>
preface = <span class="hljs-property">@superReference</span>(o) + <span class="hljs-string">".call(<span class="hljs-subst">#{<span class="hljs-property">@superThis</span>(o)}</span>"</span>
<span class="hljs-keyword">if</span> compiledArgs.length <span class="hljs-keyword">then</span> preface += <span class="hljs-string">", "</span>
fragments.push <span class="hljs-property">@makeCode</span> preface
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@isNew</span> <span class="hljs-keyword">then</span> fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">'new '</span>
fragments.push <span class="hljs-property">@variable</span>.compileToFragments(o, LEVEL_ACCESS)...
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"("</span>
fragments.push compiledArgs...
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">")"</span>
fragments</pre></div></div>
</li>
<li id="section-60">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-60">¶</a>
</div>
<p>If you call a function with a splat, it’s converted into a JavaScript
<code>.apply()</code> call to allow an array of arguments to be passed.
If it’s a constructor, then things get real tricky. We have to inject an
inner constructor in order to be able to pass the varargs.</p>
<p>splatArgs is an array of CodeFragments to put into the ‘apply’.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileSplat</span>: <span class="hljs-function"><span class="hljs-params">(o, splatArgs)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@isSuper</span>
<span class="hljs-keyword">return</span> [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{ <span class="hljs-property">@superReference</span> o }</span>.apply(<span class="hljs-subst">#{<span class="hljs-property">@superThis</span>(o)}</span>, "</span>),
splatArgs, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">")"</span>)
<span class="hljs-keyword">if</span> <span class="hljs-property">@isNew</span>
idt = <span class="hljs-property">@tab</span> + TAB
<span class="hljs-keyword">return</span> [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"""
(function(func, args, ctor) {
<span class="hljs-subst">#{idt}</span>ctor.prototype = func.prototype;
<span class="hljs-subst">#{idt}</span>var child = new ctor, result = func.apply(child, args);
<span class="hljs-subst">#{idt}</span>return Object(result) === result ? result : child;
<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>})("""</span>),
(<span class="hljs-property">@variable</span>.compileToFragments o, LEVEL_LIST),
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">", "</span>), splatArgs, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">", function(){})"</span>)
answer = []
base = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@variable</span>
<span class="hljs-keyword">if</span> (name = base.properties.pop()) <span class="hljs-keyword">and</span> base.isComplex()
ref = o.scope.freeVariable <span class="hljs-string">'ref'</span>
answer = answer.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"(<span class="hljs-subst">#{ref}</span> = "</span>),
(base.compileToFragments o, LEVEL_LIST),
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">")"</span>),
name.compileToFragments(o)
<span class="hljs-keyword">else</span>
fun = base.compileToFragments o, LEVEL_ACCESS
fun = <span class="hljs-property">@wrapInBraces</span> fun <span class="hljs-keyword">if</span> SIMPLENUM.test fragmentsToText fun
<span class="hljs-keyword">if</span> name
ref = fragmentsToText fun
fun.push (name.compileToFragments o)...
<span class="hljs-keyword">else</span>
ref = <span class="hljs-string">'null'</span>
answer = answer.concat fun
answer = answer.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">".apply(<span class="hljs-subst">#{ref}</span>, "</span>), splatArgs, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">")"</span>)</pre></div></div>
</li>
<li id="section-61">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-61">¶</a>
</div>
<h3 id="extends">Extends</h3>
</div>
</li>
<li id="section-62">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-62">¶</a>
</div>
<p>Node to extend an object’s prototype with an ancestor object.
After <code>goog.inherits</code> from the
<a href="http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.html">Closure Library</a>.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Extends = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Extends</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@child</span>, <span class="hljs-property">@parent</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'child'</span>, <span class="hljs-string">'parent'</span>]</pre></div></div>
</li>
<li id="section-63">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-63">¶</a>
</div>
<p>Hooks one constructor into another’s prototype chain.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">new</span> Call(<span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Literal utility <span class="hljs-string">'extend'</span>, o), [<span class="hljs-property">@child</span>, <span class="hljs-property">@parent</span>]).compileToFragments o</pre></div></div>
</li>
<li id="section-64">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-64">¶</a>
</div>
<h3 id="access">Access</h3>
</div>
</li>
<li id="section-65">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-65">¶</a>
</div>
<p>A <code>.</code> access into a property of a value, or the <code>::</code> shorthand for
an access into the object’s prototype.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Access = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Access</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@name</span>, tag)</span> -></span>
<span class="hljs-property">@name</span>.asKey = <span class="hljs-literal">yes</span>
<span class="hljs-property">@soak</span> = tag <span class="hljs-keyword">is</span> <span class="hljs-string">'soak'</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'name'</span>]
<span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
name = <span class="hljs-property">@name</span>.compileToFragments o
<span class="hljs-keyword">if</span> IDENTIFIER.test fragmentsToText name
name.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"."</span>
<span class="hljs-keyword">else</span>
name.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"["</span>
name.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"]"</span>
name
<span class="hljs-attribute">isComplex</span>: NO</pre></div></div>
</li>
<li id="section-66">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-66">¶</a>
</div>
<h3 id="index">Index</h3>
</div>
</li>
<li id="section-67">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-67">¶</a>
</div>
<p>A <code>[ ... ]</code> indexed access into an array or object.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Index = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Index</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@index</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'index'</span>]
<span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"["</span>), <span class="hljs-property">@index</span>.compileToFragments(o, LEVEL_PAREN), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"]"</span>)
<span class="hljs-attribute">isComplex</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@index</span>.isComplex()</pre></div></div>
</li>
<li id="section-68">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-68">¶</a>
</div>
<h3 id="range">Range</h3>
</div>
</li>
<li id="section-69">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-69">¶</a>
</div>
<p>A range literal. Ranges can be used to extract portions (slices) of arrays,
to specify a range for comprehensions, or as a value, to be expanded into the
corresponding array of integers at runtime.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Range = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Range</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'from'</span>, <span class="hljs-string">'to'</span>]
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@from</span>, <span class="hljs-property">@to</span>, tag)</span> -></span>
<span class="hljs-property">@exclusive</span> = tag <span class="hljs-keyword">is</span> <span class="hljs-string">'exclusive'</span>
<span class="hljs-property">@equals</span> = <span class="hljs-keyword">if</span> <span class="hljs-property">@exclusive</span> <span class="hljs-keyword">then</span> <span class="hljs-string">''</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'='</span></pre></div></div>
</li>
<li id="section-70">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-70">¶</a>
</div>
<p>Compiles the range’s source variables — where it starts and where it ends.
But only if they need to be cached to avoid double evaluation.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileVariables</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
o = merge o, <span class="hljs-attribute">top</span>: <span class="hljs-literal">true</span>
isComplex = del o, <span class="hljs-string">'isComplex'</span>
[<span class="hljs-property">@fromC</span>, <span class="hljs-property">@fromVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@from</span>.cache o, LEVEL_LIST, isComplex
[<span class="hljs-property">@toC</span>, <span class="hljs-property">@toVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@to</span>.cache o, LEVEL_LIST, isComplex
[<span class="hljs-property">@step</span>, <span class="hljs-property">@stepVar</span>] = <span class="hljs-property">@cacheToCodeFragments</span> step.cache o, LEVEL_LIST, isComplex <span class="hljs-keyword">if</span> step = del o, <span class="hljs-string">'step'</span>
[<span class="hljs-property">@fromNum</span>, <span class="hljs-property">@toNum</span>] = [<span class="hljs-property">@fromVar</span>.match(NUMBER), <span class="hljs-property">@toVar</span>.match(NUMBER)]
<span class="hljs-property">@stepNum</span> = <span class="hljs-property">@stepVar</span>.match(NUMBER) <span class="hljs-keyword">if</span> <span class="hljs-property">@stepVar</span></pre></div></div>
</li>
<li id="section-71">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-71">¶</a>
</div>
<p>When compiled normally, the range returns the contents of the <em>for loop</em>
needed to iterate over the values in the range. Used by comprehensions.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@compileVariables</span> o <span class="hljs-keyword">unless</span> <span class="hljs-property">@fromVar</span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileArray</span>(o) <span class="hljs-keyword">unless</span> o.index</pre></div></div>
</li>
<li id="section-72">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-72">¶</a>
</div>
<p>Set up endpoints.</p>
</div>
<div class="content"><div class='highlight'><pre> known = <span class="hljs-property">@fromNum</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@toNum</span>
idx = del o, <span class="hljs-string">'index'</span>
idxName = del o, <span class="hljs-string">'name'</span>
namedIndex = idxName <span class="hljs-keyword">and</span> idxName <span class="hljs-keyword">isnt</span> idx
varPart = <span class="hljs-string">"<span class="hljs-subst">#{idx}</span> = <span class="hljs-subst">#{<span class="hljs-property">@fromC</span>}</span>"</span>
varPart += <span class="hljs-string">", <span class="hljs-subst">#{<span class="hljs-property">@toC</span>}</span>"</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@toC</span> <span class="hljs-keyword">isnt</span> <span class="hljs-property">@toVar</span>
varPart += <span class="hljs-string">", <span class="hljs-subst">#{<span class="hljs-property">@step</span>}</span>"</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@step</span> <span class="hljs-keyword">isnt</span> <span class="hljs-property">@stepVar</span>
[lt, gt] = [<span class="hljs-string">"<span class="hljs-subst">#{idx}</span> <<span class="hljs-subst">#{<span class="hljs-property">@equals</span>}</span>"</span>, <span class="hljs-string">"<span class="hljs-subst">#{idx}</span> ><span class="hljs-subst">#{<span class="hljs-property">@equals</span>}</span>"</span>]</pre></div></div>
</li>
<li id="section-73">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-73">¶</a>
</div>
<p>Generate the condition.</p>
</div>
<div class="content"><div class='highlight'><pre> condPart = <span class="hljs-keyword">if</span> <span class="hljs-property">@stepNum</span>
<span class="hljs-keyword">if</span> parseNum(<span class="hljs-property">@stepNum</span>[<span class="hljs-number">0</span>]) > <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{lt}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"<span class="hljs-subst">#{gt}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>"</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> known
[from, to] = [parseNum(<span class="hljs-property">@fromNum</span>[<span class="hljs-number">0</span>]), parseNum(<span class="hljs-property">@toNum</span>[<span class="hljs-number">0</span>])]
<span class="hljs-keyword">if</span> from <= to <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{lt}</span> <span class="hljs-subst">#{to}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"<span class="hljs-subst">#{gt}</span> <span class="hljs-subst">#{to}</span>"</span>
<span class="hljs-keyword">else</span>
cond = <span class="hljs-keyword">if</span> <span class="hljs-property">@stepVar</span> <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@stepVar</span>}</span> > 0"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@fromVar</span>}</span> <= <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>"</span>
<span class="hljs-string">"<span class="hljs-subst">#{cond}</span> ? <span class="hljs-subst">#{lt}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span> : <span class="hljs-subst">#{gt}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>"</span></pre></div></div>
</li>
<li id="section-74">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-74">¶</a>
</div>
<p>Generate the step.</p>
</div>
<div class="content"><div class='highlight'><pre> stepPart = <span class="hljs-keyword">if</span> <span class="hljs-property">@stepVar</span>
<span class="hljs-string">"<span class="hljs-subst">#{idx}</span> += <span class="hljs-subst">#{<span class="hljs-property">@stepVar</span>}</span>"</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> known
<span class="hljs-keyword">if</span> namedIndex
<span class="hljs-keyword">if</span> from <= to <span class="hljs-keyword">then</span> <span class="hljs-string">"++<span class="hljs-subst">#{idx}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"--<span class="hljs-subst">#{idx}</span>"</span>
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">if</span> from <= to <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{idx}</span>++"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"<span class="hljs-subst">#{idx}</span>--"</span>
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">if</span> namedIndex
<span class="hljs-string">"<span class="hljs-subst">#{cond}</span> ? ++<span class="hljs-subst">#{idx}</span> : --<span class="hljs-subst">#{idx}</span>"</span>
<span class="hljs-keyword">else</span>
<span class="hljs-string">"<span class="hljs-subst">#{cond}</span> ? <span class="hljs-subst">#{idx}</span>++ : <span class="hljs-subst">#{idx}</span>--"</span>
varPart = <span class="hljs-string">"<span class="hljs-subst">#{idxName}</span> = <span class="hljs-subst">#{varPart}</span>"</span> <span class="hljs-keyword">if</span> namedIndex
stepPart = <span class="hljs-string">"<span class="hljs-subst">#{idxName}</span> = <span class="hljs-subst">#{stepPart}</span>"</span> <span class="hljs-keyword">if</span> namedIndex</pre></div></div>
</li>
<li id="section-75">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-75">¶</a>
</div>
<p>The final loop body.</p>
</div>
<div class="content"><div class='highlight'><pre> [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"<span class="hljs-subst">#{varPart}</span>; <span class="hljs-subst">#{condPart}</span>; <span class="hljs-subst">#{stepPart}</span>"</span>]</pre></div></div>
</li>
<li id="section-76">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-76">¶</a>
</div>
<p>When used as a value, expand the range into the equivalent array.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileArray</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@fromNum</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@toNum</span> <span class="hljs-keyword">and</span> Math.abs(<span class="hljs-property">@fromNum</span> - <span class="hljs-property">@toNum</span>) <= <span class="hljs-number">20</span>
range = [+<span class="hljs-property">@fromNum</span>..+<span class="hljs-property">@toNum</span>]
range.pop() <span class="hljs-keyword">if</span> <span class="hljs-property">@exclusive</span>
<span class="hljs-keyword">return</span> [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"[<span class="hljs-subst">#{ range.join(<span class="hljs-string">', '</span>) }</span>]"</span>]
idt = <span class="hljs-property">@tab</span> + TAB
i = o.scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
result = o.scope.freeVariable <span class="hljs-string">'results'</span>
pre = <span class="hljs-string">"\n<span class="hljs-subst">#{idt}</span><span class="hljs-subst">#{result}</span> = [];"</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@fromNum</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@toNum</span>
o.index = i
body = fragmentsToText <span class="hljs-property">@compileNode</span> o
<span class="hljs-keyword">else</span>
vars = <span class="hljs-string">"<span class="hljs-subst">#{i}</span> = <span class="hljs-subst">#{<span class="hljs-property">@fromC</span>}</span>"</span> + <span class="hljs-keyword">if</span> <span class="hljs-property">@toC</span> <span class="hljs-keyword">isnt</span> <span class="hljs-property">@toVar</span> <span class="hljs-keyword">then</span> <span class="hljs-string">", <span class="hljs-subst">#{<span class="hljs-property">@toC</span>}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span>
cond = <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@fromVar</span>}</span> <= <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>"</span>
body = <span class="hljs-string">"var <span class="hljs-subst">#{vars}</span>; <span class="hljs-subst">#{cond}</span> ? <span class="hljs-subst">#{i}</span> <<span class="hljs-subst">#{<span class="hljs-property">@equals</span>}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span> : <span class="hljs-subst">#{i}</span> ><span class="hljs-subst">#{<span class="hljs-property">@equals</span>}</span> <span class="hljs-subst">#{<span class="hljs-property">@toVar</span>}</span>; <span class="hljs-subst">#{cond}</span> ? <span class="hljs-subst">#{i}</span>++ : <span class="hljs-subst">#{i}</span>--"</span>
post = <span class="hljs-string">"{ <span class="hljs-subst">#{result}</span>.push(<span class="hljs-subst">#{i}</span>); }\n<span class="hljs-subst">#{idt}</span>return <span class="hljs-subst">#{result}</span>;\n<span class="hljs-subst">#{o.indent}</span>"</span>
<span class="hljs-function"><span class="hljs-title">hasArgs</span> = <span class="hljs-params">(node)</span> -></span> node?.contains isLiteralArguments
args = <span class="hljs-string">', arguments'</span> <span class="hljs-keyword">if</span> hasArgs(<span class="hljs-property">@from</span>) <span class="hljs-keyword">or</span> hasArgs(<span class="hljs-property">@to</span>)
[<span class="hljs-property">@makeCode</span> <span class="hljs-string">"(function() {<span class="hljs-subst">#{pre}</span>\n<span class="hljs-subst">#{idt}</span>for (<span class="hljs-subst">#{body}</span>)<span class="hljs-subst">#{post}</span>}).apply(this<span class="hljs-subst">#{args ? <span class="hljs-string">''</span>}</span>)"</span>]</pre></div></div>
</li>
<li id="section-77">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-77">¶</a>
</div>
<h3 id="slice">Slice</h3>
</div>
</li>
<li id="section-78">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-78">¶</a>
</div>
<p>An array slice literal. Unlike JavaScript’s <code>Array#slice</code>, the second parameter
specifies the index of the end of the slice, just as the first parameter
is the index of the beginning.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Slice = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Slice</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'range'</span>]
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@range</span>)</span> -></span>
<span class="hljs-keyword">super</span>()</pre></div></div>
</li>
<li id="section-79">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-79">¶</a>
</div>
<p>We have to be careful when trying to slice through the end of the array,
<code>9e9</code> is used because not all implementations respect <code>undefined</code> or <code>1/0</code>.
<code>9e9</code> should be safe because <code>9e9</code> > <code>2**32</code>, the max array length.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
{to, from} = <span class="hljs-property">@range</span>
fromCompiled = from <span class="hljs-keyword">and</span> from.compileToFragments(o, LEVEL_PAREN) <span class="hljs-keyword">or</span> [<span class="hljs-property">@makeCode</span> <span class="hljs-string">'0'</span>]</pre></div></div>
</li>
<li id="section-80">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-80">¶</a>
</div>
<p>TODO: jwalton - move this into the ‘if’?</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> to
compiled = to.compileToFragments o, LEVEL_PAREN
compiledText = fragmentsToText compiled
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> (<span class="hljs-keyword">not</span> <span class="hljs-property">@range</span>.exclusive <span class="hljs-keyword">and</span> +compiledText <span class="hljs-keyword">is</span> -<span class="hljs-number">1</span>)
toStr = <span class="hljs-string">', '</span> + <span class="hljs-keyword">if</span> <span class="hljs-property">@range</span>.exclusive
compiledText
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> SIMPLENUM.test compiledText
<span class="hljs-string">"<span class="hljs-subst">#{+compiledText + <span class="hljs-number">1</span>}</span>"</span>
<span class="hljs-keyword">else</span>
compiled = to.compileToFragments o, LEVEL_ACCESS
<span class="hljs-string">"+<span class="hljs-subst">#{fragmentsToText compiled}</span> + 1 || 9e9"</span>
[<span class="hljs-property">@makeCode</span> <span class="hljs-string">".slice(<span class="hljs-subst">#{ fragmentsToText fromCompiled }</span><span class="hljs-subst">#{ toStr <span class="hljs-keyword">or</span> <span class="hljs-string">''</span> }</span>)"</span>]</pre></div></div>
</li>
<li id="section-81">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-81">¶</a>
</div>
<h3 id="obj">Obj</h3>
</div>
</li>
<li id="section-82">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-82">¶</a>
</div>
<p>An object literal, nothing fancy.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Obj = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Obj</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(props, <span class="hljs-property">@generated</span> = <span class="hljs-literal">false</span>)</span> -></span>
<span class="hljs-property">@objects</span> = <span class="hljs-property">@properties</span> = props <span class="hljs-keyword">or</span> []
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'properties'</span>]
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
props = <span class="hljs-property">@properties</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@generated</span>
<span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> props <span class="hljs-keyword">when</span> node <span class="hljs-keyword">instanceof</span> Value
node.error <span class="hljs-string">'cannot have an implicit value in an implicit object'</span>
<span class="hljs-keyword">break</span> <span class="hljs-keyword">for</span> prop, dynamicIndex <span class="hljs-keyword">in</span> props <span class="hljs-keyword">when</span> (prop.variable <span class="hljs-keyword">or</span> prop).base <span class="hljs-keyword">instanceof</span> Parens
hasDynamic = dynamicIndex < props.length
idt = o.indent += TAB
lastNoncom = <span class="hljs-property">@lastNonComment</span> <span class="hljs-property">@properties</span>
answer = []
<span class="hljs-keyword">if</span> hasDynamic
oref = o.scope.freeVariable <span class="hljs-string">'obj'</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"(\n<span class="hljs-subst">#{idt}</span><span class="hljs-subst">#{oref}</span> = "</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"{<span class="hljs-subst">#{<span class="hljs-keyword">if</span> props.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">or</span> dynamicIndex <span class="hljs-keyword">is</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'}'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'\n'</span>}</span>"</span>
<span class="hljs-keyword">for</span> prop, i <span class="hljs-keyword">in</span> props
<span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> dynamicIndex
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n<span class="hljs-subst">#{idt}</span>}"</span> <span class="hljs-keyword">unless</span> i <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">',\n'</span>
join = <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> props.length - <span class="hljs-number">1</span> <span class="hljs-keyword">or</span> i <span class="hljs-keyword">is</span> dynamicIndex - <span class="hljs-number">1</span>
<span class="hljs-string">''</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> prop <span class="hljs-keyword">is</span> lastNoncom <span class="hljs-keyword">or</span> prop <span class="hljs-keyword">instanceof</span> Comment
<span class="hljs-string">'\n'</span>
<span class="hljs-keyword">else</span>
<span class="hljs-string">',\n'</span>
indent = <span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Comment <span class="hljs-keyword">then</span> <span class="hljs-string">''</span> <span class="hljs-keyword">else</span> idt
indent += TAB <span class="hljs-keyword">if</span> hasDynamic <span class="hljs-keyword">and</span> i < dynamicIndex
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Assign <span class="hljs-keyword">and</span> prop.variable <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> prop.variable.hasProperties()
prop.variable.error <span class="hljs-string">'invalid object key'</span>
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> prop.<span class="hljs-keyword">this</span>
prop = <span class="hljs-keyword">new</span> Assign prop.properties[<span class="hljs-number">0</span>].name, prop, <span class="hljs-string">'object'</span>
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Comment
<span class="hljs-keyword">if</span> i < dynamicIndex
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Assign
prop = <span class="hljs-keyword">new</span> Assign prop, prop, <span class="hljs-string">'object'</span>
(prop.variable.base <span class="hljs-keyword">or</span> prop.variable).asKey = <span class="hljs-literal">yes</span>
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">if</span> prop <span class="hljs-keyword">instanceof</span> Assign
key = prop.variable
value = prop.value
<span class="hljs-keyword">else</span>
[key, value] = prop.base.cache o
prop = <span class="hljs-keyword">new</span> Assign (<span class="hljs-keyword">new</span> Value (<span class="hljs-keyword">new</span> Literal oref), [<span class="hljs-keyword">new</span> Access key]), value
<span class="hljs-keyword">if</span> indent <span class="hljs-keyword">then</span> answer.push <span class="hljs-property">@makeCode</span> indent
answer.push prop.compileToFragments(o, LEVEL_TOP)...
<span class="hljs-keyword">if</span> join <span class="hljs-keyword">then</span> answer.push <span class="hljs-property">@makeCode</span> join
<span class="hljs-keyword">if</span> hasDynamic
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">",\n<span class="hljs-subst">#{idt}</span><span class="hljs-subst">#{oref}</span>\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>)"</span>
<span class="hljs-keyword">else</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span> <span class="hljs-keyword">unless</span> props.length <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@front</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> hasDynamic <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> answer <span class="hljs-keyword">else</span> answer
<span class="hljs-attribute">assigns</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
<span class="hljs-keyword">for</span> prop <span class="hljs-keyword">in</span> <span class="hljs-property">@properties</span> <span class="hljs-keyword">when</span> prop.assigns name <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span>
<span class="hljs-literal">no</span></pre></div></div>
</li>
<li id="section-83">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-83">¶</a>
</div>
<h3 id="arr">Arr</h3>
</div>
</li>
<li id="section-84">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-84">¶</a>
</div>
<p>An array literal.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Arr = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Arr</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(objs)</span> -></span>
<span class="hljs-property">@objects</span> = objs <span class="hljs-keyword">or</span> []
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'objects'</span>]
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">return</span> [<span class="hljs-property">@makeCode</span> <span class="hljs-string">'[]'</span>] <span class="hljs-keyword">unless</span> <span class="hljs-property">@objects</span>.length
o.indent += TAB
answer = Splat.compileSplattedArray o, <span class="hljs-property">@objects</span>
<span class="hljs-keyword">return</span> answer <span class="hljs-keyword">if</span> answer.length
answer = []
compiledObjs = (obj.compileToFragments o, LEVEL_LIST <span class="hljs-keyword">for</span> obj <span class="hljs-keyword">in</span> <span class="hljs-property">@objects</span>)
<span class="hljs-keyword">for</span> fragments, index <span class="hljs-keyword">in</span> compiledObjs
<span class="hljs-keyword">if</span> index
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">", "</span>
answer.push fragments...
<span class="hljs-keyword">if</span> fragmentsToText(answer).indexOf(<span class="hljs-string">'\n'</span>) >= <span class="hljs-number">0</span>
answer.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"[\n<span class="hljs-subst">#{o.indent}</span>"</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>]"</span>
<span class="hljs-keyword">else</span>
answer.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-string">"["</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"]"</span>
answer
<span class="hljs-attribute">assigns</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
<span class="hljs-keyword">for</span> obj <span class="hljs-keyword">in</span> <span class="hljs-property">@objects</span> <span class="hljs-keyword">when</span> obj.assigns name <span class="hljs-keyword">then</span> <span class="hljs-keyword">return</span> <span class="hljs-literal">yes</span>
<span class="hljs-literal">no</span></pre></div></div>
</li>
<li id="section-85">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-85">¶</a>
</div>
<h3 id="class">Class</h3>
</div>
</li>
<li id="section-86">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-86">¶</a>
</div>
<p>The CoffeeScript class definition.
Initialize a <strong>Class</strong> with its name, an optional superclass, and a
list of prototype property assignments.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Class = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Class</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@variable</span>, <span class="hljs-property">@parent</span>, <span class="hljs-property">@body</span> = <span class="hljs-keyword">new</span> Block)</span> -></span>
<span class="hljs-property">@boundFuncs</span> = []
<span class="hljs-property">@body</span>.classBody = <span class="hljs-literal">yes</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'variable'</span>, <span class="hljs-string">'parent'</span>, <span class="hljs-string">'body'</span>]</pre></div></div>
</li>
<li id="section-87">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-87">¶</a>
</div>
<p>Figure out the appropriate name for the constructor function of this class.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">determineName</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@variable</span>
[..., tail] = <span class="hljs-property">@variable</span>.properties
decl = <span class="hljs-keyword">if</span> tail
tail <span class="hljs-keyword">instanceof</span> Access <span class="hljs-keyword">and</span> tail.name.value
<span class="hljs-keyword">else</span>
<span class="hljs-property">@variable</span>.base.value
<span class="hljs-keyword">if</span> decl <span class="hljs-keyword">in</span> STRICT_PROSCRIBED
<span class="hljs-property">@variable</span>.error <span class="hljs-string">"class variable name may not be <span class="hljs-subst">#{decl}</span>"</span>
decl <span class="hljs-keyword">and</span>= IDENTIFIER.test(decl) <span class="hljs-keyword">and</span> decl</pre></div></div>
</li>
<li id="section-88">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-88">¶</a>
</div>
<p>For all <code>this</code>-references and bound functions in the class definition,
<code>this</code> is the Class being constructed.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">setContext</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
<span class="hljs-property">@body</span>.traverseChildren <span class="hljs-literal">false</span>, <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span> <span class="hljs-keyword">if</span> node.classBody
<span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span> node.value <span class="hljs-keyword">is</span> <span class="hljs-string">'this'</span>
node.value = name
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Code
node.context = name <span class="hljs-keyword">if</span> node.bound</pre></div></div>
</li>
<li id="section-89">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-89">¶</a>
</div>
<p>Ensure that all functions bound to the instance are proxied in the
constructor.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">addBoundFunctions</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">for</span> bvar <span class="hljs-keyword">in</span> <span class="hljs-property">@boundFuncs</span>
lhs = (<span class="hljs-keyword">new</span> Value (<span class="hljs-keyword">new</span> Literal <span class="hljs-string">"this"</span>), [<span class="hljs-keyword">new</span> Access bvar]).compile o
<span class="hljs-property">@ctor</span>.body.unshift <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{lhs}</span> = <span class="hljs-subst">#{utility <span class="hljs-string">'bind'</span>, o}</span>(<span class="hljs-subst">#{lhs}</span>, this)"</span>
<span class="hljs-keyword">return</span></pre></div></div>
</li>
<li id="section-90">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-90">¶</a>
</div>
<p>Merge the properties from a top-level object as prototypal properties
on the class.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">addProperties</span>: <span class="hljs-function"><span class="hljs-params">(node, name, o)</span> -></span>
props = node.base.properties[..]
exprs = <span class="hljs-keyword">while</span> assign = props.shift()
<span class="hljs-keyword">if</span> assign <span class="hljs-keyword">instanceof</span> Assign
base = assign.variable.base
<span class="hljs-keyword">delete</span> assign.context
func = assign.value
<span class="hljs-keyword">if</span> base.value <span class="hljs-keyword">is</span> <span class="hljs-string">'constructor'</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@ctor</span>
assign.error <span class="hljs-string">'cannot define more than one constructor in a class'</span>
<span class="hljs-keyword">if</span> func.bound
assign.error <span class="hljs-string">'cannot define a constructor as a bound function'</span>
<span class="hljs-keyword">if</span> func <span class="hljs-keyword">instanceof</span> Code
assign = <span class="hljs-property">@ctor</span> = func
<span class="hljs-keyword">else</span>
<span class="hljs-property">@externalCtor</span> = o.classScope.freeVariable <span class="hljs-string">'class'</span>
assign = <span class="hljs-keyword">new</span> Assign <span class="hljs-keyword">new</span> Literal(<span class="hljs-property">@externalCtor</span>), func
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">if</span> assign.variable.<span class="hljs-keyword">this</span>
func.static = <span class="hljs-literal">yes</span>
<span class="hljs-keyword">else</span>
acc = <span class="hljs-keyword">if</span> base.isComplex() <span class="hljs-keyword">then</span> <span class="hljs-keyword">new</span> Index base <span class="hljs-keyword">else</span> <span class="hljs-keyword">new</span> Access base
assign.variable = <span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Literal(name), [(<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'prototype'</span>), acc])
<span class="hljs-keyword">if</span> func <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span> func.bound
<span class="hljs-property">@boundFuncs</span>.push base
func.bound = <span class="hljs-literal">no</span>
assign
compact exprs</pre></div></div>
</li>
<li id="section-91">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-91">¶</a>
</div>
<p>Walk the body of the class, looking for prototype properties to be converted
and tagging static assignments.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">walkBody</span>: <span class="hljs-function"><span class="hljs-params">(name, o)</span> -></span>
<span class="hljs-property">@traverseChildren</span> <span class="hljs-literal">false</span>, <span class="hljs-function"><span class="hljs-params">(child)</span> =></span>
cont = <span class="hljs-literal">true</span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span> <span class="hljs-keyword">if</span> child <span class="hljs-keyword">instanceof</span> Class
<span class="hljs-keyword">if</span> child <span class="hljs-keyword">instanceof</span> Block
<span class="hljs-keyword">for</span> node, i <span class="hljs-keyword">in</span> exps = child.expressions
<span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Assign <span class="hljs-keyword">and</span> node.variable.looksStatic name
node.value.static = <span class="hljs-literal">yes</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> node.isObject(<span class="hljs-literal">true</span>)
cont = <span class="hljs-literal">false</span>
exps[i] = <span class="hljs-property">@addProperties</span> node, name, o
child.expressions = exps = flatten exps
cont <span class="hljs-keyword">and</span> child <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Class</pre></div></div>
</li>
<li id="section-92">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-92">¶</a>
</div>
<p><code>use strict</code> (and other directives) must be the first expression statement(s)
of a function body. This method ensures the prologue is correctly positioned
above the <code>constructor</code>.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">hoistDirectivePrologue</span>:<span class="hljs-function"> -></span>
index = <span class="hljs-number">0</span>
{expressions} = <span class="hljs-property">@body</span>
++index <span class="hljs-keyword">while</span> (node = expressions[index]) <span class="hljs-keyword">and</span> node <span class="hljs-keyword">instanceof</span> Comment <span class="hljs-keyword">or</span>
node <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> node.isString()
<span class="hljs-property">@directives</span> = expressions.splice <span class="hljs-number">0</span>, index</pre></div></div>
</li>
<li id="section-93">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-93">¶</a>
</div>
<p>Make sure that a constructor is defined for the class, and properly
configured.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">ensureConstructor</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@ctor</span>
<span class="hljs-property">@ctor</span> = <span class="hljs-keyword">new</span> Code
<span class="hljs-keyword">if</span> <span class="hljs-property">@externalCtor</span>
<span class="hljs-property">@ctor</span>.body.push <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@externalCtor</span>}</span>.apply(this, arguments)"</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@parent</span>
<span class="hljs-property">@ctor</span>.body.push <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{name}</span>.__super__.constructor.apply(this, arguments)"</span>
<span class="hljs-property">@ctor</span>.body.makeReturn()
<span class="hljs-property">@body</span>.expressions.unshift <span class="hljs-property">@ctor</span>
<span class="hljs-property">@ctor</span>.ctor = <span class="hljs-property">@ctor</span>.name = name
<span class="hljs-property">@ctor</span>.klass = <span class="hljs-literal">null</span>
<span class="hljs-property">@ctor</span>.noReturn = <span class="hljs-literal">yes</span></pre></div></div>
</li>
<li id="section-94">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-94">¶</a>
</div>
<p>Instead of generating the JavaScript string directly, we build up the
equivalent syntax tree and compile that, in pieces. You can see the
constructor, property assignments, and inheritance getting built out below.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> jumpNode = <span class="hljs-property">@body</span>.jumps()
jumpNode.error <span class="hljs-string">'Class bodies cannot contain pure statements'</span>
<span class="hljs-keyword">if</span> argumentsNode = <span class="hljs-property">@body</span>.contains isLiteralArguments
argumentsNode.error <span class="hljs-string">"Class bodies shouldn't reference arguments"</span>
name = <span class="hljs-property">@determineName</span>() <span class="hljs-keyword">or</span> <span class="hljs-string">'_Class'</span>
name = <span class="hljs-string">"_<span class="hljs-subst">#{name}</span>"</span> <span class="hljs-keyword">if</span> name.reserved
lname = <span class="hljs-keyword">new</span> Literal name
func = <span class="hljs-keyword">new</span> Code [], Block.wrap [<span class="hljs-property">@body</span>]
args = []
o.classScope = func.makeScope o.scope
<span class="hljs-property">@hoistDirectivePrologue</span>()
<span class="hljs-property">@setContext</span> name
<span class="hljs-property">@walkBody</span> name, o
<span class="hljs-property">@ensureConstructor</span> name
<span class="hljs-property">@addBoundFunctions</span> o
<span class="hljs-property">@body</span>.spaced = <span class="hljs-literal">yes</span>
<span class="hljs-property">@body</span>.expressions.push lname
<span class="hljs-keyword">if</span> <span class="hljs-property">@parent</span>
superClass = <span class="hljs-keyword">new</span> Literal o.classScope.freeVariable <span class="hljs-string">'superClass'</span>, <span class="hljs-attribute">reserve</span>: <span class="hljs-literal">no</span>
<span class="hljs-property">@body</span>.expressions.unshift <span class="hljs-keyword">new</span> Extends lname, superClass
func.params.push <span class="hljs-keyword">new</span> Param superClass
args.push <span class="hljs-property">@parent</span>
<span class="hljs-property">@body</span>.expressions.unshift <span class="hljs-property">@directives</span>...
klass = <span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">new</span> Call func, args
klass = <span class="hljs-keyword">new</span> Assign <span class="hljs-property">@variable</span>, klass <span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>
klass.compileToFragments o</pre></div></div>
</li>
<li id="section-95">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-95">¶</a>
</div>
<h3 id="assign">Assign</h3>
</div>
</li>
<li id="section-96">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-96">¶</a>
</div>
<p>The <strong>Assign</strong> is used to assign a local variable to value, or to set the
property of an object — including within object literals.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Assign = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Assign</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@variable</span>, <span class="hljs-property">@value</span>, <span class="hljs-property">@context</span>, options)</span> -></span>
<span class="hljs-property">@param</span> = options <span class="hljs-keyword">and</span> options.param
<span class="hljs-property">@subpattern</span> = options <span class="hljs-keyword">and</span> options.subpattern
forbidden = (name = <span class="hljs-property">@variable</span>.unwrapAll().value) <span class="hljs-keyword">in</span> STRICT_PROSCRIBED
<span class="hljs-keyword">if</span> forbidden <span class="hljs-keyword">and</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">isnt</span> <span class="hljs-string">'object'</span>
<span class="hljs-property">@variable</span>.error <span class="hljs-string">"variable name may not be \"<span class="hljs-subst">#{name}</span>\""</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'variable'</span>, <span class="hljs-string">'value'</span>]
<span class="hljs-attribute">isStatement</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
o?.level <span class="hljs-keyword">is</span> LEVEL_TOP <span class="hljs-keyword">and</span> <span class="hljs-property">@context</span>? <span class="hljs-keyword">and</span> <span class="hljs-string">"?"</span> <span class="hljs-keyword">in</span> <span class="hljs-property">@context</span>
<span class="hljs-attribute">assigns</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
@[<span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'value'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'variable'</span>].assigns name
<span class="hljs-attribute">unfoldSoak</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
unfoldSoak o, <span class="hljs-keyword">this</span>, <span class="hljs-string">'variable'</span></pre></div></div>
</li>
<li id="section-97">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-97">¶</a>
</div>
<p>Compile an assignment, delegating to <code>compilePatternMatch</code> or
<code>compileSplice</code> if appropriate. Keep track of the name of the base object
we’ve been assigned to, for correct internal references. If the variable
has not been seen yet within the current scope, declare it.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> isValue = <span class="hljs-property">@variable</span> <span class="hljs-keyword">instanceof</span> Value
<span class="hljs-keyword">return</span> <span class="hljs-property">@compilePatternMatch</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>.isArray() <span class="hljs-keyword">or</span> <span class="hljs-property">@variable</span>.isObject()
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileSplice</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>.isSplice()
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileConditional</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'||='</span>, <span class="hljs-string">'&&='</span>, <span class="hljs-string">'?='</span>]
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileSpecialMath</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'**='</span>, <span class="hljs-string">'//='</span>, <span class="hljs-string">'%%='</span>]
<span class="hljs-keyword">if</span> <span class="hljs-property">@value</span> <span class="hljs-keyword">instanceof</span> Code
<span class="hljs-keyword">if</span> <span class="hljs-property">@value</span>.static
<span class="hljs-property">@value</span>.klass = <span class="hljs-property">@variable</span>.base
<span class="hljs-property">@value</span>.name = <span class="hljs-property">@variable</span>.properties[<span class="hljs-number">0</span>]
<span class="hljs-property">@value</span>.variable = <span class="hljs-property">@variable</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@variable</span>.properties?.length >= <span class="hljs-number">2</span>
[properties..., prototype, name] = <span class="hljs-property">@variable</span>.properties
<span class="hljs-keyword">if</span> prototype.name?.value <span class="hljs-keyword">is</span> <span class="hljs-string">'prototype'</span>
<span class="hljs-property">@value</span>.klass = <span class="hljs-keyword">new</span> Value <span class="hljs-property">@variable</span>.base, properties
<span class="hljs-property">@value</span>.name = name
<span class="hljs-property">@value</span>.variable = <span class="hljs-property">@variable</span>
<span class="hljs-keyword">unless</span> <span class="hljs-property">@context</span>
varBase = <span class="hljs-property">@variable</span>.unwrapAll()
<span class="hljs-keyword">unless</span> varBase.isAssignable()
<span class="hljs-property">@variable</span>.error <span class="hljs-string">"\"<span class="hljs-subst">#{<span class="hljs-property">@variable</span>.compile o}</span>\" cannot be assigned"</span>
<span class="hljs-keyword">unless</span> varBase.hasProperties?()
<span class="hljs-keyword">if</span> <span class="hljs-property">@param</span>
o.scope.add varBase.value, <span class="hljs-string">'var'</span>
<span class="hljs-keyword">else</span>
o.scope.find varBase.value
val = <span class="hljs-property">@value</span>.compileToFragments o, LEVEL_LIST
compiledName = <span class="hljs-property">@variable</span>.compileToFragments o, LEVEL_LIST
<span class="hljs-keyword">return</span> (compiledName.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">": "</span>), val) <span class="hljs-keyword">if</span> <span class="hljs-property">@context</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span>
answer = compiledName.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" <span class="hljs-subst">#{ <span class="hljs-property">@context</span> <span class="hljs-keyword">or</span> <span class="hljs-string">'='</span> }</span> "</span>), val
<span class="hljs-keyword">if</span> o.level <= LEVEL_LIST <span class="hljs-keyword">then</span> answer <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> answer</pre></div></div>
</li>
<li id="section-98">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-98">¶</a>
</div>
<p>Brief implementation of recursive pattern matching, when assigning array or
object literals to a value. Peeks at their properties to assign inner names.
See the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">ECMAScript Harmony Wiki</a>
for details.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compilePatternMatch</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
top = o.level <span class="hljs-keyword">is</span> LEVEL_TOP
{value} = <span class="hljs-keyword">this</span>
{objects} = <span class="hljs-property">@variable</span>.base
<span class="hljs-keyword">unless</span> olen = objects.length
code = value.compileToFragments o
<span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> o.level >= LEVEL_OP <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> code <span class="hljs-keyword">else</span> code
isObject = <span class="hljs-property">@variable</span>.isObject()
<span class="hljs-keyword">if</span> top <span class="hljs-keyword">and</span> olen <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> (obj = objects[<span class="hljs-number">0</span>]) <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Splat</pre></div></div>
</li>
<li id="section-99">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-99">¶</a>
</div>
<p>Unroll simplest cases: <code>{v} = x</code> -> <code>v = x.v</code></p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> obj <span class="hljs-keyword">instanceof</span> Assign
{<span class="hljs-attribute">variable</span>: {<span class="hljs-attribute">base</span>: idx}, <span class="hljs-attribute">value</span>: obj} = obj
<span class="hljs-keyword">else</span>
idx = <span class="hljs-keyword">if</span> isObject
<span class="hljs-keyword">if</span> obj.<span class="hljs-keyword">this</span> <span class="hljs-keyword">then</span> obj.properties[<span class="hljs-number">0</span>].name <span class="hljs-keyword">else</span> obj
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">new</span> Literal <span class="hljs-number">0</span>
acc = IDENTIFIER.test idx.unwrap().value <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>
value = <span class="hljs-keyword">new</span> Value value
value.properties.push <span class="hljs-keyword">new</span> (<span class="hljs-keyword">if</span> acc <span class="hljs-keyword">then</span> Access <span class="hljs-keyword">else</span> Index) idx
<span class="hljs-keyword">if</span> obj.unwrap().value <span class="hljs-keyword">in</span> RESERVED
obj.error <span class="hljs-string">"assignment to a reserved word: <span class="hljs-subst">#{obj.compile o}</span>"</span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Assign(obj, value, <span class="hljs-literal">null</span>, <span class="hljs-attribute">param</span>: <span class="hljs-property">@param</span>).compileToFragments o, LEVEL_TOP
vvar = value.compileToFragments o, LEVEL_LIST
vvarText = fragmentsToText vvar
assigns = []
expandedIdx = <span class="hljs-literal">false</span></pre></div></div>
</li>
<li id="section-100">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-100">¶</a>
</div>
<p>Make vvar into a simple variable if it isn’t already.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> IDENTIFIER.test(vvarText) <span class="hljs-keyword">or</span> <span class="hljs-property">@variable</span>.assigns(vvarText)
assigns.push [<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{ ref = o.scope.freeVariable <span class="hljs-string">'ref'</span> }</span> = "</span>), vvar...]
vvar = [<span class="hljs-property">@makeCode</span> ref]
vvarText = ref
<span class="hljs-keyword">for</span> obj, i <span class="hljs-keyword">in</span> objects</pre></div></div>
</li>
<li id="section-101">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-101">¶</a>
</div>
<p>A regular array pattern-match.</p>
</div>
<div class="content"><div class='highlight'><pre> idx = i
<span class="hljs-keyword">if</span> isObject
<span class="hljs-keyword">if</span> obj <span class="hljs-keyword">instanceof</span> Assign</pre></div></div>
</li>
<li id="section-102">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-102">¶</a>
</div>
<p>A regular object pattern-match.</p>
</div>
<div class="content"><div class='highlight'><pre> {<span class="hljs-attribute">variable</span>: {<span class="hljs-attribute">base</span>: idx}, <span class="hljs-attribute">value</span>: obj} = obj
<span class="hljs-keyword">else</span></pre></div></div>
</li>
<li id="section-103">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-103">¶</a>
</div>
<p>A shorthand <code>{a, b, @c} = val</code> pattern-match.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> obj.base <span class="hljs-keyword">instanceof</span> Parens
[obj, idx] = <span class="hljs-keyword">new</span> Value(obj.unwrapAll()).cacheReference o
<span class="hljs-keyword">else</span>
idx = <span class="hljs-keyword">if</span> obj.<span class="hljs-keyword">this</span> <span class="hljs-keyword">then</span> obj.properties[<span class="hljs-number">0</span>].name <span class="hljs-keyword">else</span> obj
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> expandedIdx <span class="hljs-keyword">and</span> obj <span class="hljs-keyword">instanceof</span> Splat
name = obj.name.unwrap().value
obj = obj.unwrap()
val = <span class="hljs-string">"<span class="hljs-subst">#{olen}</span> <= <span class="hljs-subst">#{vvarText}</span>.length ? <span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span>, o }</span>.call(<span class="hljs-subst">#{vvarText}</span>, <span class="hljs-subst">#{i}</span>"</span>
<span class="hljs-keyword">if</span> rest = olen - i - <span class="hljs-number">1</span>
ivar = o.scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
val += <span class="hljs-string">", <span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{vvarText}</span>.length - <span class="hljs-subst">#{rest}</span>) : (<span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{i}</span>, [])"</span>
<span class="hljs-keyword">else</span>
val += <span class="hljs-string">") : []"</span>
val = <span class="hljs-keyword">new</span> Literal val
expandedIdx = <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span>++"</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> expandedIdx <span class="hljs-keyword">and</span> obj <span class="hljs-keyword">instanceof</span> Expansion
<span class="hljs-keyword">if</span> rest = olen - i - <span class="hljs-number">1</span>
<span class="hljs-keyword">if</span> rest <span class="hljs-keyword">is</span> <span class="hljs-number">1</span>
expandedIdx = <span class="hljs-string">"<span class="hljs-subst">#{vvarText}</span>.length - 1"</span>
<span class="hljs-keyword">else</span>
ivar = o.scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
val = <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{vvarText}</span>.length - <span class="hljs-subst">#{rest}</span>"</span>
expandedIdx = <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span>++"</span>
assigns.push val.compileToFragments o, LEVEL_LIST
<span class="hljs-keyword">continue</span>
<span class="hljs-keyword">else</span>
name = obj.unwrap().value
<span class="hljs-keyword">if</span> obj <span class="hljs-keyword">instanceof</span> Splat <span class="hljs-keyword">or</span> obj <span class="hljs-keyword">instanceof</span> Expansion
obj.error <span class="hljs-string">"multiple splats/expansions are disallowed in an assignment"</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">typeof</span> idx <span class="hljs-keyword">is</span> <span class="hljs-string">'number'</span>
idx = <span class="hljs-keyword">new</span> Literal expandedIdx <span class="hljs-keyword">or</span> idx
acc = <span class="hljs-literal">no</span>
<span class="hljs-keyword">else</span>
acc = isObject <span class="hljs-keyword">and</span> IDENTIFIER.test idx.unwrap().value <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>
val = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal(vvarText), [<span class="hljs-keyword">new</span> (<span class="hljs-keyword">if</span> acc <span class="hljs-keyword">then</span> Access <span class="hljs-keyword">else</span> Index) idx]
<span class="hljs-keyword">if</span> name? <span class="hljs-keyword">and</span> name <span class="hljs-keyword">in</span> RESERVED
obj.error <span class="hljs-string">"assignment to a reserved word: <span class="hljs-subst">#{obj.compile o}</span>"</span>
assigns.push <span class="hljs-keyword">new</span> Assign(obj, val, <span class="hljs-literal">null</span>, <span class="hljs-attribute">param</span>: <span class="hljs-property">@param</span>, <span class="hljs-attribute">subpattern</span>: <span class="hljs-literal">yes</span>).compileToFragments o, LEVEL_LIST
assigns.push vvar <span class="hljs-keyword">unless</span> top <span class="hljs-keyword">or</span> <span class="hljs-property">@subpattern</span>
fragments = <span class="hljs-property">@joinFragmentArrays</span> assigns, <span class="hljs-string">', '</span>
<span class="hljs-keyword">if</span> o.level < LEVEL_LIST <span class="hljs-keyword">then</span> fragments <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> fragments</pre></div></div>
</li>
<li id="section-104">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-104">¶</a>
</div>
<p>When compiling a conditional assignment, take care to ensure that the
operands are only evaluated once, even though we have to reference them
more than once.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileConditional</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[left, right] = <span class="hljs-property">@variable</span>.cacheReference o</pre></div></div>
</li>
<li id="section-105">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-105">¶</a>
</div>
<p>Disallow conditional assignment of undefined variables.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> left.properties.length <span class="hljs-keyword">and</span> left.base <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span>
left.base.value != <span class="hljs-string">"this"</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> o.scope.check left.base.value
<span class="hljs-property">@variable</span>.error <span class="hljs-string">"the variable \"<span class="hljs-subst">#{left.base.value}</span>\" can't be assigned with <span class="hljs-subst">#{<span class="hljs-property">@context</span>}</span> because it has not been declared before"</span>
<span class="hljs-keyword">if</span> <span class="hljs-string">"?"</span> <span class="hljs-keyword">in</span> <span class="hljs-property">@context</span>
o.isExistentialEquals = <span class="hljs-literal">true</span>
<span class="hljs-keyword">new</span> If(<span class="hljs-keyword">new</span> Existence(left), right, <span class="hljs-attribute">type</span>: <span class="hljs-string">'if'</span>).addElse(<span class="hljs-keyword">new</span> Assign(right, <span class="hljs-property">@value</span>, <span class="hljs-string">'='</span>)).compileToFragments o
<span class="hljs-keyword">else</span>
fragments = <span class="hljs-keyword">new</span> Op(<span class="hljs-property">@context</span>[...-<span class="hljs-number">1</span>], left, <span class="hljs-keyword">new</span> Assign(right, <span class="hljs-property">@value</span>, <span class="hljs-string">'='</span>)).compileToFragments o
<span class="hljs-keyword">if</span> o.level <= LEVEL_LIST <span class="hljs-keyword">then</span> fragments <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> fragments</pre></div></div>
</li>
<li id="section-106">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-106">¶</a>
</div>
<p>Convert special math assignment operators like <code>a **= b</code> to the equivalent
extended form <code>a = a ** b</code> and then compiles that.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileSpecialMath</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[left, right] = <span class="hljs-property">@variable</span>.cacheReference o
<span class="hljs-keyword">new</span> Assign(left, <span class="hljs-keyword">new</span> Op(<span class="hljs-property">@context</span>[...-<span class="hljs-number">1</span>], right, <span class="hljs-property">@value</span>)).compileToFragments o</pre></div></div>
</li>
<li id="section-107">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-107">¶</a>
</div>
<p>Compile the assignment from an array splice literal, using JavaScript’s
<code>Array#splice</code> method.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileSplice</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
{<span class="hljs-attribute">range</span>: {from, to, exclusive}} = <span class="hljs-property">@variable</span>.properties.pop()
name = <span class="hljs-property">@variable</span>.compile o
<span class="hljs-keyword">if</span> from
[fromDecl, fromRef] = <span class="hljs-property">@cacheToCodeFragments</span> from.cache o, LEVEL_OP
<span class="hljs-keyword">else</span>
fromDecl = fromRef = <span class="hljs-string">'0'</span>
<span class="hljs-keyword">if</span> to
<span class="hljs-keyword">if</span> from <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> from.isSimpleNumber() <span class="hljs-keyword">and</span>
to <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> to.isSimpleNumber()
to = to.compile(o) - fromRef
to += <span class="hljs-number">1</span> <span class="hljs-keyword">unless</span> exclusive
<span class="hljs-keyword">else</span>
to = to.compile(o, LEVEL_ACCESS) + <span class="hljs-string">' - '</span> + fromRef
to += <span class="hljs-string">' + 1'</span> <span class="hljs-keyword">unless</span> exclusive
<span class="hljs-keyword">else</span>
to = <span class="hljs-string">"9e9"</span>
[valDef, valRef] = <span class="hljs-property">@value</span>.cache o, LEVEL_LIST
answer = [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"[].splice.apply(<span class="hljs-subst">#{name}</span>, [<span class="hljs-subst">#{fromDecl}</span>, <span class="hljs-subst">#{to}</span>].concat("</span>), valDef, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">")), "</span>), valRef
<span class="hljs-keyword">if</span> o.level > LEVEL_TOP <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> answer <span class="hljs-keyword">else</span> answer</pre></div></div>
</li>
<li id="section-108">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-108">¶</a>
</div>
<h3 id="code">Code</h3>
</div>
</li>
<li id="section-109">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-109">¶</a>
</div>
<p>A function definition. This is the only node that creates a new Scope.
When for the purposes of walking the contents of a function body, the Code
has no <em>children</em> — they’re within the inner scope.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Code = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Code</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(params, body, tag)</span> -></span>
<span class="hljs-property">@params</span> = params <span class="hljs-keyword">or</span> []
<span class="hljs-property">@body</span> = body <span class="hljs-keyword">or</span> <span class="hljs-keyword">new</span> Block
<span class="hljs-property">@bound</span> = tag <span class="hljs-keyword">is</span> <span class="hljs-string">'boundfunc'</span>
<span class="hljs-property">@isGenerator</span> = !!<span class="hljs-property">@body</span>.contains <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
node <span class="hljs-keyword">instanceof</span> Op <span class="hljs-keyword">and</span> node.operator <span class="hljs-keyword">in</span> [<span class="hljs-string">'yield'</span>, <span class="hljs-string">'yield*'</span>]
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'params'</span>, <span class="hljs-string">'body'</span>]
<span class="hljs-attribute">isStatement</span>:<span class="hljs-function"> -></span> !!<span class="hljs-property">@ctor</span>
<span class="hljs-attribute">jumps</span>: NO
<span class="hljs-attribute">makeScope</span>: <span class="hljs-function"><span class="hljs-params">(parentScope)</span> -></span> <span class="hljs-keyword">new</span> Scope parentScope, <span class="hljs-property">@body</span>, <span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-110">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-110">¶</a>
</div>
<p>Compilation creates a new scope unless explicitly asked to share with the
outer scope. Handles splat parameters in the parameter list by peeking at
the JavaScript <code>arguments</code> object. If the function is bound with the <code>=></code>
arrow, generates a wrapper that saves the current value of <code>this</code> through
a closure.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@bound</span> <span class="hljs-keyword">and</span> o.scope.method?.bound
<span class="hljs-property">@context</span> = o.scope.method.context</pre></div></div>
</li>
<li id="section-111">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-111">¶</a>
</div>
<p>Handle bound functions early.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> <span class="hljs-property">@bound</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@context</span>
<span class="hljs-property">@context</span> = <span class="hljs-string">'_this'</span>
wrapper = <span class="hljs-keyword">new</span> Code [<span class="hljs-keyword">new</span> Param <span class="hljs-keyword">new</span> Literal <span class="hljs-property">@context</span>], <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">this</span>]
boundfunc = <span class="hljs-keyword">new</span> Call(wrapper, [<span class="hljs-keyword">new</span> Literal <span class="hljs-string">'this'</span>])
boundfunc.updateLocationDataIfMissing <span class="hljs-property">@locationData</span>
<span class="hljs-keyword">return</span> boundfunc.compileNode(o)
o.scope = del(o, <span class="hljs-string">'classScope'</span>) <span class="hljs-keyword">or</span> <span class="hljs-property">@makeScope</span> o.scope
o.scope.shared = del(o, <span class="hljs-string">'sharedScope'</span>)
o.indent += TAB
<span class="hljs-keyword">delete</span> o.bare
<span class="hljs-keyword">delete</span> o.isExistentialEquals
params = []
exprs = []
<span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> param <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Expansion
o.scope.parameter param.asReference o
<span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> param.splat <span class="hljs-keyword">or</span> param <span class="hljs-keyword">instanceof</span> Expansion
<span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span> <span class="hljs-keyword">when</span> p <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Expansion <span class="hljs-keyword">and</span> p.name.value
o.scope.add p.name.value, <span class="hljs-string">'var'</span>, <span class="hljs-literal">yes</span>
splats = <span class="hljs-keyword">new</span> Assign <span class="hljs-keyword">new</span> Value(<span class="hljs-keyword">new</span> Arr(p.asReference o <span class="hljs-keyword">for</span> p <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span>)),
<span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'arguments'</span>
<span class="hljs-keyword">break</span>
<span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span>
<span class="hljs-keyword">if</span> param.isComplex()
val = ref = param.asReference o
val = <span class="hljs-keyword">new</span> Op <span class="hljs-string">'?'</span>, ref, param.value <span class="hljs-keyword">if</span> param.value
exprs.push <span class="hljs-keyword">new</span> Assign <span class="hljs-keyword">new</span> Value(param.name), val, <span class="hljs-string">'='</span>, <span class="hljs-attribute">param</span>: <span class="hljs-literal">yes</span>
<span class="hljs-keyword">else</span>
ref = param
<span class="hljs-keyword">if</span> param.value
lit = <span class="hljs-keyword">new</span> Literal ref.name.value + <span class="hljs-string">' == null'</span>
val = <span class="hljs-keyword">new</span> Assign <span class="hljs-keyword">new</span> Value(param.name), param.value, <span class="hljs-string">'='</span>
exprs.push <span class="hljs-keyword">new</span> If lit, val
params.push ref <span class="hljs-keyword">unless</span> splats
wasEmpty = <span class="hljs-property">@body</span>.isEmpty()
exprs.unshift splats <span class="hljs-keyword">if</span> splats
<span class="hljs-property">@body</span>.expressions.unshift exprs... <span class="hljs-keyword">if</span> exprs.length
<span class="hljs-keyword">for</span> p, i <span class="hljs-keyword">in</span> params
params[i] = p.compileToFragments o
o.scope.parameter fragmentsToText params[i]
uniqs = []
<span class="hljs-property">@eachParamName</span> <span class="hljs-function"><span class="hljs-params">(name, node)</span> -></span>
node.error <span class="hljs-string">"multiple parameters named <span class="hljs-subst">#{name}</span>"</span> <span class="hljs-keyword">if</span> name <span class="hljs-keyword">in</span> uniqs
uniqs.push name
<span class="hljs-property">@body</span>.makeReturn() <span class="hljs-keyword">unless</span> wasEmpty <span class="hljs-keyword">or</span> <span class="hljs-property">@noReturn</span>
code = <span class="hljs-string">'function'</span>
code += <span class="hljs-string">'*'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@isGenerator</span>
code += <span class="hljs-string">' '</span> + <span class="hljs-property">@name</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@ctor</span>
code += <span class="hljs-string">'('</span>
answer = [<span class="hljs-property">@makeCode</span>(code)]
<span class="hljs-keyword">for</span> p, i <span class="hljs-keyword">in</span> params
<span class="hljs-keyword">if</span> i <span class="hljs-keyword">then</span> answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">", "</span>
answer.push p...
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">') {'</span>
answer = answer.concat(<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>), <span class="hljs-property">@body</span>.compileWithDeclarations(o), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>"</span>)) <span class="hljs-keyword">unless</span> <span class="hljs-property">@body</span>.isEmpty()
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">'}'</span>
<span class="hljs-keyword">return</span> [<span class="hljs-property">@makeCode</span>(<span class="hljs-property">@tab</span>), answer...] <span class="hljs-keyword">if</span> <span class="hljs-property">@ctor</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@front</span> <span class="hljs-keyword">or</span> (o.level >= LEVEL_ACCESS) <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> answer <span class="hljs-keyword">else</span> answer
<span class="hljs-attribute">eachParamName</span>: <span class="hljs-function"><span class="hljs-params">(iterator)</span> -></span>
param.eachName iterator <span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> <span class="hljs-property">@params</span></pre></div></div>
</li>
<li id="section-112">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-112">¶</a>
</div>
<p>Short-circuit <code>traverseChildren</code> method to prevent it from crossing scope boundaries
unless <code>crossScope</code> is <code>true</code>.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">traverseChildren</span>: <span class="hljs-function"><span class="hljs-params">(crossScope, func)</span> -></span>
<span class="hljs-keyword">super</span>(crossScope, func) <span class="hljs-keyword">if</span> crossScope</pre></div></div>
</li>
<li id="section-113">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-113">¶</a>
</div>
<h3 id="param">Param</h3>
</div>
</li>
<li id="section-114">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-114">¶</a>
</div>
<p>A parameter in a function definition. Beyond a typical Javascript parameter,
these parameters can also attach themselves to the context of the function,
as well as be a splat, gathering up a group of parameters into an array.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Param = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Param</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@name</span>, <span class="hljs-property">@value</span>, <span class="hljs-property">@splat</span>)</span> -></span>
<span class="hljs-keyword">if</span> (name = <span class="hljs-property">@name</span>.unwrapAll().value) <span class="hljs-keyword">in</span> STRICT_PROSCRIBED
<span class="hljs-property">@name</span>.error <span class="hljs-string">"parameter name \"<span class="hljs-subst">#{name}</span>\" is not allowed"</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'name'</span>, <span class="hljs-string">'value'</span>]
<span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@name</span>.compileToFragments o, LEVEL_LIST
<span class="hljs-attribute">asReference</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@reference</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@reference</span>
node = <span class="hljs-property">@name</span>
<span class="hljs-keyword">if</span> node.<span class="hljs-keyword">this</span>
name = node.properties[<span class="hljs-number">0</span>].name.value
name = <span class="hljs-string">"_<span class="hljs-subst">#{name}</span>"</span> <span class="hljs-keyword">if</span> name.reserved
node = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable name
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> node.isComplex()
node = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'arg'</span>
node = <span class="hljs-keyword">new</span> Value node
node = <span class="hljs-keyword">new</span> Splat node <span class="hljs-keyword">if</span> <span class="hljs-property">@splat</span>
node.updateLocationDataIfMissing <span class="hljs-property">@locationData</span>
<span class="hljs-property">@reference</span> = node
<span class="hljs-attribute">isComplex</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@name</span>.isComplex()</pre></div></div>
</li>
<li id="section-115">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-115">¶</a>
</div>
<p>Iterates the name or names of a <code>Param</code>.
In a sense, a destructured parameter represents multiple JS parameters. This
method allows to iterate them all.
The <code>iterator</code> function will be called as <code>iterator(name, node)</code> where
<code>name</code> is the name of the parameter and <code>node</code> is the AST node corresponding
to that name.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">eachName</span>: <span class="hljs-function"><span class="hljs-params">(iterator, name = <span class="hljs-property">@name</span>)</span>-></span>
<span class="hljs-function"><span class="hljs-title">atParam</span> = <span class="hljs-params">(obj)</span> -></span> iterator <span class="hljs-string">"@<span class="hljs-subst">#{obj.properties[<span class="hljs-number">0</span>].name.value}</span>"</span>, obj</pre></div></div>
</li>
<li id="section-116">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-116">¶</a>
</div>
<ul>
<li>simple literals <code>foo</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> iterator name.value, name <span class="hljs-keyword">if</span> name <span class="hljs-keyword">instanceof</span> Literal</pre></div></div>
</li>
<li id="section-117">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-117">¶</a>
</div>
<ul>
<li>at-params <code>@foo</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> atParam name <span class="hljs-keyword">if</span> name <span class="hljs-keyword">instanceof</span> Value
<span class="hljs-keyword">for</span> obj <span class="hljs-keyword">in</span> name.objects</pre></div></div>
</li>
<li id="section-118">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-118">¶</a>
</div>
<ul>
<li>assignments within destructured parameters <code>{foo:bar}</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> obj <span class="hljs-keyword">instanceof</span> Assign
<span class="hljs-property">@eachName</span> iterator, obj.value.unwrap()</pre></div></div>
</li>
<li id="section-119">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-119">¶</a>
</div>
<ul>
<li>splats within destructured parameters <code>[xs...]</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> obj <span class="hljs-keyword">instanceof</span> Splat
node = obj.name.unwrap()
iterator node.value, node
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> obj <span class="hljs-keyword">instanceof</span> Value</pre></div></div>
</li>
<li id="section-120">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-120">¶</a>
</div>
<ul>
<li>destructured parameters within destructured parameters <code>[{a}]</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> obj.isArray() <span class="hljs-keyword">or</span> obj.isObject()
<span class="hljs-property">@eachName</span> iterator, obj.base</pre></div></div>
</li>
<li id="section-121">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-121">¶</a>
</div>
<ul>
<li>at-params within destructured parameters <code>{@foo}</code></li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> obj.<span class="hljs-keyword">this</span>
atParam obj</pre></div></div>
</li>
<li id="section-122">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-122">¶</a>
</div>
<ul>
<li>simple destructured parameters {foo}</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">else</span> iterator obj.base.value, obj.base
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> obj <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Expansion
obj.error <span class="hljs-string">"illegal parameter <span class="hljs-subst">#{obj.compile()}</span>"</span>
<span class="hljs-keyword">return</span></pre></div></div>
</li>
<li id="section-123">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-123">¶</a>
</div>
<h3 id="splat">Splat</h3>
</div>
</li>
<li id="section-124">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-124">¶</a>
</div>
<p>A splat, either as a parameter to a function, an argument to a call,
or as part of a destructuring assignment.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Splat = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Splat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'name'</span>]
<span class="hljs-attribute">isAssignable</span>: YES
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
<span class="hljs-property">@name</span> = <span class="hljs-keyword">if</span> name.compile <span class="hljs-keyword">then</span> name <span class="hljs-keyword">else</span> <span class="hljs-keyword">new</span> Literal name
<span class="hljs-attribute">assigns</span>: <span class="hljs-function"><span class="hljs-params">(name)</span> -></span>
<span class="hljs-property">@name</span>.assigns name
<span class="hljs-attribute">compileToFragments</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@name</span>.compileToFragments o
<span class="hljs-attribute">unwrap</span>:<span class="hljs-function"> -></span> <span class="hljs-property">@name</span></pre></div></div>
</li>
<li id="section-125">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-125">¶</a>
</div>
<p>Utility function that converts an arbitrary number of elements, mixed with
splats, to a proper array.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@compileSplattedArray</span>: <span class="hljs-function"><span class="hljs-params">(o, list, apply)</span> -></span>
index = -<span class="hljs-number">1</span>
<span class="hljs-keyword">continue</span> <span class="hljs-keyword">while</span> (node = list[++index]) <span class="hljs-keyword">and</span> node <span class="hljs-keyword">not</span> <span class="hljs-keyword">instanceof</span> Splat
<span class="hljs-keyword">return</span> [] <span class="hljs-keyword">if</span> index >= list.length
<span class="hljs-keyword">if</span> list.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span>
node = list[<span class="hljs-number">0</span>]
fragments = node.compileToFragments o, LEVEL_LIST
<span class="hljs-keyword">return</span> fragments <span class="hljs-keyword">if</span> apply
<span class="hljs-keyword">return</span> [].concat node.makeCode(<span class="hljs-string">"<span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span>, o }</span>.call("</span>), fragments, node.makeCode(<span class="hljs-string">")"</span>)
args = list[index..]
<span class="hljs-keyword">for</span> node, i <span class="hljs-keyword">in</span> args
compiledNode = node.compileToFragments o, LEVEL_LIST
args[i] = <span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Splat
<span class="hljs-keyword">then</span> [].concat node.makeCode(<span class="hljs-string">"<span class="hljs-subst">#{ utility <span class="hljs-string">'slice'</span>, o }</span>.call("</span>), compiledNode, node.makeCode(<span class="hljs-string">")"</span>)
<span class="hljs-keyword">else</span> [].concat node.makeCode(<span class="hljs-string">"["</span>), compiledNode, node.makeCode(<span class="hljs-string">"]"</span>)
<span class="hljs-keyword">if</span> index <span class="hljs-keyword">is</span> <span class="hljs-number">0</span>
node = list[<span class="hljs-number">0</span>]
concatPart = (node.joinFragmentArrays args[<span class="hljs-number">1.</span>.], <span class="hljs-string">', '</span>)
<span class="hljs-keyword">return</span> args[<span class="hljs-number">0</span>].concat node.makeCode(<span class="hljs-string">".concat("</span>), concatPart, node.makeCode(<span class="hljs-string">")"</span>)
base = (node.compileToFragments o, LEVEL_LIST <span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> list[...index])
base = list[<span class="hljs-number">0</span>].joinFragmentArrays base, <span class="hljs-string">', '</span>
concatPart = list[index].joinFragmentArrays args, <span class="hljs-string">', '</span>
[..., last] = list
[].concat list[<span class="hljs-number">0</span>].makeCode(<span class="hljs-string">"["</span>), base, list[index].makeCode(<span class="hljs-string">"].concat("</span>), concatPart, last.makeCode(<span class="hljs-string">")"</span>)</pre></div></div>
</li>
<li id="section-126">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-126">¶</a>
</div>
<h3 id="expansion">Expansion</h3>
</div>
</li>
<li id="section-127">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-127">¶</a>
</div>
<p>Used to skip values inside an array destructuring (pattern matching) or
parameter list.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Expansion = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Expansion</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">isComplex</span>: NO
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@error</span> <span class="hljs-string">'Expansion must be used inside a destructuring assignment or parameter list'</span>
<span class="hljs-attribute">asReference</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">eachName</span>: <span class="hljs-function"><span class="hljs-params">(iterator)</span> -></span></pre></div></div>
</li>
<li id="section-128">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-128">¶</a>
</div>
<h3 id="while">While</h3>
</div>
</li>
<li id="section-129">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-129">¶</a>
</div>
<p>A while loop, the only sort of low-level loop exposed by CoffeeScript. From
it, all other loops can be manufactured. Useful in cases where you need more
flexibility or more speed than a comprehension can provide.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.While = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">While</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(condition, options)</span> -></span>
<span class="hljs-property">@condition</span> = <span class="hljs-keyword">if</span> options?.invert <span class="hljs-keyword">then</span> condition.invert() <span class="hljs-keyword">else</span> condition
<span class="hljs-property">@guard</span> = options?.guard
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'condition'</span>, <span class="hljs-string">'guard'</span>, <span class="hljs-string">'body'</span>]
<span class="hljs-attribute">isStatement</span>: YES
<span class="hljs-attribute">makeReturn</span>: <span class="hljs-function"><span class="hljs-params">(res)</span> -></span>
<span class="hljs-keyword">if</span> res
<span class="hljs-keyword">super</span>
<span class="hljs-keyword">else</span>
<span class="hljs-property">@returns</span> = <span class="hljs-keyword">not</span> <span class="hljs-property">@jumps</span> <span class="hljs-attribute">loop</span>: <span class="hljs-literal">yes</span>
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">addBody</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@body</span>)</span> -></span>
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">jumps</span>:<span class="hljs-function"> -></span>
{expressions} = <span class="hljs-property">@body</span>
<span class="hljs-keyword">return</span> <span class="hljs-literal">no</span> <span class="hljs-keyword">unless</span> expressions.length
<span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> expressions
<span class="hljs-keyword">return</span> jumpNode <span class="hljs-keyword">if</span> jumpNode = node.jumps <span class="hljs-attribute">loop</span>: <span class="hljs-literal">yes</span>
<span class="hljs-literal">no</span></pre></div></div>
</li>
<li id="section-130">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-130">¶</a>
</div>
<p>The main difference from a JavaScript <em>while</em> is that the CoffeeScript
<em>while</em> can be used as a part of a larger expression — while loops may
return an array containing the computed result of each iteration.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
o.indent += TAB
set = <span class="hljs-string">''</span>
{body} = <span class="hljs-keyword">this</span>
<span class="hljs-keyword">if</span> body.isEmpty()
body = <span class="hljs-property">@makeCode</span> <span class="hljs-string">''</span>
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@returns</span>
body.makeReturn rvar = o.scope.freeVariable <span class="hljs-string">'results'</span>
set = <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{rvar}</span> = [];\n"</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@guard</span>
<span class="hljs-keyword">if</span> body.expressions.length > <span class="hljs-number">1</span>
body.expressions.unshift <span class="hljs-keyword">new</span> If (<span class="hljs-keyword">new</span> Parens <span class="hljs-property">@guard</span>).invert(), <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"continue"</span>
<span class="hljs-keyword">else</span>
body = Block.wrap [<span class="hljs-keyword">new</span> If <span class="hljs-property">@guard</span>, body] <span class="hljs-keyword">if</span> <span class="hljs-property">@guard</span>
body = [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>), (body.compileToFragments o, LEVEL_TOP), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>"</span>)
answer = [].concat <span class="hljs-property">@makeCode</span>(set + <span class="hljs-property">@tab</span> + <span class="hljs-string">"while ("</span>), <span class="hljs-property">@condition</span>.compileToFragments(o, LEVEL_PAREN),
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">") {"</span>), body, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"}"</span>)
<span class="hljs-keyword">if</span> <span class="hljs-property">@returns</span>
answer.push <span class="hljs-property">@makeCode</span> <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>return <span class="hljs-subst">#{rvar}</span>;"</span>
answer</pre></div></div>
</li>
<li id="section-131">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-131">¶</a>
</div>
<h3 id="op">Op</h3>
</div>
</li>
<li id="section-132">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-132">¶</a>
</div>
<p>Simple Arithmetic and logical operations. Performs some conversion from
CoffeeScript operations into their JavaScript equivalents.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Op = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Op</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(op, first, second, flip )</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> In first, second <span class="hljs-keyword">if</span> op <span class="hljs-keyword">is</span> <span class="hljs-string">'in'</span>
<span class="hljs-keyword">if</span> op <span class="hljs-keyword">is</span> <span class="hljs-string">'do'</span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@generateDo</span> first
<span class="hljs-keyword">if</span> op <span class="hljs-keyword">is</span> <span class="hljs-string">'new'</span>
<span class="hljs-keyword">return</span> first.newInstance() <span class="hljs-keyword">if</span> first <span class="hljs-keyword">instanceof</span> Call <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> first.<span class="hljs-keyword">do</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> first.isNew
first = <span class="hljs-keyword">new</span> Parens first <span class="hljs-keyword">if</span> first <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span> first.bound <span class="hljs-keyword">or</span> first.<span class="hljs-keyword">do</span>
<span class="hljs-property">@operator</span> = CONVERSIONS[op] <span class="hljs-keyword">or</span> op
<span class="hljs-property">@first</span> = first
<span class="hljs-property">@second</span> = second
<span class="hljs-property">@flip</span> = !!flip
<span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-133">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-133">¶</a>
</div>
<p>The map of conversions from CoffeeScript to JavaScript symbols.</p>
</div>
<div class="content"><div class='highlight'><pre> CONVERSIONS =
<span class="hljs-string">'=='</span>: <span class="hljs-string">'==='</span>
<span class="hljs-string">'!='</span>: <span class="hljs-string">'!=='</span>
<span class="hljs-string">'of'</span>: <span class="hljs-string">'in'</span>
<span class="hljs-string">'yieldfrom'</span>: <span class="hljs-string">'yield*'</span></pre></div></div>
</li>
<li id="section-134">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-134">¶</a>
</div>
<p>The map of invertible operators.</p>
</div>
<div class="content"><div class='highlight'><pre> INVERSIONS =
<span class="hljs-string">'!=='</span>: <span class="hljs-string">'==='</span>
<span class="hljs-string">'==='</span>: <span class="hljs-string">'!=='</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'first'</span>, <span class="hljs-string">'second'</span>]
<span class="hljs-attribute">isSimpleNumber</span>: NO
<span class="hljs-attribute">isYield</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'yield'</span>, <span class="hljs-string">'yield*'</span>]
<span class="hljs-attribute">isYieldReturn</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@isYield</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Return
<span class="hljs-attribute">isUnary</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">not</span> <span class="hljs-property">@second</span>
<span class="hljs-attribute">isComplex</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">not</span> (<span class="hljs-property">@isUnary</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'+'</span>, <span class="hljs-string">'-'</span>] <span class="hljs-keyword">and</span>
<span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.isSimpleNumber())</pre></div></div>
</li>
<li id="section-135">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-135">¶</a>
</div>
<p>Am I capable of
<a href="http://docs.python.org/reference/expressions.html#notin">Python-style comparison chaining</a>?</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">isChainable</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'<'</span>, <span class="hljs-string">'>'</span>, <span class="hljs-string">'>='</span>, <span class="hljs-string">'<='</span>, <span class="hljs-string">'==='</span>, <span class="hljs-string">'!=='</span>]
<span class="hljs-attribute">invert</span>:<span class="hljs-function"> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@isChainable</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.isChainable()
allInvertable = <span class="hljs-literal">yes</span>
curr = <span class="hljs-keyword">this</span>
<span class="hljs-keyword">while</span> curr <span class="hljs-keyword">and</span> curr.operator
allInvertable <span class="hljs-keyword">and</span>= (curr.operator <span class="hljs-keyword">of</span> INVERSIONS)
curr = curr.first
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Parens(<span class="hljs-keyword">this</span>).invert() <span class="hljs-keyword">unless</span> allInvertable
curr = <span class="hljs-keyword">this</span>
<span class="hljs-keyword">while</span> curr <span class="hljs-keyword">and</span> curr.operator
curr.invert = !curr.invert
curr.operator = INVERSIONS[curr.operator]
curr = curr.first
<span class="hljs-keyword">this</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> op = INVERSIONS[<span class="hljs-property">@operator</span>]
<span class="hljs-property">@operator</span> = op
<span class="hljs-keyword">if</span> <span class="hljs-property">@first</span>.unwrap() <span class="hljs-keyword">instanceof</span> Op
<span class="hljs-property">@first</span>.invert()
<span class="hljs-keyword">this</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@second</span>
<span class="hljs-keyword">new</span> Parens(<span class="hljs-keyword">this</span>).invert()
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'!'</span> <span class="hljs-keyword">and</span> (fst = <span class="hljs-property">@first</span>.unwrap()) <span class="hljs-keyword">instanceof</span> Op <span class="hljs-keyword">and</span>
fst.operator <span class="hljs-keyword">in</span> [<span class="hljs-string">'!'</span>, <span class="hljs-string">'in'</span>, <span class="hljs-string">'instanceof'</span>]
fst
<span class="hljs-keyword">else</span>
<span class="hljs-keyword">new</span> Op <span class="hljs-string">'!'</span>, <span class="hljs-keyword">this</span>
<span class="hljs-attribute">unfoldSoak</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'++'</span>, <span class="hljs-string">'--'</span>, <span class="hljs-string">'delete'</span>] <span class="hljs-keyword">and</span> unfoldSoak o, <span class="hljs-keyword">this</span>, <span class="hljs-string">'first'</span>
<span class="hljs-attribute">generateDo</span>: <span class="hljs-function"><span class="hljs-params">(exp)</span> -></span>
passedParams = []
func = <span class="hljs-keyword">if</span> exp <span class="hljs-keyword">instanceof</span> Assign <span class="hljs-keyword">and</span> (ref = exp.value.unwrap()) <span class="hljs-keyword">instanceof</span> Code
ref
<span class="hljs-keyword">else</span>
exp
<span class="hljs-keyword">for</span> param <span class="hljs-keyword">in</span> func.params <span class="hljs-keyword">or</span> []
<span class="hljs-keyword">if</span> param.value
passedParams.push param.value
<span class="hljs-keyword">delete</span> param.value
<span class="hljs-keyword">else</span>
passedParams.push param
call = <span class="hljs-keyword">new</span> Call exp, passedParams
call.<span class="hljs-keyword">do</span> = <span class="hljs-literal">yes</span>
call
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
isChain = <span class="hljs-property">@isChainable</span>() <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.isChainable()</pre></div></div>
</li>
<li id="section-136">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-136">¶</a>
</div>
<p>In chains, there’s no need to wrap bare obj literals in parens,
as the chained expression is wrapped.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-property">@first</span>.front = <span class="hljs-property">@front</span> <span class="hljs-keyword">unless</span> isChain
<span class="hljs-keyword">if</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">is</span> <span class="hljs-string">'delete'</span> <span class="hljs-keyword">and</span> o.scope.check(<span class="hljs-property">@first</span>.unwrapAll().value)
<span class="hljs-property">@error</span> <span class="hljs-string">'delete operand may not be argument or var'</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@operator</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">'--'</span>, <span class="hljs-string">'++'</span>] <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.unwrapAll().value <span class="hljs-keyword">in</span> STRICT_PROSCRIBED
<span class="hljs-property">@error</span> <span class="hljs-string">"cannot increment/decrement \"<span class="hljs-subst">#{<span class="hljs-property">@first</span>.unwrapAll().value}</span>\""</span>
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileYield</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@isYield</span>()
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileUnary</span> o <span class="hljs-keyword">if</span> <span class="hljs-property">@isUnary</span>()
<span class="hljs-keyword">return</span> <span class="hljs-property">@compileChain</span> o <span class="hljs-keyword">if</span> isChain
<span class="hljs-keyword">switch</span> <span class="hljs-property">@operator</span>
<span class="hljs-keyword">when</span> <span class="hljs-string">'?'</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@compileExistence</span> o
<span class="hljs-keyword">when</span> <span class="hljs-string">'**'</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@compilePower</span> o
<span class="hljs-keyword">when</span> <span class="hljs-string">'//'</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@compileFloorDivision</span> o
<span class="hljs-keyword">when</span> <span class="hljs-string">'%%'</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@compileModulo</span> o
<span class="hljs-keyword">else</span>
lhs = <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_OP
rhs = <span class="hljs-property">@second</span>.compileToFragments o, LEVEL_OP
answer = [].concat lhs, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" <span class="hljs-subst">#{<span class="hljs-property">@operator</span>}</span> "</span>), rhs
<span class="hljs-keyword">if</span> o.level <= LEVEL_OP <span class="hljs-keyword">then</span> answer <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> answer</pre></div></div>
</li>
<li id="section-137">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-137">¶</a>
</div>
<p>Mimic Python’s chained comparisons when multiple comparison operators are
used sequentially. For example:</p>
<pre><code>bin/coffee -e <span class="hljs-string">'console.log 50 < 65 > 10'</span>
<span class="hljs-literal">true</span>
</code></pre>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileChain</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[<span class="hljs-property">@first</span>.second, shared] = <span class="hljs-property">@first</span>.second.cache o
fst = <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_OP
fragments = fst.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" <span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@invert</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'&&'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'||'</span>}</span> "</span>),
(shared.compileToFragments o), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" <span class="hljs-subst">#{<span class="hljs-property">@operator</span>}</span> "</span>), (<span class="hljs-property">@second</span>.compileToFragments o, LEVEL_OP)
<span class="hljs-property">@wrapInBraces</span> fragments</pre></div></div>
</li>
<li id="section-138">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-138">¶</a>
</div>
<p>Keep reference to the left expression, unless this an existential assignment</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileExistence</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@first</span>.isComplex()
ref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'ref'</span>
fst = <span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">new</span> Assign ref, <span class="hljs-property">@first</span>
<span class="hljs-keyword">else</span>
fst = <span class="hljs-property">@first</span>
ref = fst
<span class="hljs-keyword">new</span> If(<span class="hljs-keyword">new</span> Existence(fst), ref, <span class="hljs-attribute">type</span>: <span class="hljs-string">'if'</span>).addElse(<span class="hljs-property">@second</span>).compileToFragments o</pre></div></div>
</li>
<li id="section-139">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-139">¶</a>
</div>
<p>Compile a unary <strong>Op</strong>.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileUnary</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
parts = []
op = <span class="hljs-property">@operator</span>
parts.push [<span class="hljs-property">@makeCode</span> op]
<span class="hljs-keyword">if</span> op <span class="hljs-keyword">is</span> <span class="hljs-string">'!'</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Existence
<span class="hljs-property">@first</span>.negated = <span class="hljs-keyword">not</span> <span class="hljs-property">@first</span>.negated
<span class="hljs-keyword">return</span> <span class="hljs-property">@first</span>.compileToFragments o
<span class="hljs-keyword">if</span> o.level >= LEVEL_ACCESS
<span class="hljs-keyword">return</span> (<span class="hljs-keyword">new</span> Parens <span class="hljs-keyword">this</span>).compileToFragments o
plusMinus = op <span class="hljs-keyword">in</span> [<span class="hljs-string">'+'</span>, <span class="hljs-string">'-'</span>]
parts.push [<span class="hljs-property">@makeCode</span>(<span class="hljs-string">' '</span>)] <span class="hljs-keyword">if</span> op <span class="hljs-keyword">in</span> [<span class="hljs-string">'new'</span>, <span class="hljs-string">'typeof'</span>, <span class="hljs-string">'delete'</span>] <span class="hljs-keyword">or</span>
plusMinus <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Op <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.operator <span class="hljs-keyword">is</span> op
<span class="hljs-keyword">if</span> (plusMinus <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Op) <span class="hljs-keyword">or</span> (op <span class="hljs-keyword">is</span> <span class="hljs-string">'new'</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@first</span>.isStatement o)
<span class="hljs-property">@first</span> = <span class="hljs-keyword">new</span> Parens <span class="hljs-property">@first</span>
parts.push <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_OP
parts.reverse() <span class="hljs-keyword">if</span> <span class="hljs-property">@flip</span>
<span class="hljs-property">@joinFragmentArrays</span> parts, <span class="hljs-string">''</span>
<span class="hljs-attribute">compileYield</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
parts = []
op = <span class="hljs-property">@operator</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> o.scope.parent?
<span class="hljs-property">@error</span> <span class="hljs-string">'yield statements must occur within a function generator.'</span>
<span class="hljs-keyword">if</span> <span class="hljs-string">'expression'</span> <span class="hljs-keyword">in</span> Object.keys(<span class="hljs-property">@first</span>) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> (<span class="hljs-property">@first</span> <span class="hljs-keyword">instanceof</span> Throw)
<span class="hljs-keyword">if</span> <span class="hljs-property">@isYieldReturn</span>()
parts.push <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_TOP
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@first</span>.expression?
parts.push <span class="hljs-property">@first</span>.expression.compileToFragments o, LEVEL_OP
<span class="hljs-keyword">else</span>
parts.push [<span class="hljs-property">@makeCode</span> <span class="hljs-string">"(<span class="hljs-subst">#{op}</span> "</span>]
parts.push <span class="hljs-property">@first</span>.compileToFragments o, LEVEL_OP
parts.push [<span class="hljs-property">@makeCode</span> <span class="hljs-string">")"</span>]
<span class="hljs-property">@joinFragmentArrays</span> parts, <span class="hljs-string">''</span>
<span class="hljs-attribute">compilePower</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span></pre></div></div>
</li>
<li id="section-140">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-140">¶</a>
</div>
<p>Make a Math.pow call</p>
</div>
<div class="content"><div class='highlight'><pre> pow = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal(<span class="hljs-string">'Math'</span>), [<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'pow'</span>]
<span class="hljs-keyword">new</span> Call(pow, [<span class="hljs-property">@first</span>, <span class="hljs-property">@second</span>]).compileToFragments o
<span class="hljs-attribute">compileFloorDivision</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
floor = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal(<span class="hljs-string">'Math'</span>), [<span class="hljs-keyword">new</span> Access <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'floor'</span>]
div = <span class="hljs-keyword">new</span> Op <span class="hljs-string">'/'</span>, <span class="hljs-property">@first</span>, <span class="hljs-property">@second</span>
<span class="hljs-keyword">new</span> Call(floor, [div]).compileToFragments o
<span class="hljs-attribute">compileModulo</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
mod = <span class="hljs-keyword">new</span> Value <span class="hljs-keyword">new</span> Literal utility <span class="hljs-string">'modulo'</span>, o
<span class="hljs-keyword">new</span> Call(mod, [<span class="hljs-property">@first</span>, <span class="hljs-property">@second</span>]).compileToFragments o
<span class="hljs-attribute">toString</span>: <span class="hljs-function"><span class="hljs-params">(idt)</span> -></span>
<span class="hljs-keyword">super</span> idt, <span class="hljs-property">@constructor</span>.name + <span class="hljs-string">' '</span> + <span class="hljs-property">@operator</span></pre></div></div>
</li>
<li id="section-141">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-141">¶</a>
</div>
<h3 id="in">In</h3>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.In = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">In</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@object</span>, <span class="hljs-property">@array</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'object'</span>, <span class="hljs-string">'array'</span>]
<span class="hljs-attribute">invert</span>: NEGATE
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@array</span> <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> <span class="hljs-property">@array</span>.isArray() <span class="hljs-keyword">and</span> <span class="hljs-property">@array</span>.base.objects.length
<span class="hljs-keyword">for</span> obj <span class="hljs-keyword">in</span> <span class="hljs-property">@array</span>.base.objects <span class="hljs-keyword">when</span> obj <span class="hljs-keyword">instanceof</span> Splat
hasSplat = <span class="hljs-literal">yes</span>
<span class="hljs-keyword">break</span></pre></div></div>
</li>
<li id="section-142">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-142">¶</a>
</div>
<p><code>compileOrTest</code> only if we have an array literal with no splats</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-property">@compileOrTest</span> o <span class="hljs-keyword">unless</span> hasSplat
<span class="hljs-property">@compileLoopTest</span> o
<span class="hljs-attribute">compileOrTest</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[sub, ref] = <span class="hljs-property">@object</span>.cache o, LEVEL_OP
[cmp, cnj] = <span class="hljs-keyword">if</span> <span class="hljs-property">@negated</span> <span class="hljs-keyword">then</span> [<span class="hljs-string">' !== '</span>, <span class="hljs-string">' && '</span>] <span class="hljs-keyword">else</span> [<span class="hljs-string">' === '</span>, <span class="hljs-string">' || '</span>]
tests = []
<span class="hljs-keyword">for</span> item, i <span class="hljs-keyword">in</span> <span class="hljs-property">@array</span>.base.objects
<span class="hljs-keyword">if</span> i <span class="hljs-keyword">then</span> tests.push <span class="hljs-property">@makeCode</span> cnj
tests = tests.concat (<span class="hljs-keyword">if</span> i <span class="hljs-keyword">then</span> ref <span class="hljs-keyword">else</span> sub), <span class="hljs-property">@makeCode</span>(cmp), item.compileToFragments(o, LEVEL_ACCESS)
<span class="hljs-keyword">if</span> o.level < LEVEL_OP <span class="hljs-keyword">then</span> tests <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> tests
<span class="hljs-attribute">compileLoopTest</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[sub, ref] = <span class="hljs-property">@object</span>.cache o, LEVEL_LIST
fragments = [].concat <span class="hljs-property">@makeCode</span>(utility(<span class="hljs-string">'indexOf'</span>, o) + <span class="hljs-string">".call("</span>), <span class="hljs-property">@array</span>.compileToFragments(o, LEVEL_LIST),
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">", "</span>), ref, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">") "</span> + <span class="hljs-keyword">if</span> <span class="hljs-property">@negated</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'< 0'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'>= 0'</span>)
<span class="hljs-keyword">return</span> fragments <span class="hljs-keyword">if</span> fragmentsToText(sub) <span class="hljs-keyword">is</span> fragmentsToText(ref)
fragments = sub.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">', '</span>), fragments
<span class="hljs-keyword">if</span> o.level < LEVEL_LIST <span class="hljs-keyword">then</span> fragments <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> fragments
<span class="hljs-attribute">toString</span>: <span class="hljs-function"><span class="hljs-params">(idt)</span> -></span>
<span class="hljs-keyword">super</span> idt, <span class="hljs-property">@constructor</span>.name + <span class="hljs-keyword">if</span> <span class="hljs-property">@negated</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'!'</span> <span class="hljs-keyword">else</span> <span class="hljs-string">''</span></pre></div></div>
</li>
<li id="section-143">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-143">¶</a>
</div>
<h3 id="try">Try</h3>
</div>
</li>
<li id="section-144">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-144">¶</a>
</div>
<p>A classic <em>try/catch/finally</em> block.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Try = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Try</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@attempt</span>, <span class="hljs-property">@errorVariable</span>, <span class="hljs-property">@recovery</span>, <span class="hljs-property">@ensure</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'attempt'</span>, <span class="hljs-string">'recovery'</span>, <span class="hljs-string">'ensure'</span>]
<span class="hljs-attribute">isStatement</span>: YES
<span class="hljs-attribute">jumps</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span> <span class="hljs-property">@attempt</span>.jumps(o) <span class="hljs-keyword">or</span> <span class="hljs-property">@recovery</span>?.jumps(o)
<span class="hljs-attribute">makeReturn</span>: <span class="hljs-function"><span class="hljs-params">(res)</span> -></span>
<span class="hljs-property">@attempt</span> = <span class="hljs-property">@attempt</span> .makeReturn res <span class="hljs-keyword">if</span> <span class="hljs-property">@attempt</span>
<span class="hljs-property">@recovery</span> = <span class="hljs-property">@recovery</span>.makeReturn res <span class="hljs-keyword">if</span> <span class="hljs-property">@recovery</span>
<span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-145">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-145">¶</a>
</div>
<p>Compilation is more or less as you would expect — the <em>finally</em> clause
is optional, the <em>catch</em> is not.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
o.indent += TAB
tryPart = <span class="hljs-property">@attempt</span>.compileToFragments o, LEVEL_TOP
catchPart = <span class="hljs-keyword">if</span> <span class="hljs-property">@recovery</span>
placeholder = <span class="hljs-keyword">new</span> Literal <span class="hljs-string">'_error'</span>
<span class="hljs-property">@recovery</span>.unshift <span class="hljs-keyword">new</span> Assign <span class="hljs-property">@errorVariable</span>, placeholder <span class="hljs-keyword">if</span> <span class="hljs-property">@errorVariable</span>
[].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" catch ("</span>), placeholder.compileToFragments(o), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">") {\n"</span>),
<span class="hljs-property">@recovery</span>.compileToFragments(o, LEVEL_TOP), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span>)
<span class="hljs-keyword">else</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@ensure</span> <span class="hljs-keyword">or</span> <span class="hljs-property">@recovery</span>
[<span class="hljs-property">@makeCode</span>(<span class="hljs-string">' catch (_error) {}'</span>)]
<span class="hljs-keyword">else</span>
[]
ensurePart = <span class="hljs-keyword">if</span> <span class="hljs-property">@ensure</span> <span class="hljs-keyword">then</span> ([].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" finally {\n"</span>), <span class="hljs-property">@ensure</span>.compileToFragments(o, LEVEL_TOP),
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span>)) <span class="hljs-keyword">else</span> []
[].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>try {\n"</span>),
tryPart,
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span>), catchPart, ensurePart</pre></div></div>
</li>
<li id="section-146">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-146">¶</a>
</div>
<h3 id="throw">Throw</h3>
</div>
</li>
<li id="section-147">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-147">¶</a>
</div>
<p>Simple node to throw an exception.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Throw = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Throw</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@expression</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expression'</span>]
<span class="hljs-attribute">isStatement</span>: YES
<span class="hljs-attribute">jumps</span>: NO</pre></div></div>
</li>
<li id="section-148">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-148">¶</a>
</div>
<p>A <strong>Throw</strong> is already a return, of sorts…</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">makeReturn</span>: THIS
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
[].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-property">@tab</span> + <span class="hljs-string">"throw "</span>), <span class="hljs-property">@expression</span>.compileToFragments(o), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">";"</span>)</pre></div></div>
</li>
<li id="section-149">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-149">¶</a>
</div>
<h3 id="existence">Existence</h3>
</div>
</li>
<li id="section-150">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-150">¶</a>
</div>
<p>Checks a variable for existence — not <em>null</em> and not <em>undefined</em>. This is
similar to <code>.nil?</code> in Ruby, and avoids having to consult a JavaScript truth
table.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Existence = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Existence</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@expression</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'expression'</span>]
<span class="hljs-attribute">invert</span>: NEGATE
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-property">@expression</span>.front = <span class="hljs-property">@front</span>
code = <span class="hljs-property">@expression</span>.compile o, LEVEL_OP
<span class="hljs-keyword">if</span> IDENTIFIER.test(code) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> o.scope.check code
[cmp, cnj] = <span class="hljs-keyword">if</span> <span class="hljs-property">@negated</span> <span class="hljs-keyword">then</span> [<span class="hljs-string">'==='</span>, <span class="hljs-string">'||'</span>] <span class="hljs-keyword">else</span> [<span class="hljs-string">'!=='</span>, <span class="hljs-string">'&&'</span>]
code = <span class="hljs-string">"typeof <span class="hljs-subst">#{code}</span> <span class="hljs-subst">#{cmp}</span> \"undefined\" <span class="hljs-subst">#{cnj}</span> <span class="hljs-subst">#{code}</span> <span class="hljs-subst">#{cmp}</span> null"</span>
<span class="hljs-keyword">else</span></pre></div></div>
</li>
<li id="section-151">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-151">¶</a>
</div>
<p>do not use strict equality here; it will break existing code</p>
</div>
<div class="content"><div class='highlight'><pre> code = <span class="hljs-string">"<span class="hljs-subst">#{code}</span> <span class="hljs-subst">#{<span class="hljs-keyword">if</span> <span class="hljs-property">@negated</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'=='</span> <span class="hljs-keyword">else</span> <span class="hljs-string">'!='</span>}</span> null"</span>
[<span class="hljs-property">@makeCode</span>(<span class="hljs-keyword">if</span> o.level <= LEVEL_COND <span class="hljs-keyword">then</span> code <span class="hljs-keyword">else</span> <span class="hljs-string">"(<span class="hljs-subst">#{code}</span>)"</span>)]</pre></div></div>
</li>
<li id="section-152">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-152">¶</a>
</div>
<h3 id="parens">Parens</h3>
</div>
</li>
<li id="section-153">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-153">¶</a>
</div>
<p>An extra set of parentheses, specified explicitly in the source. At one time
we tried to clean up the results by detecting and removing redundant
parentheses, but no longer — you can put in as many as you please.</p>
<p>Parentheses are a good way to force any statement to become an expression.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Parens = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Parens</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@body</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'body'</span>]
unwrap :<span class="hljs-function"> -></span> <span class="hljs-property">@body</span>
isComplex :<span class="hljs-function"> -></span> <span class="hljs-property">@body</span>.isComplex()
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
expr = <span class="hljs-property">@body</span>.unwrap()
<span class="hljs-keyword">if</span> expr <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> expr.isAtomic()
expr.front = <span class="hljs-property">@front</span>
<span class="hljs-keyword">return</span> expr.compileToFragments o
fragments = expr.compileToFragments o, LEVEL_PAREN
bare = o.level < LEVEL_OP <span class="hljs-keyword">and</span> (expr <span class="hljs-keyword">instanceof</span> Op <span class="hljs-keyword">or</span> expr <span class="hljs-keyword">instanceof</span> Call <span class="hljs-keyword">or</span>
(expr <span class="hljs-keyword">instanceof</span> For <span class="hljs-keyword">and</span> expr.returns))
<span class="hljs-keyword">if</span> bare <span class="hljs-keyword">then</span> fragments <span class="hljs-keyword">else</span> <span class="hljs-property">@wrapInBraces</span> fragments</pre></div></div>
</li>
<li id="section-154">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-154">¶</a>
</div>
<h3 id="for">For</h3>
</div>
</li>
<li id="section-155">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-155">¶</a>
</div>
<p>CoffeeScript’s replacement for the <em>for</em> loop is our array and object
comprehensions, that compile into <em>for</em> loops here. They also act as an
expression, able to return the result of each filtered iteration.</p>
<p>Unlike Python array comprehensions, they can be multi-line, and you can pass
the current index of the loop as a second parameter. Unlike Ruby blocks,
you can map and filter in a single pass.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.For = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">For</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">While</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(body, source)</span> -></span>
{<span class="hljs-property">@source</span>, <span class="hljs-property">@guard</span>, <span class="hljs-property">@step</span>, <span class="hljs-property">@name</span>, <span class="hljs-property">@index</span>} = source
<span class="hljs-property">@body</span> = Block.wrap [body]
<span class="hljs-property">@own</span> = !!source.own
<span class="hljs-property">@object</span> = !!source.object
[<span class="hljs-property">@name</span>, <span class="hljs-property">@index</span>] = [<span class="hljs-property">@index</span>, <span class="hljs-property">@name</span>] <span class="hljs-keyword">if</span> <span class="hljs-property">@object</span>
<span class="hljs-property">@index</span>.error <span class="hljs-string">'index cannot be a pattern matching expression'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@index</span> <span class="hljs-keyword">instanceof</span> Value
<span class="hljs-property">@range</span> = <span class="hljs-property">@source</span> <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span> <span class="hljs-property">@source</span>.base <span class="hljs-keyword">instanceof</span> Range <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@source</span>.properties.length
<span class="hljs-property">@pattern</span> = <span class="hljs-property">@name</span> <span class="hljs-keyword">instanceof</span> Value
<span class="hljs-property">@index</span>.error <span class="hljs-string">'indexes do not apply to range loops'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@range</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@index</span>
<span class="hljs-property">@name</span>.error <span class="hljs-string">'cannot pattern match over range loops'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@range</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@pattern</span>
<span class="hljs-property">@name</span>.error <span class="hljs-string">'cannot use own with for-in'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@own</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@object</span>
<span class="hljs-property">@returns</span> = <span class="hljs-literal">false</span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'body'</span>, <span class="hljs-string">'source'</span>, <span class="hljs-string">'guard'</span>, <span class="hljs-string">'step'</span>]</pre></div></div>
</li>
<li id="section-156">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-156">¶</a>
</div>
<p>Welcome to the hairiest method in all of CoffeeScript. Handles the inner
loop, filtering, stepping, and result saving for array, object, and range
comprehensions. Some of the generated code can be shared in common, and
some cannot.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
body = Block.wrap [<span class="hljs-property">@body</span>]
[..., last] = body.expressions
<span class="hljs-property">@returns</span> = <span class="hljs-literal">no</span> <span class="hljs-keyword">if</span> last?.jumps() <span class="hljs-keyword">instanceof</span> Return
source = <span class="hljs-keyword">if</span> <span class="hljs-property">@range</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@source</span>.base <span class="hljs-keyword">else</span> <span class="hljs-property">@source</span>
scope = o.scope
name = <span class="hljs-property">@name</span> <span class="hljs-keyword">and</span> (<span class="hljs-property">@name</span>.compile o, LEVEL_LIST) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@pattern</span>
index = <span class="hljs-property">@index</span> <span class="hljs-keyword">and</span> (<span class="hljs-property">@index</span>.compile o, LEVEL_LIST)
scope.find(name) <span class="hljs-keyword">if</span> name <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@pattern</span>
scope.find(index) <span class="hljs-keyword">if</span> index
rvar = scope.freeVariable <span class="hljs-string">'results'</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@returns</span>
ivar = (<span class="hljs-property">@object</span> <span class="hljs-keyword">and</span> index) <span class="hljs-keyword">or</span> scope.freeVariable <span class="hljs-string">'i'</span>, <span class="hljs-attribute">single</span>: <span class="hljs-literal">true</span>
kvar = (<span class="hljs-property">@range</span> <span class="hljs-keyword">and</span> name) <span class="hljs-keyword">or</span> index <span class="hljs-keyword">or</span> ivar
kvarAssign = <span class="hljs-keyword">if</span> kvar <span class="hljs-keyword">isnt</span> ivar <span class="hljs-keyword">then</span> <span class="hljs-string">"<span class="hljs-subst">#{kvar}</span> = "</span> <span class="hljs-keyword">else</span> <span class="hljs-string">""</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@step</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@range</span>
[step, stepVar] = <span class="hljs-property">@cacheToCodeFragments</span> <span class="hljs-property">@step</span>.cache o, LEVEL_LIST, isComplexOrAssignable
stepNum = stepVar.match NUMBER
name = ivar <span class="hljs-keyword">if</span> <span class="hljs-property">@pattern</span>
varPart = <span class="hljs-string">''</span>
guardPart = <span class="hljs-string">''</span>
defPart = <span class="hljs-string">''</span>
idt1 = <span class="hljs-property">@tab</span> + TAB
<span class="hljs-keyword">if</span> <span class="hljs-property">@range</span>
forPartFragments = source.compileToFragments merge o,
{<span class="hljs-attribute">index</span>: ivar, name, <span class="hljs-property">@step</span>, <span class="hljs-attribute">isComplex</span>: isComplexOrAssignable}
<span class="hljs-keyword">else</span>
svar = <span class="hljs-property">@source</span>.compile o, LEVEL_LIST
<span class="hljs-keyword">if</span> (name <span class="hljs-keyword">or</span> <span class="hljs-property">@own</span>) <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> IDENTIFIER.test svar
defPart += <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{ref = scope.freeVariable <span class="hljs-string">'ref'</span>}</span> = <span class="hljs-subst">#{svar}</span>;\n"</span>
svar = ref
<span class="hljs-keyword">if</span> name <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@pattern</span>
namePart = <span class="hljs-string">"<span class="hljs-subst">#{name}</span> = <span class="hljs-subst">#{svar}</span>[<span class="hljs-subst">#{kvar}</span>]"</span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@object</span>
defPart += <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{step}</span>;\n"</span> <span class="hljs-keyword">if</span> step <span class="hljs-keyword">isnt</span> stepVar
lvar = scope.freeVariable <span class="hljs-string">'len'</span> <span class="hljs-keyword">unless</span> <span class="hljs-property">@step</span> <span class="hljs-keyword">and</span> stepNum <span class="hljs-keyword">and</span> down = (parseNum(stepNum[<span class="hljs-number">0</span>]) < <span class="hljs-number">0</span>)
declare = <span class="hljs-string">"<span class="hljs-subst">#{kvarAssign}</span><span class="hljs-subst">#{ivar}</span> = 0, <span class="hljs-subst">#{lvar}</span> = <span class="hljs-subst">#{svar}</span>.length"</span>
declareDown = <span class="hljs-string">"<span class="hljs-subst">#{kvarAssign}</span><span class="hljs-subst">#{ivar}</span> = <span class="hljs-subst">#{svar}</span>.length - 1"</span>
compare = <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span> < <span class="hljs-subst">#{lvar}</span>"</span>
compareDown = <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span> >= 0"</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@step</span>
<span class="hljs-keyword">if</span> stepNum
<span class="hljs-keyword">if</span> down
compare = compareDown
declare = declareDown
<span class="hljs-keyword">else</span>
compare = <span class="hljs-string">"<span class="hljs-subst">#{stepVar}</span> > 0 ? <span class="hljs-subst">#{compare}</span> : <span class="hljs-subst">#{compareDown}</span>"</span>
declare = <span class="hljs-string">"(<span class="hljs-subst">#{stepVar}</span> > 0 ? (<span class="hljs-subst">#{declare}</span>) : <span class="hljs-subst">#{declareDown}</span>)"</span>
increment = <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span> += <span class="hljs-subst">#{stepVar}</span>"</span>
<span class="hljs-keyword">else</span>
increment = <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-keyword">if</span> kvar <span class="hljs-keyword">isnt</span> ivar <span class="hljs-keyword">then</span> <span class="hljs-string">"++<span class="hljs-subst">#{ivar}</span>"</span> <span class="hljs-keyword">else</span> <span class="hljs-string">"<span class="hljs-subst">#{ivar}</span>++"</span>}</span>"</span>
forPartFragments = [<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{declare}</span>; <span class="hljs-subst">#{compare}</span>; <span class="hljs-subst">#{kvarAssign}</span><span class="hljs-subst">#{increment}</span>"</span>)]
<span class="hljs-keyword">if</span> <span class="hljs-property">@returns</span>
resultPart = <span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span><span class="hljs-subst">#{rvar}</span> = [];\n"</span>
returnResult = <span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>return <span class="hljs-subst">#{rvar}</span>;"</span>
body.makeReturn rvar
<span class="hljs-keyword">if</span> <span class="hljs-property">@guard</span>
<span class="hljs-keyword">if</span> body.expressions.length > <span class="hljs-number">1</span>
body.expressions.unshift <span class="hljs-keyword">new</span> If (<span class="hljs-keyword">new</span> Parens <span class="hljs-property">@guard</span>).invert(), <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"continue"</span>
<span class="hljs-keyword">else</span>
body = Block.wrap [<span class="hljs-keyword">new</span> If <span class="hljs-property">@guard</span>, body] <span class="hljs-keyword">if</span> <span class="hljs-property">@guard</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@pattern</span>
body.expressions.unshift <span class="hljs-keyword">new</span> Assign <span class="hljs-property">@name</span>, <span class="hljs-keyword">new</span> Literal <span class="hljs-string">"<span class="hljs-subst">#{svar}</span>[<span class="hljs-subst">#{kvar}</span>]"</span>
defPartFragments = [].concat <span class="hljs-property">@makeCode</span>(defPart), <span class="hljs-property">@pluckDirectCall</span>(o, body)
varPart = <span class="hljs-string">"\n<span class="hljs-subst">#{idt1}</span><span class="hljs-subst">#{namePart}</span>;"</span> <span class="hljs-keyword">if</span> namePart
<span class="hljs-keyword">if</span> <span class="hljs-property">@object</span>
forPartFragments = [<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{kvar}</span> in <span class="hljs-subst">#{svar}</span>"</span>)]
guardPart = <span class="hljs-string">"\n<span class="hljs-subst">#{idt1}</span>if (!<span class="hljs-subst">#{utility <span class="hljs-string">'hasProp'</span>, o}</span>.call(<span class="hljs-subst">#{svar}</span>, <span class="hljs-subst">#{kvar}</span>)) continue;"</span> <span class="hljs-keyword">if</span> <span class="hljs-property">@own</span>
bodyFragments = body.compileToFragments merge(o, <span class="hljs-attribute">indent</span>: idt1), LEVEL_TOP
<span class="hljs-keyword">if</span> bodyFragments <span class="hljs-keyword">and</span> (bodyFragments.length > <span class="hljs-number">0</span>)
bodyFragments = [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>), bodyFragments, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>)
[].concat defPartFragments, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{resultPart <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>}</span><span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>for ("</span>),
forPartFragments, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">") {<span class="hljs-subst">#{guardPart}</span><span class="hljs-subst">#{varPart}</span>"</span>), bodyFragments,
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">"<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}<span class="hljs-subst">#{returnResult <span class="hljs-keyword">or</span> <span class="hljs-string">''</span>}</span>"</span>)
<span class="hljs-attribute">pluckDirectCall</span>: <span class="hljs-function"><span class="hljs-params">(o, body)</span> -></span>
defs = []
<span class="hljs-keyword">for</span> expr, idx <span class="hljs-keyword">in</span> body.expressions
expr = expr.unwrapAll()
<span class="hljs-keyword">continue</span> <span class="hljs-keyword">unless</span> expr <span class="hljs-keyword">instanceof</span> Call
val = expr.variable?.unwrapAll()
<span class="hljs-keyword">continue</span> <span class="hljs-keyword">unless</span> (val <span class="hljs-keyword">instanceof</span> Code) <span class="hljs-keyword">or</span>
(val <span class="hljs-keyword">instanceof</span> Value <span class="hljs-keyword">and</span>
val.base?.unwrapAll() <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span>
val.properties.length <span class="hljs-keyword">is</span> <span class="hljs-number">1</span> <span class="hljs-keyword">and</span>
val.properties[<span class="hljs-number">0</span>].name?.value <span class="hljs-keyword">in</span> [<span class="hljs-string">'call'</span>, <span class="hljs-string">'apply'</span>])
fn = val.base?.unwrapAll() <span class="hljs-keyword">or</span> val
ref = <span class="hljs-keyword">new</span> Literal o.scope.freeVariable <span class="hljs-string">'fn'</span>
base = <span class="hljs-keyword">new</span> Value ref
<span class="hljs-keyword">if</span> val.base
[val.base, base] = [base, val]
body.expressions[idx] = <span class="hljs-keyword">new</span> Call base, expr.args
defs = defs.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-property">@tab</span>), (<span class="hljs-keyword">new</span> Assign(ref, fn).compileToFragments(o, LEVEL_TOP)), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">';\n'</span>)
defs</pre></div></div>
</li>
<li id="section-157">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-157">¶</a>
</div>
<h3 id="switch">Switch</h3>
</div>
</li>
<li id="section-158">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-158">¶</a>
</div>
<p>A JavaScript <em>switch</em> statement. Converts into a returnable expression on-demand.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.Switch = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Switch</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(<span class="hljs-property">@subject</span>, <span class="hljs-property">@cases</span>, <span class="hljs-property">@otherwise</span>)</span> -></span>
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'subject'</span>, <span class="hljs-string">'cases'</span>, <span class="hljs-string">'otherwise'</span>]
<span class="hljs-attribute">isStatement</span>: YES
<span class="hljs-attribute">jumps</span>: <span class="hljs-function"><span class="hljs-params">(o = {block: <span class="hljs-literal">yes</span>})</span> -></span>
<span class="hljs-keyword">for</span> [conds, block] <span class="hljs-keyword">in</span> <span class="hljs-property">@cases</span>
<span class="hljs-keyword">return</span> jumpNode <span class="hljs-keyword">if</span> jumpNode = block.jumps o
<span class="hljs-property">@otherwise</span>?.jumps o
<span class="hljs-attribute">makeReturn</span>: <span class="hljs-function"><span class="hljs-params">(res)</span> -></span>
pair[<span class="hljs-number">1</span>].makeReturn res <span class="hljs-keyword">for</span> pair <span class="hljs-keyword">in</span> <span class="hljs-property">@cases</span>
<span class="hljs-property">@otherwise</span> <span class="hljs-keyword">or</span>= <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">new</span> Literal <span class="hljs-string">'void 0'</span>] <span class="hljs-keyword">if</span> res
<span class="hljs-property">@otherwise</span>?.makeReturn res
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
idt1 = o.indent + TAB
idt2 = o.indent = idt1 + TAB
fragments = [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-property">@tab</span> + <span class="hljs-string">"switch ("</span>),
(<span class="hljs-keyword">if</span> <span class="hljs-property">@subject</span> <span class="hljs-keyword">then</span> <span class="hljs-property">@subject</span>.compileToFragments(o, LEVEL_PAREN) <span class="hljs-keyword">else</span> <span class="hljs-property">@makeCode</span> <span class="hljs-string">"false"</span>),
<span class="hljs-property">@makeCode</span>(<span class="hljs-string">") {\n"</span>)
<span class="hljs-keyword">for</span> [conditions, block], i <span class="hljs-keyword">in</span> <span class="hljs-property">@cases</span>
<span class="hljs-keyword">for</span> cond <span class="hljs-keyword">in</span> flatten [conditions]
cond = cond.invert() <span class="hljs-keyword">unless</span> <span class="hljs-property">@subject</span>
fragments = fragments.concat <span class="hljs-property">@makeCode</span>(idt1 + <span class="hljs-string">"case "</span>), cond.compileToFragments(o, LEVEL_PAREN), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">":\n"</span>)
fragments = fragments.concat body, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">'\n'</span>) <span class="hljs-keyword">if</span> (body = block.compileToFragments o, LEVEL_TOP).length > <span class="hljs-number">0</span>
<span class="hljs-keyword">break</span> <span class="hljs-keyword">if</span> i <span class="hljs-keyword">is</span> <span class="hljs-property">@cases</span>.length - <span class="hljs-number">1</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> <span class="hljs-property">@otherwise</span>
expr = <span class="hljs-property">@lastNonComment</span> block.expressions
<span class="hljs-keyword">continue</span> <span class="hljs-keyword">if</span> expr <span class="hljs-keyword">instanceof</span> Return <span class="hljs-keyword">or</span> (expr <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span> expr.jumps() <span class="hljs-keyword">and</span> expr.value <span class="hljs-keyword">isnt</span> <span class="hljs-string">'debugger'</span>)
fragments.push cond.makeCode(idt2 + <span class="hljs-string">'break;\n'</span>)
<span class="hljs-keyword">if</span> <span class="hljs-property">@otherwise</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@otherwise</span>.expressions.length
fragments.push <span class="hljs-property">@makeCode</span>(idt1 + <span class="hljs-string">"default:\n"</span>), (<span class="hljs-property">@otherwise</span>.compileToFragments o, LEVEL_TOP)..., <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n"</span>)
fragments.push <span class="hljs-property">@makeCode</span> <span class="hljs-property">@tab</span> + <span class="hljs-string">'}'</span>
fragments</pre></div></div>
</li>
<li id="section-159">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-159">¶</a>
</div>
<h3 id="if">If</h3>
</div>
</li>
<li id="section-160">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-160">¶</a>
</div>
<p><em>If/else</em> statements. Acts as an expression by pushing down requested returns
to the last line of each clause.</p>
<p>Single-expression <strong>Ifs</strong> are compiled into conditional operators if possible,
because ternaries are already proper expressions, and don’t need conversion.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.If = <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">If</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Base</span></span>
<span class="hljs-attribute">constructor</span>: <span class="hljs-function"><span class="hljs-params">(condition, <span class="hljs-property">@body</span>, options = {})</span> -></span>
<span class="hljs-property">@condition</span> = <span class="hljs-keyword">if</span> options.type <span class="hljs-keyword">is</span> <span class="hljs-string">'unless'</span> <span class="hljs-keyword">then</span> condition.invert() <span class="hljs-keyword">else</span> condition
<span class="hljs-property">@elseBody</span> = <span class="hljs-literal">null</span>
<span class="hljs-property">@isChain</span> = <span class="hljs-literal">false</span>
{<span class="hljs-property">@soak</span>} = options
<span class="hljs-attribute">children</span>: [<span class="hljs-string">'condition'</span>, <span class="hljs-string">'body'</span>, <span class="hljs-string">'elseBody'</span>]
<span class="hljs-attribute">bodyNode</span>:<span class="hljs-function"> -></span> <span class="hljs-property">@body</span>?.unwrap()
<span class="hljs-attribute">elseBodyNode</span>:<span class="hljs-function"> -></span> <span class="hljs-property">@elseBody</span>?.unwrap()</pre></div></div>
</li>
<li id="section-161">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-161">¶</a>
</div>
<p>Rewrite a chain of <strong>Ifs</strong> to add a default case as the final <em>else</em>.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">addElse</span>: <span class="hljs-function"><span class="hljs-params">(elseBody)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@isChain</span>
<span class="hljs-property">@elseBodyNode</span>().addElse elseBody
<span class="hljs-keyword">else</span>
<span class="hljs-property">@isChain</span> = elseBody <span class="hljs-keyword">instanceof</span> If
<span class="hljs-property">@elseBody</span> = <span class="hljs-property">@ensureBlock</span> elseBody
<span class="hljs-property">@elseBody</span>.updateLocationDataIfMissing elseBody.locationData
<span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-162">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-162">¶</a>
</div>
<p>The <strong>If</strong> only compiles into a statement if either of its bodies needs
to be a statement. Otherwise a conditional operator is safe.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">isStatement</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
o?.level <span class="hljs-keyword">is</span> LEVEL_TOP <span class="hljs-keyword">or</span>
<span class="hljs-property">@bodyNode</span>().isStatement(o) <span class="hljs-keyword">or</span> <span class="hljs-property">@elseBodyNode</span>()?.isStatement(o)
<span class="hljs-attribute">jumps</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span> <span class="hljs-property">@body</span>.jumps(o) <span class="hljs-keyword">or</span> <span class="hljs-property">@elseBody</span>?.jumps(o)
<span class="hljs-attribute">compileNode</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@isStatement</span> o <span class="hljs-keyword">then</span> <span class="hljs-property">@compileStatement</span> o <span class="hljs-keyword">else</span> <span class="hljs-property">@compileExpression</span> o
<span class="hljs-attribute">makeReturn</span>: <span class="hljs-function"><span class="hljs-params">(res)</span> -></span>
<span class="hljs-property">@elseBody</span> <span class="hljs-keyword">or</span>= <span class="hljs-keyword">new</span> Block [<span class="hljs-keyword">new</span> Literal <span class="hljs-string">'void 0'</span>] <span class="hljs-keyword">if</span> res
<span class="hljs-property">@body</span> <span class="hljs-keyword">and</span>= <span class="hljs-keyword">new</span> Block [<span class="hljs-property">@body</span>.makeReturn res]
<span class="hljs-property">@elseBody</span> <span class="hljs-keyword">and</span>= <span class="hljs-keyword">new</span> Block [<span class="hljs-property">@elseBody</span>.makeReturn res]
<span class="hljs-keyword">this</span>
<span class="hljs-attribute">ensureBlock</span>: <span class="hljs-function"><span class="hljs-params">(node)</span> -></span>
<span class="hljs-keyword">if</span> node <span class="hljs-keyword">instanceof</span> Block <span class="hljs-keyword">then</span> node <span class="hljs-keyword">else</span> <span class="hljs-keyword">new</span> Block [node]</pre></div></div>
</li>
<li id="section-163">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-163">¶</a>
</div>
<p>Compile the <code>If</code> as a regular <em>if-else</em> statement. Flattened chains
force inner <em>else</em> bodies into statement form.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileStatement</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
child = del o, <span class="hljs-string">'chainChild'</span>
exeq = del o, <span class="hljs-string">'isExistentialEquals'</span>
<span class="hljs-keyword">if</span> exeq
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> If(<span class="hljs-property">@condition</span>.invert(), <span class="hljs-property">@elseBodyNode</span>(), <span class="hljs-attribute">type</span>: <span class="hljs-string">'if'</span>).compileToFragments o
indent = o.indent + TAB
cond = <span class="hljs-property">@condition</span>.compileToFragments o, LEVEL_PAREN
body = <span class="hljs-property">@ensureBlock</span>(<span class="hljs-property">@body</span>).compileToFragments merge o, {indent}
ifPart = [].concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"if ("</span>), cond, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">") {\n"</span>), body, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span>)
ifPart.unshift <span class="hljs-property">@makeCode</span> <span class="hljs-property">@tab</span> <span class="hljs-keyword">unless</span> child
<span class="hljs-keyword">return</span> ifPart <span class="hljs-keyword">unless</span> <span class="hljs-property">@elseBody</span>
answer = ifPart.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">' else '</span>)
<span class="hljs-keyword">if</span> <span class="hljs-property">@isChain</span>
o.chainChild = <span class="hljs-literal">yes</span>
answer = answer.concat <span class="hljs-property">@elseBody</span>.unwrap().compileToFragments o, LEVEL_TOP
<span class="hljs-keyword">else</span>
answer = answer.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"{\n"</span>), <span class="hljs-property">@elseBody</span>.compileToFragments(merge(o, {indent}), LEVEL_TOP), <span class="hljs-property">@makeCode</span>(<span class="hljs-string">"\n<span class="hljs-subst">#{<span class="hljs-property">@tab</span>}</span>}"</span>)
answer</pre></div></div>
</li>
<li id="section-164">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-164">¶</a>
</div>
<p>Compile the <code>If</code> as a conditional operator.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">compileExpression</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span>
cond = <span class="hljs-property">@condition</span>.compileToFragments o, LEVEL_COND
body = <span class="hljs-property">@bodyNode</span>().compileToFragments o, LEVEL_LIST
alt = <span class="hljs-keyword">if</span> <span class="hljs-property">@elseBodyNode</span>() <span class="hljs-keyword">then</span> <span class="hljs-property">@elseBodyNode</span>().compileToFragments(o, LEVEL_LIST) <span class="hljs-keyword">else</span> [<span class="hljs-property">@makeCode</span>(<span class="hljs-string">'void 0'</span>)]
fragments = cond.concat <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" ? "</span>), body, <span class="hljs-property">@makeCode</span>(<span class="hljs-string">" : "</span>), alt
<span class="hljs-keyword">if</span> o.level >= LEVEL_COND <span class="hljs-keyword">then</span> <span class="hljs-property">@wrapInBraces</span> fragments <span class="hljs-keyword">else</span> fragments
<span class="hljs-attribute">unfoldSoak</span>:<span class="hljs-function"> -></span>
<span class="hljs-property">@soak</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">this</span></pre></div></div>
</li>
<li id="section-165">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-165">¶</a>
</div>
<h2 id="constants">Constants</h2>
</div>
</li>
<li id="section-166">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-166">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre>
UTILITIES =</pre></div></div>
</li>
<li id="section-167">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-167">¶</a>
</div>
<p>Correctly set up a prototype chain for inheritance, including a reference
to the superclass for <code>super()</code> calls, and copies of any static properties.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">extend</span>: <span class="hljs-function"><span class="hljs-params">(o)</span> -></span> <span class="hljs-string">"
function(child, parent) {
for (var key in parent) {
if (<span class="hljs-subst">#{utility <span class="hljs-string">'hasProp'</span>, o}</span>.call(parent, key)) child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.__super__ = parent.prototype;
return child;
}
"</span></pre></div></div>
</li>
<li id="section-168">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-168">¶</a>
</div>
<p>Create a function bound to the current value of “this”.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">bind</span>:<span class="hljs-function"> -></span> <span class="hljs-string">'
function(fn, me){
return function(){
return fn.apply(me, arguments);
};
}
'</span></pre></div></div>
</li>
<li id="section-169">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-169">¶</a>
</div>
<p>Discover if an item is in an array.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">indexOf</span>:<span class="hljs-function"> -></span> <span class="hljs-string">"
[].indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item) return i;
}
return -1;
}
"</span>
<span class="hljs-attribute">modulo</span>:<span class="hljs-function"> -></span> <span class="hljs-string">"""
function(a, b) { return (+a % (b = +b) + b) % b; }
"""</span></pre></div></div>
</li>
<li id="section-170">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-170">¶</a>
</div>
<p>Shortcuts to speed up the lookup time for native functions.</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attribute">hasProp</span>:<span class="hljs-function"> -></span> <span class="hljs-string">'{}.hasOwnProperty'</span>
slice :<span class="hljs-function"> -></span> <span class="hljs-string">'[].slice'</span></pre></div></div>
</li>
<li id="section-171">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-171">¶</a>
</div>
<p>Levels indicate a node’s position in the AST. Useful for knowing if
parens are necessary or superfluous.</p>
</div>
<div class="content"><div class='highlight'><pre>LEVEL_TOP = <span class="hljs-number">1</span> <span class="hljs-comment"># ...;</span>
LEVEL_PAREN = <span class="hljs-number">2</span> <span class="hljs-comment"># (...)</span>
LEVEL_LIST = <span class="hljs-number">3</span> <span class="hljs-comment"># [...]</span>
LEVEL_COND = <span class="hljs-number">4</span> <span class="hljs-comment"># ... ? x : y</span>
LEVEL_OP = <span class="hljs-number">5</span> <span class="hljs-comment"># !...</span>
LEVEL_ACCESS = <span class="hljs-number">6</span> <span class="hljs-comment"># ...[0]</span></pre></div></div>
</li>
<li id="section-172">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-172">¶</a>
</div>
<p>Tabs are two spaces for pretty printing.</p>
</div>
<div class="content"><div class='highlight'><pre>TAB = <span class="hljs-string">' '</span>
IDENTIFIER = <span class="hljs-regexp">/// ^ (?!\d) [$\w\x7f-\uffff]+ $ ///</span>
SIMPLENUM = <span class="hljs-regexp">/^[+-]?\d+$/</span>
HEXNUM = <span class="hljs-regexp">/^[+-]?0x[\da-f]+/i</span>
NUMBER = <span class="hljs-regexp">///^[+-]?(?:
0x[\da-f]+ | <span class="hljs-comment"># hex</span>
\d*\.?\d+ (?:e[+-]?\d+)? <span class="hljs-comment"># decimal</span>
)$///</span>i</pre></div></div>
</li>
<li id="section-173">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-173">¶</a>
</div>
<p>Is a literal value a string/regex?</p>
</div>
<div class="content"><div class='highlight'><pre>IS_STRING = <span class="hljs-regexp">/^['"]/</span>
IS_REGEX = <span class="hljs-regexp">/^\//</span></pre></div></div>
</li>
<li id="section-174">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-174">¶</a>
</div>
<h2 id="helper-functions">Helper Functions</h2>
</div>
</li>
<li id="section-175">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-175">¶</a>
</div>
</div>
</li>
<li id="section-176">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-176">¶</a>
</div>
<p>Helper for ensuring that utility functions are assigned at the top level.</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">utility</span> = <span class="hljs-params">(name, o)</span> -></span>
{root} = o.scope
<span class="hljs-keyword">if</span> name <span class="hljs-keyword">of</span> root.utilities
root.utilities[name]
<span class="hljs-keyword">else</span>
ref = root.freeVariable name
root.assign ref, UTILITIES[name] o
root.utilities[name] = ref
<span class="hljs-function"><span class="hljs-title">multident</span> = <span class="hljs-params">(code, tab)</span> -></span>
code = code.replace <span class="hljs-regexp">/\n/g</span>, <span class="hljs-string">'$&'</span> + tab
code.replace <span class="hljs-regexp">/\s+$/</span>, <span class="hljs-string">''</span></pre></div></div>
</li>
<li id="section-177">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-177">¶</a>
</div>
<p>Parse a number (+- decimal/hexadecimal)
Examples: 0, -1, 1, 2e3, 2e-3, -0xfe, 0xfe</p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">parseNum</span> = <span class="hljs-params">(x)</span> -></span>
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> x?
<span class="hljs-number">0</span>
<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> x.match HEXNUM
parseInt x, <span class="hljs-number">16</span>
<span class="hljs-keyword">else</span>
parseFloat x
<span class="hljs-function"><span class="hljs-title">isLiteralArguments</span> = <span class="hljs-params">(node)</span> -></span>
node <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span> node.value <span class="hljs-keyword">is</span> <span class="hljs-string">'arguments'</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> node.asKey
<span class="hljs-function"><span class="hljs-title">isLiteralThis</span> = <span class="hljs-params">(node)</span> -></span>
(node <span class="hljs-keyword">instanceof</span> Literal <span class="hljs-keyword">and</span> node.value <span class="hljs-keyword">is</span> <span class="hljs-string">'this'</span> <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> node.asKey) <span class="hljs-keyword">or</span>
(node <span class="hljs-keyword">instanceof</span> Code <span class="hljs-keyword">and</span> node.bound) <span class="hljs-keyword">or</span>
(node <span class="hljs-keyword">instanceof</span> Call <span class="hljs-keyword">and</span> node.isSuper)
<span class="hljs-function"><span class="hljs-title">isComplexOrAssignable</span> = <span class="hljs-params">(node)</span> -></span> node.isComplex() <span class="hljs-keyword">or</span> node.isAssignable?()</pre></div></div>
</li>
<li id="section-178">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-178">¶</a>
</div>
<p>Unfold a node’s child if soak, then tuck the node under created <code>If</code></p>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">unfoldSoak</span> = <span class="hljs-params">(o, parent, name)</span> -></span>
<span class="hljs-keyword">return</span> <span class="hljs-keyword">unless</span> ifn = parent[name].unfoldSoak o
parent[name] = ifn.body
ifn.body = <span class="hljs-keyword">new</span> Value parent
ifn</pre></div></div>
</li>
</ul>
</div>
</body>
</html>
|