Skip to content

Commit 76d94c7

Browse files
marklawlorCopilot
andauthored
feat: run two passes for lightningcss to improve output (#164)
* feat: optimize CSS with a pre-pass in lightningcss * Update src/compiler/compiler.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 95e11b9 commit 76d94c7

File tree

14 files changed

+98
-434
lines changed

14 files changed

+98
-434
lines changed

src/__tests__/compiler/compiler.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,27 @@ test("warnings", () => {
381381
},
382382
});
383383
});
384+
385+
test("simplifies rem", () => {
386+
const compiled = compile(`.test {
387+
border-width: calc(10rem + 2px);
388+
}`);
389+
390+
expect(compiled.stylesheet()).toStrictEqual({
391+
s: [
392+
[
393+
"test",
394+
[
395+
{
396+
d: [
397+
{
398+
borderWidth: 142,
399+
},
400+
],
401+
s: [1, 1],
402+
},
403+
],
404+
],
405+
],
406+
});
407+
});

src/__tests__/native/calc.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,6 @@ test("infinity", () => {
201201

202202
expect(component.type).toBe("View");
203203
expect(component.props.style).toStrictEqual({
204-
borderRadius: 9999,
204+
borderRadius: 9007199254740990,
205205
});
206206
});

src/__tests__/vendor/tailwind.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ test("line-clamp", () => {
330330
[
331331
{
332332
d: [
333+
[1, ["numberOfLines"]],
333334
{
334335
overflow: "hidden",
335336
},
336-
[1, ["numberOfLines"]],
337337
],
338338
s: [1, 1],
339339
},

src/__tests__/vendor/tailwind/_tailwind.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export async function render(
8686
console.log(`Output CSS:\n---\n${output}\n---\n`);
8787
}
8888

89-
const compiled = registerCSS(output, { debug: false });
89+
const compiled = registerCSS(output, { debug: Boolean(debug) });
9090

9191
if (debug) {
9292
console.log(

src/__tests__/vendor/tailwind/backgrounds.test.tsx

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,6 @@ describe("Backgrounds - Background Image", () => {
209209
"linear-gradient(to top in oklab, #fb2c36 0%, #2b7fff 100%)",
210210
},
211211
},
212-
warnings: {
213-
values: {
214-
"background-image": ["initial", "initial", "initial"],
215-
},
216-
},
217212
});
218213
});
219214
test("bg-gradient-to-tr", async () => {
@@ -228,11 +223,6 @@ describe("Backgrounds - Background Image", () => {
228223
"linear-gradient(to top right in oklab, #fb2c36 0%, #2b7fff 100%)",
229224
},
230225
},
231-
warnings: {
232-
values: {
233-
"background-image": ["initial", "initial", "initial"],
234-
},
235-
},
236226
});
237227
});
238228
test("bg-gradient-to-r", async () => {
@@ -247,11 +237,6 @@ describe("Backgrounds - Background Image", () => {
247237
"linear-gradient(to right in oklab, #fb2c36 0%, #2b7fff 100%)",
248238
},
249239
},
250-
warnings: {
251-
values: {
252-
"background-image": ["initial", "initial", "initial"],
253-
},
254-
},
255240
});
256241
});
257242
test("bg-gradient-to-br", async () => {
@@ -266,11 +251,6 @@ describe("Backgrounds - Background Image", () => {
266251
"linear-gradient(to bottom right in oklab, #fb2c36 0%, #2b7fff 100%)",
267252
},
268253
},
269-
warnings: {
270-
values: {
271-
"background-image": ["initial", "initial", "initial"],
272-
},
273-
},
274254
});
275255
});
276256
test("bg-gradient-to-b", async () => {
@@ -285,11 +265,6 @@ describe("Backgrounds - Background Image", () => {
285265
"linear-gradient(to bottom in oklab, #fb2c36 0%, #2b7fff 100%)",
286266
},
287267
},
288-
warnings: {
289-
values: {
290-
"background-image": ["initial", "initial", "initial"],
291-
},
292-
},
293268
});
294269
});
295270
test("bg-gradient-to-bl", async () => {
@@ -304,11 +279,6 @@ describe("Backgrounds - Background Image", () => {
304279
"linear-gradient(to bottom left in oklab, #fb2c36 0%, #2b7fff 100%)",
305280
},
306281
},
307-
warnings: {
308-
values: {
309-
"background-image": ["initial", "initial", "initial"],
310-
},
311-
},
312282
});
313283
});
314284
test("bg-gradient-to-l", async () => {
@@ -323,11 +293,6 @@ describe("Backgrounds - Background Image", () => {
323293
"linear-gradient(to left in oklab, #fb2c36 0%, #2b7fff 100%)",
324294
},
325295
},
326-
warnings: {
327-
values: {
328-
"background-image": ["initial", "initial", "initial"],
329-
},
330-
},
331296
});
332297
});
333298
test("bg-gradient-to-tl", async () => {
@@ -342,11 +307,6 @@ describe("Backgrounds - Background Image", () => {
342307
"linear-gradient(to top left in oklab, #fb2c36 0%, #2b7fff 100%)",
343308
},
344309
},
345-
warnings: {
346-
values: {
347-
"background-image": ["initial", "initial", "initial"],
348-
},
349-
},
350310
});
351311
});
352312
});

src/__tests__/vendor/tailwind/borders.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("Border - Border Radius", () => {
2020
});
2121
test("rounded-full", async () => {
2222
expect(await renderCurrentTest()).toStrictEqual({
23-
props: { style: { borderRadius: 9999 } },
23+
props: { style: { borderRadius: 9007199254740990 } },
2424
});
2525
});
2626
});

src/__tests__/vendor/tailwind/effects.test.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ describe("Effects - Box Shadow", () => {
2727
],
2828
},
2929
},
30-
warnings: {
31-
values: {
32-
"box-shadow": ["initial", "initial", "initial", "initial", "initial"],
33-
},
34-
},
3530
});
3631
});
3732

@@ -57,11 +52,6 @@ describe("Effects - Box Shadow", () => {
5752
],
5853
},
5954
},
60-
warnings: {
61-
values: {
62-
"box-shadow": ["initial", "initial", "initial", "initial", "initial"],
63-
},
64-
},
6555
});
6656
});
6757
test("shadow-none", async () => {
@@ -71,11 +61,6 @@ describe("Effects - Box Shadow", () => {
7161
boxShadow: [],
7262
},
7363
},
74-
warnings: {
75-
values: {
76-
"box-shadow": ["initial", "initial", "initial", "initial", "initial"],
77-
},
78-
},
7964
});
8065
});
8166
});

0 commit comments

Comments
 (0)