pull/13673/head
Dominic Gannaway 2 years ago
parent dc8ab171f8
commit c2566ce259

@ -549,27 +549,28 @@ const instance_script = {
let labeled_statement;
// Analyze declaration bindings to see if they're exclusively updated within a single reactive statement
const possible_derived = bindings.every(
(binding) =>
binding.initial !== null &&
binding.references.every((reference) => {
const declaration = reference.path.find((el) => el.type === 'VariableDeclaration');
const assignment = reference.path.find((el) => el.type === 'AssignmentExpression');
const update = reference.path.find((el) => el.type === 'UpdateExpression');
const labeled = reference.path.find(
(el) => el.type === 'LabeledStatement' && el.label.name === '$'
);
const possible_derived = bindings.every((binding) =>
binding.references.every((reference) => {
const declaration = reference.path.find((el) => el.type === 'VariableDeclaration');
const assignment = reference.path.find((el) => el.type === 'AssignmentExpression');
const update = reference.path.find((el) => el.type === 'UpdateExpression');
const labeled = reference.path.find(
(el) => el.type === 'LabeledStatement' && el.label.name === '$'
);
if (assignment && labeled) {
if (assignment_in_labeled) return false;
assignment_in_labeled = /** @type {AssignmentExpression} */ (assignment);
labeled_statement = /** @type {LabeledStatement} */ (labeled);
}
if (assignment && labeled) {
if (assignment_in_labeled) return false;
assignment_in_labeled = /** @type {AssignmentExpression} */ (assignment);
labeled_statement = /** @type {LabeledStatement} */ (labeled);
}
return (
!update && (declaration || (labeled && assignment) || (!labeled && !assignment))
);
})
return (
!update &&
((declaration && binding.initial) ||
(labeled && assignment) ||
(!labeled && !assignment))
);
})
);
const labeled_has_single_assignment =

@ -6,7 +6,10 @@
// triple
let triple = $state();
// update triple
let triple = $derived(count * 3)
// trailing comment
// in triple;
function increment() {
count += 1;
@ -16,12 +19,7 @@
run(() => {
console.log({ count, double });
});
run(() => {
// update triple
triple = count * 3;
// trailing comment
// in triple
});
</script>
<button onclick={increment}>

@ -2,10 +2,8 @@
import { run } from 'svelte/legacy';
let count = $state(0);
let double = $state();
run(() => {
double = count * 2;
});
let double = $derived(count * 2);
let quadruple = $state();
run(() => {
@ -43,13 +41,10 @@
evenmore_doubled = evenmore * 2;
});
let almost_infinity = $state();
run(() => {
almost_infinity = count * 128;
});
let almost_infinity = $derived(count * 128);
let should_be_state = $state();
let should_be_state = $state();
let should_be_state = $state(42);
let should_be_state_too = $state(42);

Loading…
Cancel
Save