Skip to content

Commit c76ca70

Browse files
committed
more
1 parent 702226d commit c76ca70

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export function RegularElement(node, context) {
8383
const lets = [];
8484

8585
const is_custom_element = is_custom_element_node(node);
86-
let needs_content_reset = false;
8786

8887
if (is_custom_element) {
8988
// cloneNode is faster, but it does not instantiate the underlying class of the
@@ -93,13 +92,6 @@ export function RegularElement(node, context) {
9392
metadata.context.template_needs_import_node = true;
9493
}
9594

96-
// visit let directives first, to set state
97-
for (const attribute of node.attributes) {
98-
if (attribute.type === 'LetDirective') {
99-
lets.push(/** @type {ExpressionStatement} */ (context.visit(attribute)));
100-
}
101-
}
102-
10395
/** @type {Map<string, AST.Attribute>} */
10496
const lookup = new Map();
10597

@@ -109,21 +101,15 @@ export function RegularElement(node, context) {
109101
let has_spread = false;
110102

111103
for (const attribute of node.attributes) {
112-
if (attribute.type === 'Attribute') {
113-
lookup.set(attribute.name, attribute);
114-
115-
if (
116-
(attribute.name === 'value' || attribute.name === 'checked') &&
117-
!is_text_attribute(attribute)
118-
) {
119-
needs_content_reset = true;
120-
}
121-
} else if (attribute.type === 'SpreadAttribute') {
104+
if (attribute.type === 'SpreadAttribute') {
122105
has_spread = true;
123-
}
124-
125-
if (attribute.type === 'BindDirective') {
106+
} else if (attribute.type === 'Attribute') {
107+
lookup.set(attribute.name, attribute);
108+
} else if (attribute.type === 'BindDirective') {
126109
bindings.set(attribute.name, attribute);
110+
} else if (attribute.type === 'LetDirective') {
111+
// visit let directives before everything else, to set state
112+
lets.push(/** @type {ExpressionStatement} */ (context.visit(attribute)));
127113
}
128114
}
129115

@@ -178,8 +164,13 @@ export function RegularElement(node, context) {
178164
context.state.init.push(b.stmt(b.call('$.remove_input_defaults', context.state.node)));
179165
}
180166

181-
if (node.name === 'textarea' && (has_spread || bindings.has('value') || needs_content_reset)) {
182-
context.state.init.push(b.stmt(b.call('$.remove_textarea_child', context.state.node)));
167+
if (node.name === 'textarea') {
168+
const attribute = lookup.get('value') ?? lookup.get('checked');
169+
const needs_content_reset = attribute && !is_text_attribute(attribute);
170+
171+
if (has_spread || bindings.has('value') || needs_content_reset) {
172+
context.state.init.push(b.stmt(b.call('$.remove_textarea_child', context.state.node)));
173+
}
183174
}
184175

185176
if (node.name === 'select' && bindings.has('value')) {

0 commit comments

Comments
 (0)