Extract shared condition parsing into parse-condition.ts - #288
Merged
Conversation
Pulls media-feature (incl. range syntax), supports-condition (incl. compound and/or/not), and style()/selector()/font-tech() function- condition parsing out of AtRulePreludeParser into a new ConditionParser class, so this logic has one implementation instead of being duplicated in a soon-to-follow if()-parsing change to ValueNodeParser. ConditionParser takes an already-constructed ValueNodeParser rather than importing and instantiating its own, since parse-atrule-prelude.ts already imports value-node-parser.ts — a plain runtime import the other way would be circular. The constructor parameter is typed via `import type`, which is erased at build time and creates no runtime dependency in either direction. ConditionParser owns its own Lexer, separate from whichever class composes it (matching this codebase's existing sub-parser convention, e.g. how AtRulePreludeParser already composes ValueNodeParser). Where AtRulePreludeParser calls into it mid-scan on its own lexer, it now explicitly reseeks to ConditionParser.end_position afterward, since the delegated work no longer advances AtRulePreludeParser's lexer as a side effect the way an in-class method call would have. Pure refactor: no behavior change for @media/@supports/@container/ @import parsing, verified by the full existing test suite (1391 tests, unchanged assertions) plus a clean build with no circular- import issues.
commit: |
Contributor
|
| 📦 Package | 📏 Base Size | 📏 Source Size | 📈 Size Change |
|---|---|---|---|
| @projectwallace/css-parser | 41.2 kB | 42.1 kB | +902 B |
bartveneman
commented
Aug 16, 2026
…ment - Condense the end_position getter's doc comment to match this file's usual comment length elsewhere. - Give the range-operator's second-char check in parse_feature_range an explicit block body instead of a single-line if.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prep refactor split out of #253, so that PR stays focused on the
if()-parsing feature itself.Pulls media-feature (incl. range syntax), supports-condition (incl. compound
and/or/not), andstyle()/selector()/font-tech()function-condition parsing out ofAtRulePreludeParserinto a newConditionParserclass (src/parse-condition.ts), so this logic has a single implementation instead of being duplicated by an upcoming change toValueNodeParser(needed soif()'smedia()/supports()/style()condition functions produce realMediaFeature/FeatureRange/SupportsQuery/SupportsDeclarationnodes instead of ad-hoc ones).Design notes
ConditionParsertakes an already-constructedValueNodeParserrather than importing and instantiating its own, sinceparse-atrule-prelude.tsalready importsvalue-node-parser.ts— a runtime import the other way would be circular. The constructor parameter is typed viaimport type, which is erased at build time and creates no runtime dependency in either direction.ConditionParserowns its ownLexer, separate from whichever class composes it — matching this codebase's existing sub-parser convention (e.g. howAtRulePreludeParseralready composesValueNodeParser). WhereAtRulePreludeParsercalls into it mid-scan on its own lexer, it now explicitly reseeks toConditionParser.end_positionafterward, since the delegated work no longer advancesAtRulePreludeParser's lexer as a side effect the way an in-class method call would have.Test plan
@media/@supports/@container/@importparsing.tsc --noEmit,oxlint,oxfmt --checkall clean.pnpm run buildsucceeds with no circular-import issues;publintclean.Generated by Claude Code