Skip to content

Commit c2a6207

Browse files
committed
WIP
1 parent 57b13d3 commit c2a6207

File tree

5 files changed

+21
-22
lines changed

5 files changed

+21
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export function RegularElement(node, context) {
331331
trimmed.some((node) => node.type === 'ExpressionTag');
332332

333333
if (use_text_content) {
334-
const { value } = build_template_chunk(trimmed, context.visit, child_state);
334+
const { value } = build_template_chunk(trimmed, context, child_state);
335335
const empty_string = value.type === 'Literal' && value.value === '';
336336

337337
if (!empty_string) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { build_template_chunk } from './shared/utils.js';
1010
export function TitleElement(node, context) {
1111
const { has_state, value } = build_template_chunk(
1212
/** @type {any} */ (node.fragment.nodes),
13-
context.visit,
14-
context.state
13+
context
1514
);
1615

1716
const statement = b.stmt(b.assignment('=', b.id('$.document.title'), value));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function build_attribute_value(value, context, memoize = (value) => value
129129
};
130130
}
131131

132-
return build_template_chunk(value, context.visit, context.state, memoize);
132+
return build_template_chunk(value, context, context.state, memoize);
133133
}
134134

135135
/**

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { build_template_chunk } from './utils.js';
1616
* @param {boolean} is_element
1717
* @param {ComponentContext} context
1818
*/
19-
export function process_children(nodes, initial, is_element, { visit, state }) {
20-
const within_bound_contenteditable = state.metadata.bound_contenteditable;
19+
export function process_children(nodes, initial, is_element, context) {
20+
const within_bound_contenteditable = context.state.metadata.bound_contenteditable;
2121
let prev = initial;
2222
let skipped = 0;
2323

@@ -48,8 +48,8 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
4848
let id = expression;
4949

5050
if (id.type !== 'Identifier') {
51-
id = b.id(state.scope.generate(name));
52-
state.init.push(b.var(id, expression));
51+
id = b.id(context.state.scope.generate(name));
52+
context.state.init.push(b.var(id, expression));
5353
}
5454

5555
prev = () => id;
@@ -64,13 +64,13 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
6464
function flush_sequence(sequence) {
6565
if (sequence.every((node) => node.type === 'Text')) {
6666
skipped += 1;
67-
state.template.push_text(sequence);
67+
context.state.template.push_text(sequence);
6868
return;
6969
}
7070

71-
state.template.push_text([{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]);
71+
context.state.template.push_text([{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]);
7272

73-
const { has_state, value } = build_template_chunk(sequence, visit, state);
73+
const { has_state, value } = build_template_chunk(sequence, context);
7474

7575
// if this is a standalone `{expression}`, make sure we handle the case where
7676
// no text node was created because the expression was empty during SSR
@@ -80,9 +80,9 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
8080
const update = b.stmt(b.call('$.set_text', id, value));
8181

8282
if (has_state && !within_bound_contenteditable) {
83-
state.update.push(update);
83+
context.state.update.push(update);
8484
} else {
85-
state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value)));
85+
context.state.init.push(b.stmt(b.assignment('=', b.member(id, 'nodeValue'), value)));
8686
}
8787
}
8888

@@ -95,18 +95,18 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
9595
sequence = [];
9696
}
9797

98-
let child_state = state;
98+
let child_state = context.state;
9999

100-
if (is_static_element(node, state)) {
100+
if (is_static_element(node, context.state)) {
101101
skipped += 1;
102102
} else if (node.type === 'EachBlock' && nodes.length === 1 && is_element) {
103103
node.metadata.is_controlled = true;
104104
} else {
105105
const id = flush_node(false, node.type === 'RegularElement' ? node.name : 'node');
106-
child_state = { ...state, node: id };
106+
child_state = { ...context.state, node: id };
107107
}
108108

109-
visit(node, child_state);
109+
context.visit(node, child_state);
110110
}
111111
}
112112

@@ -118,7 +118,7 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
118118
// traverse to the last (n - 1) one when hydrating
119119
if (skipped > 1) {
120120
skipped -= 1;
121-
state.init.push(b.stmt(b.call('$.next', skipped !== 1 && b.literal(skipped))));
121+
context.state.init.push(b.stmt(b.call('$.next', skipped !== 1 && b.literal(skipped))));
122122
}
123123
}
124124

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export function get_expression_id(expressions, value) {
3131

3232
/**
3333
* @param {Array<AST.Text | AST.ExpressionTag>} values
34-
* @param {(node: AST.SvelteNode, state: any) => any} visit
34+
* @param {ComponentContext} context
3535
* @param {ComponentClientTransformState} state
3636
* @param {(value: Expression, metadata: ExpressionMetadata) => Expression} memoize
3737
* @returns {{ value: Expression, has_state: boolean }}
3838
*/
3939
export function build_template_chunk(
4040
values,
41-
visit,
42-
state,
41+
context,
42+
state = context.state,
4343
memoize = (value, metadata) =>
4444
metadata.has_call ? get_expression_id(state.expressions, value) : value
4545
) {
@@ -66,7 +66,7 @@ export function build_template_chunk(
6666
state.scope.get('undefined')
6767
) {
6868
let value = memoize(
69-
/** @type {Expression} */ (visit(node.expression, state)),
69+
/** @type {Expression} */ (context.visit(node.expression, state)),
7070
node.metadata.expression
7171
);
7272

0 commit comments

Comments
 (0)