@@ -4,57 +4,70 @@ const script = "<script>let color = 'blue';</script>";
44
55describe ( 'Bind variable to CSS' , ( ) => {
66 test ( 'root elements' , async ( ) => {
7- const output = await compiler ( {
8- source : `${ script } <div>blue</div><div>red</div><style module>div{color:bind(color)}</style>` ,
9- } , {
10- cssVariableHash : '123' ,
11- } ) ;
7+ const output = await compiler (
8+ {
9+ source : `${ script } <div>blue</div><div>red</div><style module>div{color:bind(color)}</style>` ,
10+ } ,
11+ {
12+ cssVariableHash : '123' ,
13+ }
14+ ) ;
1215
1316 expect ( output ) . toBe (
1417 `${ script } <div style="--color-123:{color};">blue</div><div style="--color-123:{color};">red</div><style module>:global(div){color:var(--color-123)}</style>`
1518 ) ;
1619 } ) ;
1720
1821 test ( 'root element with attributes' , async ( ) => {
19- const output = await compiler ( {
20- source : `${ script } <div class="blue">blue</div><style module>.blue{color:bind(color)}</style>` ,
21- } , {
22- cssVariableHash : '123' ,
23- localIdentName : '[local]-123' ,
24- } ) ;
22+ const output = await compiler (
23+ {
24+ source : `${ script } <div class="blue">blue</div><style module>.blue{color:bind(color)}</style>` ,
25+ } ,
26+ {
27+ cssVariableHash : '123' ,
28+ localIdentName : '[local]-123' ,
29+ }
30+ ) ;
2531
2632 expect ( output ) . toBe (
2733 `${ script } <div class="blue-123" style="--color-123:{color};">blue</div><style module>:global(.blue-123){color:var(--color-123)}</style>`
2834 ) ;
2935 } ) ;
3036
3137 test ( 'root element with style attribute' , async ( ) => {
32- const output = await compiler ( {
33- source : `${ script } <div style="display:block">blue</div><style module>div{color:bind(color)}</style>` ,
34- } , {
35- cssVariableHash : '123' ,
36- } ) ;
38+ const output = await compiler (
39+ {
40+ source : `${ script } <div style="display:block">blue</div><style module>div{color:bind(color)}</style>` ,
41+ } ,
42+ {
43+ cssVariableHash : '123' ,
44+ }
45+ ) ;
3746
3847 expect ( output ) . toBe (
3948 `${ script } <div style="--color-123:{color};display:block">blue</div><style module>:global(div){color:var(--color-123)}</style>`
4049 ) ;
4150 } ) ;
4251
4352 test ( 'element wrapped by a root component' , async ( ) => {
44- const output = await compiler ( {
45- source : `${ script } <Component><div>blue</div></Component><style module>div{color:bind(color)}</style>` ,
46- } , {
47- cssVariableHash : '123' ,
48- } ) ;
53+ const output = await compiler (
54+ {
55+ source : `${ script } <Component><div>blue</div></Component><style module>div{color:bind(color)}</style>` ,
56+ } ,
57+ {
58+ cssVariableHash : '123' ,
59+ }
60+ ) ;
4961
5062 expect ( output ) . toBe (
5163 `${ script } <Component><div style="--color-123:{color};">blue</div></Component><style module>:global(div){color:var(--color-123)}</style>`
5264 ) ;
5365 } ) ;
5466
5567 test ( 'deep nested element in components' , async ( ) => {
56- const output = await compiler ( {
57- source : `${ script }
68+ const output = await compiler (
69+ {
70+ source : `${ script }
5871 <Component1><Component2><Component3><div>blue</div></Component3></Component2></Component1>
5972 <Component2>
6073 <div>blue</div>
@@ -66,10 +79,12 @@ describe('Bind variable to CSS', () => {
6679 </Component2>
6780 <div>yellow <Component1><i>blue</i></Component1></div>
6881 <style module>div{color:bind('color')}</style>` ,
69- } , {
70- cssVariableHash : '123' ,
71- mode : 'scoped' ,
72- } ) ;
82+ } ,
83+ {
84+ cssVariableHash : '123' ,
85+ mode : 'scoped' ,
86+ }
87+ ) ;
7388
7489 expect ( output ) . toBe (
7590 `${ script }
@@ -88,19 +103,22 @@ describe('Bind variable to CSS', () => {
88103 } ) ;
89104
90105 test ( 'root elements bound with js expression' , async ( ) => {
91- const output = await compiler ( {
92- source : `<script>let style = { display: 'none', margin: { top: '20px' } };</script>
106+ const output = await compiler (
107+ {
108+ source : `<script>let style = { display: 'none', margin: { top: '20px' } };</script>
93109 <div>black</div>
94110 <style module>
95111 div{
96112 margin-top:bind('style.margin.top');
97113 display:bind("style.display");
98114 }
99115 </style>` ,
100- } , {
101- cssVariableHash : '123' ,
102- mode : 'scoped' ,
103- } ) ;
116+ } ,
117+ {
118+ cssVariableHash : '123' ,
119+ mode : 'scoped' ,
120+ }
121+ ) ;
104122
105123 expect ( output ) . toBe (
106124 `<script>let style = { display: 'none', margin: { top: '20px' } };</script>
@@ -115,90 +133,106 @@ describe('Bind variable to CSS', () => {
115133 } ) ;
116134
117135 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- } ) ;
136+ const output = await compiler (
137+ {
138+ source :
139+ `${ script } ` +
140+ `{#if color === 'blue'}<div>blue</div>` +
141+ `{:else if color === 'red'}<div>red</div>` +
142+ `{:else}<div>none</div>` +
143+ `{/if}<style module>div{color:bind(color)}</style>` ,
144+ } ,
145+ {
146+ cssVariableHash : '123' ,
147+ }
148+ ) ;
127149
128150 expect ( output ) . toBe (
129151 `${ 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>`
152+ `{#if color === 'blue'}<div style="--color-123:{color};">blue</div>` +
153+ `{:else if color === 'red'}<div style="--color-123:{color};">red</div>` +
154+ `{:else}<div style="--color-123:{color};">none</div>` +
155+ `{/if}<style module>:global(div){color:var(--color-123)}</style>`
134156 ) ;
135157 } ) ;
136158
137159 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- } ) ;
160+ const output = await compiler (
161+ {
162+ source :
163+ `${ script } ` +
164+ `{#each [0,1,2,3] as number}` +
165+ `<div>{number}</div>` +
166+ `{/each}<style module>div{color:bind(color)}</style>` ,
167+ } ,
168+ {
169+ cssVariableHash : '123' ,
170+ }
171+ ) ;
146172
147173 expect ( output ) . toBe (
148174 `${ 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>`
175+ `{#each [0,1,2,3] as number}` +
176+ `<div style="--color-123:{color};">{number}</div>` +
177+ `{/each}<style module>:global(div){color:var(--color-123)}</style>`
152178 ) ;
153179 } ) ;
154180
155181 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- } ) ;
182+ const output = await compiler (
183+ {
184+ source :
185+ `${ script } ` +
186+ `{#await promise}` +
187+ `<p>...waiting</p>` +
188+ `{:then number}` +
189+ `<p>The number is {number}</p>` +
190+ `{:catch error}` +
191+ `<p>{error.message}</p>` +
192+ `{/await}` +
193+ `{#await promise then value}` +
194+ `<p>the value is {value}</p>` +
195+ `{/await}<style module>div{color:bind(color)}</style>` ,
196+ } ,
197+ {
198+ cssVariableHash : '123' ,
199+ }
200+ ) ;
171201
172202 expect ( output ) . toBe (
173203 `${ 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>`
204+ `{#await promise}` +
205+ `<p style="--color-123:{color};">...waiting</p>` +
206+ `{:then number}` +
207+ `<p style="--color-123:{color};">The number is {number}</p>` +
208+ `{:catch error}` +
209+ `<p style="--color-123:{color};">{error.message}</p>` +
210+ `{/await}` +
211+ `{#await promise then value}` +
212+ `<p style="--color-123:{color};">the value is {value}</p>` +
213+ `{/await}<style module>:global(div){color:var(--color-123)}</style>`
184214 ) ;
185215 } ) ;
186216
187217 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- } ) ;
218+ const output = await compiler (
219+ {
220+ source :
221+ `${ script } ` +
222+ `{#key value}` +
223+ `<div transition:fade>{value}</div>` +
224+ `{/key}<style module>div{color:bind(color)}</style>` ,
225+ } ,
226+ {
227+ cssVariableHash : '123' ,
228+ }
229+ ) ;
196230
197231 expect ( output ) . toBe (
198232 `${ 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>`
233+ `{#key value}` +
234+ `<div transition:fade style="--color-123:{color};">{value}</div>` +
235+ `{/key}<style module>:global(div){color:var(--color-123)}</style>`
202236 ) ;
203237 } ) ;
204238} ) ;
0 commit comments