Skip to content

Commit

Permalink
fix: don't lowercase variable in css modules (prettier#4152)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Mar 15, 2018
1 parent e237320 commit 5537140
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/language-css/parser-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function parseNestedCSS(node) {

try {
node.selector = parseSelector(selector);
node.raws.selector = selector;
} catch (e) {
// Fail silently. It's better to print it as is than to try and parse it
// Note: A common failure is for SCSS nested properties. `background:
Expand Down
8 changes: 7 additions & 1 deletion src/language-css/printer-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ function genericPrint(path, options, print) {
node.value.type === "value-root" &&
node.value.group.type === "value-value" &&
node.prop === "composes";
const ruleAncestorNode = getAncestorNode(path, "css-rule");
const isiCSS =
ruleAncestorNode &&
ruleAncestorNode.raws.selector &&
(ruleAncestorNode.raws.selector.startsWith(":import") ||
ruleAncestorNode.raws.selector.startsWith(":export"));

return concat([
node.raws.before.replace(/[\s;]/g, ""),
maybeToLowerCase(node.prop),
isiCSS ? node.prop : maybeToLowerCase(node.prop),
node.raws.between.trim() === ":" ? ":" : node.raws.between.trim(),
isValueExtend ? "" : " ",
isComposed
Expand Down
82 changes: 82 additions & 0 deletions tests/css_modules/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,16 +1,98 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`modules.css 1`] = `
@value colors: './colors.css';
@value first, second, third from colors;
.title {
@nest :global(h1)& {
background: red;
}
}
.className {
color: green;
background: red;
}
.otherClassName {
composes: className;
color: yellow;
}
.otherClassName {
composes: className from "./style.css";
}
.otherClassName {
composes: globalClassName from global;
}
:global {
.global-class-name {
color: green;
}
}
.root :global .text {
color: brown;
font-size: 24px;
font-family: helvetica, arial, sans-serif;
font-weight: 600;
}
:import("path/to/dep.css") {
localAlias: keyFromDep;
}
:export {
exportedKey: exportedValue;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@value colors: './colors.css';
@value first, second, third from colors;
.title {
@nest :global(h1)& {
background: red;
}
}
.className {
color: green;
background: red;
}
.otherClassName {
composes: className;
color: yellow;
}
.otherClassName {
composes: className from "./style.css";
}
.otherClassName {
composes: globalClassName from global;
}
:global {
.global-class-name {
color: green;
}
}
.root :global .text {
color: brown;
font-size: 24px;
font-family: helvetica, arial, sans-serif;
font-weight: 600;
}
:import("path/to/dep.css") {
localAlias: keyFromDep;
}
:export {
exportedKey: exportedValue;
}
`;
41 changes: 41 additions & 0 deletions tests/css_modules/modules.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
@value colors: './colors.css';
@value first, second, third from colors;

.title {
@nest :global(h1)& {
background: red;
}
}

.className {
color: green;
background: red;
}

.otherClassName {
composes: className;
color: yellow;
}

.otherClassName {
composes: className from "./style.css";
}

.otherClassName {
composes: globalClassName from global;
}

:global {
.global-class-name {
color: green;
}
}

.root :global .text {
color: brown;
font-size: 24px;
font-family: helvetica, arial, sans-serif;
font-weight: 600;
}

:import("path/to/dep.css") {
localAlias: keyFromDep;
}
:export {
exportedKey: exportedValue;
}

0 comments on commit 5537140

Please sign in to comment.