Skip to content

Commit 59902cc

Browse files
committed
chore: simplify process_children
1 parent 95ce311 commit 59902cc

File tree

5 files changed

+19
-46
lines changed

5 files changed

+19
-46
lines changed

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

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function Fragment(node, context) {
6969
template: [],
7070
locations: [],
7171
transform: { ...context.state.transform },
72+
is_functional_template_mode: context.state.is_functional_template_mode,
7273
metadata: {
7374
context: {
7475
template_needs_import_node: false,
@@ -125,40 +126,22 @@ export function Fragment(node, context) {
125126
// special case — we can use `$.text` instead of creating a unique template
126127
const id = b.id(context.state.scope.generate('text'));
127128

128-
process_children(
129-
trimmed,
130-
() => id,
131-
false,
132-
{
133-
...context,
134-
state
135-
},
136-
context.state.is_functional_template_mode
137-
);
129+
process_children(trimmed, () => id, false, {
130+
...context,
131+
state
132+
});
138133

139134
body.push(b.var(id, b.call('$.text')));
140135
close = b.stmt(b.call('$.append', b.id('$$anchor'), id));
141136
} else {
142137
if (is_standalone) {
143138
// no need to create a template, we can just use the existing block's anchor
144-
process_children(
145-
trimmed,
146-
() => b.id('$$anchor'),
147-
false,
148-
{ ...context, state },
149-
context.state.is_functional_template_mode
150-
);
139+
process_children(trimmed, () => b.id('$$anchor'), false, { ...context, state });
151140
} else {
152141
/** @type {(is_text: boolean) => Expression} */
153142
const expression = (is_text) => b.call('$.first_child', id, is_text && b.true);
154143

155-
process_children(
156-
trimmed,
157-
expression,
158-
false,
159-
{ ...context, state },
160-
context.state.is_functional_template_mode
161-
);
144+
process_children(trimmed, expression, false, { ...context, state });
162145

163146
let flags = TEMPLATE_FRAGMENT;
164147

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ export function RegularElement(node, context) {
375375
locations: [],
376376
scope: /** @type {Scope} */ (context.state.scopes.get(node.fragment)),
377377
preserve_whitespace:
378-
context.state.preserve_whitespace || node.name === 'pre' || node.name === 'textarea'
378+
context.state.preserve_whitespace || node.name === 'pre' || node.name === 'textarea',
379+
is_functional_template_mode: context.state.is_functional_template_mode
379380
};
380381

381382
const { hoisted, trimmed } = clean_nodes(
@@ -430,16 +431,10 @@ export function RegularElement(node, context) {
430431
arg = b.member(arg, 'content');
431432
}
432433

433-
process_children(
434-
trimmed,
435-
(is_text) => b.call('$.child', arg, is_text && b.true),
436-
true,
437-
{
438-
...context,
439-
state: child_state
440-
},
441-
context.state.is_functional_template_mode
442-
);
434+
process_children(trimmed, (is_text) => b.call('$.child', arg, is_text && b.true), true, {
435+
...context,
436+
state: child_state
437+
});
443438

444439
if (needs_reset) {
445440
child_state.init.push(b.stmt(b.call('$.reset', context.state.node)));

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@ import { build_template_chunk } from './utils.js';
1515
* @param {(is_text: boolean) => Expression} initial
1616
* @param {boolean} is_element
1717
* @param {ComponentContext} context
18-
* @param {boolean} [is_functional_template_mode]
1918
*/
20-
export function process_children(
21-
nodes,
22-
initial,
23-
is_element,
24-
{ visit, state },
25-
is_functional_template_mode
26-
) {
19+
export function process_children(nodes, initial, is_element, { visit, state }) {
2720
const within_bound_contenteditable = state.metadata.bound_contenteditable;
2821
let prev = initial;
2922
let skipped = 0;
@@ -74,7 +67,9 @@ export function process_children(
7467
state.template.push({
7568
kind: 'create_text',
7669
args: [
77-
sequence.map((node) => (is_functional_template_mode ? node.data : node.raw)).join('')
70+
sequence
71+
.map((node) => (state.is_functional_template_mode ? node.data : node.raw))
72+
.join('')
7873
]
7974
});
8075
return;

packages/svelte/src/compiler/phases/3-transform/server/visitors/Fragment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function Fragment(node, context) {
2020
context.state,
2121
context.state.preserve_whitespace,
2222
context.state.options.preserveComments,
23-
// prevent template cloning should always be false on the server
23+
// templating mode doesn't affect server builds
2424
false
2525
);
2626

packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function RegularElement(node, context) {
4848
},
4949
state.preserve_whitespace,
5050
state.options.preserveComments,
51-
// prevent template cloning should always be false on the server
51+
// templating mode doesn't affect server builds
5252
false
5353
);
5454

0 commit comments

Comments
 (0)