All files / src/compiler/phases/3-transform/server transform-server.js

97.47% Statements 2243/2301
97.17% Branches 584/601
94.73% Functions 54/57
97.46% Lines 2227/2285

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 22862x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 22826x 22826x 22826x 2x 2x 2x 2x 2x 2x 2x 4188x 4188x 4188x 4188x 4188x 4188x 4188x 4188x 4188x 4188x 4188x 4801x 4801x 4801x 4188x 4188x 4188x 22222x 22222x 22222x 2246x 1388x 1388x 2246x 2246x 22222x 19976x 19976x 19976x 19976x 14714x 14714x 19976x 4615x 4615x 4615x 5262x 647x 647x 647x 19976x 22222x 4188x 4188x 3413x 3413x 4188x 4188x 4188x 2x 2x 2x 2x 2x 2x 2x 7920x 7920x 7920x 7920x 7920x 4615x 4615x 4615x 4615x 4615x 4615x 4615x 6542x 6542x 6542x 4088x 4088x 4088x 6542x 11x 11x 11x 2454x 2443x 2443x 2443x 2443x 2443x 2443x 2443x 6542x 4615x 4615x 4615x 7920x 7920x 12420x 12420x 12420x 6542x 12420x 5878x 1776x 1776x 1776x 5878x 5878x 5878x 12420x 7920x 7920x 2839x 2839x 7920x 2x 2x 2x 2x 2x 2x 2x 405x 405x 401x 401x 4x 4x 4x 4x 4x 4x 10x 10x 4x 4x 4x 2x 2x 2x 2x 2x 2x 12885x 12885x 12885x 12885x 3322x 3322x 3322x 9563x 12885x 214x 214x 214x 214x 214x 214x 214x 214x 9349x 12885x 26x 26x 9323x 9323x 9323x 2x 2x 2x 2x 2x 895x 895x 791x 791x 791x 791x 93x 93x 93x 93x 791x 791x 104x 104x 104x 2x 2x 2x 2x 1085x 1085x 1085x 2x 2x 2x 2x 2x 2x 2x 1185x 1185x 1185x 1185x 1185x 1185x 1128x 1185x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 114x 114x 114x 114x 114x 57x 57x 41x 41x 41x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 1128x 1185x     1128x 1128x 1128x 1185x 319x 319x 319x 1128x 1185x 43x 43x 1085x 1085x 1185x 1185x 1185x 1185x 1080x 1185x     1080x 1080x 1185x 1185x 1185x 1185x 1185x 1185x 220x 1185x 185x 185x 185x 895x 895x 1179x 791x 42x 42x 42x 42x 42x 42x 749x 1185x 8x 8x 8x 8x 8x 8x 8x 8x 96x 96x 2x 2x 2x 2x 2x 2x 1476x 1476x 1476x 1356x 1356x 1356x 1356x 1476x 1476x 2x 2x 2x 2x 16365x 12607x 29x 29x 12578x 12578x 2x 2x 1071x 2x 2x 143x 143x 143x 143x 9x 9x 9x 9x 9x 9x 9x 9x 134x 134x 2x 2x 1548x 1548x 1548x     1548x 1548x 4x 4x 1544x 1548x 4x 4x 4x 1540x 1548x 1x 1x 1539x 1548x 3x 3x 3x 3x 3x 3x 1536x 1548x 12x 12x 1524x 1524x 1524x 2x 2x 2x 2x 2x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 110x 110x 60x 110x 59x 59x 59x 59x 59x 59x 53x 53x 13x 13x 13x 13x 13x 13x 13x 13x 1x 13x 12x 12x 13x 53x 59x 110x 41x 41x 41x 12x 12x     12x 12x 12x 12x 41x 41x 41x 41x 41x 41x 41x 41x 110x 110x 60x 110x 59x 59x 59x 59x 59x 59x 13x 13x 13x 13x 13x 13x 13x 13x 13x 1x 13x 12x 12x 12x 12x 12x 12x 12x 12x                   12x 13x 13x 13x 59x 97x 97x 97x 41x 41x 2x 2x 47x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x 41x                   41x 6x 2x 2x 790x 790x 790x 791x 791x 791x 223x 223x 223x 568x 791x 108x 108x 108x 57x 57x 27x 57x 23x 23x 23x 23x 23x 57x 108x 108x 108x 108x 460x 460x 460x 460x 791x 791x 791x 791x 6x 6x 6x 6x 6x 6x 6x 6x 454x 776x 448x 448x 448x 6x 764x 4x 4x 4x 4x 4x 2x 2x 2x 790x 790x 790x 790x 790x 2x 2x 376x 376x 199x 199x 199x 53x 53x 146x 146x 199x 199x 103x 199x 18x 18x 199x 305x 2x 2x 401x 27x 27x 1x 1x 27x 400x 400x 400x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2246x 2246x 27x 27x 2219x 2246x 2150x 2150x 2150x 1217x 1217x 1217x 1217x 1217x 1217x 933x 933x 933x 69x 69x 69x 69x 69x 69x 69x 2186x 179x 179x 179x 94x 94x 94x 179x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 179x 69x 69x 69x 2x 2x 2x 2x 2x 2x 2x 2x 2x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 111x 8x 3x 3x 3x 3x 3x 3x 8x 8x 8x 6x 6x 8x 8x 8x 111x 111x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 111x 111x 4x 111x 2x 2x 111x 111x 111x 182x 70x 70x 70x 70x 70x 70x 70x 70x 112x 112x 111x 111x 111x 111x 111x 111x 2x 2x 2x 2x 2x 2x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 1048x 1048x 1048x 1048x 1048x 516x 516x 1048x 675x 761x 70x 761x 26x 691x 493x 47x 47x 47x 47x 446x 493x 8x 8x 446x 493x 2x 2x 446x 446x 446x 665x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 109x 761x 675x 675x 8x 8x 675x 675x 675x 675x 675x 675x 861x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 855x 855x 861x 243x 243x 243x 243x 243x 243x 84x 84x 243x 855x 861x 861x 861x 675x 675x 675x 675x 675x 675x 310x 310x 310x 310x 310x 310x 310x 310x 310x 310x 310x 95x 310x 310x 310x 310x 310x 247x 247x 247x 247x 310x 310x 310x 310x 310x 310x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 310x 85x 85x 85x 310x 675x 675x 216x 216x 675x 675x 675x 521x 675x 675x 26x 26x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 675x 6x 6x 675x 675x 675x 675x 675x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 675x 651x 44x 44x 651x 651x 651x 651x 315x 315x 651x 675x 2x 2x 2x 2x 2560x 2560x 2560x 2560x 2900x 2900x 2900x 2900x 2900x 2900x 2900x 457x 457x 457x 2443x 2900x 2040x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 31x 31x 31x 31x 31x 31x 31x 31x 5x 5x 2035x 2035x 2035x 2035x 2035x 2035x 2040x 2040x 2040x 2040x 2040x 2040x 2040x 987x 987x 987x 987x 987x 2035x 2035x 2035x 2035x 2035x 403x 403x 403x 403x 403x 2900x 2900x 2900x 2900x 2560x 2560x 2560x 2560x 2560x 2x 2x 150x 150x 148x 148x 148x 148x 148x 148x 148x 148x 148x 148x 148x 148x 2x 2x 2x 2x 2x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 4063x 236x 236x 4063x 4063x 142x 142x 142x 4063x 4063x 4063x 4063x 2x 2x 57x 57x 2x 2x 128x 128x 128x 128x 2x 2x                                   2x 2x 69x 69x 69x 69x 69x 69x 69x 69x 69x 26x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 58x 58x 2x 2x   2x 2x   2x 2x 3845x 3845x 3845x 3845x 3845x 6x 6x 6x 6x 6x 6x 6x 3839x 3839x 3839x 3839x 3839x 3839x 3839x 3839x 3842x 3830x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 3845x 10x 10x 3839x 3845x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 83x 3839x 3844x 3820x 3845x 19x 19x 19x 13x 13x 13x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 3839x 3845x 3532x 3532x 3839x 3845x 83x 83x 2x 2x 69x 69x 28x 28x 28x 28x 69x 69x 9x 8x 8x 9x 9x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 9x 9x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 69x 9x 9x 2x 2x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 41x 41x 471x 1x 1x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 471x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 471x 445x 445x 2x 2x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 325x 2x 2x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 85x 2x 2x 14x 14x 2x 2x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 5x 5x 2x 2x 612x 2x 2x 11x 2x 2x 52x 52x 52x 52x 52x 2x 2x 105x 97x 97x 97x 8x 8x 8x 8x 102x 14x 14x 8x 8x 8x 8x 8x 8x 8x 8x 102x 6x 105x 105x 105x 105x 105x 105x 105x 105x 105x 2x 2x 142x 2x 2x 31x 52x 24x 24x 24x 24x 52x 31x 31x 31x 31x 2x 2x 18x 18x 18x 18x 18x 18x 2x 2x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 170x 4x 170x 165x 165x 165x 79x 165x 84x 62x 84x 22x 22x 84x 166x 1x 1x 170x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 237x 2x 2x 30x 30x 30x 30x 30x 30x 2x 2x 2x 2x 2x 2x 2x 2x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 3914x 2667x 1548x 151x 7x 7x 7x 2x 7x           7x 151x 137x 137x 137x 137x 151x 151x 1548x 245x 245x   245x     1397x 1152x 512x 1152x 38x 38x 1152x 1152x 2667x 318x 285x 318x 98x 98x 26x 26x 26x 23x 98x 318x 1x 1x 317x 213x 213x 318x 194x 311x 7x 311x 5x 5x 5x 5x 187x 66x 66x 66x 66x 66x 66x 66x 130x 130x 130x 66x 66x 66x 66x 66x 66x 66x 66x 66x 66x 66x 42x 42x 42x 66x 24x 24x 24x 66x 66x 66x 66x 66x 66x 66x 66x 178x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 116x 1119x 112x 112x 112x 1x 1x 1x 791x 45x       689x 25x 644x 41x 619x 10x 578x 568x 568x 2667x 3914x 3914x 17x 17x 17x 17x 17x 10x 10x 17x 3914x 3914x 27x 27x 27x 27x 27x 27x 5x 5x 27x 3914x 3914x 3914x 3914x 3914x 111x 111x 111x 111x 111x 111x 111x 3914x 3803x 1406x 973x 973x 973x 973x 973x 973x 973x 973x 973x 970x 970x 970x 970x 970x 970x 970x 970x 970x 970x 973x 973x 433x 433x 433x 433x 433x 433x 433x 433x 433x 433x 1406x 1406x 1406x 3803x 3914x 3914x 1x 2x 2x 1x 3914x 3914x 3914x 2x 2x 2x 2x 2x 2x 2x 17x 17x 22x 17x 17x 10x 10x 17x 17x 5x 5x 15x 2x 2x 2x 2x 2x 2x 2x 2x 2x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 2x 2x 2x 2x 2x 2x 27x 27x 36x 36x 36x 36x 36x 1x 1x 36x 27x 27x 27x 27x 27x 27x 5x 5x 5x 27x 27x 27x 27x 2x 2x 2x 2x 2x 2x 2x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 845x 845x 2413x 2413x 1906x 1886x 1886x 20x 20x 1906x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 148x 148x     148x 148x 148x 112x 148x 95x 90x 90x 67x 67x 90x 95x 148x 148x 148x 2413x 2413x 47x 47x 47x 47x 47x 47x 2413x 2413x 2413x 2413x 80x 80x 262x 1x 1x 80x 80x 80x 262x 1x 1x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 80x 2413x 2413x 2413x 2413x 2413x 2413x 88x 88x 88x 88x 88x 2413x 2413x 2413x 2413x 2413x 8283x 2088x 2088x 8283x 2413x 139x 139x 2413x 1124x 1124x 1124x 1124x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 557x 557x 557x 2413x 2413x 10x 10x 10x 39x 39x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 2413x 2413x 25x 25x 25x 25x 2413x 2413x 3x 3x 2413x 2413x 2413x 2413x 2x 2x 2x 2x 2x 2x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2413x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 117x 2409x 2292x 2292x 2413x 2413x 117x 117x 117x 117x 117x 117x 117x 2413x 2413x 2413x 2413x 2413x 2413x 2413x 2x 2x 2x 2x 2x 2x 2x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x  
import { walk } from 'zimmerframe';
import { set_scope, get_rune } from '../../scope.js';
import {
	extract_identifiers,
	extract_paths,
	is_event_attribute,
	is_expression_async,
	is_text_attribute,
	unwrap_optional
} from '../../../utils/ast.js';
import * as b from '../../../utils/builders.js';
import is_reference from 'is-reference';
import {
	ContentEditableBindings,
	LoadErrorElements,
	VoidElements,
	WhitespaceInsensitiveAttributes
} from '../../constants.js';
import {
	clean_nodes,
	determine_namespace_for_children,
	infer_namespace,
	transform_inspect_rune
} from '../utils.js';
import { create_attribute, is_custom_element_node, is_element_node } from '../../nodes.js';
import { binding_properties } from '../../bindings.js';
import { regex_starts_with_newline, regex_whitespaces_strict } from '../../patterns.js';
import {
	DOMBooleanAttributes,
	ELEMENT_IS_NAMESPACED,
	ELEMENT_PRESERVE_ATTRIBUTE_CASE
} from '../../../../constants.js';
import { escape_html } from '../../../../escaping.js';
import { sanitize_template_string } from '../../../utils/sanitize_template_string.js';
import {
	EMPTY_COMMENT,
	BLOCK_CLOSE,
	BLOCK_OPEN,
	BLOCK_OPEN_ELSE
} from '../../../../internal/server/hydration.js';
import { filename, locator } from '../../../state.js';
import { render_stylesheet } from '../css/index.js';
 
