SCSS/LESS: Fix comment inside parens (#9710)
This commit is contained in:
1 parent
d8e40cd978
commit
25d53fa9b3
6 files changed
+138
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
#### Fix broken comment inside parens (#9710 by @fisker)
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```scss
|
||||||
|
// Input
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prettier stable
|
||||||
|
.simplification {
|
||||||
|
foo: (calc() // not a comment anymore);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prettier master
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -534,6 +534,9 @@ function genericPrint(path, options, print) {
|
|||||||
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
|
const atRuleAncestorNode = getAncestorNode(path, "css-atrule");
|
||||||
const isControlDirective =
|
const isControlDirective =
|
||||||
atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
|
atRuleAncestorNode && isSCSSControlDirectiveNode(atRuleAncestorNode);
|
||||||
|
const hasInlineComment = node.groups.some((node) =>
|
||||||
|
isInlineValueCommentNode(node)
|
||||||
|
);
|
||||||
|
|
||||||
const printed = path.map(print, "groups");
|
const printed = path.map(print, "groups");
|
||||||
const parts = [];
|
const parts = [];
|
||||||
@@ -800,6 +803,10 @@ function genericPrint(path, options, print) {
|
|||||||
parts.push(line);
|
parts.push(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasInlineComment) {
|
||||||
|
parts.push(breakParent);
|
||||||
|
}
|
||||||
|
|
||||||
if (didBreak) {
|
if (didBreak) {
|
||||||
parts.unshift(hardline);
|
parts.unshift(hardline);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,6 +198,46 @@ printWidth: 80
|
|||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`in-value.less format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["less"]
|
||||||
|
printWidth: 80
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
.real-world-example {
|
||||||
|
background: radial-gradient(
|
||||||
|
circle at left 0% bottom $position,
|
||||||
|
transparent,
|
||||||
|
transparent $diameter,
|
||||||
|
#fbfbfb calc(#{$diameter} + 1px) // Add 1px for edge-smoothing.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
.real-world-example {
|
||||||
|
background: radial-gradient(
|
||||||
|
circle at left 0% bottom $position,
|
||||||
|
transparent,
|
||||||
|
transparent $diameter,
|
||||||
|
#fbfbfb calc(#{$diameter} + 1px) // Add 1px for edge-smoothing.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`issue-8130.less format 1`] = `
|
exports[`issue-8130.less format 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["less"]
|
parsers: ["less"]
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
.real-world-example {
|
||||||
|
background: radial-gradient(
|
||||||
|
circle at left 0% bottom $position,
|
||||||
|
transparent,
|
||||||
|
transparent $diameter,
|
||||||
|
#fbfbfb calc(#{$diameter} + 1px) // Add 1px for edge-smoothing.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -338,6 +338,46 @@ printWidth: 80
|
|||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`in-value.scss format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["scss"]
|
||||||
|
printWidth: 80
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
.real-world-example {
|
||||||
|
background: radial-gradient(
|
||||||
|
circle at left 0% bottom $position,
|
||||||
|
transparent,
|
||||||
|
transparent $diameter,
|
||||||
|
#fbfbfb calc(#{$diameter} + 1px) // Add 1px for edge-smoothing.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
.real-world-example {
|
||||||
|
background: radial-gradient(
|
||||||
|
circle at left 0% bottom $position,
|
||||||
|
transparent,
|
||||||
|
transparent $diameter,
|
||||||
|
#fbfbfb calc(#{$diameter} + 1px) // Add 1px for edge-smoothing.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`lists.scss format 1`] = `
|
exports[`lists.scss format 1`] = `
|
||||||
====================================options=====================================
|
====================================options=====================================
|
||||||
parsers: ["scss"]
|
parsers: ["scss"]
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
.real-world-example {
|
||||||
|
background: radial-gradient(
|
||||||
|
circle at left 0% bottom $position,
|
||||||
|
transparent,
|
||||||
|
transparent $diameter,
|
||||||
|
#fbfbfb calc(#{$diameter} + 1px) // Add 1px for edge-smoothing.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.simplification {
|
||||||
|
foo: (
|
||||||
|
calc() // not a comment anymore
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user