Skip to content

Commit 43a60fd

Browse files
committed
drive-by tidy up
1 parent 6403a25 commit 43a60fd

File tree

1 file changed

+11
-13
lines changed
  • packages/svelte/src/compiler/migrate

1 file changed

+11
-13
lines changed

packages/svelte/src/compiler/migrate/index.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -944,22 +944,20 @@ const instance_script = {
944944
node.body.type === 'ExpressionStatement' &&
945945
node.body.expression.type === 'AssignmentExpression'
946946
) {
947-
const ids = extract_identifiers(node.body.expression.left);
948-
const [, expression_ids] = extract_all_identifiers_from_expression(
949-
node.body.expression.right
950-
);
947+
const { left, right } = node.body.expression;
948+
949+
const ids = extract_identifiers(left);
950+
const [, expression_ids] = extract_all_identifiers_from_expression(right);
951951
const bindings = ids.map((id) => /** @type {Binding} */ (state.scope.get(id.name)));
952952
const reassigned_bindings = bindings.filter((b) => b.reassigned);
953953

954-
if (!bindings.some((b) => b.kind === 'state')) {
954+
if (bindings.every((b) => b.kind === 'legacy_reactive')) {
955955
if (
956-
node.body.expression.right.type !== 'Literal' &&
957-
!bindings.some((b) => b.kind === 'store_sub') &&
958-
node.body.expression.left.type !== 'MemberExpression'
956+
right.type !== 'Literal' &&
957+
bindings.every((b) => b.kind !== 'store_sub') &&
958+
left.type !== 'MemberExpression'
959959
) {
960-
let { start, end } = /** @type {{ start: number, end: number }} */ (
961-
node.body.expression.right
962-
);
960+
let { start, end } = /** @type {{ start: number, end: number }} */ (right);
963961

964962
check_rune_binding('derived');
965963

@@ -970,7 +968,7 @@ const instance_script = {
970968
'let '
971969
);
972970

973-
if (node.body.expression.right.type === 'SequenceExpression') {
971+
if (right.type === 'SequenceExpression') {
974972
while (state.str.original[start] !== '(') start -= 1;
975973
while (state.str.original[end - 1] !== ')') end += 1;
976974
}
@@ -992,7 +990,7 @@ const instance_script = {
992990
binding.kind === 'state'
993991
? ' = $state()'
994992
: expression_ids.length === 0
995-
? ` = $state(${state.str.original.substring(/** @type {number} */ (node.body.expression.right.start), node.body.expression.right.end)})`
993+
? ` = $state(${state.str.original.substring(/** @type {number} */ (right.start), right.end)})`
996994
: '';
997995
// implicitly-declared variable which we need to make explicit
998996
state.str.prependLeft(

0 commit comments

Comments
 (0)