/** Opens an if/each block, so that we can remove nodes in the case of a mismatch */
const block_open = b.literal(BLOCK_OPEN);
 
/** Closes an if/each block, so that we can remove nodes in the case of a mismatch. Also serves as an anchor for these blocks */
const block_close = b.literal(BLOCK_CLOSE);
 
/** Empty comment to keep text nodes separate, or provide an anchor node for blocks */
const empty_comment = b.literal(EMPTY_COMMENT);
 
/**
 * @param {import('estree').Node} node
 * @returns {node is import('estree').Statement}
 */
function is_statement(node) {
	return node.type.endsWith('Statement') || node.type.endsWith('Declaration');
}
 
/**
 * @param {Array<import('estree').Statement | import('estree').Expression>} template
 * @param {import('estree').Identifier} out
 * @param {import('estree').AssignmentOperator} operator
 * @returns {import('estree').Statement[]}
 */
function serialize_template(template, out = b.id('$$payload.out'), operator = '+=') {
	/** @type {import('estree').TemplateElement[]} */
	let quasis = [];
 
	/** @type {import('estree').Expression[]} */
	let expressions = [];
 
	/** @type {import('estree').Statement[]} */
	const statements = [];
 
	const flush = () => {
		statements.push(b.stmt(b.assignment(operator, out, b.template(quasis, expressions))));
		quasis = [];
		expressions = [];
	};
 
	for (let i = 0; i < template.length; i++) {
		const node = template[i];
 
		if (is_statement(node)) {
			if (quasis.length !== 0) {
				flush();
			}
 
			statements.push(node);
		} else {
			let last = quasis.at(-1);
			if (!last) quasis.push((last = b.quasi('', false)));
 
			if (node.type === 'Literal') {
				last.value.raw +=
					typeof node.value === 'string' ? sanitize_template_string(node.value) : node.value;
			} else if (node.type === 'TemplateLiteral') {
				last.value.raw += node.quasis[0].value.raw;
				quasis.push(...node.quasis.slice(1));
				expressions.push(...node.expressions);
			} else {
				expressions.push(node);
				quasis.push(b.quasi('', i + 1 === template.length || is_statement(template[i + 1])));
			}
		}
	}
 
	if (quasis.length !== 0) {
		flush();
	}
 
	return statements;
}
 
/**
 * Processes an array of template nodes, joining sibling text/expression nodes and
 * recursing into child nodes.
 * @param {Array<import('#compiler').SvelteNode>} nodes
 * @param {import('./types').ComponentContext} context
 */
function process_children(nodes, { visit, state }) {
	/** @type {Array<import('#compiler').Text | import('#compiler').Comment | import('#compiler').ExpressionTag>} */
	let sequence = [];
 
	function flush() {
		let quasi = b.quasi('', false);
		const quasis = [quasi];
 
		/** @type {import('estree').Expression[]} */
		const expressions = [];
 
		for (let i = 0; i < sequence.length; i++) {
			const node = sequence[i];
 
			if (node.type === 'Text' || node.type === 'Comment') {
				quasi.value.raw += sanitize_template_string(
					node.type === 'Comment' ? `<!--${node.data}-->` : escape_html(node.data)
				);
			} else if (node.type === 'ExpressionTag' && node.expression.type === 'Literal') {
				if (node.expression.value != null) {
					quasi.value.raw += sanitize_template_string(escape_html(node.expression.value + ''));
				}
			} else {
				expressions.push(
					b.call('$.escape', /** @type {import('estree').Expression} */ (visit(node.expression)))
				);
 
				quasi = b.quasi('', i + 1 === sequence.length);
				quasis.push(quasi);
			}
		}
 
		state.template.push(b.template(quasis, expressions));
	}
 
	for (let i = 0; i < nodes.length; i += 1) {
		const node = nodes[i];
 
		if (node.type === 'Text' || node.type === 'Comment' || node.type === 'ExpressionTag') {
			sequence.push(node);
		} else {
			if (sequence.length > 0) {
				flush();
				sequence = [];
			}
 
			visit(node, { ...state });
		}
	}
 
	if (sequence.length > 0) {
		flush();
	}
}
 
/**
 * @param {import('estree').VariableDeclarator} declarator
 * @param {import('../../scope').Scope} scope
 * @param {import('estree').Expression} value
 * @returns {import('estree').VariableDeclarator[]}
 */
function create_state_declarators(declarator, scope, value) {
	if (declarator.id.type === 'Identifier') {
		return [b.declarator(declarator.id, value)];
	}
 
	const tmp = scope.generate('tmp');
	const paths = extract_paths(declarator.id);
	return [
		b.declarator(b.id(tmp), value), // TODO inject declarator for opts, so we can use it below
		...paths.map((path) => {
			const value = path.expression?.(b.id(tmp));
			return b.declarator(path.node, value);
		})
	];
}
 
/**
 * @param {import('estree').Identifier} node
 * @param {import('./types').ServerTransformState} state
 * @returns {import('estree').Expression}
 */
function serialize_get_binding(node, state) {
	const binding = state.scope.get(node.name);
 
	if (binding === null || node === binding.node) {
		// No associated binding or the declaration itself which shouldn't be transformed
		return node;
	}
 
	if (binding.kind === 'store_sub') {
		const store_id = b.id(node.name.slice(1));
		return b.call(
			'$.store_get',
			b.assignment('??=', b.id('$$store_subs'), b.object([])),
			b.literal(node.name),
			serialize_get_binding(store_id, state)
		);
	}
 
	if (binding.expression) {
		return typeof binding.expression === 'function' ? binding.expression(node) : binding.expression;
	}
 
	return node;
}
 
/**
 * @param {import('estree').AssignmentExpression} node
 * @param {Pick<import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types').ServerTransformState>, 'visit' | 'state'>} context
 */
function get_assignment_value(node, { state, visit }) {
	if (node.left.type === 'Identifier') {
		const operator = node.operator;
		return operator === '='
			? /** @type {import('estree').Expression} */ (visit(node.right))
			: // turn something like x += 1 into x = x + 1
				b.binary(
					/** @type {import('estree').BinaryOperator} */ (operator.slice(0, -1)),
					serialize_get_binding(node.left, state),
					/** @type {import('estree').Expression} */ (visit(node.right))
				);
	}
 
	return /** @type {import('estree').Expression} */ (visit(node.right));
}
 
/**
 * @param {string} name
 */
function is_store_name(name) {
	return name[0] === '$' && /[A-Za-z_]/.test(name[1]);
}
 
