File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
src/compiler/phases/2-analyze/visitors
tests/validator/samples/static-state-reference Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,8 @@ export function Identifier(node, context) {
114114 binding . initial . arguments [ 0 ] . type !== 'SpreadElement' &&
115115 ! should_proxy ( binding . initial . arguments [ 0 ] , context . state . scope ) ) ) ) ||
116116 binding . kind === 'raw_state' ||
117- binding . kind === 'derived' ) &&
117+ binding . kind === 'derived' ||
118+ binding . kind === 'prop' ) &&
118119 // We're only concerned with reads here
119120 ( parent . type !== 'AssignmentExpression' || parent . left !== node ) &&
120121 parent . type !== 'UpdateExpression'
Original file line number Diff line number Diff line change 88 console .log (count );
99 console .log (doubled );
1010
11+ let {
12+ prop
13+ } = $props ();
14+ let prop_state = $state (prop );
15+ let prop_derived = $derived (prop );
16+ console .log (prop );
17+ console .log (prop_derived );
18+
1119 // writes are okay
1220 count ++ ;
1321 count = 1 ;
1422 obj .a ++ ;
1523 obj .a = 1 ;
24+ prop_state = 1 ;
25+ prop_derived = 1 ;
1626
1727 // `count` here is correctly identified as a non-reference
1828 let typed: { count: number } | null = null ;
Original file line number Diff line number Diff line change 3434 "column" : 20 ,
3535 "line" : 9
3636 }
37+ },
38+ {
39+ "code" : " state_referenced_locally" ,
40+ "end" : {
41+ "column" : 29 ,
42+ "line" : 14
43+ },
44+ "message" : " This reference only captures the initial value of `prop`. Did you mean to reference it inside a closure instead?" ,
45+ "start" : {
46+ "column" : 25 ,
47+ "line" : 14
48+ }
49+ },
50+ {
51+ "code" : " state_referenced_locally" ,
52+ "end" : {
53+ "column" : 17 ,
54+ "line" : 16
55+ },
56+ "message" : " This reference only captures the initial value of `prop`. Did you mean to reference it inside a closure instead?" ,
57+ "start" : {
58+ "column" : 13 ,
59+ "line" : 16
60+ }
61+ },
62+ {
63+ "code" : " state_referenced_locally" ,
64+ "end" : {
65+ "column" : 25 ,
66+ "line" : 17
67+ },
68+ "message" : " This reference only captures the initial value of `prop_derived`. Did you mean to reference it inside a closure instead?" ,
69+ "start" : {
70+ "column" : 13 ,
71+ "line" : 17
72+ }
3773 }
3874]
You can’t perform that action at this time.
0 commit comments