File tree Expand file tree Collapse file tree 4 files changed +63
-0
lines changed
src/compiler/phases/2-analyze
tests/runtime-legacy/samples/inline-style-directive-shorthand-declaration-only Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " svelte " : patch
3
+ ---
4
+
5
+ fix: detect style shorthands as stateful variables in legacy mode
Original file line number Diff line number Diff line change @@ -870,6 +870,16 @@ const legacy_scope_tweaker = {
870
870
}
871
871
}
872
872
}
873
+ } ,
874
+ StyleDirective ( node , { state } ) {
875
+ // the case for node.value different from true is already covered by the Identifier visitor
876
+ if ( node . value === true ) {
877
+ // get the binding for node.name and change the binding to state
878
+ let binding = state . scope . get ( node . name ) ;
879
+ if ( binding ?. mutated && binding . kind === 'normal' ) {
880
+ binding . kind = 'state' ;
881
+ }
882
+ }
873
883
}
874
884
} ;
875
885
Original file line number Diff line number Diff line change
1
+ import { test } from '../../test' ;
2
+
3
+ export default test ( {
4
+ html : `
5
+ <p style="color: red;"></p>
6
+ <p style="color: red;"></p>
7
+ <button></button>
8
+ ` ,
9
+
10
+ async test ( { assert, target, window } ) {
11
+ const [ p1 , p2 ] = target . querySelectorAll ( 'p' ) ;
12
+
13
+ assert . equal ( window . getComputedStyle ( p1 ) . color , 'red' ) ;
14
+ assert . equal ( window . getComputedStyle ( p2 ) . color , 'red' ) ;
15
+
16
+ const btn = target . querySelector ( 'button' ) ;
17
+ console . log ( btn ) ;
18
+ btn ?. click ( ) ;
19
+ await Promise . resolve ( ) ;
20
+
21
+ assert . htmlEqual (
22
+ target . innerHTML ,
23
+ `
24
+ <p style="color: green;"></p>
25
+ <p style="color: green;"></p>
26
+ <button></button>
27
+ `
28
+ ) ;
29
+
30
+ assert . equal ( window . getComputedStyle ( p1 ) . color , 'green' ) ;
31
+ assert . equal ( window . getComputedStyle ( p2 ) . color , 'green' ) ;
32
+ }
33
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let color = " red" ;
3
+
4
+ function change (){
5
+ color = " green" ;
6
+ }
7
+ </script >
8
+
9
+ <p style:color ></p >
10
+
11
+ {#each [1 ] as _ }
12
+ <p style:color ></p >
13
+ {/each }
14
+
15
+ <button on:click ={change }></button >
You can’t perform that action at this time.
0 commit comments