/**
 * @param {import('estree').AssignmentExpression} node
 * @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types').ServerTransformState>} context
 * @param {() => any} fallback
 * @returns {import('estree').Expression}
 */
function serialize_set_binding(node, context, fallback) {
	const { state, visit } = context;
 
	if (
		node.left.type === 'ArrayPattern' ||
		node.left.type === 'ObjectPattern' ||
		node.left.type === 'RestElement'
	) {
		// Turn assignment into an IIFE, so that `$.set` calls etc don't produce invalid code
		const tmp_id = context.state.scope.generate('tmp');
 
		/** @type {import('estree').AssignmentExpression[]} */
		const original_assignments = [];
 
		/** @type {import('estree').Expression[]} */
		const assignments = [];
 
		const paths = extract_paths(node.left);
 
		for (const path of paths) {
			const value = path.expression?.(b.id(tmp_id));
			const assignment = b.assignment('=', path.node, value);
			original_assignments.push(assignment);
			assignments.push(serialize_set_binding(assignment, context, () => assignment));
		}
 
		if (assignments.every((assignment, i) => assignment === original_assignments[i])) {
			// No change to output -> nothing to transform -> we can keep the original assignment
			return fallback();
		}
 
		return b.call(
			b.thunk(
				b.block([
					b.const(tmp_id, /** @type {import('estree').Expression} */ (visit(node.right))),
					b.stmt(b.sequence(assignments)),
					b.return(b.id(tmp_id))
				])
			)
		);
	}
 
	if (node.left.type !== 'Identifier' && node.left.type !== 'MemberExpression') {
		throw new Error(`Unexpected assignment type ${node.left.type}`);
	}
 
	let left = node.left;
 
	while (left.type === 'MemberExpression') {
		// @ts-expect-error
		left = left.object;
	}
 
	if (left.type !== 'Identifier') {
		return fallback();
	}
 
	const is_store = is_store_name(left.name);
	const left_name = is_store ? left.name.slice(1) : left.name;
	const binding = state.scope.get(left_name);
 
	if (!binding) return fallback();
 
	if (binding.mutation !== null) {
		return binding.mutation(node, context);
	}
 
	if (
		binding.kind !== 'state' &&
		binding.kind !== 'frozen_state' &&
		binding.kind !== 'prop' &&
		binding.kind !== 'bindable_prop' &&
		binding.kind !== 'each' &&
		binding.kind !== 'legacy_reactive' &&
		!is_store
	) {
		// TODO error if it's a computed (or rest prop)? or does that already happen elsewhere?
		return fallback();
	}
 
	const value = get_assignment_value(node, { state, visit });
	if (left === node.left) {
		if (is_store) {
			return b.call(
				'$.store_set',
				b.id(left_name),
				/** @type {import('estree').Expression} */ (visit(node.right))
			);
		}
		return fallback();
	} else if (is_store) {
		return b.call(
			'$.mutate_store',
			b.assignment('??=', b.id('$$store_subs'), b.object([])),
			b.literal(left.name),
			b.id(left_name),
			b.assignment(node.operator, /** @type {import('estree').Pattern} */ (visit(node.left)), value)
		);
	}
	return fallback();
}
 
/**
 * @param {import('#compiler').RegularElement | import('#compiler').SvelteElement} element
 * @param {import('#compiler').Attribute} attribute
 * @param {{ state: { namespace: import('#compiler').Namespace }}} context
 */
function get_attribute_name(element, attribute, context) {
	let name = attribute.name;
	if (!element.metadata.svg && !element.metadata.mathml && context.state.namespace !== 'foreign') {
		name = name.toLowerCase();
		// don't lookup boolean aliases here, the server runtime function does only
		// check for the lowercase variants of boolean attributes
	}
	return name;
}
 
/** @type {import('./types').Visitors} */
const global_visitors = {
	Identifier(node, { path, state }) {
		if (is_reference(node, /** @type {import('estree').Node} */ (path.at(-1)))) {
			if (node.name === '$$props') {
				return b.id('$$sanitized_props');
			}
			return serialize_get_binding(node, state);
		}
	},
	AssignmentExpression(node, context) {
		return serialize_set_binding(node, context, context.next);
	},
	UpdateExpression(node, context) {
		const { state, next } = context;
		const argument = node.argument;
 
		if (argument.type === 'Identifier' && state.scope.get(argument.name)?.kind === 'store_sub') {
			return b.call(
				node.prefix ? '$.update_store_pre' : '$.update_store',
				b.assignment('??=', b.id('$$store_subs'), b.object([])),
				b.literal(argument.name),
				b.id(argument.name.slice(1)),
				node.operator === '--' && b.literal(-1)
			);
		}
 
		return next();
	},
	CallExpression(node, context) {
		const rune = get_rune(node, context.state.scope);
 
		if (rune === '$host') {
			return b.id('undefined');
		}
 
		if (rune === '$effect.tracking') {
			return b.literal(false);
		}
 
		if (rune === '$effect.root') {
			// ignore $effect.root() calls, just return a noop which mimics the cleanup function
			return b.arrow([], b.block([]));
		}
 
		if (rune === '$state.snapshot') {
			return /** @type {import('estree').Expression} */ (context.visit(node.arguments[0]));
		}
 
		if (rune === '$state.is') {
			return b.call(
				'Object.is',
				/** @type {import('estree').Expression} */ (context.visit(node.arguments[0])),
				/** @type {import('estree').Expression} */ (context.visit(node.arguments[1]))
			);
		}
 
		if (rune === '$inspect' || rune === '$inspect().with') {
			return transform_inspect_rune(node, context);
		}
 
		context.next();
	}
};
 
/** @type {import('./types').Visitors} */
const javascript_visitors_runes = {
	ClassBody(node, { state, visit }) {
		/** @type {Map<string, import('../../3-transform/client/types.js').StateField>} */
		const public_derived = new Map();
 
		/** @type {Map<string, import('../../3-transform/client/types.js').StateField>} */
		const private_derived = new Map();
 
		/** @type {string[]} */
		const private_ids = [];
 
		for (const definition of node.body) {
			if (
				definition.type === 'PropertyDefinition' &&
				(definition.key.type === 'Identifier' || definition.key.type === 'PrivateIdentifier')
			) {
				const { type, name } = definition.key;
 
				const is_private = type === 'PrivateIdentifier';
				if (is_private) private_ids.push(name);
 
				if (definition.value?.type === 'CallExpression') {
					const rune = get_rune(definition.value, state.scope);
					if (rune === '$derived' || rune === '$derived.by') {
						/** @type {import('../../3-transform/client/types.js').StateField} */
						const field = {
							kind: rune === '$derived.by' ? 'derived_call' : 'derived',
							// @ts-expect-error this is set in the next pass
							id: is_private ? definition.key : null
						};
 
						if (is_private) {
							private_derived.set(name, field);
						} else {
							public_derived.set(name, field);
						}
					}
				}
			}
		}
 
		// each `foo = $derived()` needs a backing `#foo` field
		for (const [name, field] of public_derived) {
			let deconflicted = name;
			while (private_ids.includes(deconflicted)) {
				deconflicted = '_' + deconflicted;
			}
 
			private_ids.push(deconflicted);
			field.id = b.private_id(deconflicted);
		}
 
		/** @type {Array<import('estree').MethodDefinition | import('estree').PropertyDefinition>} */
		const body = [];
 
		const child_state = { ...state, private_derived };
 
		// Replace parts of the class body
		for (const definition of node.body) {
			if (
				definition.type === 'PropertyDefinition' &&
				(definition.key.type === 'Identifier' || definition.key.type === 'PrivateIdentifier')
			) {
				const name = definition.key.name;
 
				const is_private = definition.key.type === 'PrivateIdentifier';
				const field = (is_private ? private_derived : public_derived).get(name);
 
				if (definition.value?.type === 'CallExpression' && field !== undefined) {
					const init = /** @type {import('estree').Expression} **/ (
						visit(definition.value.arguments[0], child_state)
					);
					const value =
						field.kind === 'derived_call'
							? b.call('$.once', init)
							: b.call('$.once', b.thunk(init));
 
					if (is_private) {
						body.push(b.prop_def(field.id, value));
					} else {
						// #foo;
						const member = b.member(b.this, field.id);
						body.push(b.prop_def(field.id, value));
 
						// get foo() { return this.#foo; }
						body.push(b.method('get', definition.key, [], [b.return(b.call(member))]));
 
						if ((field.kind === 'derived' || field.kind === 'derived_call') && state.options.dev) {
							body.push(
								b.method(
									'set',
									definition.key,
									[b.id('_')],
									[b.throw_error(`Cannot update a derived property ('${name}')`)]
								)
							);
						}
					}
 
					continue;
				}
			}
 
			body.push(/** @type {import('estree').MethodDefinition} **/ (visit(definition, child_state)));
		}
 
		return { ...node, body };
	},
	PropertyDefinition(node, { state, next, visit }) {
		if (node.value != null && node.value.type === 'CallExpression') {
			const rune = get_rune(node.value, state.scope);
 
			if (rune === '$state' || rune === '$state.frozen' || rune === '$derived') {
				return {
					...node,
					value:
						node.value.arguments.length === 0
							? null
							: /** @type {import('estree').Expression} */ (visit(node.value.arguments[0]))
				};
			}
			if (rune === '$derived.by') {
				return {
					...node,
					value:
						node.value.arguments.length === 0
							? null
							: b.call(/** @type {import('estree').Expression} */ (visit(node.value.arguments[0])))
				};
			}
		}
		next();
	},
	VariableDeclaration(node, { state, visit }) {
		const declarations = [];
 
		for (const declarator of node.declarations) {
			const init = declarator.init;
			const rune = get_rune(init, state.scope);
			if (!rune || rune === '$effect.tracking' || rune === '$inspect' || rune === '$effect.root') {
				declarations.push(/** @type {import('estree').VariableDeclarator} */ (visit(declarator)));
				continue;
			}
 
			if (rune === '$props') {
				// remove $bindable() from props declaration
				const id = walk(declarator.id, null, {
					AssignmentPattern(node) {
						if (
							node.right.type === 'CallExpression' &&
							get_rune(node.right, state.scope) === '$bindable'
						) {
							const right = node.right.arguments.length
								? /** @type {import('estree').Expression} */ (visit(node.right.arguments[0]))
								: b.id('undefined');
							return b.assignment_pattern(node.left, right);
						}
					}
				});
				declarations.push(b.declarator(id, b.id('$$props')));
				continue;
			}
 
			const args = /** @type {import('estree').CallExpression} */ (init).arguments;
			const value =
				args.length === 0
					? b.id('undefined')
					: /** @type {import('estree').Expression} */ (visit(args[0]));
 
			if (rune === '$derived.by') {
				declarations.push(
					b.declarator(
						/** @type {import('estree').Pattern} */ (visit(declarator.id)),
						b.call(value)
					)
				);
				continue;
			}
 
			if (declarator.id.type === 'Identifier') {
				declarations.push(b.declarator(declarator.id, value));
				continue;
			}
 
			if (rune === '$derived') {
				declarations.push(
					b.declarator(/** @type {import('estree').Pattern} */ (visit(declarator.id)), value)
				);
				continue;
			}
 
			declarations.push(...create_state_declarators(declarator, state.scope, value));
		}
 
		return {
			...node,
			declarations
		};
	},
	ExpressionStatement(node, context) {
		const expression = node.expression;
		if (expression.type === 'CallExpression') {
			const callee = expression.callee;
 
			if (callee.type === 'Identifier' && callee.name === '$effect') {
				return b.empty;
			}
 
			if (
				callee.type === 'MemberExpression' &&
				callee.object.type === 'Identifier' &&
				callee.object.name === '$effect'
			) {
				return b.empty;
			}
		}
		context.next();
	},
	MemberExpression(node, context) {
		if (node.object.type === 'ThisExpression' && node.property.type === 'PrivateIdentifier') {
			const field = context.state.private_derived.get(node.property.name);
			if (field) {
				return b.call(node);
			}
		}
 
		context.next();
	}
};
 
