fix(printer-postcss): ignore escape \ and escaped / in Less (#5597)

Avoid messing up Less files containing \\/ (escaped /).
Ignore escape \ and escaped / in Less.
master
Dmitriy Sharshakov aka. sh7dm 2018-12-17 03:28:48 +03:00 committed by Ika
parent cbf06bf388
commit 6a45924379
7 changed files with 91 additions and 0 deletions

View File

@ -511,6 +511,27 @@ function genericPrint(path, options, print) {
continue;
}
// Ignore escape `\`
if (
iNode.value &&
iNode.value.indexOf("\\") !== -1 &&
iNextNode &&
iNextNode.type !== "value-comment"
) {
continue;
}
// Ignore escaped `/`
if (
iPrevNode &&
iPrevNode.value &&
iPrevNode.value.indexOf("\\") === iPrevNode.value.length - 1 &&
iNode.type === "value-operator" &&
iNode.value === "/"
) {
continue;
}
// Ignore `\` (i.e. `$variable: \@small;`)
if (iNode.value === "\\") {
continue;

View File

@ -54,6 +54,11 @@ printWidth: 80
content: "\\21D3";
}
/* Ignore escape "\\" in CSS classes */
.bar\\/baz {
animation-name: \\@mymove;
content: "\\21D3";
}
=====================================output=====================================
#♥ {
@ -145,5 +150,11 @@ printWidth: 80
content: "\\21D3";
}
/* Ignore escape "\\" in CSS classes */
.bar\\/baz {
animation-name: \\@mymove;
content: "\\21D3";
}
================================================================================
`;

View File

@ -46,3 +46,8 @@
content: "\21D3";
}
/* Ignore escape "\" in CSS classes */
.bar\/baz {
animation-name: \@mymove;
content: "\21D3";
}

View File

@ -1668,6 +1668,15 @@ li + li {
@import // Comment
"@{themes}/tidal-wave.less";
// Mixin with escaped /
.margin-bottom-1\\/3() {
margin-bottom: 0.8rem;
}
label {
.margin-bottom-1\\/3;
}
=====================================output=====================================
@nice-blue: #5b83ad;
@light-blue: @nice-blue + #111;
@ -3263,5 +3272,14 @@ li + li {
@import // Comment
"@{themes}/tidal-wave.less";
// Mixin with escaped /
.margin-bottom-1\\/3() {
margin-bottom: 0.8rem;
}
label {
.margin-bottom-1\\/3;
}
================================================================================
`;

View File

@ -1659,3 +1659,12 @@ li + li {
// Usage
@import // Comment
"@{themes}/tidal-wave.less";
// Mixin with escaped /
.margin-bottom-1\/3() {
margin-bottom: 0.8rem;
}
label {
.margin-bottom-1\/3;
}

View File

@ -1061,6 +1061,15 @@ $my-map: (
grid-template-columns: 1 2fr (3 + 4);
}
// Ignore escape "\\" in SCSS mixins
@mixin margin-bottom-1\\/3 {
margin-bottom: 0.8rem;
}
label {
@include margin-bottom-1\\/3;
}
=====================================output=====================================
@media #{$g-breakpoint-tiny} {
}
@ -2015,5 +2024,14 @@ $my-map: (
grid-template-columns: 1 2fr (3 + 4);
}
// Ignore escape "\\" in SCSS mixins
@mixin margin-bottom-1\\/3 {
margin-bottom: 0.8rem;
}
label {
@include margin-bottom-1\\/3;
}
================================================================================
`;

View File

@ -1038,3 +1038,12 @@ $my-map: (
.something {
grid-template-columns: 1 2fr (3 + 4);
}
// Ignore escape "\" in SCSS mixins
@mixin margin-bottom-1\/3 {
margin-bottom: 0.8rem;
}
label {
@include margin-bottom-1\/3;
}