Prevent SCSS math expressions in group treated as map item (#18530)
This commit is contained in:
1 parent
e82248225a
commit
4f1c4d9eb8
4 files changed
+132
No files matched your search
@@ -0,0 +1,18 @@
|
|||||||
|
#### Prevent adding trailing comma in math expression within function arguments (#18530 by @kovsu)
|
||||||
|
|
||||||
|
<!-- prettier-ignore -->
|
||||||
|
```scss
|
||||||
|
// Input
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
|
||||||
|
// Prettier stable
|
||||||
|
@include container(
|
||||||
|
$foo: 2 *
|
||||||
|
(
|
||||||
|
$bar + $baz,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Prettier main
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
```
|
||||||
@@ -292,6 +292,11 @@ function isSCSSMapItemNode(path, options) {
|
|||||||
|
|
||||||
// List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
|
// List as value of key inside SCSS map (i.e. `$map: (key: (value other-value other-other-value))`)
|
||||||
if (isKeyValuePairInParenGroupNode(parentParentNode)) {
|
if (isKeyValuePairInParenGroupNode(parentParentNode)) {
|
||||||
|
// If there is any operator in the value, it is not a map item
|
||||||
|
if (parentNode.groups.some((node) => isMathOperatorNode(node))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
@include container($foo: 2);
|
||||||
|
@include container($foo: 2 * ($bar));
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
|
||||||
|
@include container($foo: 1, $bar: 2);
|
||||||
|
|
||||||
|
@include container($foo: (
|
||||||
|
$bar,
|
||||||
|
$baz
|
||||||
|
));
|
||||||
|
|
||||||
|
@include container($foo: (
|
||||||
|
$bar + $baz,
|
||||||
|
$qux * 2
|
||||||
|
));
|
||||||
@@ -523,3 +523,97 @@ $colors: (
|
|||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`7419.scss - {"trailingComma":"es5"} format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["scss"]
|
||||||
|
printWidth: 80
|
||||||
|
trailingComma: "es5"
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
@include container($foo: 2);
|
||||||
|
@include container($foo: 2 * ($bar));
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
|
||||||
|
@include container($foo: 1, $bar: 2);
|
||||||
|
|
||||||
|
@include container($foo: (
|
||||||
|
$bar,
|
||||||
|
$baz
|
||||||
|
));
|
||||||
|
|
||||||
|
@include container($foo: (
|
||||||
|
$bar + $baz,
|
||||||
|
$qux * 2
|
||||||
|
));
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
@include container($foo: 2);
|
||||||
|
@include container($foo: 2 * ($bar));
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
|
||||||
|
@include container($foo: 1, $bar: 2);
|
||||||
|
|
||||||
|
@include container(
|
||||||
|
$foo: (
|
||||||
|
$bar,
|
||||||
|
$baz,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@include container(
|
||||||
|
$foo: (
|
||||||
|
$bar + $baz,
|
||||||
|
$qux * 2,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`7419.scss - {"trailingComma":"none"} format 1`] = `
|
||||||
|
====================================options=====================================
|
||||||
|
parsers: ["scss"]
|
||||||
|
printWidth: 80
|
||||||
|
trailingComma: "none"
|
||||||
|
| printWidth
|
||||||
|
=====================================input======================================
|
||||||
|
@include container($foo: 2);
|
||||||
|
@include container($foo: 2 * ($bar));
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
|
||||||
|
@include container($foo: 1, $bar: 2);
|
||||||
|
|
||||||
|
@include container($foo: (
|
||||||
|
$bar,
|
||||||
|
$baz
|
||||||
|
));
|
||||||
|
|
||||||
|
@include container($foo: (
|
||||||
|
$bar + $baz,
|
||||||
|
$qux * 2
|
||||||
|
));
|
||||||
|
|
||||||
|
=====================================output=====================================
|
||||||
|
@include container($foo: 2);
|
||||||
|
@include container($foo: 2 * ($bar));
|
||||||
|
@include container($foo: 2 * ($bar + $baz));
|
||||||
|
|
||||||
|
@include container($foo: 1, $bar: 2);
|
||||||
|
|
||||||
|
@include container(
|
||||||
|
$foo: (
|
||||||
|
$bar,
|
||||||
|
$baz
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@include container(
|
||||||
|
$foo: (
|
||||||
|
$bar + $baz,
|
||||||
|
$qux * 2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
||||||
Reference in new issue
Block a user