/**
 *
 * @param {true | Array<import('#compiler').Text | import('#compiler').ExpressionTag>} value
 * @param {import('./types').ComponentContext} context
 * @param {boolean} trim_whitespace
 * @param {boolean} is_component
 * @returns {import('estree').Expression}
 */
function serialize_attribute_value(value, context, trim_whitespace = false, is_component = false) {
	if (value === true) {
		return b.true;
	}
 
	if (value.length === 1) {
		const chunk = value[0];
 
		if (chunk.type === 'Text') {
			const data = trim_whitespace
				? chunk.data.replace(regex_whitespaces_strict, ' ').trim()
				: chunk.data;
 
			return b.literal(is_component ? data : escape_html(data, true));
		}
 
		return /** @type {import('estree').Expression} */ (context.visit(chunk.expression));
	}
 
	let quasi = b.quasi('', false);
	const quasis = [quasi];
 
	/** @type {import('estree').Expression[]} */
	const expressions = [];
 
	for (let i = 0; i < value.length; i++) {
		const node = value[i];
 
		if (node.type === 'Text') {
			quasi.value.raw += trim_whitespace
				? node.data.replace(regex_whitespaces_strict, ' ')
				: node.data;
		} else {
			expressions.push(
				b.call(
					'$.stringify',
					/** @type {import('estree').Expression} */ (context.visit(node.expression))
				)
			);
 
			quasi = b.quasi('', i + 1 === value.length);
			quasis.push(quasi);
		}
	}
 
	return b.template(quasis, expressions);
}
 
/**
 *
 * @param {import('#compiler').RegularElement | import('#compiler').SvelteElement} element
 * @param {Array<import('#compiler').Attribute | import('#compiler').SpreadAttribute>} attributes
 * @param {import('#compiler').StyleDirective[]} style_directives
 * @param {import('#compiler').ClassDirective[]} class_directives
 * @param {import('./types').ComponentContext} context
 */
function serialize_element_spread_attributes(
	element,
	attributes,
	style_directives,
	class_directives,
	context
) {
	let classes;
	let styles;
	let flags = 0;
 
	if (class_directives.length > 0 || context.state.analysis.css.hash) {
		const properties = class_directives.map((directive) =>
			b.init(
				directive.name,
				directive.expression.type === 'Identifier' && directive.expression.name === directive.name
					? b.id(directive.name)
					: /** @type {import('estree').Expression} */ (context.visit(directive.expression))
			)
		);
 
		if (context.state.analysis.css.hash) {
			properties.unshift(b.init(context.state.analysis.css.hash, b.literal(true)));
		}
 
		classes = b.object(properties);
	}
 
	if (style_directives.length > 0) {
		const properties = style_directives.map((directive) =>
			b.init(
				directive.name,
				directive.value === true
					? b.id(directive.name)
					: serialize_attribute_value(directive.value, context, true)
			)
		);
 
		styles = b.object(properties);
	}
 
	if (element.metadata.svg || element.metadata.mathml) {
		flags |= ELEMENT_IS_NAMESPACED | ELEMENT_PRESERVE_ATTRIBUTE_CASE;
	} else if (is_custom_element_node(element)) {
		flags |= ELEMENT_PRESERVE_ATTRIBUTE_CASE;
	}
 
	const object = b.object(
		attributes.map((attribute) => {
			if (attribute.type === 'Attribute') {
				const name = get_attribute_name(element, attribute, context);
				const value = serialize_attribute_value(
					attribute.value,
					context,
					WhitespaceInsensitiveAttributes.includes(name)
				);
				return b.prop('init', b.key(name), value);
			}
 
			return b.spread(/** @type {import('estree').Expression} */ (context.visit(attribute)));
		})
	);
 
	const args = [object, classes, styles, flags ? b.literal(flags) : undefined];
	context.state.template.push(b.call('$.spread_attributes', ...args));
}
 
/**
 * @param {import('#compiler').Component | import('#compiler').SvelteComponent | import('#compiler').SvelteSelf} node
 * @param {import('estree').Expression} expression
 * @param {import('./types').ComponentContext} context
 */
function serialize_inline_component(node, expression, context) {
	/** @type {Array<import('estree').Property[] | import('estree').Expression>} */
	const props_and_spreads = [];
 
	/** @type {import('estree').Property[]} */
	const custom_css_props = [];
 
	/** @type {import('estree').ExpressionStatement[]} */
	const lets = [];
 
	/** @type {Record<string, import('#compiler').TemplateNode[]>} */
	const children = {};
 
	/**
	 * If this component has a slot property, it is a named slot within another component. In this case
	 * the slot scope applies to the component itself, too, and not just its children.
	 */
	let slot_scope_applies_to_itself = false;
 
	/**
	 * Components may have a children prop and also have child nodes. In this case, we assume
	 * that the child component isn't using render tags yet and pass the slot as $$slots.default.
	 * We're not doing it for spread attributes, as this would result in too many false positives.
	 */
	let has_children_prop = false;
 
	/**
	 * @param {import('estree').Property} prop
	 */
	function push_prop(prop) {
		const current = props_and_spreads.at(-1);
		const current_is_props = Array.isArray(current);
		const props = current_is_props ? current : [];
		props.push(prop);
		if (!current_is_props) {
			props_and_spreads.push(props);
		}
	}
	for (const attribute of node.attributes) {
		if (attribute.type === 'LetDirective') {
			lets.push(/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute)));
		} else if (attribute.type === 'SpreadAttribute') {
			props_and_spreads.push(/** @type {import('estree').Expression} */ (context.visit(attribute)));
		} else if (attribute.type === 'Attribute') {
			if (attribute.name.startsWith('--')) {
				const value = serialize_attribute_value(attribute.value, context, false, true);
				custom_css_props.push(b.init(attribute.name, value));
				continue;
			}
 
			if (attribute.name === 'slot') {
				slot_scope_applies_to_itself = true;
			}
 
			if (attribute.name === 'children') {
				has_children_prop = true;
			}
 
			const value = serialize_attribute_value(attribute.value, context, false, true);
			push_prop(b.prop('init', b.key(attribute.name), value));
		} else if (attribute.type === 'BindDirective' && attribute.name !== 'this') {
			// TODO this needs to turn the whole thing into a while loop because the binding could be mutated eagerly in the child
			push_prop(
				b.get(attribute.name, [
					b.return(/** @type {import('estree').Expression} */ (context.visit(attribute.expression)))
				])
			);
			push_prop(
				b.set(attribute.name, [
					b.stmt(
						/** @type {import('estree').Expression} */ (
							context.visit(b.assignment('=', attribute.expression, b.id('$$value')))
						)
					),
					b.stmt(b.assignment('=', b.id('$$settled'), b.false))
				])
			);
		}
	}
 
	if (slot_scope_applies_to_itself) {
		context.state.init.push(...lets);
	}
 
	/** @type {import('estree').Statement[]} */
	const snippet_declarations = [];
 
	// Group children by slot
	for (const child of node.fragment.nodes) {
		if (child.type === 'SnippetBlock') {
			// the SnippetBlock visitor adds a declaration to `init`, but if it's directly
			// inside a component then we want to hoist them into a block so that they
			// can be used as props without creating conflicts
			context.visit(child, {
				...context.state,
				init: snippet_declarations
			});
 
			push_prop(b.prop('init', child.expression, child.expression));
 
			continue;
		}
 
		let slot_name = 'default';
		if (is_element_node(child)) {
			const attribute = /** @type {import('#compiler').Attribute | undefined} */ (
				child.attributes.find(
					(attribute) => attribute.type === 'Attribute' && attribute.name === 'slot'
				)
			);
			if (attribute !== undefined) {
				slot_name = /** @type {import('#compiler').Text[]} */ (attribute.value)[0].data;
			}
		}
 
		children[slot_name] = children[slot_name] || [];
		children[slot_name].push(child);
	}
 
	// Serialize each slot
	/** @type {import('estree').Property[]} */
	const serialized_slots = [];
 
	for (const slot_name of Object.keys(children)) {
		const block = /** @type {import('estree').BlockStatement} */ (
			context.visit(
				{
					...node.fragment,
					// @ts-expect-error
					nodes: children[slot_name]
				},
				{
					...context.state,
					scope:
						context.state.scopes.get(slot_name === 'default' ? children[slot_name][0] : node) ??
						context.state.scope
				}
			)
		);
 
		if (block.body.length === 0) continue;
 
		const slot_fn = b.arrow(
			[b.id('$$payload'), b.id('$$slotProps')],
			b.block([
				...(slot_name === 'default' && !slot_scope_applies_to_itself ? lets : []),
				...block.body
			])
		);
 
		if (slot_name === 'default' && !has_children_prop) {
			push_prop(
				b.prop(
					'init',
					b.id('children'),
					context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
				)
			);
			// We additionally add the default slot as a boolean, so that the slot render function on the other
			// side knows it should get the content to render from $$props.children
			serialized_slots.push(b.init('default', b.true));
		} else {
			const slot = b.prop('init', b.literal(slot_name), slot_fn);
			serialized_slots.push(slot);
		}
	}
 
	if (serialized_slots.length > 0) {
		push_prop(b.prop('init', b.id('$$slots'), b.object(serialized_slots)));
	}
 
	const props_expression =
		props_and_spreads.length === 0 ||
		(props_and_spreads.length === 1 && Array.isArray(props_and_spreads[0]))
			? b.object(/** @type {import('estree').Property[]} */ (props_and_spreads[0] || []))
			: b.call(
					'$.spread_props',
					b.array(props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p)))
				);
 
	/** @type {import('estree').Statement} */
	let statement = b.stmt(
		(node.type === 'SvelteComponent' ? b.maybe_call : b.call)(
			context.state.options.dev ? b.call('$.validate_component', expression) : expression,
			b.id('$$payload'),
			props_expression
		)
	);
 
	if (snippet_declarations.length > 0) {
		statement = b.block([...snippet_declarations, statement]);
	}
 
	const dynamic =
		node.type === 'SvelteComponent' || (node.type === 'Component' && node.metadata.dynamic);
 
	if (custom_css_props.length > 0) {
		context.state.template.push(
			b.stmt(
				b.call(
					'$.css_props',
					b.id('$$payload'),
					b.literal(context.state.namespace === 'svg' ? false : true),
					b.object(custom_css_props),
					b.thunk(b.block([statement])),
					dynamic && b.true
				)
			)
		);
	} else {
		if (dynamic) {
			context.state.template.push(empty_comment);
		}
 
		context.state.template.push(statement);
 
		if (!context.state.skip_hydration_boundaries) {
			context.state.template.push(empty_comment);
		}
	}
}
 
