File tree Expand file tree Collapse file tree 4 files changed +40
-3
lines changed
src/compiler/phases/2-analyze
tests/runtime-legacy/samples/reactive-value-assign-properties Expand file tree Collapse file tree 4 files changed +40
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: take into account member expressions when determining legacy reactive dependencies
Original file line number Diff line number Diff line change @@ -500,7 +500,15 @@ const legacy_scope_tweaker = {
500
500
node . body . type === 'ExpressionStatement' &&
501
501
node . body . expression . type === 'AssignmentExpression'
502
502
) {
503
- for ( const id of extract_identifiers ( node . body . expression . left ) ) {
503
+ let ids = extract_identifiers ( node . body . expression . left ) ;
504
+ if ( node . body . expression . left . type === 'MemberExpression' ) {
505
+ const id = object ( node . body . expression . left ) ;
506
+ if ( id !== null ) {
507
+ ids = [ id ] ;
508
+ }
509
+ }
510
+
511
+ for ( const id of ids ) {
504
512
const binding = state . scope . get ( id . name ) ;
505
513
if ( binding ?. kind === 'legacy_reactive' ) {
506
514
// TODO does this include `let double; $: double = x * 2`?
@@ -511,8 +519,15 @@ const legacy_scope_tweaker = {
511
519
} ,
512
520
AssignmentExpression ( node , { state, next } ) {
513
521
if ( state . reactive_statement && node . operator === '=' ) {
514
- for ( const id of extract_identifiers ( node . left ) ) {
515
- state . reactive_statement . assignments . add ( id ) ;
522
+ if ( node . left . type === 'MemberExpression' ) {
523
+ const id = object ( node . left ) ;
524
+ if ( id !== null ) {
525
+ state . reactive_statement . assignments . add ( id ) ;
526
+ }
527
+ } else {
528
+ for ( const id of extract_identifiers ( node . left ) ) {
529
+ state . reactive_statement . assignments . add ( id ) ;
530
+ }
516
531
}
517
532
}
518
533
Original file line number Diff line number Diff line change
1
+ import { test } from '../../test' ;
2
+
3
+ export default test ( {
4
+ html : `1 1`
5
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let button = { title: ' ' , label: ' ' };
3
+ let title = ' ' ;
4
+ let label = ' ' ;
5
+
6
+ title = label = ' 1' ; // to add dependencies/generate update block
7
+
8
+ $: button .title = title;
9
+ $: button .label = label;
10
+ </script >
11
+
12
+ {button .title } {button .label }
You can’t perform that action at this time.
0 commit comments