Skip to content

feat: State declarations in class constructors #15820

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

Merged
merged 65 commits into from
May 19, 2025
Merged
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
134d435
feat: State declarations in class constructors
elliott-with-the-longest-name-on-github Apr 23, 2025
fb8d6d7
feat: Analysis phase
elliott-with-the-longest-name-on-github Apr 24, 2025
033a466
misc
elliott-with-the-longest-name-on-github Apr 25, 2025
005ba29
feat: client
elliott-with-the-longest-name-on-github Apr 26, 2025
4d6422c
improvements
elliott-with-the-longest-name-on-github Apr 26, 2025
adb6e71
feat: It is now at least backwards compatible. though the new stuff m…
elliott-with-the-longest-name-on-github Apr 29, 2025
92940ff
feat: It works I think?
elliott-with-the-longest-name-on-github Apr 29, 2025
ac42ad5
final cleanup??
elliott-with-the-longest-name-on-github Apr 29, 2025
b44eed9
tests
elliott-with-the-longest-name-on-github Apr 29, 2025
12a02b7
test for better types
elliott-with-the-longest-name-on-github Apr 29, 2025
4a19fd1
Merge branch 'main' into elliott/class-constructor-state
Rich-Harris May 15, 2025
50adbfb
changeset
Rich-Harris May 15, 2025
682b0e6
rename functions (the function doesn't test call-expression-ness)
Rich-Harris May 15, 2025
76b07e5
small readability tweak
Rich-Harris May 15, 2025
6395085
failing test
Rich-Harris May 15, 2025
0024e1e
fix
Rich-Harris May 15, 2025
8c7ad3c
disallow computed state fields
Rich-Harris May 15, 2025
15c7b14
tweak message to better accommodate the case in which state is declar…
Rich-Harris May 15, 2025
0ac22c1
failing test
Rich-Harris May 15, 2025
4edebbc
wildly confusing to have so many things called 'class analysis' - ren…
Rich-Harris May 15, 2025
1e0f423
missed a spot
Rich-Harris May 15, 2025
f81405c
and another
Rich-Harris May 15, 2025
41e8ade
store analysis for use during transformation
Rich-Harris May 15, 2025
1d1f0eb
move code to where it is used
Rich-Harris May 15, 2025
823e66f
do the analysis upfront, it's way simpler
Rich-Harris May 15, 2025
0dcd3cd
skip failing test for now
Rich-Harris May 15, 2025
7341f40
simplify
Rich-Harris May 15, 2025
75680a9
get rid of the class
Rich-Harris May 15, 2025
2ffb863
on second thoughts
Rich-Harris May 15, 2025
b1e095a
reduce indirection
Rich-Harris May 15, 2025
c407dc0
make analysis available at transform time
Rich-Harris May 15, 2025
2efb766
WIP
Rich-Harris May 16, 2025
0e9ca23
WIP
Rich-Harris May 16, 2025
b7bbae8
WIP
Rich-Harris May 16, 2025
737bfb5
fix
Rich-Harris May 16, 2025
c536ec6
remove unused stuff
Rich-Harris May 16, 2025
fbf1b4e
revert snapshot tests
Rich-Harris May 16, 2025
de015b0
unused
Rich-Harris May 16, 2025
4653f54
note to self
Rich-Harris May 16, 2025
23f269b
fix
Rich-Harris May 16, 2025
d1bb2c9
unused
Rich-Harris May 16, 2025
de77e69
unused
Rich-Harris May 16, 2025
dfb4e13
remove some unused stuff
Rich-Harris May 16, 2025
2556031
unused
Rich-Harris May 16, 2025
c7e8422
lint, tidy up
Rich-Harris May 16, 2025
1a78e27
reuse helper
Rich-Harris May 16, 2025
90e7e0d
tweak
Rich-Harris May 16, 2025
a6cc07c
simplify/DRY
Rich-Harris May 16, 2025
45115de
unused
Rich-Harris May 16, 2025
56bd834
tweak
Rich-Harris May 16, 2025
855f209
unused
Rich-Harris May 16, 2025
d31831b
more
Rich-Harris May 16, 2025
0cac3d2
tweak
Rich-Harris May 16, 2025
b1cc424
tweak
Rich-Harris May 16, 2025
bbf0191
fix proxying logic
Rich-Harris May 16, 2025
2b42182
tweak
Rich-Harris May 16, 2025
63e60c7
tweak
Rich-Harris May 16, 2025
c82ede5
adjust message to accommodate more cases
Rich-Harris May 19, 2025
d6c9859
unskip and fix test
Rich-Harris May 19, 2025
ffcabe6
fix
Rich-Harris May 19, 2025
01af3ae
move
Rich-Harris May 19, 2025
1f52cf0
revert unneeded drive-by change
Rich-Harris May 19, 2025
3bfcacc
fix
Rich-Harris May 19, 2025
ae7e5bb
fix
Rich-Harris May 19, 2025
670a7e1
update docs
Rich-Harris May 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update docs
  • Loading branch information
Rich-Harris committed May 19, 2025
commit 670a7e1de3ee971e3cf8c0e36cba05b51bb37f08
8 changes: 3 additions & 5 deletions documentation/docs/02-runes/02-$state.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ todos[0].done = !todos[0].done;

### Classes

You can also use `$state` in class fields (whether public or private):
You can also use `$state` in class fields (whether public or private), or as the first assignment to a property immediately inside the `constructor`:

```js
// @errors: 7006 2554
class Todo {
done = $state(false);
text = $state();

constructor(text) {
this.text = text;
this.text = $state(text);
}

reset() {
Expand Down Expand Up @@ -110,10 +109,9 @@ You can either use an inline function...
// @errors: 7006 2554
class Todo {
done = $state(false);
text = $state();

constructor(text) {
this.text = text;
this.text = $state(text);
}

+++reset = () => {+++
Expand Down