Skip to content

Commit

Permalink
Don't lowercase Less variables when parsed with SCSS parser (prettier…
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell authored Sep 15, 2017
1 parent 23041e2 commit fb55367
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/printer-postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ function genericPrint(path, options, print) {
/^\(\s*\)$/.test(n.params.value);
return concat([
"@",
isDetachedRulesetCall ? n.name : maybeToLowerCase(n.name),
// If a Less file ends up being parsed with the SCSS parser, Less
// variable declarations will be parsed as atrules with names ending
// with a colon, so keep the original case then.
isDetachedRulesetCall || n.name.endsWith(":")
? n.name
: maybeToLowerCase(n.name),
hasParams
? concat([
isDetachedRulesetCall ? "" : " ",
Expand Down
16 changes: 16 additions & 0 deletions tests/css_case/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ a[HREF=KeepAttrValue]:HOVER::FIRST-letter,
BACKGROUND: RED;
}
@KeepTopLevelVar: val;
$KeepScssVar: val;
.Keep(@Keep: 12e03PX) WHEN (@Keep=Case) /*:*/ {
@KeepVar: KeepName; /*:*/
@{KeepInterpolationVar}: val;
$KeepScssVar: val;
@{Keep}[@{Keep}][@{Keep}^=@{Keep-1A}]:@{Keep} {
prop: val;
Expand Down Expand Up @@ -119,9 +123,13 @@ a[href="KeepAttrValue"]:hover::first-letter,
background: RED;
}
@KeepTopLevelVar: val;
$KeepScssVar: val;
.Keep(@Keep: 12e3px) when (@Keep=Case) {
@KeepVar: KeepName; /*:*/
@{KeepInterpolationVar}: val;
$KeepScssVar: val;
@{Keep}[@{Keep}][@{Keep}^=@{Keep-1A}]:@{Keep} {
prop: val;
Expand Down Expand Up @@ -206,11 +214,15 @@ a[HREF=KeepAttrValue]:HOVER::FIRST-letter,
@RETURN 12;
}
$KeepTopLevelVar: val;
@KeepLessVar: val;
@MIXIN KeepMixinName($Keep: 15IN, $Keep: $Keep15IN, $Keep: Keep-1E-2Em) {
$KeepVar: KeepFuncName();
#{$KeepInterpolationVar}: val;
#{$Keep + 15PX}: val;
#{$Keep + $Keep15PX}: val;
@KeepLessVar: val;
#{$Keep}[#{$Keep}][#{Keep}^=#{Keep-1A}]:#{$Keep} {
prop: val;
Expand Down Expand Up @@ -286,11 +298,15 @@ a[href="KeepAttrValue"]:hover::first-letter,
@return 12;
}
$KeepTopLevelVar: val;
@KeepLessVar: val;
@mixin KeepMixinName($Keep: 15in, $Keep: $Keep15IN, $Keep: Keep-1E-2Em) {
$KeepVar: KeepFuncName();
#{$KeepInterpolationVar}: val;
#{$Keep + 15PX}: val;
#{$Keep + $Keep15PX}: val;
@KeepLessVar: val;
#{$Keep}[#{$Keep}][#{Keep}^="#{Keep-1A}"]:#{$Keep} {
prop: val;
Expand Down
4 changes: 4 additions & 0 deletions tests/css_case/case.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ a[HREF=KeepAttrValue]:HOVER::FIRST-letter,
BACKGROUND: RED;
}

@KeepTopLevelVar: val;
$KeepScssVar: val;

.Keep(@Keep: 12e03PX) WHEN (@Keep=Case) /*:*/ {
@KeepVar: KeepName; /*:*/
@{KeepInterpolationVar}: val;
$KeepScssVar: val;

@{Keep}[@{Keep}][@{Keep}^=@{Keep-1A}]:@{Keep} {
prop: val;
Expand Down
4 changes: 4 additions & 0 deletions tests/css_case/case.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ a[HREF=KeepAttrValue]:HOVER::FIRST-letter,
@RETURN 12;
}

$KeepTopLevelVar: val;
@KeepLessVar: val;

@MIXIN KeepMixinName($Keep: 15IN, $Keep: $Keep15IN, $Keep: Keep-1E-2Em) {
$KeepVar: KeepFuncName();
#{$KeepInterpolationVar}: val;
#{$Keep + 15PX}: val;
#{$Keep + $Keep15PX}: val;
@KeepLessVar: val;

#{$Keep}[#{$Keep}][#{Keep}^=#{Keep-1A}]:#{$Keep} {
prop: val;
Expand Down

0 comments on commit fb55367

Please sign in to comment.