Skip to content

Refactor comment skipping logic into reusable method - #296

Merged
bartveneman merged 4 commits into
mainfrom
claude/brave-dirac-iptk9d
Oct 1, 2026
Merged

bartveneman merged 4 commits into
mainfrom
claude/brave-dirac-iptk9d

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Summary

This PR refactors the comment-skipping logic in the lexer into a dedicated _skip_comment() method to improve code maintainability and reduce duplication.

Key Changes

  • Extracted the inline comment-skipping logic from the main tokenization loop into a new _skip_comment() method in the Lexer class
  • Updated the comment-skipping code path to call the new method instead of duplicating the logic inline
  • Added comprehensive test coverage for comment detection in various CSS contexts:
    • Comments in selectors, property values, and at-rule blocks
    • Comments in at-rule preludes (media queries, supports, layer, import, container)
  • Updated test imports to include vi from vitest for mocking

Implementation Details

  • The _skip_comment() method encapsulates the logic for advancing past /* and */ delimiters and handling the content in between
  • This refactoring sets up the foundation for the on_comment callback to be properly invoked during comment processing
  • The new tests verify that comments are correctly identified across all CSS rule types and positions

https://claude.ai/code/session_019FWMrZqm4cPwisLctbdiN1

claude added 3 commits October 1, 2026 08:05
skip_whitespace_in_range skipped comments without invoking on_comment, so
'color: /* c */ green' lost its comment. Regression from #279.
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🎉 Package Size Decrease

📦 Package 📏 Base Size 📏 Source Size 📈 Size Change
@projectwallace/css-parser 45.9 kB 45.9 kB -42 B

Copy link
Copy Markdown
Member Author

The Audit packages check is failing, but not because of this PR. pnpm audit reports 6 advisories (2 high) in brace-expansion < 1.1.19, pulled in transitively via tailwindcss > purgecss > glob > minimatch. It reproduces locally, and this PR only changes src/tokenize.ts and src/parse-options.test.ts, with no dependency changes. No fix is included here; it needs a dependency bump or override in a separate change. Unit tests, build and the other checks are unaffected.


Generated by Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@projectwallace/css-parser@8abcf15

commit: 8abcf15

@bartveneman
bartveneman merged commit 9fbe977 into main Oct 1, 2026
15 of 16 checks passed
@bartveneman
bartveneman deleted the claude/brave-dirac-iptk9d branch October 1, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants