Skip to content

Commit 7d6b603

Browse files
committed
dry out
1 parent 3eee9d5 commit 7d6b603

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ export function RenderTag(node, context) {
6767
);
6868
}
6969

70-
if (memoizer.async.length > 0) {
70+
const async_values = memoizer.async_values();
71+
72+
if (async_values) {
7173
context.state.init.push(
7274
b.stmt(
7375
b.call(
7476
'$.async',
7577
context.state.node,
76-
b.array(memoizer.async.map((memo) => b.thunk(memo.expression, true))),
78+
memoizer.async_values(),
7779
b.arrow(
7880
[context.state.node, ...memoizer.async.map((memo) => memo.id)],
7981
b.block(statements)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ export function SlotElement(node, context) {
7676
b.stmt(b.call('$.slot', context.state.node, b.id('$$props'), name, props_expression, fallback))
7777
);
7878

79-
if (memoizer.async.length > 0) {
79+
const async_values = memoizer.async_values();
80+
81+
if (async_values) {
8082
context.state.init.push(
8183
b.stmt(
8284
b.call(
8385
'$.async',
8486
context.state.node,
85-
b.array(memoizer.async.map((memo) => b.thunk(memo.expression, true))),
87+
async_values,
8688
b.arrow(
8789
[context.state.node, ...memoizer.async.map((memo) => memo.id)],
8890
b.block(statements)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,14 @@ export function build_component(node, component_name, context) {
501501

502502
memoizer.apply();
503503

504-
if (memoizer.async.length > 0) {
504+
const async_values = memoizer.async_values();
505+
506+
if (async_values) {
505507
return b.stmt(
506508
b.call(
507509
'$.async',
508510
anchor,
509-
b.array(memoizer.async.map(({ expression }) => b.thunk(expression, true))),
511+
async_values,
510512
b.arrow([b.id('$$anchor'), ...memoizer.async.map(({ id }) => id)], b.block(statements))
511513
)
512514
);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ export function build_attribute_effect(
9191
),
9292
memoizer.sync.length > 0 &&
9393
b.array(memoizer.sync.map(({ expression }) => b.thunk(expression))),
94-
memoizer.async.length > 0 &&
95-
b.array(memoizer.async.map(({ expression }) => b.thunk(expression, true))),
94+
memoizer.async_values(),
9695
element.metadata.scoped &&
9796
context.state.analysis.css.hash !== '' &&
9897
b.literal(context.state.analysis.css.hash),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export class Memoizer {
3838

3939
return all;
4040
}
41+
42+
async_values() {
43+
if (this.async.length === 0) return;
44+
return b.array(this.async.map((memo) => b.thunk(memo.expression, true)));
45+
}
4146
}
4247

4348
/**
@@ -155,8 +160,7 @@ export function build_render_statement(state) {
155160
: b.block(state.update)
156161
),
157162
all.length > 0 && b.array(memoizer.sync.map(({ expression }) => b.thunk(expression))),
158-
memoizer.async.length > 0 &&
159-
b.array(memoizer.async.map(({ expression }) => b.thunk(expression, true)))
163+
memoizer.async_values()
160164
)
161165
);
162166
}

0 commit comments

Comments
 (0)