Skip to content

Commit 9cb7b6a

Browse files
committed
fix: nested classes
1 parent ca31505 commit 9cb7b6a

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { compile } from "../../compiler";
2+
3+
test("nested classes", () => {
4+
const compiled = compile(`
5+
.my-class .test {
6+
color: red;
7+
}`);
8+
9+
expect(compiled.stylesheet()).toStrictEqual({
10+
s: {
11+
test: [
12+
{
13+
d: {
14+
color: "#f00",
15+
},
16+
s: [0, 0, 0, 0, 0],
17+
v: {
18+
"__rn-css-color": "#f00",
19+
},
20+
cq: [
21+
{
22+
n: "my-class",
23+
},
24+
],
25+
},
26+
],
27+
},
28+
});
29+
});

src/compiler/stylesheet-new.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class CompilerStyleSheet {
100100
}
101101

102102
addDeclarations(declarations?: Declaration[]) {
103-
if (!declarations) {
103+
if (!declarations || declarations.length === 0) {
104104
return;
105105
}
106106

@@ -178,7 +178,7 @@ export class CompilerStyleSheet {
178178

179179
for (const selector of selectors) {
180180
for (const partialRule of rules.getAllRules()) {
181-
const rule = this.createRule(partialRule, options);
181+
const rule = this.createRule(partialRule, selector, options);
182182
this.appendRule(selector, rule);
183183
}
184184
}
@@ -207,6 +207,7 @@ export class CompilerStyleSheet {
207207

208208
private createRule(
209209
partialRule: Partial<HybridStyleRule>,
210+
selector: NormalizedSelector,
210211
options?: { important?: boolean },
211212
): HybridStyleRule {
212213
const rule: HybridStyleRule = {
@@ -226,6 +227,13 @@ export class CompilerStyleSheet {
226227
}
227228
}
228229

230+
if (selector.type === "className") {
231+
if (selector.containerQuery) {
232+
rule.cq = [...(rule.cq ?? [])];
233+
rule.cq.push(...selector.containerQuery);
234+
}
235+
}
236+
229237
if (this.mediaStack.length > 0) {
230238
const media = this.mediaStack.flat();
231239
if (media.length === 1) {

0 commit comments

Comments
 (0)