Skip to content

Commit e37d564

Browse files
Merge pull request stylelint#41 from stylelint/at-rule-param-case
2 parents bade2c2 + 321b135 commit e37d564

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

object-parser.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ function forEach(arr, callback) {
1111
arr && arr.forEach(callback);
1212
}
1313

14-
const replaceProp = (fn) => (value) =>
15-
value.replace(/(\(\s*)(.*?)(\s*:)/g, (s, prefix, prop, suffix) => prefix + fn(prop) + suffix);
16-
const camelCaseProp = replaceProp(camelCase);
17-
const unCamelCaseProp = replaceProp(unCamelCase);
18-
1914
function defineRaws(node, prop, prefix, suffix, props) {
2015
if (!props) {
2116
props = {};
@@ -239,16 +234,8 @@ class objectParser {
239234
});
240235

241236
if (params) {
242-
atRule.params = unCamelCaseProp(params);
243-
defineRaws(atRule, 'params', '', key.suffix, {
244-
raw: {
245-
enumerable: true,
246-
get: () => camelCaseProp(atRule.params),
247-
set: (value) => {
248-
atRule.params = unCamelCaseProp(value);
249-
},
250-
},
251-
});
237+
atRule.params = params;
238+
defineRaws(atRule, 'params', '', key.suffix);
252239
}
253240

254241
rule = atRule;

test/css-in-js.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ describe('CSS in JS', () => {
5050
});
5151
});
5252

53+
it('leaves kebab-case and camelCase in media query params untouched', () => {
54+
// In previous versions, at-rule properties were converted from camelCase to kebab-case
55+
// during parsing, and back to camelCase during stringifying. This is however not correct,
56+
// params should not be changed. Also see:
57+
// https://github.com/stylelint/postcss-css-in-js/issues/38
58+
const code = `
59+
import glm from 'glamorous';
60+
const Component1 = glm.a({
61+
"@media (max-width: 1000px)": {
62+
color: "red",
63+
},
64+
"@media (maxWidth: 1000px)": {
65+
color: "red",
66+
},
67+
});
68+
`;
69+
70+
expect(syntax.parse(code).toString()).toBe(code);
71+
});
72+
5373
describe('setter for object literals', () => {
5474
it('decl.raws.prop.raw & decl.raws.value.raw', () => {
5575
const decl = syntax.parse(
@@ -74,7 +94,7 @@ describe('CSS in JS', () => {
7494
`
7595
import glm from 'glamorous';
7696
const Component1 = glm.a({
77-
'@media (maxWidth: 500px)': {
97+
'@media (max-width: 500px)': {
7898
borderRadius: '5px'
7999
}
80100
});
@@ -84,7 +104,7 @@ describe('CSS in JS', () => {
84104
},
85105
).first.first.first;
86106

87-
atRule.raws.params.raw = "(minWidth: ' + minWidth + ')";
107+
atRule.raws.params.raw = "(min-width: ' + minWidth + ')";
88108
expect(atRule.params).toBe("(min-width: ' + minWidth + ')");
89109
});
90110
});

test/fixtures/glamorous.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Component1 = glm.a(
1111
[`unknownPropertyaa${a}`]: "1.8em", // must not trigger any warnings
1212
["unknownProperty" + 1 + "a"]: "1.8em", // must not trigger any warnings
1313
display: "inline-block",
14-
[`@media (minWidth: ${minWidth}px)`]: {
14+
[`@media (min-width: ${minWidth}px)`]: {
1515
color: "red",
1616
},
1717
// unkown pseudo class selector

test/fixtures/glamorous.jsx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@
346346
"params": {
347347
"prefix": "",
348348
"suffix": "`]",
349-
"raw": "(minWidth: ${minWidth}px)",
349+
"raw": "(min-width: ${minWidth}px)",
350350
"value": "(min-width: ${minWidth}px)"
351351
},
352352
"between": ": ",

0 commit comments

Comments
 (0)