-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better migration of single-assignment labeled statements (#13461)
- Loading branch information
1 parent
7d47269
commit aa3f002
Showing
4 changed files
with
255 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
feat: support migration of single assignment labeled statements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/svelte/tests/migrate/samples/single-assignment-labeled/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
$: should_be_state_too = 42; | ||
</script> | ||
|
||
<button on:click={()=>{ | ||
count++; | ||
eight_times++; | ||
sixteen_times += 1; | ||
should_be_state_too++; | ||
}}>click</button> |
58 changes: 58 additions & 0 deletions
58
packages/svelte/tests/migrate/samples/single-assignment-labeled/output.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |