Skip to content

Commit 1f20661

Browse files
committed
refactor: fix tests
1 parent db35815 commit 1f20661

File tree

12 files changed

+147
-64
lines changed

12 files changed

+147
-64
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @see https://prettier.io/docs/en/configuration.html
3+
* @type {import("prettier").Config}
4+
*/
5+
const config = {};
6+
7+
export default config;

src/__tests__/babel/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../../tsconfig.json",
3+
"include": [
4+
"./*"
5+
]
6+
}

src/compiler/__tests__/@prop.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ test("@prop single", () => {
1818
d: [
1919
{
2020
color: "#f00",
21+
myBackgroundColor: "#00f",
2122
},
22-
["#00f", ["myBackgroundColor"]],
2323
],
2424
s: [1, 1],
2525
},
@@ -29,7 +29,7 @@ test("@prop single", () => {
2929
});
3030
});
3131

32-
test.only("@prop single, nested value", () => {
32+
test("@prop single, nested value", () => {
3333
const compiled = compile(`
3434
.test {
3535
color: red;
@@ -164,8 +164,10 @@ test("@prop multiple", () => {
164164
[
165165
{
166166
d: [
167-
["#f00", ["myColor"]],
168-
["#00f", ["myBackgroundColor"]],
167+
{
168+
myBackgroundColor: "#00f",
169+
myColor: "#f00",
170+
},
169171
],
170172
s: [1, 1],
171173
},

src/compiler/__tests__/compiler.test.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test("hello world", () => {
1414
{
1515
d: [
1616
{
17-
color: "rgb(100% 0% 0%)",
17+
color: "#f00",
1818
},
1919
],
2020
s: [1, 1],
@@ -105,6 +105,47 @@ test.skip("preserves unused CSS variables with preserve-variables", () => {
105105
});
106106
});
107107

108+
test("multiple rules with same selector", () => {
109+
const compiled = compile(`
110+
.redOrGreen:hover {
111+
color: green;
112+
}
113+
114+
.redOrGreen {
115+
color: red;
116+
}
117+
`);
118+
119+
expect(compiled).toStrictEqual({
120+
s: [
121+
[
122+
"redOrGreen",
123+
[
124+
{
125+
d: [
126+
{
127+
color: "#f00",
128+
},
129+
],
130+
s: [2, 1],
131+
},
132+
{
133+
d: [
134+
{
135+
color: "#008000",
136+
},
137+
],
138+
p: {
139+
h: 1,
140+
},
141+
s: [1, 2],
142+
},
143+
],
144+
],
145+
],
146+
});
147+
});
148+
108149
test.skip("transitions", () => {
109150
const compiled = compile(`
110151
.test {

src/compiler/attributes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test("multiple classes", () => {
1515
aq: [["a", "className", "*=", "my-class"]],
1616
d: [
1717
{
18-
color: "rgb(100% 0% 0%)",
18+
color: "#f00",
1919
},
2020
],
2121
s: [1, 2],

src/compiler/compiler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type Visitor,
1212
} from "lightningcss";
1313

14+
import { maybeMutateReactNativeOptions, parsePropAtRule } from "./atRules";
1415
import type {
1516
CompilerOptions,
1617
ContainerQuery,
@@ -20,7 +21,6 @@ import { parseContainerCondition } from "./container-query";
2021
import { parseDeclaration } from "./declarations";
2122
import { extractKeyFrames } from "./keyframes";
2223
import { parseMediaQuery } from "./media-query";
23-
import { maybeMutateReactNativeOptions, parsePropAtRule } from "./atRules";
2424
import { StylesheetBuilder } from "./stylesheet";
2525

2626
/**
@@ -37,6 +37,10 @@ export function compile(
3737
const { logger = debug("react-native-css") } = options;
3838
const features = Object.assign({}, options.features);
3939

40+
if (options.selectorPrefix && options.selectorPrefix.startsWith(".")) {
41+
options.selectorPrefix = options.selectorPrefix.slice(1);
42+
}
43+
4044
logger(`Features ${JSON.stringify(features)}`);
4145

4246
const builder = new StylesheetBuilder(options);

src/compiler/declarations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
12911291

12921292
let color: Color | undefined;
12931293

1294-
const { hexColors = true, colorPrecision = 3 } = builder.getOptions();
1294+
const { hexColors = true, colorPrecision } = builder.getOptions();
12951295

12961296
switch (cssColor.type) {
12971297
case "currentcolor":
@@ -1411,8 +1411,8 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
14111411
}
14121412
}
14131413

1414-
if (hexColors || colorPrecision) {
1415-
return color?.toString({ precision: colorPrecision });
1414+
if (!hexColors || colorPrecision) {
1415+
return color?.toString({ precision: colorPrecision ?? 3 });
14161416
} else {
14171417
return color?.toString({ format: "hex" });
14181418
}

src/compiler/inheritance.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ test("nested classes", () => {
88

99
expect(compiled).toStrictEqual({
1010
s: [
11+
[
12+
"my-class",
13+
[
14+
{
15+
c: ["my-class"],
16+
s: [0],
17+
},
18+
],
19+
],
1120
[
1221
"test",
1322
[
1423
{
1524
cq: [{ n: "my-class" }],
16-
d: [{ color: "rgb(100% 0% 0%)" }],
25+
d: [{ color: "#f00" }],
1726
s: [1, 2],
1827
},
1928
],
@@ -53,7 +62,7 @@ test("multiple tiers classes", () => {
5362
[
5463
{
5564
cq: [{ n: "one" }, { n: "two" }],
56-
d: [{ color: "rgb(100% 0% 0%)" }],
65+
d: [{ color: "#f00" }],
5766
s: [1, 3],
5867
},
5968
],
@@ -100,7 +109,7 @@ test("tiers with multiple classes", () => {
100109
n: "three",
101110
},
102111
],
103-
d: [{ color: "rgb(100% 0% 0%)" }],
112+
d: [{ color: "#f00" }],
104113
s: [1, 4],
105114
},
106115
],

src/compiler/media-query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import type {
1313
MediaFeatureComparison,
1414
StyleDescriptor,
1515
} from "./compiler.types";
16-
import type { StylesheetBuilder } from "./stylesheet";
1716
import { parseLength } from "./declarations";
17+
import type { StylesheetBuilder } from "./stylesheet";
1818

1919
export function parseMediaQuery(
2020
query: CSSMediaQuery,
2121
builder: StylesheetBuilder,
22-
): MediaCondition | undefined {
22+
) {
2323
let platformCondition: MediaCondition | undefined;
2424
let condition: MediaCondition | undefined;
2525

@@ -57,7 +57,7 @@ export function parseMediaQuery(
5757
mediaQuery = ["!", mediaQuery];
5858
}
5959

60-
return mediaQuery;
60+
builder.addMediaQuery(mediaQuery);
6161
}
6262

6363
function parseMediaQueryCondition(

src/compiler/selectors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,12 @@ function classNameSelector(
238238
getAttributeQuery().push(["a", "children", "!"]);
239239
break;
240240
}
241+
default: {
242+
// We don't support other pseudo-classes
243+
return null;
244+
}
241245
}
242-
243-
return null;
246+
break;
244247
}
245248
case "attribute": {
246249
// We don't support attribute selectors as standalone selectors

0 commit comments

Comments
 (0)