pull/13740/head
Simon Holthausen 2 years ago
parent c36784ccaf
commit ab18c98269

@ -558,14 +558,22 @@ const instance_script = {
const declaration = reference.path.find((el) => el.type === 'VariableDeclaration'); const declaration = reference.path.find((el) => el.type === 'VariableDeclaration');
const assignment = reference.path.find((el) => el.type === 'AssignmentExpression'); const assignment = reference.path.find((el) => el.type === 'AssignmentExpression');
const update = reference.path.find((el) => el.type === 'UpdateExpression'); const update = reference.path.find((el) => el.type === 'UpdateExpression');
const labeled = reference.path.find( const labeled = /** @type {LabeledStatement | undefined} */ (
(el) => el.type === 'LabeledStatement' && el.label.name === '$' reference.path.find((el) => el.type === 'LabeledStatement' && el.label.name === '$')
); );
if (assignment && labeled) { if (
assignment &&
labeled &&
// ensure that $: foo = bar * 2 is not counted as a reassignment of bar
(labeled.body.type !== 'ExpressionStatement' ||
labeled.body.expression !== assignment ||
(assignment.left.type === 'Identifier' &&
assignment.left.name === binding.node.name))
) {
if (assignment_in_labeled) return false; if (assignment_in_labeled) return false;
assignment_in_labeled = /** @type {AssignmentExpression} */ (assignment); assignment_in_labeled = /** @type {AssignmentExpression} */ (assignment);
labeled_statement = /** @type {LabeledStatement} */ (labeled); labeled_statement = labeled;
} }
return ( return (
@ -739,6 +747,7 @@ const instance_script = {
); );
const bindings = ids.map((id) => state.scope.get(id.name)); const bindings = ids.map((id) => state.scope.get(id.name));
const reassigned_bindings = bindings.filter((b) => b?.reassigned); const reassigned_bindings = bindings.filter((b) => b?.reassigned);
if ( if (
reassigned_bindings.length === 0 && reassigned_bindings.length === 0 &&
!bindings.some((b) => b?.kind === 'store_sub') && !bindings.some((b) => b?.kind === 'store_sub') &&

@ -6,6 +6,11 @@
// no semicolon at the end // no semicolon at the end
let time_8 = $derived(count * 8) let time_8 = $derived(count * 8)
let { time_16 } = $derived({ time_16: count * 16 }) let { time_16 } = $derived({ time_16: count * 16 })
// preceeding let that doesn't do anything
let time_32 = $derived(count * doubled);
let very_high = $derived(time_32 * count);
</script> </script>
{count} / {doubled} / {quadrupled} / {time_8} / {time_16} {count} / {doubled} / {quadrupled} / {time_8} / {time_16}

@ -10,7 +10,7 @@
console.log('bar'); console.log('bar');
} }
$: $count = 1; $: $count = 1;
$: $count.x = count; $: foo.x = count;
</script> </script>
<button onclick={() => count++}>increment</button> <button onclick={() => count++}>increment</button>

@ -19,7 +19,7 @@
$count = 1; $count = 1;
}); });
run(() => { run(() => {
$count.x = count; foo.x = count;
}); });
</script> </script>

Loading…
Cancel
Save