Skip to content

Commit 213274a

Browse files
authored
chore: reduce some select.value indirection (#16250)
1 parent da2feaf commit 213274a

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { process_children } from './shared/fragment.js';
2525
import {
2626
build_render_statement,
2727
build_template_chunk,
28-
build_update_assignment,
2928
get_expression_id,
3029
memoize_expression
3130
} from './shared/utils.js';
@@ -657,17 +656,15 @@ function build_element_special_value_attribute(element, node_id, attribute, cont
657656
}
658657

659658
if (has_state) {
660-
const id = state.scope.generate(`${node_id.name}_value`);
661-
build_update_assignment(
662-
state,
663-
id,
664-
// `<option>` is a special case: The value property reflects to the DOM. If the value is set to undefined,
665-
// that means the value should be set to the empty string. To be able to do that when the value is
666-
// initially undefined, we need to set a value that is guaranteed to be different.
667-
element === 'option' ? b.object([]) : undefined,
668-
value,
669-
update
670-
);
659+
const id = b.id(state.scope.generate(`${node_id.name}_value`));
660+
661+
// `<option>` is a special case: The value property reflects to the DOM. If the value is set to undefined,
662+
// that means the value should be set to the empty string. To be able to do that when the value is
663+
// initially undefined, we need to set a value that is guaranteed to be different.
664+
const init = element === 'option' ? b.object([]) : undefined;
665+
666+
state.init.push(b.var(id, init));
667+
state.update.push(b.if(b.binary('!==', id, b.assignment('=', id, value)), b.block([update])));
671668
} else {
672669
state.init.push(update);
673670
}

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,6 @@ export function parse_directive_name(name) {
165165
return expression;
166166
}
167167

168-
/**
169-
* @param {ComponentClientTransformState} state
170-
* @param {string} id
171-
* @param {Expression | undefined} init
172-
* @param {Expression} value
173-
* @param {ExpressionStatement} update
174-
*/
175-
export function build_update_assignment(state, id, init, value, update) {
176-
state.init.push(b.var(id, init));
177-
state.update.push(
178-
b.if(b.binary('!==', b.id(id), b.assignment('=', b.id(id), value)), b.block([update]))
179-
);
180-
}
181-
182168
/**
183169
* Serializes `bind:this` for components and elements.
184170
* @param {Identifier | MemberExpression | SequenceExpression} expression

0 commit comments

Comments
 (0)