Skip to content

Commit 04879c5

Browse files
authored
chore: simplify blocks (#10873)
* reduce some indirection * update tests * unify blocks before we kill them * refactor types, rename some stuff * simplify * remove block.e
1 parent b91392e commit 04879c5

File tree

16 files changed

+125
-264
lines changed

16 files changed

+125
-264
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,12 @@ function create_block(parent, name, nodes, context) {
12821282
// It's important that close is the last statement in the block, as any previous statements
12831283
// could contain element insertions into the template, which the close statement needs to
12841284
// know of when constructing the list of current inner elements.
1285+
1286+
if (context.path.length > 0) {
1287+
// this is a block — return DOM so it can be attached directly to the effect
1288+
close = b.return(close.expression);
1289+
}
1290+
12851291
body.push(close);
12861292
}
12871293

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { is_promise } from '../../../common.js';
22
import { hydrate_block_anchor } from '../hydration.js';
33
import { remove } from '../reconciler.js';
44
import {
5-
current_block,
65
current_component_context,
76
flushSync,
87
set_current_component_context,
@@ -11,20 +10,7 @@ import {
1110
} from '../../runtime.js';
1211
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/effects.js';
1312
import { DESTROYED, INERT } from '../../constants.js';
14-
15-
/** @returns {import('../../types.js').AwaitBlock} */
16-
export function create_await_block() {
17-
return {
18-
// dom
19-
d: null,
20-
// effect
21-
e: null,
22-
// parent
23-
p: /** @type {import('../../types.js').Block} */ (current_block),
24-
// pending
25-
n: true
26-
};
27-
}
13+
import { create_block } from './utils.js';
2814

2915
/**
3016
* @template V
@@ -36,7 +22,7 @@ export function create_await_block() {
3622
* @returns {void}
3723
*/
3824
export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
39-
const block = create_await_block();
25+
const block = create_block();
4026

4127
const component_context = current_component_context;
4228

0 commit comments

Comments
 (0)