From b946376f0ceaacc916051d1567e61fee3265fac4 Mon Sep 17 00:00:00 2001 From: Daniel Puckowski Date: Thu, 28 Nov 2024 05:59:38 -0500 Subject: [PATCH] fix(issue:4264) strip line comment from expression * Fix for issue #4264. Strip line comments from expressions to avoid invalid CSS output. --- packages/less/src/less/parser/parser.js | 2 +- packages/test-data/css/_main/variables.css | 15 +++++++++++++++ packages/test-data/less/_main/variables.less | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/less/src/less/parser/parser.js b/packages/less/src/less/parser/parser.js index b87b4d762..9b1803f33 100644 --- a/packages/less/src/less/parser/parser.js +++ b/packages/less/src/less/parser/parser.js @@ -2418,7 +2418,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) { do { e = this.comment(); - if (e) { + if (e && !e.isLineComment) { entities.push(e); continue; } diff --git a/packages/test-data/css/_main/variables.css b/packages/test-data/css/_main/variables.css index 3fac8c7f4..6afac9b39 100644 --- a/packages/test-data/css/_main/variables.css +++ b/packages/test-data/css/_main/variables.css @@ -80,3 +80,18 @@ .radio_checked { border-color: #fff; } +div#apple { + color: blue; +} +div#banana { + color: blue; +} +div#cherry { + color: blue; +} +div#carrot { + color: blue; +} +div#potato { + color: blue; +} diff --git a/packages/test-data/less/_main/variables.less b/packages/test-data/less/_main/variables.less index c35ccc5b0..c03d1bff4 100644 --- a/packages/test-data/less/_main/variables.less +++ b/packages/test-data/less/_main/variables.less @@ -143,3 +143,19 @@ .@{radio-cls-checked} { border-color: #fff; } + +@items: +// Fruit + apple, + banana, + cherry, +// Vegetables + carrot, + potato, +; + +each(@items, { + div#@{value} { + color: blue; + } +})