Skip to content

Commit b3bcdaf

Browse files
committed
tidy up
1 parent 53137a1 commit b3bcdaf

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,14 @@ export function build_attribute_effect(
7878
);
7979
}
8080

81-
const all = memoizer.apply();
81+
const ids = memoizer.apply();
8282

8383
context.state.init.push(
8484
b.stmt(
8585
b.call(
8686
'$.attribute_effect',
8787
element_id,
88-
b.arrow(
89-
all.map(({ id }) => id),
90-
b.object(values)
91-
),
88+
b.arrow(ids, b.object(values)),
9289
memoizer.sync_values(),
9390
memoizer.async_values(),
9491
element.metadata.scoped &&

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,48 @@ import { build_getter } from '../../utils.js';
1212

1313
export class Memoizer {
1414
/** @type {Array<{ id: Identifier, expression: Expression }>} */
15-
sync = [];
15+
#sync = [];
1616

1717
/** @type {Array<{ id: Identifier, expression: Expression }>} */
18-
async = [];
18+
#async = [];
1919

2020
/**
2121
* @param {Expression} expression
2222
* @param {boolean} has_await
2323
*/
2424
add(expression, has_await) {
25-
const id = b.id(`#`); // filled in later
25+
const id = b.id('#'); // filled in later
2626

27-
(has_await ? this.async : this.sync).push({ id, expression });
27+
(has_await ? this.#async : this.#sync).push({ id, expression });
2828

2929
return id;
3030
}
3131

3232
apply() {
33-
const all = [...this.async, ...this.sync];
34-
35-
all.forEach((memo, i) => {
33+
return [...this.#async, ...this.#sync].map((memo, i) => {
3634
memo.id.name = `$${i}`;
35+
return memo.id;
3736
});
38-
39-
return all;
4037
}
4138

4239
deriveds(runes = true) {
43-
return this.sync.map((memo) =>
40+
return this.#sync.map((memo) =>
4441
b.let(memo.id, b.call(runes ? '$.derived' : '$.derived_safe_equal', b.thunk(memo.expression)))
4542
);
4643
}
4744

4845
async_ids() {
49-
return this.async.map((memo) => memo.id);
46+
return this.#async.map((memo) => memo.id);
5047
}
5148

5249
async_values() {
53-
if (this.async.length === 0) return;
54-
return b.array(this.async.map((memo) => b.thunk(memo.expression, true)));
50+
if (this.#async.length === 0) return;
51+
return b.array(this.#async.map((memo) => b.thunk(memo.expression, true)));
5552
}
5653

5754
sync_values() {
58-
if (this.sync.length === 0) return;
59-
return b.array(this.sync.map((memo) => b.thunk(memo.expression)));
55+
if (this.#sync.length === 0) return;
56+
return b.array(this.#sync.map((memo) => b.thunk(memo.expression)));
6057
}
6158
}
6259

@@ -163,13 +160,13 @@ export function build_template_chunk(
163160
export function build_render_statement(state) {
164161
const { memoizer } = state;
165162

166-
const all = state.memoizer.apply();
163+
const ids = state.memoizer.apply();
167164

168165
return b.stmt(
169166
b.call(
170167
'$.template_effect',
171168
b.arrow(
172-
all.map(({ id }) => id),
169+
ids,
173170
state.update.length === 1 && state.update[0].type === 'ExpressionStatement'
174171
? state.update[0].expression
175172
: b.block(state.update)

0 commit comments

Comments
 (0)