Skip to content

Commit 13ca61e

Browse files
committed
fix
1 parent abe01a7 commit 13ca61e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export function VariableDeclaration(node, context) {
167167
b.arrow(
168168
[b.id('$$fn')],
169169
b.sequence([
170-
b.call(b.id('$$fn'), b.member(state_id, b.id('v'))),
170+
b.chain_call(b.id('$$fn'), b.member(state_id, b.id('v'))),
171171
b.call('$.set', state_id, b.member(state_id, b.id('v')))
172172
])
173173
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function VariableDeclaration(node, context) {
9898
const invalidation_id = /** @type {Identifier} */ (pattern.elements[1]);
9999
declarations.push(
100100
b.declarator(state_id, value),
101-
b.declarator(invalidation_id, b.arrow([b.id('$$fn')], b.call(b.id('$$fn'), state_id)))
101+
b.declarator(invalidation_id, b.arrow([b.id('$$fn')], b.chain_call(b.id('$$fn'), state_id)))
102102
);
103103
continue;
104104
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ export function call(callee, ...args) {
130130
};
131131
}
132132

133+
/**
134+
* @param {string | ESTree.Expression} callee
135+
* @param {...(ESTree.Expression | ESTree.SpreadElement | false | undefined)} args
136+
* @returns {ESTree.ChainExpression}
137+
*/
138+
export function chain_call(callee, ...args) {
139+
const expression = /** @type {ESTree.SimpleCallExpression} */ (call(callee, ...args));
140+
expression.optional = true;
141+
return { type: 'ChainExpression', expression };
142+
}
143+
133144
/**
134145
* @param {string | ESTree.Expression} callee
135146
* @param {...ESTree.Expression} args

0 commit comments

Comments
 (0)