/** @type {import('./types').Visitors} */
const javascript_visitors_legacy = {
	VariableDeclaration(node, { state, visit }) {
		/** @type {import('estree').VariableDeclarator[]} */
		const declarations = [];
 
		for (const declarator of node.declarations) {
			const bindings = /** @type {import('#compiler').Binding[]} */ (
				state.scope.get_bindings(declarator)
			);
			const has_state = bindings.some((binding) => binding.kind === 'state');
			const has_props = bindings.some((binding) => binding.kind === 'bindable_prop');
 
			if (!has_state && !has_props) {
				declarations.push(/** @type {import('estree').VariableDeclarator} */ (visit(declarator)));
				continue;
			}
 
			if (has_props) {
				if (declarator.id.type !== 'Identifier') {
					// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
					// means that foo and bar are the props (i.e. the leafs are the prop names), not x and z.
					const tmp = state.scope.generate('tmp');
					const paths = extract_paths(declarator.id);
					declarations.push(
						b.declarator(
							b.id(tmp),
							/** @type {import('estree').Expression} */ (
								visit(/** @type {import('estree').Expression} */ (declarator.init))
							)
						)
					);
					for (const path of paths) {
						const value = path.expression?.(b.id(tmp));
						const name = /** @type {import('estree').Identifier} */ (path.node).name;
						const binding = /** @type {import('#compiler').Binding} */ (state.scope.get(name));
						const prop = b.member(b.id('$$props'), b.literal(binding.prop_alias ?? name), true);
						declarations.push(
							b.declarator(path.node, b.call('$.value_or_fallback', prop, b.thunk(value)))
						);
					}
					continue;
				}
 
				const binding = /** @type {import('#compiler').Binding} */ (
					state.scope.get(declarator.id.name)
				);
				const prop = b.member(
					b.id('$$props'),
					b.literal(binding.prop_alias ?? declarator.id.name),
					true
				);
 
				/** @type {import('estree').Expression} */
				let init = prop;
				if (declarator.init) {
					const default_value = /** @type {import('estree').Expression} */ (visit(declarator.init));
					init = is_expression_async(default_value)
						? b.await(b.call('$.value_or_fallback_async', prop, b.thunk(default_value, true)))
						: b.call('$.value_or_fallback', prop, b.thunk(default_value));
				}
 
				declarations.push(b.declarator(declarator.id, init));
 
				continue;
			}
 
			declarations.push(
				...create_state_declarators(
					declarator,
					state.scope,
					/** @type {import('estree').Expression} */ (declarator.init && visit(declarator.init))
				)
			);
		}
 
		return {
			...node,
			declarations
		};
	},
	LabeledStatement(node, context) {
		if (context.path.length > 1) return;
		if (node.label.name !== '$') return;
 
		// TODO bail out if we're in module context
 
		// these statements will be topologically ordered later
		context.state.legacy_reactive_statements.set(
			node,
			// people could do "break $" inside, so we need to keep the label
			b.labeled('$', /** @type {import('estree').ExpressionStatement} */ (context.visit(node.body)))
		);
 
		return b.empty;
	}
};
 
