Skip to content

Commit 75013b1

Browse files
committed
fix: use const instead of var for css variable declaration
1 parent 7762909 commit 75013b1

File tree

4 files changed

+60
-59
lines changed

4 files changed

+60
-59
lines changed

src/utils/processRenderResponse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ export const processRenderResponse = (
9292
const codeOutput: string[] = [
9393
...imports,
9494

95-
`var ${variableName} = ${defaultExport};`,
96-
`export default ${cssModules ? JSON.stringify(cssModules) : variableName};`,
95+
`const ${variableName} = ${defaultExport}`,
96+
`export default ${cssModules ? JSON.stringify(cssModules) : variableName}`,
9797

9898
...Object.entries(namedExports).map(
99-
([n, v]) => `export const ${n} = ${JSON.stringify(v)};`,
99+
([n, v]) => `export const ${n} = ${JSON.stringify(v)}`,
100100
),
101101
];
102102

103-
return codeOutput.join('\n');
103+
return codeOutput.join(';\n');
104104
})
105105
); // @note do not `catch` here - let error propagate to rollup level
106106
};

test/index.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ const createApiOptionTestCaseTitle: TitleFn<[RollupPluginSassOptions]> = (
713713
test(title, macro, TEST_PLUGIN_OPTIONS_DEFAULT_MODERN);
714714
}
715715

716+
// #region processor and cssModules option
716717
{
717718
const postcssModulesProcessor: RollupPluginSassProcessorFn = async (
718719
styles,
@@ -725,9 +726,7 @@ const createApiOptionTestCaseTitle: TitleFn<[RollupPluginSassOptions]> = (
725726
if (json) cssModules = json;
726727
},
727728
}),
728-
]).process(styles, {
729-
from: id,
730-
});
729+
]).process(styles, { from: id });
731730

732731
return { css: postcssProcessResult.css, cssModules };
733732
};
@@ -839,6 +838,8 @@ const createApiOptionTestCaseTitle: TitleFn<[RollupPluginSassOptions]> = (
839838
test(title, macro, TEST_PLUGIN_OPTIONS_DEFAULT_MODERN);
840839
}
841840
}
841+
// #endregion processor and cssModules option
842+
842843
// #endregion processor option
843844

844845
// #region node resolution

