Skip to content

Commit 76d05e0

Browse files
committed
make process_children unaware of templating mode - the less visitors know about this, the better
1 parent 4a3fc9d commit 76d05e0

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export function template_to_functions(items) {
2828
}
2929

3030
for (let instruction of items) {
31-
const args = instruction.args ?? [];
3231
const last_element_stack = /** @type {Element} */ (elements_stack.at(-1));
3332
/**
3433
* @param {Expression | null | void} value
@@ -56,7 +55,7 @@ export function template_to_functions(items) {
5655
push(last_current_element);
5756
break;
5857
case 'create_text':
59-
push(create_text(last_element_stack, args[0]));
58+
push(create_text(last_element_stack, instruction.nodes.map((node) => node.data).join('')));
6059
break;
6160
case 'create_anchor':
6261
push(create_anchor(last_element_stack, instruction.data));
@@ -138,13 +137,13 @@ function create_text(element, value) {
138137
*
139138
* @param {Element} element
140139
* @param {string} prop
141-
* @param {string} value
140+
* @param {string | undefined} value
142141
*/
143142
function set_prop(element, prop, value) {
144143
const p = get_or_create_prop(element, 'p', b.object([]));
145144

146145
if (prop === 'is') {
147-
element.properties.push(b.prop('init', b.id(prop), b.literal(value)));
146+
element.properties.push(b.prop('init', b.id(prop), b.literal(/** @type {string} */ (value))));
148147
return;
149148
}
150149

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function template_to_string(items) {
5555
case 'create_text':
5656
insert({
5757
kind: 'text',
58-
value: instruction.args[0]
58+
value: instruction.nodes.map((node) => node.raw).join('')
5959
});
6060
break;
6161
case 'create_anchor':

packages/svelte/src/compiler/phases/3-transform/client/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type TemplateOperations = Array<
4343
}
4444
| {
4545
kind: 'create_text';
46-
args: string[];
46+
nodes: AST.Text[];
4747
}
4848
| {
4949
kind: 'create_anchor';

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,13 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
6666
skipped += 1;
6767
state.template.push({
6868
kind: 'create_text',
69-
args: [
70-
sequence
71-
.map((node) => (state.is_functional_template_mode ? node.data : node.raw))
72-
.join('')
73-
]
69+
nodes: sequence
7470
});
7571
return;
7672
}
7773
state.template.push({
7874
kind: 'create_text',
79-
args: [' ']
75+
nodes: [{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]
8076
});
8177

8278
const { has_state, value } = build_template_chunk(sequence, visit, state);

0 commit comments

Comments
 (0)