Skip to content

Conversation

@vardhan30016
Copy link

Summary

This PR fixes an issue where inline comments inside nested selectors were lost during parsing.

Changes

  • Updated packages/less/src/less/parser/parser.js to correctly capture and preserve inline comments.
  • Added test coverage to confirm that inline comments remain in the compiled output.

Testing

  • Ran pnpm grunt test locally — all tests passed.
  • Verified that nested selectors with inline comments retain comment text in compiled CSS.

Why this matters

Preserving inline comments improves readability in complex Less projects and maintains developer context when recompiled.


Contributor: @vardhan30016 (Vardhan Naidu)

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 31, 2025
@puckowski
Copy link
Contributor

I think Less 4.4.2 already preserves the comment from your provided test. PR could be improved by adding to existing .css/.less files (or creating new files) under test-data to be run and tested with pnpm test. Do you have an example where comments are not preserved in the current version of Less.js or am I missing something?
image

@vardhan30016 vardhan30016 force-pushed the fix/parser-preserve-inline-comments branch from d694eb8 to 71f3bd1 Compare November 12, 2025 14:24
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Nov 12, 2025
@vardhan30016
Copy link
Author

Hi @puckowski 👋,

Thanks for reviewing this!

I’ve re-verified the behavior on the latest master (Less v4.4.2), and inline comments inside nested selectors are still being removed during parsing in the current release.

This patch ensures that inline comments are properly preserved without affecting any existing functionality.

Verification steps:

@puckowski
Copy link
Contributor

I do not believe native CSS supports comments preceded by // so it is correct that Less strips them out.

Only /* */ comments are valid.

This CSS in your test does not seem valid:

/* inline-comments-nested.css — expected compiled result */
.container .item { // inline comment should be preserved
  color: red;
}
image image

@puckowski
Copy link
Contributor

As a quick follow up, there are currently no parser changes in your PR diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants