Skip to content

Commit 9f93942

Browse files
bartvenemanclaude
andauthored
Extract shared condition parsing into parse-condition.ts (#288)
## 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`), and `style()`/`selector()`/`font-tech()` function-condition parsing out of `AtRulePreludeParser` into a new `ConditionParser` class (`src/parse-condition.ts`), so this logic has a single implementation instead of being duplicated by an upcoming change to `ValueNodeParser` (needed so `if()`'s `media()`/`supports()`/`style()` condition functions produce real `MediaFeature`/`FeatureRange`/`SupportsQuery`/`SupportsDeclaration` nodes instead of ad-hoc ones). ## Design notes - `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 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. ## Test plan - [x] Pure refactor: no behavior change intended for `@media`/`@supports`/`@container`/`@import` parsing. - [x] Full existing test suite passes unchanged (1391 tests, no assertion changes). - [x] `tsc --noEmit`, `oxlint`, `oxfmt --check` all clean. - [x] `pnpm run build` succeeds with no circular-import issues; `publint` clean. --- _Generated by [Claude Code](https://claude.ai/code/session_015D2xHEuZHwna87DA8VeYjT)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 05bf30e commit 9f93942

2 files changed

Lines changed: 581 additions & 381 deletions

File tree

0 commit comments

Comments
 (0)