Skip to content

Commit 7c56aa2

Browse files
committed
more descriptive names
1 parent 2452e22 commit 7c56aa2

File tree

8 files changed

+45
-45
lines changed

8 files changed

+45
-45
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function get_attribute_name(element, attribute, context) {
5959
}
6060

6161
/**
62-
* Serializes each style directive into something like `$.style(element, style_property, value)`
62+
* Serializes each style directive into something like `$.set_style(element, style_property, value)`
6363
* and adds it either to init or update, depending on whether or not the value or the attributes are dynamic.
6464
* @param {import('#compiler').StyleDirective[]} style_directives
6565
* @param {import('estree').Identifier} element_id
@@ -77,7 +77,7 @@ function serialize_style_directives(style_directives, element_id, context, is_at
7777

7878
const update = b.stmt(
7979
b.call(
80-
'$.style',
80+
'$.set_style',
8181
element_id,
8282
b.literal(directive.name),
8383
value,
@@ -136,7 +136,7 @@ function serialize_class_directives(class_directives, element_id, context, is_at
136136
const state = context.state;
137137
for (const directive of class_directives) {
138138
const value = /** @type {import('estree').Expression} */ (context.visit(directive.expression));
139-
const update = b.stmt(b.call('$.class_toggle', element_id, b.literal(directive.name), value));
139+
const update = b.stmt(b.call('$.toggle_class', element_id, b.literal(directive.name), value));
140140
const contains_call_expression = directive.expression.type === 'CallExpression';
141141

