Skip to content

Commit 4fd7834

Browse files
authored
chore: rename serialize_ prefix to build_ (#12696)
1 parent 79ef645 commit 4fd7834

38 files changed

+200
-236
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { walk } from 'zimmerframe';
66
import * as b from '../../../utils/builders.js';
77
import { set_scope } from '../../scope.js';
8-
import { serialize_get_binding } from './utils.js';
8+
import { build_getter } from './utils.js';
99
import { render_stylesheet } from '../css/index.js';
1010
import { dev, filename } from '../../../state.js';
1111
import { AnimateDirective } from './visitors/AnimateDirective.js';
@@ -198,7 +198,7 @@ export function client_component(analysis, options) {
198198
}
199199

200200
// We're creating an arrow function that gets the store value which minifies better for two or more references
201-
const store_reference = serialize_get_binding(b.id(name.slice(1)), instance_state);
201+
const store_reference = build_getter(b.id(name.slice(1)), instance_state);
202202
const store_get = b.call('$.store_get', store_reference, b.literal(name), b.id('$$stores'));
203203
store_setup.push(
204204
b.const(
@@ -240,7 +240,7 @@ export function client_component(analysis, options) {
240240
/** @type {Array<ESTree.Property | ESTree.SpreadElement>} */
241241
const component_returned_object = analysis.exports.flatMap(({ name, alias }) => {
242242
const binding = instance_state.scope.get(name);
243-
const expression = serialize_get_binding(b.id(name), instance_state);
243+
const expression = build_getter(b.id(name), instance_state);
244244
const getter = b.get(alias ?? name, [b.return(expression)]);
245245

246246
if (expression.type === 'Identifier') {
@@ -365,7 +365,7 @@ export function client_component(analysis, options) {
365365
'$.bind_prop',
366366
b.id('$$props'),
367367
b.literal(alias ?? name),
368-
serialize_get_binding(b.id(name), instance_state)
368+
build_getter(b.id(name), instance_state)
369369
)
370370
)
371371
);

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function get_assignment_value(node, { state, visit }) {
3232
: // turn something like x += 1 into x = x + 1
3333
b.binary(
3434
/** @type {BinaryOperator} */ (operator.slice(0, -1)),
35-
serialize_get_binding(node.left, state),
35+
build_getter(node.left, state),
3636
/** @type {Expression} */ (visit(node.right))
3737
);
3838
} else if (
@@ -72,7 +72,7 @@ export function is_state_source(binding, state) {
7272
* @param {ClientTransformState} state
7373
* @returns {Expression}
7474
*/
75-
export function serialize_get_binding(node, state) {
75+
export function build_getter(node, state) {
7676
const binding = state.scope.get(node.name);
7777

7878
if (binding === null || node === binding.node) {
@@ -130,7 +130,7 @@ export function serialize_get_binding(node, state) {
130130
* @param {{skip_proxy_and_freeze?: boolean}} [options]
131131
* @returns {Expression}
132132
*/
133-
export function serialize_set_binding(node, context, fallback, prefix, options) {
133+
export function build_setter(node, context, fallback, prefix, options) {
134134
const { state, visit } = context;
135135

136136
const assignee = node.left;
@@ -154,9 +154,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
154154
const value = path.expression?.(b.id(tmp_id));
155155
const assignment = b.assignment('=', path.node, value);
156156
original_assignments.push(assignment);
157-
assignments.push(
158-
serialize_set_binding(assignment, context, () => assignment, prefix, options)
159-
);
157+
assignments.push(build_setter(assignment, context, () => assignment, prefix, options));
160158
}
161159

162160
if (assignments.every((assignment, i) => assignment === original_assignments[i])) {
@@ -213,7 +211,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
213211
assignment.right =
214212
private_state.kind === 'frozen_state'
215213
? b.call('$.freeze', value)
216-
: serialize_proxy_reassignment(value, private_state.id);
214+
: build_proxy_reassignment(value, private_state.id);
217215
return assignment;
218216
}
219217
}
@@ -226,7 +224,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
226224
should_proxy_or_freeze(value, context.state.scope)
227225
? private_state.kind === 'frozen_state'
228226
? b.call('$.freeze', value)
229-
: serialize_proxy_reassignment(value, private_state.id)
227+
: build_proxy_reassignment(value, private_state.id)
230228
: value
231229
);
232230
}
@@ -250,7 +248,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
250248
assignment.right =
251249
public_state.kind === 'frozen_state'
252250
? b.call('$.freeze', value)
253-
: serialize_proxy_reassignment(value, public_state.id);
251+
: build_proxy_reassignment(value, public_state.id);
254252
return assignment;
255253
}
256254
}
@@ -324,7 +322,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
324322
if ((binding.kind === 'prop' || binding.kind === 'bindable_prop') && !is_initial_proxy) {
325323
return b.call(left, value);
326324
} else if (is_store) {
327-
return b.call('$.store_set', serialize_get_binding(b.id(left_name), state), value);
325+
return b.call('$.store_set', build_getter(b.id(left_name), state), value);
328326
} else {
329327
let call;
330328
if (binding.kind === 'state') {
@@ -334,7 +332,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
334332
context.state.analysis.runes &&
335333
!options?.skip_proxy_and_freeze &&
336334
should_proxy_or_freeze(value, context.state.scope)
337-
? serialize_proxy_reassignment(value, left_name)
335+
? build_proxy_reassignment(value, left_name)
338336
: value
339337
);
340338
} else if (binding.kind === 'frozen_state') {
@@ -357,7 +355,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
357355
!options?.skip_proxy_and_freeze &&
358356
should_proxy_or_freeze(value, context.state.scope) &&
359357
binding.kind === 'bindable_prop'
360-
? serialize_proxy_reassignment(value, left_name)
358+
? build_proxy_reassignment(value, left_name)
361359
: value
362360
);
363361
} else {
@@ -401,7 +399,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
401399
return maybe_skip_ownership_validation(
402400
b.call(
403401
'$.store_mutate',
404-
serialize_get_binding(b.id(left_name), state),
402+
build_getter(b.id(left_name), state),
405403
b.assignment(node.operator, /** @type {Pattern}} */ (visit_node(node.left)), value),
406404
b.call('$.untrack', b.id('$' + left_name))
407405
)
@@ -453,7 +451,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
453451
};
454452

455453
if (value.type === 'BinaryExpression' && /** @type {any} */ (value.operator) === '??') {
456-
return b.logical('??', serialize_get_binding(b.id(left_name), state), serialize());
454+
return b.logical('??', build_getter(b.id(left_name), state), serialize());
457455
}
458456

459457
return serialize();
@@ -463,7 +461,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
463461
* @param {Expression} value
464462
* @param {PrivateIdentifier | string} proxy_reference
465463
*/
466-
export function serialize_proxy_reassignment(value, proxy_reference) {
464+
export function build_proxy_reassignment(value, proxy_reference) {
467465
return dev
468466
? b.call(
469467
'$.proxy',
@@ -549,7 +547,7 @@ function get_hoistable_params(node, context) {
549547
* @param {ComponentContext} context
550548
* @returns {Pattern[]}
551549
*/
552-
export function serialize_hoistable_params(node, context) {
550+
export function build_hoistable_params(node, context) {
553551
const hoistable_params = get_hoistable_params(node, context);
554552
node.metadata.hoistable_params = hoistable_params;
555553

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/** @import { AssignmentExpression } from 'estree' */
22
/** @import { Context } from '../types' */
3-
import { serialize_set_binding } from '../utils.js';
3+
import { build_setter } from '../utils.js';
44

55
/**
66
* @param {AssignmentExpression} node
77
* @param {Context} context
88
*/
99
export function AssignmentExpression(node, context) {
10-
return serialize_set_binding(node, context, context.next);
10+
return build_setter(node, context, context.next);
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/** @import { Attribute } from '#compiler' */
22
/** @import { ComponentContext } from '../types' */
33
import { is_event_attribute } from '../../../../utils/ast.js';
4-
import { serialize_event_attribute } from './shared/element.js';
4+
import { build_event_attribute } from './shared/element.js';
55

66
/**
77
* @param {Attribute} node
88
* @param {ComponentContext} context
99
*/
1010
export function Attribute(node, context) {
1111
if (is_event_attribute(node)) {
12-
serialize_event_attribute(node, context);
12+
build_event_attribute(node, context);
1313
}
1414
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { dev, is_ignored } from '../../../../state.js';
55
import { is_text_attribute } from '../../../../utils/ast.js';
66
import * as b from '../../../../utils/builders.js';
77
import { binding_properties } from '../../../bindings.js';
8-
import { serialize_set_binding } from '../utils.js';
9-
import { serialize_attribute_value } from './shared/element.js';
10-
import { serialize_bind_this, serialize_validate_binding } from './shared/utils.js';
8+
import { build_setter } from '../utils.js';
9+
import { build_attribute_value } from './shared/element.js';
10+
import { build_bind_this, build_validate_binding } from './shared/utils.js';
1111

1212
/**
1313
* @param {BindDirective} node
@@ -31,7 +31,7 @@ export function BindDirective(node, context) {
3131
!is_ignored(node, 'binding_property_non_reactive')
3232
) {
3333
context.state.init.push(
34-
serialize_validate_binding(
34+
build_validate_binding(
3535
context.state,
3636
node,
3737
/**@type {MemberExpression} */ (context.visit(expression))
@@ -43,7 +43,7 @@ export function BindDirective(node, context) {
4343
const assignment = b.assignment('=', expression, b.id('$$value'));
4444
const setter = b.arrow(
4545
[b.id('$$value')],
46-
serialize_set_binding(
46+
build_setter(
4747
assignment,
4848
context,
4949
() => /** @type {Expression} */ (context.visit(assignment)),
@@ -161,7 +161,7 @@ export function BindDirective(node, context) {
161161
break;
162162

163163
case 'this':
164-
call = serialize_bind_this(expression, context.state.node, context);
164+
call = build_bind_this(expression, context.state.node, context);
165165
break;
166166

167167
case 'textContent':
@@ -212,7 +212,7 @@ export function BindDirective(node, context) {
212212
if (value !== undefined) {
213213
group_getter = b.thunk(
214214
b.block([
215-
b.stmt(serialize_attribute_value(value, context)[1]),
215+
b.stmt(build_attribute_value(value, context)[1]),
216216
b.return(/** @type {Expression} */ (context.visit(expression)))
217217
])
218218
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { dev, is_ignored } from '../../../../state.js';
55
import * as b from '../../../../utils/builders.js';
66
import { regex_invalid_identifier_chars } from '../../../patterns.js';
77
import { get_rune } from '../../../scope.js';
8-
import { serialize_proxy_reassignment, should_proxy_or_freeze } from '../utils.js';
8+
import { build_proxy_reassignment, should_proxy_or_freeze } from '../utils.js';
99

1010
/**
1111
* @param {ClassBody} node
@@ -149,7 +149,7 @@ export function ClassBody(node, context) {
149149
'set',
150150
definition.key,
151151
[value],
152-
[b.stmt(b.call('$.set', member, serialize_proxy_reassignment(value, field.id)))]
152+
[b.stmt(b.call('$.set', member, build_proxy_reassignment(value, field.id)))]
153153
)
154154
);
155155
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** @import { Component } from '#compiler' */
33
/** @import { ComponentContext } from '../types' */
44
import * as b from '../../../../utils/builders.js';
5-
import { serialize_component } from './shared/component.js';
5+
import { build_component } from './shared/component.js';
66

77
/**
88
* @param {Component} node
@@ -11,7 +11,7 @@ import { serialize_component } from './shared/component.js';
1111
export function Component(node, context) {
1212
if (node.metadata.dynamic) {
1313
// Handle dynamic references to what seems like static inline components
14-
const component = serialize_component(node, '$$component', context, b.id('$$anchor'));
14+
const component = build_component(node, '$$component', context, b.id('$$anchor'));
1515
context.state.init.push(
1616
b.stmt(
1717
b.call(
@@ -27,6 +27,6 @@ export function Component(node, context) {
2727
return;
2828
}
2929

30-
const component = serialize_component(node, node.name, context);
30+
const component = build_component(node, node.name, context);
3131
context.state.init.push(component);
3232
}

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ import {
1212
import { dev } from '../../../../state.js';
1313
import { extract_paths, object } from '../../../../utils/ast.js';
1414
import * as b from '../../../../utils/builders.js';
15-
import {
16-
get_assignment_value,
17-
serialize_get_binding,
18-
serialize_set_binding,
19-
with_loc
20-
} from '../utils.js';
15+
import { get_assignment_value, build_getter, build_setter, with_loc } from '../utils.js';
2116

2217
/**
2318
* @param {EachBlock} node
@@ -94,7 +89,7 @@ export function EachBlock(node, context) {
9489
// Legacy mode: find the parent each blocks which contain the arrays to invalidate
9590
const indirect_dependencies = collect_parent_each_blocks(context).flatMap((block) => {
9691
const array = /** @type {Expression} */ (context.visit(block.expression));
97-
const transitive_dependencies = serialize_transitive_dependencies(
92+
const transitive_dependencies = build_transitive_dependencies(
9893
block.metadata.references,
9994
context
10095
);
@@ -106,7 +101,7 @@ export function EachBlock(node, context) {
106101
} else {
107102
indirect_dependencies.push(collection);
108103

109-
const transitive_dependencies = serialize_transitive_dependencies(
104+
const transitive_dependencies = build_transitive_dependencies(
110105
each_node_meta.references,
111106
context
112107
);
@@ -131,9 +126,9 @@ export function EachBlock(node, context) {
131126
const create_mutation = (expression_for_id) => {
132127
return (assignment, context) => {
133128
if (assignment.left.type !== 'Identifier' && assignment.left.type !== 'MemberExpression') {
134-
// serialize_set_binding turns other patterns into IIFEs and separates the assignments
129+
// build_setter turns other patterns into IIFEs and separates the assignments
135130
// into separate expressions, at which point this is called again with an identifier or member expression
136-
return serialize_set_binding(assignment, context, () => assignment);
131+
return build_setter(assignment, context, () => assignment);
137132
}
138133

139134
const left = object(assignment.left);
@@ -282,7 +277,7 @@ function collect_parent_each_blocks(context) {
282277
* @param {Binding[]} references
283278
* @param {ComponentContext} context
284279
*/
285-
function serialize_transitive_dependencies(references, context) {
280+
function build_transitive_dependencies(references, context) {
286281
/** @type {Set<Binding>} */
287282
const dependencies = new Set();
288283

@@ -293,7 +288,7 @@ function serialize_transitive_dependencies(references, context) {
293288
}
294289
}
295290

296-
return [...dependencies].map((dep) => serialize_get_binding({ ...dep.node }, context.state));
291+
return [...dependencies].map((dep) => build_getter({ ...dep.node }, context.state));
297292
}
298293

299294
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { dev } from '../../../../state.js';
77
import * as b from '../../../../utils/builders.js';
88
import { clean_nodes, infer_namespace } from '../../utils.js';
99
import { process_children } from './shared/fragment.js';
10-
import { serialize_render_stmt } from './shared/utils.js';
10+
import { build_render_statement } from './shared/utils.js';
1111

1212
/**
1313
* @param {Fragment} node
@@ -97,7 +97,7 @@ export function Fragment(node, context) {
9797
'$.add_locations',
9898
call,
9999
b.member(b.id(context.state.analysis.name), b.id('$.FILENAME'), true),
100-
serialize_locations(state.locations)
100+
build_locations(state.locations)
101101
);
102102
}
103103

@@ -184,7 +184,7 @@ export function Fragment(node, context) {
184184
}
185185

186186
if (state.update.length > 0) {
187-
body.push(serialize_render_stmt(state.update));
187+
body.push(build_render_statement(state.update));
188188
}
189189

190190
body.push(...state.after_update);
@@ -221,13 +221,13 @@ function get_template_function(namespace, state) {
221221
/**
222222
* @param {SourceLocation[]} locations
223223
*/
224-
function serialize_locations(locations) {
224+
function build_locations(locations) {
225225
return b.array(
226226
locations.map((loc) => {
227227
const expression = b.array([b.literal(loc[0]), b.literal(loc[1])]);
228228

229229
if (loc.length === 3) {
230-
expression.elements.push(serialize_locations(loc[2]));
230+
expression.elements.push(build_locations(loc[2]));
231231
}
232232

233233
return expression;

0 commit comments

Comments
 (0)