Skip to content

Commit b89124d

Browse files
committed
move code to where it is used
1 parent 984e102 commit b89124d

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -269,41 +269,6 @@ export function should_proxy(node, scope) {
269269
return true;
270270
}
271271

272-
/**
273-
* @param {Pattern} node
274-
* @param {import('zimmerframe').Context<AST.SvelteNode, ComponentClientTransformState>} context
275-
* @returns {{ id: Pattern, declarations: null | Statement[] }}
276-
*/
277-
export function create_derived_block_argument(node, context) {
278-
if (node.type === 'Identifier') {
279-
context.state.transform[node.name] = { read: get_value };
280-
return { id: node, declarations: null };
281-
}
282-
283-
const pattern = /** @type {Pattern} */ (context.visit(node));
284-
const identifiers = extract_identifiers(node);
285-
286-
const id = b.id('$$source');
287-
const value = b.id('$$value');
288-
289-
const block = b.block([
290-
b.var(pattern, b.call('$.get', id)),
291-
b.return(b.object(identifiers.map((identifier) => b.prop('init', identifier, identifier))))
292-
]);
293-
294-
const declarations = [b.var(value, create_derived(context.state, b.thunk(block)))];
295-
296-
for (const id of identifiers) {
297-
context.state.transform[id.name] = { read: get_value };
298-
299-
declarations.push(
300-
b.var(id, create_derived(context.state, b.thunk(b.member(b.call('$.get', value), id))))
301-
);
302-
}
303-
304-
return { id, declarations };
305-
}
306-
307272
/**
308273
* Svelte legacy mode should use safe equals in most places, runes mode shouldn't
309274
* @param {ComponentClientTransformState} state

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/** @import { BlockStatement, Expression, Pattern, Statement } from 'estree' */
22
/** @import { AST } from '#compiler' */
3-
/** @import { ComponentContext } from '../types' */
3+
/** @import { ComponentClientTransformState, ComponentContext } from '../types' */
4+
import { extract_identifiers } from '../../../../utils/ast.js';
45
import * as b from '../../../../utils/builders.js';
5-
import { create_derived_block_argument } from '../utils.js';
6+
import { create_derived } from '../utils.js';
7+
import { get_value } from './shared/declarations.js';
68

79
/**
810
* @param {AST.AwaitBlock} node
@@ -65,3 +67,38 @@ export function AwaitBlock(node, context) {
6567
)
6668
);
6769
}
70+
71+
/**
72+
* @param {Pattern} node
73+
* @param {import('zimmerframe').Context<AST.SvelteNode, ComponentClientTransformState>} context
74+
* @returns {{ id: Pattern, declarations: null | Statement[] }}
75+
*/
76+
function create_derived_block_argument(node, context) {
77+
if (node.type === 'Identifier') {
78+
context.state.transform[node.name] = { read: get_value };
79+
return { id: node, declarations: null };
80+
}
81+
82+
const pattern = /** @type {Pattern} */ (context.visit(node));
83+
const identifiers = extract_identifiers(node);
84+
85+
const id = b.id('$$source');
86+
const value = b.id('$$value');
87+
88+
const block = b.block([
89+
b.var(pattern, b.call('$.get', id)),
90+
b.return(b.object(identifiers.map((identifier) => b.prop('init', identifier, identifier))))
91+
]);
92+
93+
const declarations = [b.var(value, create_derived(context.state, b.thunk(block)))];
94+
95+
for (const id of identifiers) {
96+
context.state.transform[id.name] = { read: get_value };
97+
98+
declarations.push(
99+
b.var(id, create_derived(context.state, b.thunk(b.member(b.call('$.get', value), id))))
100+
);
101+
}
102+
103+
return { id, declarations };
104+
}

0 commit comments

Comments
 (0)