Skip to content

Commit 4606750

Browse files
authored
feat: correct parsing of :is & :where (#69)
1 parent 40667c5 commit 4606750

File tree

11 files changed

+756
-99
lines changed

11 files changed

+756
-99
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { getClassNameSelectors } from "../selector-builder";
2+
3+
test("empty", () => {
4+
expect(getClassNameSelectors([])).toStrictEqual([]);
5+
});
6+
7+
test(".my-class { &:is(:where(.my-parent, .my-second-parent):hover *) {} }", () => {
8+
const result = getClassNameSelectors([
9+
[
10+
{
11+
type: "class",
12+
name: "my-class",
13+
},
14+
{
15+
type: "nesting",
16+
},
17+
{
18+
type: "pseudo-class",
19+
kind: "is",
20+
selectors: [
21+
[
22+
{
23+
type: "pseudo-class",
24+
kind: "where",
25+
selectors: [
26+
[
27+
{
28+
type: "class",
29+
name: "my-parent",
30+
},
31+
],
32+
33+
[
34+
{
35+
type: "class",
36+
name: "my-second-parent",
37+
},
38+
],
39+
],
40+
},
41+
{
42+
type: "pseudo-class",
43+
kind: "hover",
44+
},
45+
{
46+
type: "combinator",
47+
value: "descendant",
48+
},
49+
{
50+
type: "universal",
51+
},
52+
],
53+
],
54+
},
55+
],
56+
]);
57+
58+
expect(result).toStrictEqual([
59+
{
60+
className: "my-class",
61+
containerQuery: [
62+
{
63+
n: "my-parent",
64+
p: {
65+
h: 1,
66+
},
67+
},
68+
],
69+
specificity: [0, 2],
70+
type: "className",
71+
},
72+
{
73+
className: "my-class",
74+
containerQuery: [
75+
{
76+
n: "my-second-parent",
77+
p: {
78+
h: 1,
79+
},
80+
},
81+
],
82+
specificity: [0, 2],
83+
type: "className",
84+
},
85+
]);
86+
});

src/compiler/compiler.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { parseContainerCondition } from "./container-query";
1919
import { parseDeclaration } from "./declarations";
2020
import { extractKeyFrames } from "./keyframes";
2121
import { parseMediaQuery } from "./media-query";
22-
import { getSelectors } from "./selectors";
2322
import { StylesheetBuilder } from "./stylesheet";
2423

2524
const defaultLogger = debug("react-native-css:compiler");
@@ -165,14 +164,9 @@ function extractRule(rule: Rule, builder: StylesheetBuilder) {
165164

166165
const declarationBlock = value.declarations;
167166
const mapping = parsePropAtRule(value.rules);
168-
const selectors = getSelectors(
169-
value.selectors,
170-
false,
171-
builder.getOptions(),
172-
);
173167

174168
// If the rule is a style declaration, extract it with the `getExtractedStyle` function and store it in the `declarations` map
175-
builder = builder.fork("style", selectors);
169+
builder = builder.fork("style", value.selectors);
176170

177171
if (declarationBlock) {
178172
if (declarationBlock.declarations) {

src/compiler/inheritance.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ test("tiers with multiple classes", () => {
9494
"three",
9595
[
9696
{
97-
c: ["three"],
97+
c: ["three.two"],
9898
s: [0],
99+
aq: [["a", "className", "*=", "two"]],
99100
},
100101
],
101102
],
@@ -106,8 +107,7 @@ test("tiers with multiple classes", () => {
106107
cq: [
107108
{ n: "one" },
108109
{
109-
a: [["a", "className", "*=", "two"]],
110-
n: "three",
110+
n: "three.two",
111111
},
112112
],
113113
d: [{ color: "#f00" }],

0 commit comments

Comments
 (0)