Skip to content

Commit 3ce79bc

Browse files
committed
fix: fix compilation with media and with separate pseudos
1 parent 24f36a8 commit 3ce79bc

9 files changed

+65
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.1
2+
3+
* [FIX] Fix compilation for CSS with separate (unnested) pseudoclasses.
4+
15
## 0.3.0
26

37
* [BREAKING] Component spec format changed from using `.` as a delimiter between

src/Syntax.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @copyright 2016-present, React CSS Components team
3+
* @flow
4+
*/
5+
6+
const COMPONENT_RE = /^[a-zA-Z_0-9]+$/;
7+
8+
export function isComponent(node: PostCSSNode) {
9+
return (
10+
node.type === 'rule' &&
11+
COMPONENT_RE.exec(node.selector) &&
12+
node.parent &&
13+
node.parent.type === 'root'
14+
);
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:local(.Label) {
2+
color: red
3+
}
4+
:local(.Label:hover) {
5+
color: red
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import styles from "css";
3+
export function Label(props) {
4+
return React.createElement("div", { ...props, className: styles.Label
5+
});
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Label {
2+
color: red;
3+
}
4+
Label:hover {
5+
color: red;
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:local(.Label) {
2+
3+
color: red
4+
}
5+
6+
@media (min-width: 1000px) {
7+
:local(.Label) {
8+
9+
color: white
10+
}
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from "react";
2+
import styles from "css";
3+
export function Label(props) {
4+
return React.createElement("div", { ...props, className: styles.Label
5+
});
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Label {
2+
color: red;
3+
}
4+
5+
@media (min-width: 1000px) {
6+
Label {
7+
color: white;
8+
}
9+
}

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import generate from 'babel-generator';
1010
import transformVariants, {isVariant} from './transformVariants';
1111
import HTMLTagList from './HTMLTagList';
1212
import * as ComponentRef from './ComponentRef';
13+
import * as Syntax from './Syntax';
1314

1415
const LOADER = require.resolve('../webpack');
1516

@@ -57,7 +58,7 @@ function renderToJS(source: string, config: RenderConfig): string {
5758
let statements = [];
5859
let component = types.stringLiteral('div');
5960
root.walkRules(node => {
60-
if (isVariant(node)) {
61+
if (!Syntax.isComponent(node)) {
6162
return;
6263
}
6364
node.walkDecls(decl => {

0 commit comments

Comments
 (0)