/** @type {import('./types').ComponentVisitors} */
const template_visitors = {
	Fragment(node, context) {
		const parent = context.path.at(-1) ?? node;
		const namespace = infer_namespace(context.state.namespace, parent, node.nodes);
 
		const { hoisted, trimmed, is_standalone, is_text_first } = clean_nodes(
			parent,
			node.nodes,
			context.path,
			namespace,
			context.state,
			context.state.preserve_whitespace,
			context.state.options.preserveComments
		);
 
		/** @type {import('./types').ComponentServerTransformState} */
		const state = {
			...context.state,
			init: [],
			template: [],
			namespace,
			skip_hydration_boundaries: is_standalone
		};
 
		for (const node of hoisted) {
			context.visit(node, state);
		}
 
		if (is_text_first) {
			// insert `<!---->` to prevent this from being glued to the previous fragment
			state.template.push(empty_comment);
		}
 
		process_children(trimmed, { ...context, state });
 
		return b.block([...state.init, ...serialize_template(state.template)]);
	},
	HtmlTag(node, context) {
		const expression = /** @type {import('estree').Expression} */ (context.visit(node.expression));
		context.state.template.push(b.call('$.html', expression));
	},
	ConstTag(node, { state, visit }) {
		const declaration = node.declaration.declarations[0];
		const pattern = /** @type {import('estree').Pattern} */ (visit(declaration.id));
		const init = /** @type {import('estree').Expression} */ (visit(declaration.init));
		state.init.push(b.declaration('const', pattern, init));
	},
	DebugTag(node, { state, visit }) {
		state.template.push(
			b.stmt(
				b.call(
					'console.log',
					b.object(
						node.identifiers.map((identifier) =>
							b.prop(
								'init',
								identifier,
								/** @type {import('estree').Expression} */ (visit(identifier))
							)
						)
					)
				)
			),
			b.debugger
		);
	},
	RenderTag(node, context) {
		const callee = unwrap_optional(node.expression).callee;
		const raw_args = unwrap_optional(node.expression).arguments;
 
		const expression = /** @type {import('estree').Expression} */ (context.visit(callee));
		const snippet_function = context.state.options.dev
			? b.call('$.validate_snippet', expression)
			: expression;
 
		const snippet_args = raw_args.map((arg) => {
			return /** @type {import('estree').Expression} */ (context.visit(arg));
		});
 
		context.state.template.push(
			b.stmt(
				(node.expression.type === 'CallExpression' ? b.call : b.maybe_call)(
					snippet_function,
					b.id('$$payload'),
					...snippet_args
				)
			)
		);
 
		if (!context.state.skip_hydration_boundaries) {
			context.state.template.push(empty_comment);
		}
	},
	ClassDirective() {
		throw new Error('Node should have been handled elsewhere');
	},
	StyleDirective() {
		throw new Error('Node should have been handled elsewhere');
	},
	RegularElement(node, context) {
		context.state.template.push(b.literal(`<${node.name}`));
		const body = serialize_element_attributes(node, context);
		context.state.template.push(b.literal('>'));
 
		if ((node.name === 'script' || node.name === 'style') && node.fragment.nodes.length === 1) {
			context.state.template.push(
				b.literal(/** @type {import('#compiler').Text} */ (node.fragment.nodes[0]).data),
				b.literal(`</${node.name}>`)
			);
 
			return;
		}
 
		const namespace = determine_namespace_for_children(node, context.state.namespace);
 
		/** @type {import('./types').ComponentServerTransformState} */
		const state = {
			...context.state,
			namespace,
			preserve_whitespace:
				context.state.preserve_whitespace ||
				((node.name === 'pre' || node.name === 'textarea') && namespace !== 'foreign')
		};
 
		const { hoisted, trimmed } = clean_nodes(
			node,
			node.fragment.nodes,
			context.path,
			namespace,
			{
				...state,
				scope: /** @type {import('../../scope').Scope} */ (state.scopes.get(node.fragment))
			},
			state.preserve_whitespace,
			state.options.preserveComments
		);
 
		for (const node of hoisted) {
			context.visit(node, state);
		}
 
		if (state.options.dev) {
			const location = /** @type {import('locate-character').Location} */ (locator(node.start));
			state.template.push(
				b.stmt(
					b.call(
						'$.push_element',
						b.id('$$payload'),
						b.literal(node.name),
						b.literal(location.line),
						b.literal(location.column)
					)
				)
			);
		}
 
		if (body === null) {
			process_children(trimmed, { ...context, state });
		} else {
			let id = body;
 
			if (body.type !== 'Identifier') {
				id = b.id(state.scope.generate('$$body'));
				state.template.push(b.const(id, body));
			}
 
			// if this is a `<textarea>` value or a contenteditable binding, we only add
			// the body if the attribute/binding is falsy
			const inner_state = { ...state, template: [], init: [] };
			process_children(trimmed, { ...context, state: inner_state });
 
			// Use the body expression as the body if it's truthy, otherwise use the inner template
			state.template.push(
				b.if(
					id,
					b.block(serialize_template([id])),
					b.block([...inner_state.init, ...serialize_template(inner_state.template)])
				)
			);
		}
 
		if (!VoidElements.includes(node.name) && namespace !== 'foreign') {
			state.template.push(b.literal(`</${node.name}>`));
		}
 
		if (state.options.dev) {
			state.template.push(b.stmt(b.call('$.pop_element')));
		}
	},
	SvelteElement(node, context) {
		let tag = /** @type {import('estree').Expression} */ (context.visit(node.tag));
		if (tag.type !== 'Identifier') {
			const tag_id = context.state.scope.generate('$$tag');
			context.state.init.push(b.const(tag_id, tag));
			tag = b.id(tag_id);
		}
 
		if (context.state.options.dev) {
			if (node.fragment.nodes.length > 0) {
				context.state.init.push(b.stmt(b.call('$.validate_void_dynamic_element', b.thunk(tag))));
			}
			context.state.init.push(b.stmt(b.call('$.validate_dynamic_element_tag', b.thunk(tag))));
		}
 
		const state = {
			...context.state,
			namespace: determine_namespace_for_children(node, context.state.namespace),
			template: [],
			init: []
		};
 
		serialize_element_attributes(node, { ...context, state });
 
		if (context.state.options.dev) {
			context.state.template.push(b.stmt(b.call('$.push_element', tag, b.id('$$payload'))));
		}
 
		const attributes = b.block([...state.init, ...serialize_template(state.template)]);
		const children = /** @type {import('estree').BlockStatement} */ (
			context.visit(node.fragment, state)
		);
 
		context.state.template.push(
			b.stmt(
				b.call(
					'$.element',
					b.id('$$payload'),
					tag,
					attributes.body.length > 0 && b.thunk(attributes),
					children.body.length > 0 && b.thunk(children)
				)
			)
		);
 
		if (context.state.options.dev) {
			context.state.template.push(b.stmt(b.call('$.pop_element')));
		}
	},
	EachBlock(node, context) {
		const state = context.state;
 
		const each_node_meta = node.metadata;
		const collection = /** @type {import('estree').Expression} */ (context.visit(node.expression));
		const item = each_node_meta.item;
		const index =
			each_node_meta.contains_group_binding || !node.index
				? each_node_meta.index
				: b.id(node.index);
 
		const array_id = state.scope.root.unique('each_array');
		state.init.push(b.const(array_id, b.call('$.ensure_array_like', collection)));
 
		/** @type {import('estree').Statement[]} */
		const each = [b.const(item, b.member(array_id, index, true))];
 
		if (node.context.type !== 'Identifier') {
			each.push(b.const(/** @type {import('estree').Pattern} */ (node.context), item));
		}
		if (index.name !== node.index && node.index != null) {
			each.push(b.let(node.index, index));
		}
 
		each.push(.../** @type {import('estree').BlockStatement} */ (context.visit(node.body)).body);
 
		const for_loop = b.for(
			b.let(index, b.literal(0)),
			b.binary('<', index, b.member(array_id, b.id('length'))),
			b.update('++', index, false),
			b.block(each)
		);
 
		if (node.fallback) {
			const open = b.stmt(b.assignment('+=', b.id('$$payload.out'), block_open));
 
			const fallback = /** @type {import('estree').BlockStatement} */ (
				context.visit(node.fallback)
			);
 
			fallback.body.unshift(
				b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN_ELSE)))
			);
 
			state.template.push(
				b.if(
					b.binary('!==', b.member(array_id, b.id('length')), b.literal(0)),
					b.block([open, for_loop]),
					fallback
				),
				block_close
			);
		} else {
			state.template.push(block_open, for_loop, block_close);
		}
	},
	IfBlock(node, context) {
		const test = /** @type {import('estree').Expression} */ (context.visit(node.test));
 
		const consequent = /** @type {import('estree').BlockStatement} */ (
			context.visit(node.consequent)
		);
 
		const alternate = node.alternate
			? /** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
			: b.block([]);
 
		consequent.body.unshift(b.stmt(b.assignment('+=', b.id('$$payload.out'), block_open)));
 
		alternate.body.unshift(
			b.stmt(b.assignment('+=', b.id('$$payload.out'), b.literal(BLOCK_OPEN_ELSE)))
		);
 
		context.state.template.push(b.if(test, consequent, alternate), block_close);
	},
	AwaitBlock(node, context) {
		context.state.template.push(
			empty_comment,
			b.stmt(
				b.call(
					'$.await',
					/** @type {import('estree').Expression} */ (context.visit(node.expression)),
					b.thunk(
						node.pending
							? /** @type {import('estree').BlockStatement} */ (context.visit(node.pending))
							: b.block([])
					),
					b.arrow(
						node.value ? [/** @type {import('estree').Pattern} */ (context.visit(node.value))] : [],
						node.then
							? /** @type {import('estree').BlockStatement} */ (context.visit(node.then))
							: b.block([])
					),
					b.arrow(
						node.error ? [/** @type {import('estree').Pattern} */ (context.visit(node.error))] : [],
						node.catch
							? /** @type {import('estree').BlockStatement} */ (context.visit(node.catch))
							: b.block([])
					)
				)
			),
			empty_comment
		);
	},
	KeyBlock(node, context) {
		const block = /** @type {import('estree').BlockStatement} */ (context.visit(node.fragment));
		context.state.template.push(empty_comment, block, empty_comment);
	},
	SnippetBlock(node, context) {
		const fn = b.function_declaration(
			node.expression,
			[b.id('$$payload'), ...node.parameters],
			/** @type {import('estree').BlockStatement} */ (context.visit(node.body))
		);
		// @ts-expect-error - TODO remove this hack once $$render_inner for legacy bindings is gone
		fn.___snippet = true;
		// TODO hoist where possible
		context.state.init.push(fn);
 
		if (context.state.options.dev) {
			context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression)));
		}
	},
	Component(node, context) {
		serialize_inline_component(node, b.id(node.name), context);
	},
	SvelteSelf(node, context) {
		serialize_inline_component(node, b.id(context.state.analysis.name), context);
	},
	SvelteComponent(node, context) {
		serialize_inline_component(
			node,
			/** @type {import('estree').Expression} */ (context.visit(node.expression)),
			context
		);
	},
	LetDirective(node, { state }) {
		if (node.expression === null || node.expression.type === 'Identifier') {
			const name = node.expression === null ? node.name : node.expression.name;
			return b.const(name, b.member(b.id('$$slotProps'), b.id(node.name)));
		}
 
		const name = state.scope.generate(node.name);
		const bindings = state.scope.get_bindings(node);
 
		for (const binding of bindings) {
			binding.expression = b.member(b.id(name), b.id(binding.node.name));
		}
 
		return b.const(
			name,
			b.call(
				b.thunk(
					b.block([
						b.let(
							node.expression.type === 'ObjectExpression'
								? // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
									b.object_pattern(node.expression.properties)
								: // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
									b.array_pattern(node.expression.elements),
							b.member(b.id('$$slotProps'), b.id(node.name))
						),
						b.return(b.object(bindings.map((binding) => b.init(binding.node.name, binding.node))))
					])
				)
			)
		);
	},
	SpreadAttribute(node, { visit }) {
		return visit(node.expression);
	},
	SvelteFragment(node, context) {
		for (const attribute of node.attributes) {
			if (attribute.type === 'LetDirective') {
				context.state.template.push(
					/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute))
				);
			}
		}
 
		const block = /** @type {import('estree').BlockStatement} */ (context.visit(node.fragment));
 
		context.state.template.push(block);
	},
	TitleElement(node, context) {
		// title is guaranteed to contain only text/expression tag children
		const template = [b.literal('<title>')];
		process_children(node.fragment.nodes, { ...context, state: { ...context.state, template } });
		template.push(b.literal('</title>'));
 
		context.state.init.push(...serialize_template(template, b.id('$$payload.title'), '='));
	},
	SlotElement(node, context) {
		/** @type {import('estree').Property[]} */
		const props = [];
 
		/** @type {import('estree').Expression[]} */
		const spreads = [];
 
		/** @type {import('estree').ExpressionStatement[]} */
		const lets = [];
 
		/** @type {import('estree').Expression} */
		let expression = b.call('$.default_slot', b.id('$$props'));
 
		for (const attribute of node.attributes) {
			if (attribute.type === 'SpreadAttribute') {
				spreads.push(/** @type {import('estree').Expression} */ (context.visit(attribute)));
			} else if (attribute.type === 'Attribute') {
				const value = serialize_attribute_value(attribute.value, context, false, true);
 
				if (attribute.name === 'name') {
					expression = b.member(b.member_id('$$props.$$slots'), value, true, true);
				} else if (attribute.name !== 'slot') {
					if (attribute.metadata.dynamic) {
						props.push(b.get(attribute.name, [b.return(value)]));
					} else {
						props.push(b.init(attribute.name, value));
					}
				}
			} else if (attribute.type === 'LetDirective') {
				lets.push(/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute)));
			}
		}
 
		// Let bindings first, they can be used on attributes
		context.state.init.push(...lets);
 
		const props_expression =
			spreads.length === 0
				? b.object(props)
				: b.call('$.spread_props', b.array([b.object(props), ...spreads]));
 
		const fallback =
			node.fragment.nodes.length === 0
				? b.literal(null)
				: b.thunk(/** @type {import('estree').BlockStatement} */ (context.visit(node.fragment)));
 
		const slot = b.call('$.slot', b.id('$$payload'), expression, props_expression, fallback);
 
		context.state.template.push(empty_comment, b.stmt(slot), empty_comment);
	},
	SvelteHead(node, context) {
		const block = /** @type {import('estree').BlockStatement} */ (context.visit(node.fragment));
 
		context.state.template.push(
			b.stmt(b.call('$.head', b.id('$$payload'), b.arrow([b.id('$$payload')], block)))
		);
	}
};
 