142142
if (!is_attributes_reactive && contains_call_expression) {
@@ -280,14 +280,14 @@ function serialize_element_spread_attributes(
280280

281281
const lowercase_attributes =
282282
element.metadata.svg || is_custom_element_node(element) ? b.false : b.true;
283-
const id = context.state.scope.generate('spread_attributes');
283+
const id = context.state.scope.generate('attributes');
284284

285285
const update = b.stmt(
286286
b.assignment(
287287
'=',
288288
b.id(id),
289289
b.call(
290-
'$.spread_attributes',
290+
'$.set_attributes',
291291
element_id,
292292
b.id(id),
293293
b.array(values),
@@ -337,7 +337,7 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
337337
if (attributes.length === 0) {
338338
if (context.state.analysis.css.hash) {
339339
context.state.init.push(
340-
b.stmt(b.call('$.class_name', element_id, b.literal(context.state.analysis.css.hash)))
340+
b.stmt(b.call('$.set_class', element_id, b.literal(context.state.analysis.css.hash)))
341341
);
342342
}
343343
return false;
@@ -368,15 +368,15 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
368368
}
369369

370370
if (needs_isolation || is_reactive) {
371-
const id = context.state.scope.generate('spread_attributes');
371+
const id = context.state.scope.generate('attributes');
372372
context.state.init.push(b.let(id));
373373

374374
const update = b.stmt(
375375
b.assignment(
376376
'=',
377377
b.id(id),
378378
b.call(
379-
'$.spread_dynamic_element_attributes',
379+
'$.set_dynamic_element_attributes',
380380
element_id,
381381
b.id(id),
382382
b.array(values),
@@ -397,7 +397,7 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
397397
context.state.init.push(
398398
b.stmt(
399399
b.call(
400-
'$.spread_dynamic_element_attributes',
400+
'$.set_dynamic_element_attributes',
401401
element_id,
402402
b.literal(null),
403403
b.array(values),
@@ -415,7 +415,7 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
415415
* ```js
416416
* element.property = value;
417417
* // or
418-
* $.attr(element, property, value);
418+
* $.set_attribute(element, property, value);
419419
* });
420420
* ```
421421
* Resulting code for dynamic looks something like this:
@@ -425,7 +425,7 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
425425
* if (value !== (value = 'new value')) {
426426
* element.property = value;
427427
* // or
428-
* $.attr(element, property, value);
428+
* $.set_attribute(element, property, value);
429429
* }
430430
* });
431431
* ```
@@ -444,7 +444,9 @@ function serialize_element_attribute_update_assignment(element, node_id, attribu
444444

445445
// The foreign namespace doesn't have any special handling, everything goes through the attr function
446446
if (context.state.metadata.namespace === 'foreign') {
447-
const statement = { grouped: b.stmt(b.call('$.attr', node_id, b.literal(name), value)) };
447+
const statement = {
448+
grouped: b.stmt(b.call('$.set_attribute', node_id, b.literal(name), value))
449+
};
448450
if (attribute.metadata.dynamic) {
449451
const id = state.scope.generate(`${node_id.name}_${name}`);
450452
serialize_update_assignment(state, id, undefined, value, statement, contains_call_expression);
@@ -464,11 +466,11 @@ function serialize_element_attribute_update_assignment(element, node_id, attribu
464466
let update;
465467

466468
if (name === 'class') {
467-
update = b.stmt(b.call(is_svg ? '$.svg_class_name' : '$.class_name', node_id, value));
469+
update = b.stmt(b.call(is_svg ? '$.set_svg_class' : '$.set_class', node_id, value));
468470
} else if (DOMProperties.includes(name)) {
469471
update = b.stmt(b.assignment('=', b.member(node_id, b.id(name)), value));
470472
} else {
471-
const callee = name.startsWith('xlink') ? '$.xlink_attr' : '$.attr';
473+
const callee = name.startsWith('xlink') ? '$.set_xlink_attribute' : '$.set_attribute';
472474
update = b.stmt(b.call(callee, node_id, b.literal(name), value));
473475
}
474476

@@ -1397,7 +1399,7 @@ function process_children(nodes, expression, is_element, { visit, state }) {
13971399

13981400
const update = b.stmt(
13991401
b.call(
1400-
'$.text',
1402+
'$.set_text',
14011403
text_id,
14021404
/** @type {import('estree').Expression} */ (visit(node.expression))
14031405
)
@@ -1431,7 +1433,7 @@ function process_children(nodes, expression, is_element, { visit, state }) {
14311433

14321434
const [contains_call_expression, value] = serialize_template_literal(sequence, visit);
14331435

1434-
const update = b.stmt(b.call('$.text', text_id, value));
1436+
const update = b.stmt(b.call('$.set_text', text_id, value));
14351437

14361438
if (contains_call_expression && !within_bound_contenteditable) {
14371439
state.init.push(serialize_update(update));

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { autofocus } from './misc.js';
1313
*/
1414
export function remove_input_attr_defaults(dom) {
1515
if (hydrating) {
16-
attr(dom, 'value', null);
17-
attr(dom, 'checked', null);
16+
set_attribute(dom, 'value', null);
17+
set_attribute(dom, 'checked', null);
1818
}
1919
}
2020

@@ -23,7 +23,7 @@ export function remove_input_attr_defaults(dom) {
2323
* @param {string} attribute
2424
* @param {string | null} value
2525
*/
26-
export function attr(element, attribute, value) {
26+
export function set_attribute(element, attribute, value) {
2727
value = value == null ? null : value + '';
2828

2929
// @ts-expect-error
@@ -57,7 +57,7 @@ export function attr(element, attribute, value) {
5757
* @param {string} attribute
5858
* @param {string} value
5959
*/
60-
export function xlink_attr(dom, attribute, value) {
60+
export function set_xlink_attribute(dom, attribute, value) {
6161
dom.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);
6262
}
6363

@@ -70,7 +70,7 @@ export function set_custom_element_data(node, prop, value) {
7070
if (prop in node) {
7171
node[prop] = typeof node[prop] === 'boolean' && value === '' ? true : value;
7272
} else {
73-
attr(node, prop, value);
73+
set_attribute(node, prop, value);
7474
}
7575
}
7676

@@ -83,7 +83,7 @@ export function set_custom_element_data(node, prop, value) {
8383
* @param {string} css_hash
8484
* @returns {Record<string, unknown>}
8585
*/
86-
export function spread_attributes(element, prev, attrs, lowercase_attributes, css_hash) {
86+
export function set_attributes(element, prev, attrs, lowercase_attributes, css_hash) {
8787
var next = object_assign({}, ...attrs);
8888
var has_hash = css_hash.length !== 0;
8989

@@ -164,7 +164,7 @@ export function spread_attributes(element, prev, attrs, lowercase_attributes, cs
164164
value += css_hash;
165165
}
166166

167-
attr(element, name, value);
167+
set_attribute(element, name, value);
168168
}
169169
}
170170
}
@@ -178,7 +178,7 @@ export function spread_attributes(element, prev, attrs, lowercase_attributes, cs
178178
* @param {Record<string, unknown>[]} attrs
179179
* @param {string} css_hash
180180
*/
181-
export function spread_dynamic_element_attributes(node, prev, attrs, css_hash) {
181+
export function set_dynamic_element_attributes(node, prev, attrs, css_hash) {
182182
if (node.tagName.includes('-')) {
183183
var next = object_assign({}, ...attrs);
184184

@@ -193,15 +193,15 @@ export function spread_dynamic_element_attributes(node, prev, attrs, css_hash) {
193193
}
194194

195195
return next;
196-
} else {
197-
return spread_attributes(
198-
/** @type {Element & ElementCSSInlineStyle} */ (node),
199-
prev,
200-
attrs,
201-
node.namespaceURI !== namespace_svg,
202-
css_hash
203-
);
204196
}
197+
198+
return set_attributes(
199+
/** @type {Element & ElementCSSInlineStyle} */ (node),
200+
prev,
201+
attrs,
202+
node.namespaceURI !== namespace_svg,
203+
css_hash
204+
);
205205
}
206206

207207
/**

packages/svelte/src/internal/client/dom/elements/class.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { set_class_name } from '../operations.js';
66
* @param {string} value
77
* @returns {void}
88
*/
9-
export function svg_class_name(dom, value) {
9+
export function set_svg_class(dom, value) {
1010
// @ts-expect-error need to add __className to patched prototype
1111
var prev_class_name = dom.__className;
1212
var next_class_name = to_class(value);
@@ -35,7 +35,7 @@ export function svg_class_name(dom, value) {
3535
* @param {string} value
3636
* @returns {void}
3737
*/
38-
export function class_name(dom, value) {
38+
export function set_class(dom, value) {
3939
// @ts-expect-error need to add __className to patched prototype
4040
var prev_class_name = dom.__className;
4141
var next_class_name = to_class(value);
@@ -77,7 +77,7 @@ function to_class(value) {
7777
* @param {boolean} value
7878
* @returns {void}
7979
*/
80-
export function class_toggle(dom, class_name, value) {
80+
export function toggle_class(dom, class_name, value) {
8181
if (value) {
8282
dom.classList.add(class_name);
8383
} else {

packages/svelte/src/internal/client/dom/elements/style.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { render_effect } from '../../reactivity/effects.js';
2-
31
/**
42
* @param {HTMLElement} dom
53
* @param {string} key
64
* @param {string} value
75
* @param {boolean} [important]
86
*/
9-
export function style(dom, key, value, important) {
7+
export function set_style(dom, key, value, important) {
108
const style = dom.style;
119
const prev_value = style.getPropertyValue(key);
1210
if (value == null) {

packages/svelte/src/internal/client/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function set_should_intro(value) {
4444
* @param {string} value
4545
* @returns {void}
4646
*/
47-
export function text(dom, value) {
47+
export function set_text(dom, value) {
4848
// @ts-expect-error need to add __value to patched prototype
4949
const prev_node_value = dom.__nodeValue;
5050
const next_node_value = stringify(value);

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/client/main.svelte.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ export default function Main($$anchor, $$props) {
1717
var custom_element = $.sibling($.sibling(svg, true));
1818
var div_1 = $.sibling($.sibling(custom_element, true));
1919

20-
$.render_effect(() => $.attr(div_1, "foobar", y()));
20+
$.render_effect(() => $.set_attribute(div_1, "foobar", y()));
2121

2222
var svg_1 = $.sibling($.sibling(div_1, true));
2323

24-
$.render_effect(() => $.attr(svg_1, "viewBox", y()));
24+
$.render_effect(() => $.set_attribute(svg_1, "viewBox", y()));
2525

2626
var custom_element_1 = $.sibling($.sibling(svg_1, true));
2727

2828
$.render_effect(() => $.set_custom_element_data(custom_element_1, "fooBar", y()));
2929

3030
$.render_effect(() => {
31-
$.attr(div, "foobar", x);
32-
$.attr(svg, "viewBox", x);
31+
$.set_attribute(div, "foobar", x);
32+
$.set_attribute(svg, "viewBox", x);
3333
$.set_custom_element_data(custom_element, "fooBar", x);
3434
});
3535

packages/svelte/tests/snapshot/samples/each-string-template/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function Each_string_template($$anchor, $$props) {
1717
($$anchor, thing, $$index) => {
1818
var text = $.space_frag($$anchor);
1919

20-
$.render_effect(() => $.text(text, `${$.stringify($.unwrap(thing))}, `));
20+
$.render_effect(() => $.set_text(text, `${$.stringify($.unwrap(thing))}, `));
2121
return $.close($$anchor, text);
2222
},
2323
null

packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/client/index.svelte.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function Function_prop_no_getter($$anchor, $$props) {
2323
children: ($$anchor, $$slotProps) => {
2424
var text = $.space_frag($$anchor);
2525

26-
$.render_effect(() => $.text(text, `clicks: ${$.stringify($.get(count))}`));
26+
$.render_effect(() => $.set_text(text, `clicks: ${$.stringify($.get(count))}`));
2727
return $.close($$anchor, text);
2828
}
2929
});

0 commit comments

Comments
 (0)