@@ -240,13 +240,14 @@ function process_children(nodes, parent, { visit, state }) {
240
240
241
241
/**
242
242
* @param {import('#compiler').SvelteNode } parent
243
+ * @param {import('#compiler').Fragment } fragment
243
244
* @param {import('#compiler').SvelteNode[] } nodes
244
245
* @param {import('./types').ComponentContext } context
245
246
* @param {import('./types').Anchor } [anchor]
246
247
* @returns {import('estree').Statement[] }
247
248
*/
248
- function create_block ( parent , nodes , context , anchor ) {
249
- const namespace = infer_namespace ( context . state . metadata . namespace , parent , nodes , context . path ) ;
249
+ function create_block ( parent , fragment , nodes , context , anchor ) {
250
+ const namespace = infer_namespace ( context . state . metadata . namespace , parent , nodes ) ;
250
251
251
252
const { hoisted, trimmed } = clean_nodes (
252
253
parent ,
@@ -264,6 +265,7 @@ function create_block(parent, nodes, context, anchor) {
264
265
/** @type {import('./types').ComponentServerTransformState } */
265
266
const state = {
266
267
...context . state ,
268
+ scope : context . state . scopes . get ( fragment ) ?? context . state . scope ,
267
269
init : [ ] ,
268
270
template : [ ] ,
269
271
metadata : {
@@ -1085,7 +1087,7 @@ function serialize_inline_component(node, component_name, context) {
1085
1087
const serialized_slots = [ ] ;
1086
1088
1087
1089
for ( const slot_name of Object . keys ( children ) ) {
1088
- const body = create_block ( node , children [ slot_name ] , context ) ;
1090
+ const body = create_block ( node , node . fragment , children [ slot_name ] , context ) ;
1089
1091
if ( body . length === 0 ) continue ;
1090
1092
1091
1093
const slot_fn = b . arrow (
@@ -1268,7 +1270,7 @@ const javascript_visitors_legacy = {
1268
1270
/** @type {import('./types').ComponentVisitors } */
1269
1271
const template_visitors = {
1270
1272
Fragment ( node , context ) {
1271
- const body = create_block ( node , node . nodes , context ) ;
1273
+ const body = create_block ( context . path . at ( - 1 ) ?? node , node , node . nodes , context ) ;
1272
1274
return b . block ( body ) ;
1273
1275
} ,
1274
1276
HtmlTag ( node , context ) {
@@ -1472,7 +1474,7 @@ const template_visitors = {
1472
1474
1473
1475
context . state . template . push ( block_open ) ;
1474
1476
1475
- const main = create_block ( node , node . fragment . nodes , {
1477
+ const main = create_block ( node , node . fragment , node . fragment . nodes , {
1476
1478
...context ,
1477
1479
state : { ...context . state , metadata }
1478
1480
} ) ;
@@ -1541,7 +1543,9 @@ const template_visitors = {
1541
1543
each . push ( b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( block_open . value ) ) ) ) ;
1542
1544
1543
1545
each . push (
1544
- .../** @type {import('estree').Statement[] } */ ( create_block ( node , children , context ) )
1546
+ .../** @type {import('estree').Statement[] } */ (
1547
+ create_block ( node , node . body , children , context )
1548
+ )
1545
1549
) ;
1546
1550
1547
1551
each . push ( b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( block_close . value ) ) ) ) ;
@@ -1556,7 +1560,7 @@ const template_visitors = {
1556
1560
const close = b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( BLOCK_CLOSE ) ) ) ;
1557
1561
1558
1562
if ( node . fallback ) {
1559
- const fallback = create_block ( node , node . fallback . nodes , context ) ;
1563
+ const fallback = create_block ( node , node . fallback , node . fallback . nodes , context ) ;
1560
1564
1561
1565
fallback . push ( b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( BLOCK_CLOSE_ELSE ) ) ) ) ;
1562
1566
@@ -1577,8 +1581,10 @@ const template_visitors = {
1577
1581
const state = context . state ;
1578
1582
state . template . push ( block_open ) ;
1579
1583
1580
- const consequent = create_block ( node , node . consequent . nodes , context ) ;
1581
- const alternate = node . alternate ? create_block ( node , node . alternate . nodes , context ) : [ ] ;
1584
+ const consequent = create_block ( node , node . consequent , node . consequent . nodes , context ) ;
1585
+ const alternate = node . alternate
1586
+ ? create_block ( node , node . alternate , node . alternate . nodes , context )
1587
+ : [ ] ;
1582
1588
1583
1589
consequent . push ( b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( BLOCK_CLOSE ) ) ) ) ;
1584
1590
alternate . push ( b . stmt ( b . assignment ( '+=' , b . id ( '$$payload.out' ) , b . literal ( BLOCK_CLOSE_ELSE ) ) ) ) ;
@@ -1634,7 +1640,7 @@ const template_visitors = {
1634
1640
KeyBlock ( node , context ) {
1635
1641
const state = context . state ;
1636
1642
state . template . push ( block_open ) ;
1637
- const body = create_block ( node , node . fragment . nodes , context ) ;
1643
+ const body = create_block ( node , node . fragment , node . fragment . nodes , context ) ;
1638
1644
state . template . push ( t_statement ( b . block ( body ) ) ) ;
1639
1645
state . template . push ( block_close ) ;
1640
1646
} ,
@@ -1729,7 +1735,7 @@ const template_visitors = {
1729
1735
// TODO this logic eventually belongs in create_block, when fragments are used everywhere
1730
1736
scope : /** @type {import('../../scope').Scope } */ ( context . state . scopes . get ( node . fragment ) )
1731
1737
} ;
1732
- const body = create_block ( node , node . fragment . nodes , {
1738
+ const body = create_block ( node , node . fragment , node . fragment . nodes , {
1733
1739
...context ,
1734
1740
state
1735
1741
} ) ;
@@ -1802,15 +1808,15 @@ const template_visitors = {
1802
1808
const fallback =
1803
1809
node . fragment . nodes . length === 0
1804
1810
? b . literal ( null )
1805
- : b . thunk ( b . block ( create_block ( node , node . fragment . nodes , context ) ) ) ;
1811
+ : b . thunk ( b . block ( create_block ( node , node . fragment , node . fragment . nodes , context ) ) ) ;
1806
1812
const slot = b . call ( '$.slot' , b . id ( '$$payload' ) , expression , props_expression , fallback ) ;
1807
1813
1808
1814
state . template . push ( t_statement ( b . stmt ( slot ) ) ) ;
1809
1815
state . template . push ( block_close ) ;
1810
1816
} ,
1811
1817
SvelteHead ( node , context ) {
1812
1818
const state = context . state ;
1813
- const body = create_block ( node , node . fragment . nodes , context ) ;
1819
+ const body = create_block ( node , node . fragment , node . fragment . nodes , context ) ;
1814
1820
state . template . push (
1815
1821
t_statement (
1816
1822
b . stmt ( b . call ( '$.head' , b . id ( '$$payload' ) , b . arrow ( [ b . id ( '$$payload' ) ] , b . block ( body ) ) ) )
0 commit comments