chore: simplify `process_children`

custom-render-shim-dom
paoloricciuti 6 months ago
parent 95ce311613
commit 59902ccead

@ -69,6 +69,7 @@ export function Fragment(node, context) {
template: [],
locations: [],
transform: { ...context.state.transform },
is_functional_template_mode: context.state.is_functional_template_mode,
metadata: {
context: {
template_needs_import_node: false,
@ -125,40 +126,22 @@ export function Fragment(node, context) {
// special case — we can use `$.text` instead of creating a unique template
const id = b.id(context.state.scope.generate('text'));
process_children(
trimmed,
() => id,
false,
{
...context,
state
},
context.state.is_functional_template_mode
);
process_children(trimmed, () => id, false, {
...context,
state
});
body.push(b.var(id, b.call('$.text')));
close = b.stmt(b.call('$.append', b.id('$$anchor'), id));
} else {
if (is_standalone) {
// no need to create a template, we can just use the existing block's anchor
process_children(
trimmed,
() => b.id('$$anchor'),
false,
{ ...context, state },
context.state.is_functional_template_mode
);
process_children(trimmed, () => b.id('$$anchor'), false, { ...context, state });
} else {
/** @type {(is_text: boolean) => Expression} */
const expression = (is_text) => b.call('$.first_child', id, is_text && b.true);
process_children(
trimmed,
expression,
false,
{ ...context, state },
context.state.is_functional_template_mode
);
process_children(trimmed, expression, false, { ...context, state });
let flags = TEMPLATE_FRAGMENT;

@ -375,7 +375,8 @@ export function RegularElement(node, context) {
locations: [],
scope: /** @type {Scope} */ (context.state.scopes.get(node.fragment)),
preserve_whitespace:
context.state.preserve_whitespace || node.name === 'pre' || node.name === 'textarea'
context.state.preserve_whitespace || node.name === 'pre' || node.name === 'textarea',
is_functional_template_mode: context.state.is_functional_template_mode
};
const { hoisted, trimmed } = clean_nodes(
@ -430,16 +431,10 @@ export function RegularElement(node, context) {
arg = b.member(arg, 'content');
}
process_children(
trimmed,
(is_text) => b.call('$.child', arg, is_text && b.true),
true,
{
...context,
state: child_state
},
context.state.is_functional_template_mode
);
process_children(trimmed, (is_text) => b.call('$.child', arg, is_text && b.true), true, {
...context,
state: child_state
});
if (needs_reset) {
child_state.init.push(b.stmt(b.call('$.reset', context.state.node)));

@ -15,15 +15,8 @@ import { build_template_chunk } from './utils.js';
* @param {(is_text: boolean) => Expression} initial
* @param {boolean} is_element
* @param {ComponentContext} context
* @param {boolean} [is_functional_template_mode]
*/
export function process_children(
nodes,
initial,
is_element,
{ visit, state },
is_functional_template_mode
) {
export function process_children(nodes, initial, is_element, { visit, state }) {
const within_bound_contenteditable = state.metadata.bound_contenteditable;
let prev = initial;
let skipped = 0;
@ -74,7 +67,9 @@ export function process_children(
state.template.push({
kind: 'create_text',
args: [
sequence.map((node) => (is_functional_template_mode ? node.data : node.raw)).join('')
sequence
.map((node) => (state.is_functional_template_mode ? node.data : node.raw))
.join('')
]
});
return;

@ -20,7 +20,7 @@ export function Fragment(node, context) {
context.state,
context.state.preserve_whitespace,
context.state.options.preserveComments,
// prevent template cloning should always be false on the server
// templating mode doesn't affect server builds
false
);

@ -48,7 +48,7 @@ export function RegularElement(node, context) {
},
state.preserve_whitespace,
state.options.preserveComments,
// prevent template cloning should always be false on the server
// templating mode doesn't affect server builds
false
);

Loading…
Cancel
Save