Skip to content

Commit cfa8546

Browse files
committed
refactor: rewrite compile add function
1 parent 780fa7d commit cfa8546

16 files changed

+3461
-3551
lines changed

src/compiler/__tests__/compiler.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
import { compile } from "../compiler";
22

3+
test("hello world", () => {
4+
const compiled = compile(`
5+
.my-class {
6+
color: red;
7+
}`);
8+
9+
expect(compiled).toStrictEqual({
10+
s: [
11+
[
12+
"my-class",
13+
[
14+
{
15+
d: [
16+
{
17+
color: "rgb(100% 0% 0%)",
18+
},
19+
],
20+
s: [1, 1],
21+
},
22+
],
23+
],
24+
],
25+
});
26+
});
27+
328
test("reads global CSS variables", () => {
429
const compiled = compile(`
530
@layer theme {

src/compiler/add.ts

Lines changed: 0 additions & 260 deletions
This file was deleted.

src/compiler/atRules.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import type {
44
Rule,
55
TokenOrValue,
66
} from "lightningcss";
7-
import type { CompilerCollection, StyleRuleMapping } from "./compiler.types";
7+
import type { StyleRuleMapping } from "./compiler.types";
88
import { splitByDelimiter } from "./split-by-delimiter";
99
import { toRNProperty } from "./selectors";
10+
import type { StylesheetBuilder } from "./stylesheet";
1011

1112
export interface PropAtRule {
1213
type: "unknown";
@@ -35,7 +36,7 @@ export interface ReactNativeAtRule {
3536

3637
export function maybeMutateReactNativeOptions(
3738
rule: Rule | ReactNativeAtRule,
38-
collection: CompilerCollection,
39+
builder: StylesheetBuilder,
3940
) {
4041
if (rule.type !== "custom" || rule.value?.name !== "react-native") {
4142
return;
@@ -53,7 +54,12 @@ export function maybeMutateReactNativeOptions(
5354
if (token.type !== "dashed-ident") {
5455
return;
5556
}
56-
collection.varUsageCount.set(token.value, 1);
57+
58+
if (token.value !== "true" && token.value !== "false") {
59+
return;
60+
}
61+
62+
builder.setOptions("preserveVariables", token.value === "true");
5763
});
5864
break;
5965
}

src/compiler/attributes.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { compile } from "../compiler";
2+
3+
test("multiple classes", () => {
4+
const compiled = compile(`
5+
.my-class.test {
6+
color: red;
7+
}`);
8+
9+
expect(compiled).toStrictEqual({
10+
s: [
11+
[
12+
"test",
13+
[
14+
{
15+
aq: [["a", "className", "*=", "my-class"]],
16+
d: [
17+
{
18+
color: "rgb(100% 0% 0%)",
19+
},
20+
],
21+
s: [1, 2],
22+
},
23+
],
24+
],
25+
],
26+
});
27+
});

0 commit comments

Comments
 (0)