test/snapshots/test/index.test.ts.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Generated by [AVA](https://avajs.dev).
88

99
> Snapshot 1
1010
11-
`var actual_a = "body {\\n color: red;\\n}";␊
11+
`const actual_a = "body {\\n color: red;\\n}";␊
1212
13-
var actual_b = "body {\\n color: green;\\n}";␊
13+
const actual_b = "body {\\n color: green;\\n}";␊
1414
15-
var actual_c = "body {\\n color: blue;\\n}";␊
15+
const actual_c = "body {\\n color: blue;\\n}";␊
1616
1717
var index = actual_a + actual_b + actual_c;␊
1818
@@ -23,11 +23,11 @@ Generated by [AVA](https://avajs.dev).
2323

2424
> Snapshot 1
2525
26-
`var actual_a = "body {\\n color: red;\\n}";␊
26+
`const actual_a = "body {\\n color: red;\\n}";␊
2727
28-
var actual_b = "body {\\n color: green;\\n}";␊
28+
const actual_b = "body {\\n color: green;\\n}";␊
2929
30-
var actual_c = "body {\\n color: blue;\\n}";␊
30+
const actual_c = "body {\\n color: blue;\\n}";␊
3131
3232
var index = actual_a + actual_b + actual_c;␊
3333
@@ -38,11 +38,11 @@ Generated by [AVA](https://avajs.dev).
3838

3939
> Snapshot 1
4040
41-
`var actual_a = "body{color:red}";␊
41+
`const actual_a = "body{color:red}";␊
4242
43-
var actual_b = "body{color:green}";␊
43+
const actual_b = "body{color:green}";␊
4444
45-
var actual_c = "body{color:blue}";␊
45+
const actual_c = "body{color:blue}";␊
4646
4747
var index = actual_a + actual_b + actual_c;␊
4848
@@ -53,11 +53,11 @@ Generated by [AVA](https://avajs.dev).
5353

5454
> Snapshot 1
5555
56-
`var actual_a = "body{color:red}";␊
56+
`const actual_a = "body{color:red}";␊
5757
58-
var actual_b = "body{color:green}";␊
58+
const actual_b = "body{color:green}";␊
5959
60-
var actual_c = "body{color:blue}";␊
60+
const actual_c = "body{color:blue}";␊
6161
6262
var index = actual_a + actual_b + actual_c;␊
6363
@@ -68,7 +68,7 @@ Generated by [AVA](https://avajs.dev).
6868

6969
> Snapshot 1
7070
71-
`var actual_d = "body{color:red;background-color:green}";␊
71+
`const actual_d = "body{color:red;background-color:green}";␊
7272
7373
export { actual_d as default };␊
7474
`
@@ -77,7 +77,7 @@ Generated by [AVA](https://avajs.dev).
7777

7878
> Snapshot 1
7979
80-
`var actual_d = "body{color:red;background-color:green}";␊
80+
`const actual_d = "body{color:red;background-color:green}";␊
8181
8282
export { actual_d as default };␊
8383
`
@@ -86,7 +86,7 @@ Generated by [AVA](https://avajs.dev).
8686

8787
> Snapshot 1
8888
89-
`var style = "body{color:red}";␊
89+
`const style = "body{color:red}";␊
9090
9191
export { style as default };␊
9292
`
@@ -95,7 +95,7 @@ Generated by [AVA](https://avajs.dev).
9595

9696
> Snapshot 1
9797
98-
`var style = "body{color:red}";␊
98+
`const style = "body{color:red}";␊
9999
100100
export { style as default };␊
101101
`
@@ -104,7 +104,7 @@ Generated by [AVA](https://avajs.dev).
104104

105105
> Snapshot 1
106106
107-
`var actual_e = "body{color:red}";␊
107+
`const actual_e = "body{color:red}";␊
108108
109109
export { actual_e as default };␊
110110
`
@@ -113,7 +113,7 @@ Generated by [AVA](https://avajs.dev).
113113

114114
> Snapshot 1
115115
116-
`var actual_e = "body{color:red}";␊
116+
`const actual_e = "body{color:red}";␊
117117
118118
export { actual_e as default };␊
119119
`
@@ -142,9 +142,9 @@ Generated by [AVA](https://avajs.dev).
142142

143143
> Snapshot 1
144144
145-
`var actual_a = "}der:roloc{ydob";␊
145+
`const actual_a = "}der:roloc{ydob";␊
146146
147-
var actual_b = "}neerg:roloc{ydob";␊
147+
const actual_b = "}neerg:roloc{ydob";␊
148148
149149
var index = actual_a + actual_b;␊
150150
@@ -155,9 +155,9 @@ Generated by [AVA](https://avajs.dev).
155155

156156
> Snapshot 1
157157
158-
`var actual_a = "}der:roloc{ydob";␊
158+
`const actual_a = "}der:roloc{ydob";␊
159159
160-
var actual_b = "}neerg:roloc{ydob";␊
160+
const actual_b = "}neerg:roloc{ydob";␊
161161
162162
var index = actual_a + actual_b;␊
163163
@@ -168,10 +168,10 @@ Generated by [AVA](https://avajs.dev).
168168

169169
> Snapshot 1
170170
171-
`var actual_a = "body{color:red}";␊
171+
`const actual_a = "body{color:red}";␊
172172
const foo = "foo";␊
173173
174-
var actual_b = "body{color:green}";␊
174+
const actual_b = "body{color:green}";␊
175175
const bar = "bar";␊
176176
177177
var index = actual_a + actual_b + foo + bar;␊
@@ -183,10 +183,10 @@ Generated by [AVA](https://avajs.dev).
183183

184184
> Snapshot 1
185185
186-
`var actual_a = "body{color:red}";␊
186+
`const actual_a = "body{color:red}";␊
187187
const foo = "foo";␊
188188
189-
var actual_b = "body{color:green}";␊
189+
const actual_b = "body{color:green}";␊
190190
const bar = "bar";␊
191191
192192
var index = actual_a + actual_b + foo + bar;␊
@@ -198,9 +198,9 @@ Generated by [AVA](https://avajs.dev).
198198

199199
> Snapshot 1
200200
201-
`var actual_a = "body{color:red}";␊
201+
`const actual_a = "body{color:red}";␊
202202
203-
var actual_b = "body{color:green}";␊
203+
const actual_b = "body{color:green}";␊
204204
205205
var index = actual_a + actual_b;␊
206206
@@ -211,9 +211,9 @@ Generated by [AVA](https://avajs.dev).
211211

212212
> Snapshot 1
213213
214-
`var actual_a = "body{color:red}";␊
214+
`const actual_a = "body{color:red}";␊
215215
216-
var actual_b = "body{color:green}";␊
216+
const actual_b = "body{color:green}";␊
217217
218218
var index = actual_a + actual_b;␊
219219
@@ -224,11 +224,11 @@ Generated by [AVA](https://avajs.dev).
224224

225225
> Snapshot 1
226226
227-
`var actual_a_WithIcssExports = "body{color:red;background:blue}";␊
227+
`const actual_a_WithIcssExports = "body{color:red;background:blue}";␊
228228
const color = "red";␊
229229
const color2 = "blue";␊
230230
231-
var actual_b = "body{color:green}";␊
231+
const actual_b = "body{color:green}";␊
232232
233233
var withIcssExports = actual_a_WithIcssExports + actual_b;␊
234234
@@ -239,11 +239,11 @@ Generated by [AVA](https://avajs.dev).
239239

240240
> Snapshot 1
241241
242-
`var actual_a_WithIcssExports = "body{color:red;background:blue}";␊
242+
`const actual_a_WithIcssExports = "body{color:red;background:blue}";␊
243243
const color = "red";␊
244244
const color2 = "blue";␊
245245
246-
var actual_b = "body{color:green}";␊
246+
const actual_b = "body{color:green}";␊
247247
248248
var withIcssExports = actual_a_WithIcssExports + actual_b;␊
249249
@@ -286,7 +286,7 @@ Generated by [AVA](https://avajs.dev).
286286

287287
> Snapshot 1
288288
289-
`var style = "body{color:red}body{color:green}body{color:blue}";␊
289+
`const style = "body{color:red}body{color:green}body{color:blue}";␊
290290
291291
export { style as default };␊
292292
`
@@ -295,7 +295,7 @@ Generated by [AVA](https://avajs.dev).
295295

296296
> Snapshot 1
297297
298-
`var style = "body{color:red}body{color:green}body{color:blue}";␊
298+
`const style = "body{color:red}body{color:green}body{color:blue}";␊
299299
300300
export { style as default };␊
301301
`
@@ -304,14 +304,14 @@ Generated by [AVA](https://avajs.dev).
304304

305305
> check output result code
306306
307-
`var style = "body{color:red}body{color:green}body{color:blue}";␊
307+
`const style = "body{color:red}body{color:green}body{color:blue}";␊
308308
309309
export { style as default };␊
310310
`
311311

312312
> Ensure content exist in ESM output file
313313
314-
`var style = "body{color:red}body{color:green}body{color:blue}";␊
314+
`const style = "body{color:red}body{color:green}body{color:blue}";␊
315315
316316
export { style as default };␊
317317
`
@@ -320,7 +320,7 @@ Generated by [AVA](https://avajs.dev).
320320
321321
`'use strict';␊
322322
323-
var style = "body{color:red}body{color:green}body{color:blue}";␊
323+
const style = "body{color:red}body{color:green}body{color:blue}";␊
324324
325325
module.exports = style;␊
326326
`
@@ -329,14 +329,14 @@ Generated by [AVA](https://avajs.dev).
329329

330330
> check output result code
331331
332-
`var style = "body{color:red}body{color:green}body{color:blue}";␊
332+
`const style = "body{color:red}body{color:green}body{color:blue}";␊
333333
334334
export { style as default };␊
335335
`
336336

337337
> Ensure content exist in ESM output file
338338
339-
`var style = "body{color:red}body{color:green}body{color:blue}";␊
339+
`const style = "body{color:red}body{color:green}body{color:blue}";␊
340340
341341
export { style as default };␊
342342
`
@@ -345,7 +345,7 @@ Generated by [AVA](https://avajs.dev).
345345
346346
`'use strict';␊
347347
348-
var style = "body{color:red}body{color:green}body{color:blue}";␊
348+
const style = "body{color:red}body{color:green}body{color:blue}";␊
349349
350350
module.exports = style;␊
351351
`
@@ -354,11 +354,11 @@ Generated by [AVA](https://avajs.dev).
354354

355355
> Snapshot 1
356356
357-
`var actual_a = "body{color:red}";␊
357+
`const actual_a = "body{color:red}";␊
358358
359-
var actual_b = "body{color:green}";␊
359+
const actual_b = "body{color:green}";␊
360360
361-
var actual_c = "body{color:blue}";␊
361+
const actual_c = "body{color:blue}";␊
362362
363363
var index = actual_a + actual_b + actual_c;␊
364364
@@ -369,11 +369,11 @@ Generated by [AVA](https://avajs.dev).
369369

370370
> Snapshot 1
371371
372-
`var actual_a = "body{color:red}";␊
372+
`const actual_a = "body{color:red}";␊
373373
374-
var actual_b = "body{color:green}";␊
374+
const actual_b = "body{color:green}";␊
375375
376-
var actual_c = "body{color:blue}";␊
376+
const actual_c = "body{color:blue}";␊
377377
378378
var index = actual_a + actual_b + actual_c;␊
379379
@@ -384,12 +384,12 @@ Generated by [AVA](https://avajs.dev).
384384

385385
> Final content output
386386
387-
`var style1 = "body{color:blue}body{color:#fff}body{color:red}";␊
388-
export default style1;`
387+
`const style1 = "body{color:blue}body{color:#fff}body{color:red}";␊
388+
export default style1`
389389

390390
## module stylesheets graph should be added to watch list using 'api' = 'modern'
391391

392392
> Final content output
393393
394-
`var style1 = "body{color:blue}body{color:#fff}body{color:red}";␊
395-
export default style1;`
394+
`const style1 = "body{color:blue}body{color:#fff}body{color:red}";␊
395+
export default style1`
5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)