/**
 * Writes the output to the template output. Some elements may have attributes on them that require the
 * their output to be the child content instead. In this case, an object is returned.
 * @param {import('#compiler').RegularElement | import('#compiler').SvelteElement} node
 * @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types').ComponentServerTransformState>} context
 */
function serialize_element_attributes(node, context) {
	/** @type {Array<import('#compiler').Attribute | import('#compiler').SpreadAttribute>} */
	const attributes = [];
 
	/** @type {import('#compiler').ClassDirective[]} */
	const class_directives = [];
 
	/** @type {import('#compiler').StyleDirective[]} */
	const style_directives = [];
 
	/** @type {import('estree').ExpressionStatement[]} */
	const lets = [];
 
	/** @type {import('estree').Expression | null} */
	let content = null;
 
	let has_spread = false;
	// Use the index to keep the attributes order which is important for spreading
	let class_index = -1;
	let style_index = -1;
	let events_to_capture = new Set();
 
	for (const attribute of node.attributes) {
		if (attribute.type === 'Attribute') {
			if (attribute.name === 'value') {
				if (node.name === 'textarea') {
					if (
						attribute.value !== true &&
						attribute.value[0].type === 'Text' &&
						regex_starts_with_newline.test(attribute.value[0].data)
					) {
						// Two or more leading newlines are required to restore the leading newline immediately after `<textarea>`.
						// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
						// also see related code in analysis phase
						attribute.value[0].data = '\n' + attribute.value[0].data;
					}
					content = b.call('$.escape', serialize_attribute_value(attribute.value, context));
				} else if (node.name !== 'select') {
					// omit value attribute for select elements, it's irrelevant for the initially selected value and has no
					// effect on the selected value after the user interacts with the select element (the value _property_ does, but not the attribute)
					attributes.push(attribute);
				}
 
				// omit event handlers except for special cases
			} else if (is_event_attribute(attribute)) {
				if (
					(attribute.name === 'onload' || attribute.name === 'onerror') &&
					LoadErrorElements.includes(node.name)
				) {
					events_to_capture.add(attribute.name);
				}
			} else {
				if (attribute.name === 'class') {
					class_index = attributes.length;
				} else if (attribute.name === 'style') {
					style_index = attributes.length;
				}
				attributes.push(attribute);
			}
		} else if (attribute.type === 'BindDirective') {
			if (attribute.name === 'value' && node.name === 'select') continue;
			if (
				attribute.name === 'value' &&
				attributes.some(
					(attr) =>
						attr.type === 'Attribute' &&
						attr.name === 'type' &&
						is_text_attribute(attr) &&
						attr.value[0].data === 'file'
				)
			) {
				continue;
			}
			if (attribute.name === 'this') continue;
 
			const binding = binding_properties[attribute.name];
			if (binding?.omit_in_ssr) continue;
 
			if (ContentEditableBindings.includes(attribute.name)) {
				content = /** @type {import('estree').Expression} */ (context.visit(attribute.expression));
			} else if (attribute.name === 'value' && node.name === 'textarea') {
				content = b.call(
					'$.escape',
					/** @type {import('estree').Expression} */ (context.visit(attribute.expression))
				);
			} else if (attribute.name === 'group') {
				const value_attribute = /** @type {import('#compiler').Attribute | undefined} */ (
					node.attributes.find((attr) => attr.type === 'Attribute' && attr.name === 'value')
				);
				if (!value_attribute) continue;
 
				const is_checkbox = node.attributes.some(
					(attr) =>
						attr.type === 'Attribute' &&
						attr.name === 'type' &&
						is_text_attribute(attr) &&
						attr.value[0].data === 'checkbox'
				);
				attributes.push(
					create_attribute('checked', -1, -1, [
						{
							type: 'ExpressionTag',
							start: -1,
							end: -1,
							parent: attribute,
							expression: is_checkbox
								? b.call(
										b.member(attribute.expression, b.id('includes')),
										serialize_attribute_value(value_attribute.value, context)
									)
								: b.binary(
										'===',
										attribute.expression,
										serialize_attribute_value(value_attribute.value, context)
									),
							metadata: {
								contains_call_expression: false,
								dynamic: false
							}
						}
					])
				);
			} else {
				attributes.push(
					create_attribute(attribute.name, -1, -1, [
						{
							type: 'ExpressionTag',
							start: -1,
							end: -1,
							parent: attribute,
							expression: attribute.expression,
							metadata: {
								contains_call_expression: false,
								dynamic: false
							}
						}
					])
				);
			}
		} else if (attribute.type === 'SpreadAttribute') {
			attributes.push(attribute);
			has_spread = true;
			if (LoadErrorElements.includes(node.name)) {
				events_to_capture.add('onload');
				events_to_capture.add('onerror');
			}
		} else if (attribute.type === 'UseDirective') {
			if (LoadErrorElements.includes(node.name)) {
				events_to_capture.add('onload');
				events_to_capture.add('onerror');
			}
		} else if (attribute.type === 'ClassDirective') {
			class_directives.push(attribute);
		} else if (attribute.type === 'StyleDirective') {
			style_directives.push(attribute);
		} else if (attribute.type === 'LetDirective') {
			lets.push(/** @type {import('estree').ExpressionStatement} */ (context.visit(attribute)));
		} else {
			context.visit(attribute);
		}
	}
 
	if (class_directives.length > 0 && !has_spread) {
		const class_attribute = serialize_class_directives(
			class_directives,
			/** @type {import('#compiler').Attribute | null} */ (attributes[class_index] ?? null)
		);
		if (class_index === -1) {
			attributes.push(class_attribute);
		}
	}
 
	if (style_directives.length > 0 && !has_spread) {
		serialize_style_directives(
			style_directives,
			/** @type {import('#compiler').Attribute | null} */ (attributes[style_index] ?? null),
			context
		);
		if (style_index > -1) {
			attributes.splice(style_index, 1);
		}
	}
 
	// Let bindings first, they can be used on attributes
	context.state.init.push(...lets);
 
	if (has_spread) {
		serialize_element_spread_attributes(
			node,
			attributes,
			style_directives,
			class_directives,
			context
		);
	} else {
		for (const attribute of /** @type {import('#compiler').Attribute[]} */ (attributes)) {
			if (attribute.value === true || is_text_attribute(attribute)) {
				const name = get_attribute_name(node, attribute, context);
				const literal_value = /** @type {import('estree').Literal} */ (
					serialize_attribute_value(
						attribute.value,
						context,
						WhitespaceInsensitiveAttributes.includes(name)
					)
				).value;
				if (name !== 'class' || literal_value) {
					context.state.template.push(
						b.literal(
							` ${attribute.name}${
								DOMBooleanAttributes.includes(name) && literal_value === true
									? ''
									: `="${literal_value === true ? '' : String(literal_value)}"`
							}`
						)
					);
				}
				continue;
			}
 
			const name = get_attribute_name(node, attribute, context);
			const is_boolean = DOMBooleanAttributes.includes(name);
			const value = serialize_attribute_value(
				attribute.value,
				context,
				WhitespaceInsensitiveAttributes.includes(name)
			);
 
			context.state.template.push(
				b.call('$.attr', b.literal(name), value, is_boolean && b.literal(is_boolean))
			);
		}
	}
 
	if (events_to_capture.size !== 0) {
		for (const event of events_to_capture) {
			context.state.template.push(b.literal(` ${event}="this.__e=event"`));
		}
	}
 
	return content;
}
 
/**
 *
 * @param {import('#compiler').ClassDirective[]} class_directives
 * @param {import('#compiler').Attribute | null} class_attribute
 * @returns
 */
function serialize_class_directives(class_directives, class_attribute) {
	const expressions = class_directives.map((directive) =>
		b.conditional(directive.expression, b.literal(directive.name), b.literal(''))
	);
	if (class_attribute === null) {
		class_attribute = create_attribute('class', -1, -1, []);
	}
	const last = /** @type {any[]} */ (class_attribute.value).at(-1);
	if (last?.type === 'Text') {
		last.data += ' ';
		last.raw += ' ';
	} else if (last) {
		/** @type {import('#compiler').Text[]} */ (class_attribute.value).push({
			type: 'Text',
			start: -1,
			end: -1,
			parent: class_attribute,
			data: ' ',
			raw: ' '
		});
	}
	/** @type {import('#compiler').ExpressionTag[]} */ (class_attribute.value).push({
		type: 'ExpressionTag',
		start: -1,
		end: -1,
		parent: class_attribute,
		expression: b.call(
			b.member(
				b.call(b.member(b.array(expressions), b.id('filter')), b.id('Boolean')),
				b.id('join')
			),
			b.literal(' ')
		),
		metadata: { contains_call_expression: false, dynamic: false }
	});
	return class_attribute;
}
 
/**
 * @param {import('#compiler').StyleDirective[]} style_directives
 * @param {import('#compiler').Attribute | null} style_attribute
 * @param {import('./types').ComponentContext} context
 */
function serialize_style_directives(style_directives, style_attribute, context) {
	const styles = style_directives.map((directive) => {
		let value =
			directive.value === true
				? b.id(directive.name)
				: serialize_attribute_value(directive.value, context, true);
		if (directive.modifiers.includes('important')) {
			value = b.binary('+', value, b.literal(' !important'));
		}
		return b.init(directive.name, value);
	});
 
	const arg =
		style_attribute === null
			? b.object(styles)
			: b.call(
					'$.merge_styles',
					serialize_attribute_value(style_attribute.value, context, true),
					b.object(styles)
				);
 
	context.state.template.push(b.call('$.add_styles', arg));
}
 
/**
 * @param {import('../../types').ComponentAnalysis} analysis
 * @param {import('#compiler').ValidatedCompileOptions} options
 * @returns {import('estree').Program}
 */
