diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index b59c95a8d..a9eb7c19f 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -20,6 +20,7 @@ const { indent, dedent, ifBreak, + breakParent, }, utils: { removeLines }, } = require("../document"); @@ -501,6 +502,23 @@ function genericPrint(path, options, print) { return options.originalText.slice(start, end).trim(); } + // Same reason above + const grandParent = path.getParentNode(1); + if ( + parentNode.type === "value-paren_group" && + grandParent && + grandParent.type === "value-func" && + grandParent.value === "selector" + ) { + const start = options.locStart(parentNode.open) + 1; + const end = options.locEnd(parentNode.close) - 1; + const selector = options.originalText.slice(start, end).trim(); + + return lastLineHasInlineComment(selector) + ? concat([breakParent, selector]) + : selector; + } + return node.value; } // postcss-values-parser diff --git a/tests/less/function-selector/__snapshots__/jsfmt.spec.js.snap b/tests/less/function-selector/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..d3d590221 --- /dev/null +++ b/tests/less/function-selector/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`selector.less format 1`] = ` +====================================options===================================== +parsers: ["less"] +printWidth: 80 + | printWidth +=====================================input====================================== +@supports selector( +:focus-visible // *"a" +) { +a{color:#f00 +} +} + +=====================================output===================================== +@supports selector( + :focus-visible // *"a" +) { + a { + color: #f00; + } +} + +================================================================================ +`; diff --git a/tests/less/function-selector/jsfmt.spec.js b/tests/less/function-selector/jsfmt.spec.js new file mode 100644 index 000000000..73b809901 --- /dev/null +++ b/tests/less/function-selector/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["less"]); diff --git a/tests/less/function-selector/selector.less b/tests/less/function-selector/selector.less new file mode 100644 index 000000000..a66817b9d --- /dev/null +++ b/tests/less/function-selector/selector.less @@ -0,0 +1,6 @@ +@supports selector( +:focus-visible // *"a" +) { +a{color:#f00 +} +}