Skip to content

Commit bbdad4b

Browse files
committed
fix
1 parent d49f285 commit bbdad4b

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ function serialize_assignment(node, context, fallback) {
8181
}
8282

8383
if (left === node.left) {
84-
return b.call('$.store_set', b.id(name), /** @type {Expression} */ (context.visit(node.right)));
84+
const value =
85+
node.operator === '='
86+
? /** @type {Expression} */ (context.visit(node.right))
87+
: // turn something like x += 1 into x = x + 1
88+
b.binary(
89+
/** @type {BinaryOperator} */ (node.operator.slice(0, -1)),
90+
serialize_get_binding(node.left, context.state),
91+
/** @type {Expression} */ (context.visit(node.right))
92+
);
93+
94+
return b.call('$.store_set', b.id(name), value);
8595
}
8696

8797
return b.call(
@@ -92,31 +102,11 @@ function serialize_assignment(node, context, fallback) {
92102
b.assignment(
93103
node.operator,
94104
/** @type {Pattern} */ (context.visit(node.left)),
95-
get_assignment_value(node, context)
105+
/** @type {Expression} */ (context.visit(node.right))
96106
)
97107
);
98108
}
99109

100-
/**
101-
* @param {AssignmentExpression} node
102-
* @param {Pick<import('zimmerframe').Context<SvelteNode, ServerTransformState>, 'visit' | 'state'>} context
103-
*/
104-
function get_assignment_value(node, { state, visit }) {
105-
if (node.left.type === 'Identifier') {
106-
const operator = node.operator;
107-
return operator === '='
108-
? /** @type {Expression} */ (visit(node.right))
109-
: // turn something like x += 1 into x = x + 1
110-
b.binary(
111-
/** @type {BinaryOperator} */ (operator.slice(0, -1)),
112-
serialize_get_binding(node.left, state),
113-
/** @type {Expression} */ (visit(node.right))
114-
);
115-
}
116-
117-
return /** @type {Expression} */ (visit(node.right));
118-
}
119-
120110
/**
121111
* @param {string} name
122112
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: '<p>3</p>'
5+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import { writable } from 'svelte/store';
3+
4+
const count = writable(0);
5+
6+
$count += 1;
7+
$count += 1;
8+
$count += 1;
9+
</script>
10+
11+
<p>{$count}</p>

0 commit comments

Comments
 (0)