export function server_component(analysis, options) {
	/** @type {import('./types').ComponentServerTransformState} */
	const state = {
		analysis,
		options,
		scope: analysis.module.scope,
		scopes: analysis.template.scopes,
		hoisted: [b.import_all('$', 'svelte/internal/server')],
		legacy_reactive_statements: new Map(),
		// these are set inside the `Fragment` visitor, and cannot be used until then
		init: /** @type {any} */ (null),
		template: /** @type {any} */ (null),
		namespace: options.namespace,
		preserve_whitespace: options.preserveWhitespace,
		private_derived: new Map(),
		skip_hydration_boundaries: false
	};
 
	const module = /** @type {import('estree').Program} */ (
		walk(
			/** @type {import('#compiler').SvelteNode} */ (analysis.module.ast),
			state,
			// @ts-expect-error TODO: zimmerframe types
			{
				...set_scope(analysis.module.scopes),
				...global_visitors,
				...(analysis.runes ? javascript_visitors_runes : javascript_visitors_legacy)
			}
		)
	);
 
	const instance = /** @type {import('estree').Program} */ (
		walk(
			/** @type {import('#compiler').SvelteNode} */ (analysis.instance.ast),
			{ ...state, scope: analysis.instance.scope },
			// @ts-expect-error TODO: zimmerframe types
			{
				...set_scope(analysis.instance.scopes),
				...global_visitors,
				...(analysis.runes ? javascript_visitors_runes : javascript_visitors_legacy),
				ImportDeclaration(node) {
					state.hoisted.push(node);
					return b.empty;
				},
				ExportNamedDeclaration(node, context) {
					if (node.declaration) {
						return context.visit(node.declaration);
					}
 
					return b.empty;
				}
			}
		)
	);
 
	const template = /** @type {import('estree').Program} */ (
		walk(
			/** @type {import('#compiler').SvelteNode} */ (analysis.template.ast),
			{ ...state, scope: analysis.template.scope },
			// @ts-expect-error TODO: zimmerframe types
			{
				...set_scope(analysis.template.scopes),
				...global_visitors,
				...template_visitors
			}
		)
	);
 
	/** @type {import('estree').VariableDeclarator[]} */
	const legacy_reactive_declarations = [];
 
	for (const [node] of analysis.reactive_statements) {
		const statement = [...state.legacy_reactive_statements].find(([n]) => n === node);
		if (statement === undefined) {
			throw new Error('Could not find reactive statement');
		}
 
		if (
			node.body.type === 'ExpressionStatement' &&
			node.body.expression.type === 'AssignmentExpression'
		) {
			for (const id of extract_identifiers(node.body.expression.left)) {
				const binding = analysis.instance.scope.get(id.name);
				if (binding?.kind === 'legacy_reactive') {
					legacy_reactive_declarations.push(b.declarator(id));
				}
			}
		}
 
		instance.body.push(statement[1]);
	}
 
	if (legacy_reactive_declarations.length > 0) {
		instance.body.unshift({
			type: 'VariableDeclaration',
			kind: 'let',
			declarations: legacy_reactive_declarations
		});
	}
 
	// If the component binds to a child, we need to put the template in a loop and repeat until legacy bindings are stable.
	// We can remove this once the legacy syntax is gone.
	if (analysis.uses_component_bindings) {
		const snippets = template.body.filter(
			(node) =>
				node.type === 'FunctionDeclaration' &&
				// @ts-expect-error
				node.___snippet
		);
		const rest = template.body.filter(
			(node) =>
				node.type !== 'FunctionDeclaration' ||
				// @ts-expect-error
				!node.___snippet
		);
		template.body = [
			...snippets,
			b.let('$$settled', b.true),
			b.let('$$inner_payload'),
			b.stmt(
				b.function(
					b.id('$$render_inner'),
					[b.id('$$payload')],
					b.block(/** @type {import('estree').Statement[]} */ (rest))
				)
			),
			b.do_while(
				b.unary('!', b.id('$$settled')),
				b.block([
					b.stmt(b.assignment('=', b.id('$$settled'), b.true)),
					b.stmt(
						b.assignment('=', b.id('$$inner_payload'), b.call('$.copy_payload', b.id('$$payload')))
					),
					b.stmt(b.call('$$render_inner', b.id('$$inner_payload')))
				])
			),
			b.stmt(b.call('$.assign_payload', b.id('$$payload'), b.id('$$inner_payload')))
		];
	}
 
	if (
		[...analysis.instance.scope.declarations.values()].some(
			(binding) => binding.kind === 'store_sub'
		)
	) {
		instance.body.unshift(b.var('$$store_subs'));
		template.body.push(
			b.if(b.id('$$store_subs'), b.stmt(b.call('$.unsubscribe_stores', b.id('$$store_subs'))))
		);
	}
	// Propagate values of bound props upwards if they're undefined in the parent and have a value.
	// Don't do this as part of the props retrieval because people could eagerly mutate the prop in the instance script.
	/** @type {import('estree').Property[]} */
	const props = [];
	for (const [name, binding] of analysis.instance.scope.declarations) {
		if (binding.kind === 'bindable_prop' && !name.startsWith('$$')) {
			props.push(b.init(binding.prop_alias ?? name, b.id(name)));
		}
	}
	for (const { name, alias } of analysis.exports) {
		props.push(b.init(alias ?? name, b.id(name)));
	}
	if (props.length > 0) {
		// This has no effect in runes mode other than throwing an error when someone passes
		// undefined to a binding that has a default value.
		template.body.push(b.stmt(b.call('$.bind_props', b.id('$$props'), b.object(props))));
	}
	/** @type {import('estree').Expression[]} */
	const push_args = [];
	if (options.dev) push_args.push(b.id(analysis.name));
 
	const component_block = b.block([
		.../** @type {import('estree').Statement[]} */ (instance.body),
		.../** @type {import('estree').Statement[]} */ (template.body)
	]);
 
	let should_inject_context = analysis.needs_context || options.dev;
 
	if (should_inject_context) {
		component_block.body.unshift(b.stmt(b.call('$.push', ...push_args)));
		component_block.body.push(b.stmt(b.call('$.pop')));
	}
 
	if (analysis.uses_rest_props) {
		/** @type {string[]} */
		const named_props = analysis.exports.map(({ name, alias }) => alias ?? name);
		for (const [name, binding] of analysis.instance.scope.declarations) {
			if (binding.kind === 'bindable_prop') named_props.push(binding.prop_alias ?? name);
		}
 
		component_block.body.unshift(
			b.const(
				'$$restProps',
				b.call(
					'$.rest_props',
					b.id('$$sanitized_props'),
					b.array(named_props.map((name) => b.literal(name)))
				)
			)
		);
	}
 
	if (analysis.uses_props || analysis.uses_rest_props) {
		component_block.body.unshift(
			b.const('$$sanitized_props', b.call('$.sanitize_props', b.id('$$props')))
		);
	}
 
	if (analysis.uses_slots) {
		component_block.body.unshift(b.const('$$slots', b.call('$.sanitize_slots', b.id('$$props'))));
	}
 
	const body = [...state.hoisted, ...module.body];
 
	if (analysis.css.ast !== null && options.css === 'injected' && !options.customElement) {
		const hash = b.literal(analysis.css.hash);
		const code = b.literal(render_stylesheet(analysis.source, analysis, options).code);
 
		body.push(b.const('$$css', b.object([b.init('hash', hash), b.init('code', code)])));
		component_block.body.unshift(b.stmt(b.call('$$payload.css.add', b.id('$$css'))));
	}
 
	let should_inject_props =
		should_inject_context ||
		props.length > 0 ||
		analysis.needs_props ||
		analysis.uses_props ||
		analysis.uses_rest_props ||
		analysis.uses_slots ||
		analysis.slot_names.size > 0;
 
	const component_function = b.function_declaration(
		b.id(analysis.name),
		should_inject_props ? [b.id('$$payload'), b.id('$$props')] : [b.id('$$payload')],
		component_block
	);
	if (options.compatibility.componentApi === 4) {
		body.unshift(b.imports([['render', '$$_render']], 'svelte/server'));
		body.push(
			component_function,
			b.stmt(
				b.assignment(
					'=',
					b.member_id(`${analysis.name}.render`),
					b.function(
						null,
						[b.id('$$props'), b.id('$$opts')],
						b.block([
							b.return(
								b.call(
									'$$_render',
									b.id(analysis.name),
									b.object([
										b.init('props', b.id('$$props')),
										b.init('context', b.member(b.id('$$opts'), b.id('context'), false, true))
									])
								)
							)
						])
					)
				)
			),
			b.export_default(b.id(analysis.name))
		);
	} else if (options.dev) {
		body.push(
			component_function,
			b.stmt(
				b.assignment(
					'=',
					b.member_id(`${analysis.name}.render`),
					b.function(
						null,
						[],
						b.block([
							b.throw_error(
								`Component.render(...) is no longer valid in Svelte 5. ` +
									'See https://svelte-5-preview.vercel.app/docs/breaking-changes#components-are-no-longer-classes for more information'
							)
						])
					)
				)
			),
			b.export_default(b.id(analysis.name))
		);
	} else {
		body.push(b.export_default(component_function));
	}
 
	if (options.dev && filename) {
		// add `App.filename = 'App.svelte'` so that we can print useful messages later
		body.unshift(
			b.stmt(
				b.assignment('=', b.member(b.id(analysis.name), b.id('filename')), b.literal(filename))
			)
		);
	}
 
	return {
		type: 'Program',
		sourceType: 'module',
		body
	};
}
 
/**
 * @param {import('../../types').Analysis} analysis
 * @param {import('#compiler').ValidatedModuleCompileOptions} options
 * @returns {import('estree').Program}
 */
export function server_module(analysis, options) {
	/** @type {import('./types').ServerTransformState} */
	const state = {
		analysis,
		options,
		scope: analysis.module.scope,
		scopes: analysis.module.scopes,
		// this is an anomaly — it can only be used in components, but it needs
		// to be present for `javascript_visitors_legacy` and so is included in module
		// transform state as well as component transform state
		legacy_reactive_statements: new Map(),
		private_derived: new Map()
	};
 
	const module = /** @type {import('estree').Program} */ (
		walk(/** @type {import('#compiler').SvelteNode} */ (analysis.module.ast), state, {
			...set_scope(analysis.module.scopes),
			...global_visitors,
			...javascript_visitors_runes
		})
	);
 
	return {
		type: 'Program',
		sourceType: 'module',
		body: [b.import_all('$', 'svelte/internal/server'), ...module.body]
	};
}