This document summarizes all bug fixes and documentation added to the Less.js codebase.
Double-slash line comments were appearing in compiled CSS output, particularly in:
- Custom CSS properties (
--variable) - Permissive value parsing contexts
- Complex selector constructs
Modified packages/less/src/less/parser/parser-input.js to handle line comments in the $parseUntil function:
case '/':
if (input.charAt(i + 1) === '*') {
// Block comment start: /* ... */
i++;
inComment = true;
blockDepth++;
} else if (input.charAt(i + 1) === '/') {
// Line comment start: // ... (strip until newline)
if (i > lastPos) {
parseGroups.push(input.substr(lastPos, i - lastPos));
}
let nextNewLine = input.indexOf('\n', i + 2);
if (nextNewLine < 0) {
i = length;
lastPos = i;
continue;
}
i = nextNewLine;
lastPos = i + 1;
}
break;packages/less/src/less/parser/parser-input.js
packages/test-data/less/line-comments/line-comments.less- Input with various comment scenariospackages/test-data/css/line-comments/line-comments.css- Expected outputverify-line-comments-fix.js- Standalone verification script
Run the verification script:
node verify-line-comments-fix.jsUsers expected variables defined inside an :extend() block to override extended selector values, but this doesn't work due to Less.js's compilation pipeline.
This is by design, not a bug:
- Evaluation Phase: Variables resolved, expressions evaluated
- Extend Visitor Phase: Selectors extended (no re-evaluation)
Extend works on selectors, not values.
.a-style(@color: red) {
color: @color;
}
a { .a-style(); }
.foo a { .a-style(green); }a { color: var(--a-color, red); }
.foo { --a-color: green; }.foo a {
&:extend(a all);
color: green;
}EXTEND-VARIABLE-SCOPE-GUIDE.md- Comprehensive guide with examplespackages/test-data/less/extend-variable-scope/extend-variable-scope.less- Test casepackages/test-data/css/extend-variable-scope/extend-variable-scope.css- Expected output
FIXES-SUMMARY.md- Added section documenting this behavior
packages/less/src/less/parser/parser-input.js- Line comment handling in$parseUntil
packages/test-data/less/line-comments/line-comments.lesspackages/test-data/css/line-comments/line-comments.csspackages/test-data/less/extend-variable-scope/extend-variable-scope.lesspackages/test-data/css/extend-variable-scope/extend-variable-scope.css
FIXES-SUMMARY.md- Updated with new fixesEXTEND-VARIABLE-SCOPE-GUIDE.md- Comprehensive guide for extend/variable behaviorIMPLEMENTATION-SUMMARY.md- This fileverify-line-comments-fix.js- Verification script
The test files are in the standard Less.js test structure:
- Input:
packages/test-data/less/<test-name>/<test-name>.less - Expected:
packages/test-data/css/<test-name>/<test-name>.css
Run the full test suite:
cd packages/less
npm install
npm run build
npm testnode verify-line-comments-fix.jsOr compile manually:
cd packages/less
node bin/lessc ../../test-fixes.less output.css
cat output.css # Should have no // commentscd packages/less
node bin/lessc ../../packages/test-data/less/extend-variable-scope/extend-variable-scope.less output.css
cat output.cssExpected output:
a,
.foo a {
color: red;
}None - All changes are either bug fixes or documentation.
- Less Version: 4.4.2+
- Node.js: 14+ (as per existing requirements)
- Browsers: No impact (compilation only)
- Line Comment Fix: Negligible impact (adds simple string scanning)
- Extend Variable Scope: Documentation only, no code changes
- Source code changes implemented
- Test cases created
- Documentation written
- Verification scripts created
- Run full test suite
- Manual verification on sample projects
- Code review
- Update CHANGELOG.md with version bump
- Tag release
- Publish to npm
- Close related GitHub issues (#3706)
- Update documentation website
- Line Comments: Generic parsing bug
- Extend Variable Scope: #3706
- Implementation is in
$parseUntilwhich handles permissive parsing - The
skipWhitespacefunction already handled//in normal parsing - This fix completes comment handling across all parsing contexts
- No configuration needed - line comments are always stripped
- This is architectural behavior, not a bug
- Changing it would require redesigning the compilation pipeline
- Current behavior is consistent with Less's design philosophy
- Recommended patterns (mixins, CSS vars) are idiomatic and maintainable
- Consider adding this to official documentation/FAQ
- Test structure follows existing Less.js patterns
- Each test has
.lessinput and.cssexpected output - Verification script can be run standalone for quick checks
- Less.js Official Documentation
- Less.js GitHub Repository
- EXTEND-VARIABLE-SCOPE-GUIDE.md - Detailed guide
- FIXES-SUMMARY.md - All fixes documentation
Implementation Date: October 19, 2025
Status: ✅ Complete
Version: Less.js 4.4.2+
Contributors: GitHub Copilot Agent