File tree 3 files changed +77
-1
lines changed
src/compiler/compile/nodes/shared
test/runtime/samples/const-tag-each-arrow 3 files changed +77
-1
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,15 @@ export default class Expression {
253
253
254
254
const declaration = b `const ${ id } = ${ node } ` ;
255
255
256
- if ( dependencies . size === 0 && contextual_dependencies . size === 0 ) {
256
+ if ( owner . type === 'ConstTag' ) {
257
+ walk ( node , {
258
+ enter ( node : Node ) {
259
+ if ( node . type === 'Identifier' ) {
260
+ this . replace ( block . renderer . reference ( node , ctx ) ) ;
261
+ }
262
+ }
263
+ } ) ;
264
+ } else if ( dependencies . size === 0 && contextual_dependencies . size === 0 ) {
257
265
// we can hoist this out of the component completely
258
266
component . fully_hoisted . push ( declaration ) ;
259
267
Original file line number Diff line number Diff line change
1
+ export default {
2
+ html : `
3
+ <p>#FF0000</p>
4
+ <p>#00FF00</p>
5
+ <p>#0000FF</p>
6
+ ` ,
7
+ async test ( { component, target, assert } ) {
8
+ component . constant = 20 ;
9
+
10
+ assert . htmlEqual ( target . innerHTML , `
11
+ <p>#FF0000</p>
12
+ <p>#00FF00</p>
13
+ <p>#0000FF</p>
14
+ ` ) ;
15
+
16
+ component . tags = [
17
+ {
18
+ name : 'Red' ,
19
+ color : '#FF0000'
20
+ } ,
21
+ {
22
+ name : 'Green' ,
23
+ color : '#00FF00'
24
+ } ,
25
+ {
26
+ name : 'Blue' ,
27
+ color : '#0000FF'
28
+ } ,
29
+ {
30
+ name : 'Black' ,
31
+ color : '#000000'
32
+ } ,
33
+ {
34
+ name : 'White' ,
35
+ color : '#FFFFFF'
36
+ }
37
+ ] ;
38
+
39
+ assert . htmlEqual ( target . innerHTML , `
40
+ <p>#FF0000</p>
41
+ <p>#00FF00</p>
42
+ <p>#0000FF</p>
43
+ <p>#000000</p>
44
+ <p>#FFFFFF</p>
45
+ ` ) ;
46
+ }
47
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let tags = [
3
+ {
4
+ name: ' Red' ,
5
+ color: ' #FF0000'
6
+ },
7
+ {
8
+ name: ' Green' ,
9
+ color: ' #00FF00'
10
+ },
11
+ {
12
+ name: ' Blue' ,
13
+ color: ' #0000FF'
14
+ }
15
+ ];
16
+ </script >
17
+
18
+ {#each tags as tag }
19
+ {@const tagColor = tags .find (t => t .name === tag .name ).color }
20
+ <p >{tagColor }</p >
21
+ {/each }
You can’t perform that action at this time.
0 commit comments