@@ -113,4 +113,92 @@ describe('Bind variable to CSS', () => {
113
113
</style>`
114
114
) ;
115
115
} ) ;
116
+
117
+ test ( 'root elements has if statement' , async ( ) => {
118
+ const output = await compiler ( {
119
+ source : `${ script } ` +
120
+ `{#if color === 'blue'}<div>blue</div>` +
121
+ `{:else if color === 'red'}<div>red</div>` +
122
+ `{:else}<div>none</div>` +
123
+ `{/if}<style module>div{color:bind(color)}</style>` ,
124
+ } , {
125
+ cssVariableHash : '123' ,
126
+ } ) ;
127
+
128
+ expect ( output ) . toBe (
129
+ `${ script } ` +
130
+ `{#if color === 'blue'}<div style="--color-123:{color};">blue</div>` +
131
+ `{:else if color === 'red'}<div style="--color-123:{color};">red</div>` +
132
+ `{:else}<div style="--color-123:{color};">none</div>` +
133
+ `{/if}<style module>:global(div){color:var(--color-123)}</style>`
134
+ ) ;
135
+ } ) ;
136
+
137
+ test ( 'root elements has `each` statement' , async ( ) => {
138
+ const output = await compiler ( {
139
+ source : `${ script } ` +
140
+ `{#each [0,1,2,3] as number}` +
141
+ `<div>{number}</div>` +
142
+ `{/each}<style module>div{color:bind(color)}</style>` ,
143
+ } , {
144
+ cssVariableHash : '123' ,
145
+ } ) ;
146
+
147
+ expect ( output ) . toBe (
148
+ `${ script } ` +
149
+ `{#each [0,1,2,3] as number}` +
150
+ `<div style="--color-123:{color};">{number}</div>` +
151
+ `{/each}<style module>:global(div){color:var(--color-123)}</style>`
152
+ ) ;
153
+ } ) ;
154
+
155
+ test ( 'root element has `each` statement' , async ( ) => {
156
+ const output = await compiler ( {
157
+ source : `${ script } ` +
158
+ `{#await promise}` +
159
+ `<p>...waiting</p>` +
160
+ `{:then number}` +
161
+ `<p>The number is {number}</p>` +
162
+ `{:catch error}` +
163
+ `<p>{error.message}</p>` +
164
+ `{/await}` +
165
+ `{#await promise then value}` +
166
+ `<p>the value is {value}</p>` +
167
+ `{/await}<style module>div{color:bind(color)}</style>` ,
168
+ } , {
169
+ cssVariableHash : '123' ,
170
+ } ) ;
171
+
172
+ expect ( output ) . toBe (
173
+ `${ script } ` +
174
+ `{#await promise}` +
175
+ `<p style="--color-123:{color};">...waiting</p>` +
176
+ `{:then number}` +
177
+ `<p style="--color-123:{color};">The number is {number}</p>` +
178
+ `{:catch error}` +
179
+ `<p style="--color-123:{color};">{error.message}</p>` +
180
+ `{/await}` +
181
+ `{#await promise then value}` +
182
+ `<p style="--color-123:{color};">the value is {value}</p>` +
183
+ `{/await}<style module>:global(div){color:var(--color-123)}</style>`
184
+ ) ;
185
+ } ) ;
186
+
187
+ test ( 'root element has `key` statement' , async ( ) => {
188
+ const output = await compiler ( {
189
+ source : `${ script } ` +
190
+ `{#key value}` +
191
+ `<div transition:fade>{value}</div>` +
192
+ `{/key}<style module>div{color:bind(color)}</style>` ,
193
+ } , {
194
+ cssVariableHash : '123' ,
195
+ } ) ;
196
+
197
+ expect ( output ) . toBe (
198
+ `${ script } ` +
199
+ `{#key value}` +
200
+ `<div transition:fade style="--color-123:{color};">{value}</div>` +
201
+ `{/key}<style module>:global(div){color:var(--color-123)}</style>`
202
+ ) ;
203
+ } ) ;
116
204
} ) ;
0 commit comments