Skip to content

Commit 8e021c8

Browse files
committed
WIP
1 parent bda21bf commit 8e021c8

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/VariableDeclarator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function VariableDeclarator(node, context) {
1919
if (context.state.analysis.runes) {
2020
const init = node.init;
2121
const rune = get_rune(init, context.state.scope);
22-
const paths = extract_paths(node.id, b.id('dummy'));
22+
const { paths } = extract_paths(node.id, b.id('dummy'));
2323

2424
for (const path of paths) {
2525
validate_identifier_name(context.state.scope.get(/** @type {Identifier} */ (path.node).name));

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ export function EachBlock(node, context) {
234234
} else if (node.context) {
235235
const unwrapped = (flags & EACH_ITEM_REACTIVE) !== 0 ? b.call('$.get', item) : item;
236236

237-
for (const path of extract_paths(node.context, unwrapped)) {
237+
const { paths } = extract_paths(node.context, unwrapped);
238+
239+
for (const path of paths) {
238240
const name = /** @type {Identifier} */ (path.node).name;
239241
const needs_derived = path.has_default_value; // to ensure that default value is only called once
240242

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function SnippetBlock(node, context) {
4343
let arg_alias = `$$arg${i}`;
4444
args.push(b.id(arg_alias));
4545

46-
const paths = extract_paths(argument, b.maybe_call(b.id(arg_alias)));
46+
const { paths } = extract_paths(argument, b.maybe_call(b.id(arg_alias)));
4747

4848
for (const path of paths) {
4949
const name = /** @type {Identifier} */ (path.node).name;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function VariableDeclaration(node, context) {
142142
);
143143
} else {
144144
const tmp = b.id(context.state.scope.generate('tmp'));
145-
const paths = extract_paths(declarator.id, tmp);
145+
const { paths } = extract_paths(declarator.id, tmp);
146146
declarations.push(
147147
b.declarator(tmp, value),
148148
...paths.map((path) => {
@@ -183,7 +183,9 @@ export function VariableDeclaration(node, context) {
183183
);
184184
}
185185

186-
for (const path of extract_paths(declarator.id, rhs)) {
186+
const { paths } = extract_paths(declarator.id, rhs);
187+
188+
for (const path of paths) {
187189
declarations.push(
188190
b.declarator(path.node, b.call('$.derived', b.thunk(path.expression)))
189191
);
@@ -218,7 +220,7 @@ export function VariableDeclaration(node, context) {
218220
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
219221
// means that foo and bar are the props (i.e. the leafs are the prop names), not x and z.
220222
const tmp = b.id(context.state.scope.generate('tmp'));
221-
const paths = extract_paths(declarator.id, tmp);
223+
const { paths } = extract_paths(declarator.id, tmp);
222224

223225
declarations.push(
224226
b.declarator(
@@ -298,7 +300,7 @@ function create_state_declarators(declarator, { scope, analysis }, value) {
298300
}
299301

300302
const tmp = b.id(scope.generate('tmp'));
301-
const paths = extract_paths(declarator.id, tmp);
303+
const { paths } = extract_paths(declarator.id, tmp);
302304
return [
303305
b.declarator(tmp, value),
304306
...paths.map((path) => {

packages/svelte/src/compiler/phases/3-transform/server/visitors/VariableDeclaration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function VariableDeclaration(node, context) {
121121
// Turn export let into props. It's really really weird because export let { x: foo, z: [bar]} = ..
122122
// means that foo and bar are the props (i.e. the leafs are the prop names), not x and z.
123123
const tmp = b.id(context.state.scope.generate('tmp'));
124-
const paths = extract_paths(declarator.id, tmp);
124+
const { paths } = extract_paths(declarator.id, tmp);
125125
declarations.push(
126126
b.declarator(
127127
tmp,
@@ -189,7 +189,7 @@ function create_state_declarators(declarator, scope, value) {
189189
}
190190

191191
const tmp = b.id(scope.generate('tmp'));
192-
const paths = extract_paths(declarator.id, tmp);
192+
const { paths } = extract_paths(declarator.id, tmp);
193193
return [
194194
b.declarator(tmp, value), // TODO inject declarator for opts, so we can use it below
195195
...paths.map((path) => {

packages/svelte/src/compiler/phases/3-transform/shared/assignments.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export function visit_assignment_expression(node, context, build_assignment) {
2323

2424
let changed = false;
2525

26-
const assignments = extract_paths(node.left, rhs).map((path) => {
26+
const { paths } = extract_paths(node.left, rhs);
27+
28+
const assignments = paths.map((path) => {
2729
const value = path.expression;
2830

2931
let assignment = build_assignment('=', path.node, value, context);

packages/svelte/src/compiler/utils/ast.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,15 @@ export function extract_identifiers_from_destructuring(node, nodes = []) {
237237
* Extracts all destructured assignments from a pattern.
238238
* @param {ESTree.Node} param
239239
* @param {ESTree.Expression} initial
240-
* @returns {DestructuredAssignment[]}
240+
* @returns {{ paths: DestructuredAssignment[] }}
241241
*/
242242
export function extract_paths(param, initial) {
243-
return _extract_paths([], param, initial, initial, false);
243+
/** @type {DestructuredAssignment[]} */
244+
const paths = [];
245+
246+
_extract_paths(paths, param, initial, initial, false);
247+
248+
return { paths };
244249
}
245250

246251
/**

0 commit comments

Comments
 (0)