-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: support migration of single assignment labeled statements #13461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6695a5e
bb4b7f4
ef4b317
7da3de0
12697d1
c7d6d32
8ba0012
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
feat: support migration of single assignment labeled statements |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<script> | ||
let count = 0; | ||
let double; | ||
$:{ | ||
double = count * 2; | ||
} | ||
|
||
let quadruple; | ||
$:{ | ||
quadruple = count * 4; | ||
console.log("i have a side effect") | ||
} | ||
|
||
let eight_times; | ||
$:{ | ||
// updated | ||
eight_times = count * 8; | ||
} | ||
|
||
let sixteen_times; | ||
$:{ | ||
// reassigned outside labeled statement | ||
sixteen_times = count * 16; | ||
} | ||
|
||
let alot_times; | ||
$:{ | ||
// reassigned in multiple labeled | ||
alot_times = count * 32; | ||
} | ||
$:{ | ||
// reassigned in multiple labeled | ||
alot_times = count * 32; | ||
} | ||
|
||
let evenmore; | ||
let evenmore_doubled; | ||
$:{ | ||
// multiple stuff in label | ||
evenmore = count * 64; | ||
evenmore_doubled = evenmore * 2; | ||
} | ||
|
||
let almost_infinity; | ||
$: almost_infinity = count * 128; | ||
|
||
let should_be_state; | ||
$: should_be_state = 42; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also saw things like $: should_also_be_state = 42; without a preceeding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I planned to do that as well but since that is not a variable declaration i should've repeated a lot of code from here...i planned to do this as a separate PR to not complicate things too much in this. Should i go for this in this PR too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scratch that...it was different. Pushing now. |
||
$: should_be_state_too = 42; | ||
</script> | ||
|
||
<button on:click={()=>{ | ||
count++; | ||
eight_times++; | ||
sixteen_times += 1; | ||
should_be_state_too++; | ||
}}>click</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<script> | ||
import { run } from 'svelte/legacy'; | ||
|
||
let count = $state(0); | ||
let double = $derived(count * 2); | ||
|
||
|
||
let quadruple = $state(); | ||
run(() => { | ||
quadruple = count * 4; | ||
console.log("i have a side effect") | ||
}); | ||
|
||
let eight_times = $state(); | ||
run(() => { | ||
// updated | ||
eight_times = count * 8; | ||
}); | ||
|
||
let sixteen_times = $state(); | ||
run(() => { | ||
// reassigned outside labeled statement | ||
sixteen_times = count * 16; | ||
}); | ||
|
||
let alot_times = $state(); | ||
run(() => { | ||
// reassigned in multiple labeled | ||
alot_times = count * 32; | ||
}); | ||
run(() => { | ||
// reassigned in multiple labeled | ||
alot_times = count * 32; | ||
}); | ||
|
||
let evenmore = $state(); | ||
let evenmore_doubled = $state(); | ||
run(() => { | ||
// multiple stuff in label | ||
evenmore = count * 64; | ||
evenmore_doubled = evenmore * 2; | ||
}); | ||
|
||
let almost_infinity = $derived(count * 128); | ||
|
||
|
||
let should_be_state = $state(42); | ||
|
||
let should_be_state_too = $state(42); | ||
|
||
</script> | ||
|
||
<button onclick={()=>{ | ||
count++; | ||
eight_times++; | ||
sixteen_times += 1; | ||
should_be_state_too++; | ||
}}>click</button> |
Uh oh!
There was an error while loading. Please reload this page.