Skip to content

Commit cd65c73

Browse files
committed
tidy up
1 parent 055dda4 commit cd65c73

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ export function BindDirective(node, context) {
209209
)
210210
)?.value
211211
);
212+
212213
if (value !== undefined) {
213214
group_getter = b.thunk(
214215
b.block([
215-
b.stmt(build_attribute_value(value, context)[1]),
216+
b.stmt(build_attribute_value(value, context).value),
216217
b.return(/** @type {Expression} */ (context.visit(expression)))
217218
])
218219
);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function RegularElement(node, context) {
230230
) {
231231
const name = get_attribute_name(node, attribute, context);
232232
const literal_value = /** @type {Literal} */ (
233-
build_attribute_value(attribute.value, context)[1]
233+
build_attribute_value(attribute.value, context).value
234234
).value;
235235
if (name !== 'class' || literal_value) {
236236
// TODO namespace=foreign probably doesn't want to do template stuff at all and instead use programmatic methods
@@ -440,7 +440,7 @@ function build_element_spread_attributes(
440440
if (attribute.type === 'Attribute') {
441441
const name = get_attribute_name(element, attribute, context);
442442
// TODO: handle has_call
443-
const [, value] = build_attribute_value(attribute.value, context);
443+
const { value } = build_attribute_value(attribute.value, context);
444444

445445
if (
446446
name === 'is' &&
@@ -554,7 +554,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
554554
const name = get_attribute_name(element, attribute, context);
555555
const is_svg = context.state.metadata.namespace === 'svg' || element.name === 'svg';
556556
const is_mathml = context.state.metadata.namespace === 'mathml';
557-
let [has_call, value] = build_attribute_value(attribute.value, context);
557+
let { has_call, value } = build_attribute_value(attribute.value, context);
558558

559559
// The foreign namespace doesn't have any special handling, everything goes through the attr function
560560
if (context.state.metadata.namespace === 'foreign') {
@@ -636,7 +636,7 @@ function build_element_attribute_update_assignment(element, node_id, attribute,
636636
function build_custom_element_attribute_update_assignment(node_id, attribute, context) {
637637
const state = context.state;
638638
const name = attribute.name; // don't lowercase, as we set the element's property, which might be case sensitive
639-
let [has_call, value] = build_attribute_value(attribute.value, context);
639+
let { has_call, value } = build_attribute_value(attribute.value, context);
640640

641641
const update = b.stmt(b.call('$.set_custom_element_data', node_id, b.literal(name), value));
642642

@@ -665,7 +665,7 @@ function build_custom_element_attribute_update_assignment(node_id, attribute, co
665665
*/
666666
function build_element_special_value_attribute(element, node_id, attribute, context) {
667667
const state = context.state;
668-
const [, value] = build_attribute_value(attribute.value, context);
668+
const { value } = build_attribute_value(attribute.value, context);
669669

670670
const inner_assignment = b.assignment(
671671
'=',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export function SlotElement(node, context) {
3030
if (attribute.type === 'SpreadAttribute') {
3131
spreads.push(b.thunk(/** @type {Expression} */ (context.visit(attribute))));
3232
} else if (attribute.type === 'Attribute') {
33-
const [, value] = build_attribute_value(attribute.value, context);
33+
const { value } = build_attribute_value(attribute.value, context);
34+
3435
if (attribute.name === 'name') {
3536
name = value;
3637
is_default = false;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function SvelteElement(node, context) {
126126
get_tag,
127127
node.metadata.svg || node.metadata.mathml ? b.true : b.false,
128128
inner.length > 0 && b.arrow([element_id, b.id('$$anchor')], b.block(inner)),
129-
dynamic_namespace && b.thunk(build_attribute_value(dynamic_namespace, context)[1]),
129+
dynamic_namespace && b.thunk(build_attribute_value(dynamic_namespace, context).value),
130130
location && b.array([b.literal(location.line), b.literal(location.column)])
131131
)
132132
)
@@ -161,7 +161,7 @@ function build_dynamic_element_attributes(attributes, context, element_id) {
161161

162162
for (const attribute of attributes) {
163163
if (attribute.type === 'Attribute') {
164-
const [, value] = build_attribute_value(attribute.value, context);
164+
const { value } = build_attribute_value(attribute.value, context);
165165

166166
if (
167167
is_event_attribute(attribute) &&

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function build_component(node, component_name, context, anchor = context.
9393
} else if (attribute.type === 'Attribute') {
9494
if (attribute.name.startsWith('--')) {
9595
custom_css_props.push(
96-
b.init(attribute.name, build_attribute_value(attribute.value, context)[1])
96+
b.init(attribute.name, build_attribute_value(attribute.value, context).value)
9797
);
9898
continue;
9999
}
@@ -106,7 +106,7 @@ export function build_component(node, component_name, context, anchor = context.
106106
has_children_prop = true;
107107
}
108108

109-
const [, value] = build_attribute_value(attribute.value, context);
109+
const { value } = build_attribute_value(attribute.value, context);
110110

111111
if (attribute.metadata.expression.has_state) {
112112
let arg = value;

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function build_style_directives(
3333
let value =
3434
directive.value === true
3535
? build_getter({ name: directive.name, type: 'Identifier' }, context.state)
36-
: build_attribute_value(directive.value, context)[1];
36+
: build_attribute_value(directive.value, context).value;
3737

3838
const update = b.stmt(
3939
b.call(
@@ -92,30 +92,27 @@ export function build_class_directives(
9292
/**
9393
* @param {Attribute['value']} value
9494
* @param {ComponentContext} context
95-
* @returns {[has_call: boolean, Expression]}
9695
*/
9796
export function build_attribute_value(value, context) {
9897
if (value === true) {
99-
return [false, b.literal(true)];
98+
return { has_state: false, has_call: false, value: b.literal(true) };
10099
}
101100

102101
if (!Array.isArray(value) || value.length === 1) {
103102
const chunk = Array.isArray(value) ? value[0] : value;
104103

105104
if (chunk.type === 'Text') {
106-
return [false, b.literal(chunk.data)];
105+
return { has_state: false, has_call: false, value: b.literal(chunk.data) };
107106
}
108107

109-
return [
110-
chunk.metadata.expression.has_call,
111-
/** @type {Expression} */ (context.visit(chunk.expression))
112-
];
108+
return {
109+
has_state: chunk.metadata.expression.has_call,
110+
has_call: chunk.metadata.expression.has_call,
111+
value: /** @type {Expression} */ (context.visit(chunk.expression))
112+
};
113113
}
114114

115-
const { has_call, value: v } = build_template_literal(value, context.visit, context.state);
116-
117-
// TODO return the same signature
118-
return [has_call, v];
115+
return build_template_literal(value, context.visit, context.state);
119116
}
120117

121118
/**

0 commit comments

Comments
 (0)