.test {
color: red; // this comment appeared in CSS output ❌
}.test {
color: red;
}
/* Line comments are properly stripped ✅ */- File:
packages/less/src/less/parser/parser-input.js - Function:
$parseUntil - Change: Added line comment detection and skipping
@color: red;
a { color: @color; }
.foo {
&:extend(a all);
@color: green; // Expected .foo a to be green ❌
}a,
.foo a {
color: red; /* Both are red! */
}- Variables evaluated BEFORE extend runs
- Extend only copies selectors, not re-evaluates values
- This is by design in Less.js architecture
.a-style(@c: red) { color: @c; }
a { .a-style(); }
.foo a { .a-style(green); }Output:
a { color: red; }
.foo a { color: green; }a { color: var(--color, red); }
.foo { --color: green; }Cascades at runtime!
a { color: red; }
.foo a { color: green; }Works via CSS cascade
packages/less/src/less/parser/parser-input.js- Line comment fix
packages/test-data/less/line-comments/packages/test-data/less/extend-variable-scope/
FIXES-SUMMARY.md- All fixesEXTEND-VARIABLE-SCOPE-GUIDE.md- Detailed guideIMPLEMENTATION-SUMMARY.md- Complete summaryverify-line-comments-fix.js- Quick test script
node verify-line-comments-fix.jscd packages/less
node bin/lessc ../../packages/test-data/less/extend-variable-scope/extend-variable-scope.less output.csscd packages/less
npm install
npm run build
npm test✅ Line comments (//) are now stripped in ALL contexts
✅ Block comments (/* */) still work as before
✅ Extend works on selectors, NOT values
✅ Use mixins or CSS vars for variable overrides
✅ This is Less.js 4.4.2+ behavior
Quick Ref Version: 1.0
Date: October 19, 2025
Print this card and keep it handy! 📋