From eefe33a47f6fdcc228817df7435a1770ce9e51ea Mon Sep 17 00:00:00 2001 From: Olivier Nicodemi Date: Sat, 20 Aug 2022 19:05:21 +0200 Subject: [PATCH] Fix #2991 (#3649) * Tests for 2991 * Fix for 2991 * chore: add missing newline Co-authored-by: Olivier Nicodemi Co-authored-by: Lei Chen --- .../less/src/less/visitors/to-css-visitor.js | 4 +-- packages/test-data/css/_main/css-3.css | 2 -- .../less/_main/import-reference-issues.less | 3 +++ .../comments-2991.less | 25 +++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 packages/test-data/less/_main/import-reference-issues/comments-2991.less diff --git a/packages/less/src/less/visitors/to-css-visitor.js b/packages/less/src/less/visitors/to-css-visitor.js index d49987ea7..6654f8a82 100644 --- a/packages/less/src/less/visitors/to-css-visitor.js +++ b/packages/less/src/less/visitors/to-css-visitor.js @@ -39,9 +39,9 @@ class CSSVisitorUtils { ? (rulesetNode.paths.length > 0) : false; } - resolveVisibility(node, originalRules) { + resolveVisibility(node) { if (!node.blocksVisibility()) { - if (this.isEmpty(node) && !this.containsSilentNonBlockedChild(originalRules)) { + if (this.isEmpty(node)) { return ; } diff --git a/packages/test-data/css/_main/css-3.css b/packages/test-data/css/_main/css-3.css index 95725b870..d1316defb 100644 --- a/packages/test-data/css/_main/css-3.css +++ b/packages/test-data/css/_main/css-3.css @@ -136,8 +136,6 @@ body > .shadow { symbols: ‣; suffix: " "; } -@-ms-viewport { -} @unknown foo 42 (bar) { x { y: z; diff --git a/packages/test-data/less/_main/import-reference-issues.less b/packages/test-data/less/_main/import-reference-issues.less index f35e90feb..63ecc30af 100644 --- a/packages/test-data/less/_main/import-reference-issues.less +++ b/packages/test-data/less/_main/import-reference-issues.less @@ -5,6 +5,7 @@ // * #2716 - A file imported by reference and then normally - multiple imports should be independent // * #1968 - When using an @import (reference), mixins that contain an & selector get added to the compiled output improperly // * #2162 - Cannot put import by reference inside of a mixin (also doubles #1896) +// * #2991 - Empty @media queries generated through line comments when compiling less file with (reference) // #1878: extend inside referenced file should not extend outside selectors @import (reference) "import-reference-issues/global-scope-import.less"; @@ -48,3 +49,5 @@ show-all-content { call-mixin-with-import-by-reference-inside { .mixin-with-import-by-reference-inside(); } + +@import (reference) "import-reference-issues/comments-2991.less"; \ No newline at end of file diff --git a/packages/test-data/less/_main/import-reference-issues/comments-2991.less b/packages/test-data/less/_main/import-reference-issues/comments-2991.less new file mode 100644 index 000000000..da15b2442 --- /dev/null +++ b/packages/test-data/less/_main/import-reference-issues/comments-2991.less @@ -0,0 +1,25 @@ +.referenced { + // This file should not output anything if referenced. + @media (hover) { + // This file should not output anything if referenced. + } + // This file should not output anything if referenced. + @media (hover) { + // This file should not output anything if referenced. + } + // This file should not output anything if referenced. + @media (hover) { + /* This file should not output anything if referenced. */ + } + // This file should not output anything if referenced. + @media (hover) { + color: #000000; + } +} +// This file should not output anything if referenced. +@media (hover) { + // This file should not output anything if referenced. +} +@media (hover) { + /* This file should not output anything if referenced. */ +}