This document explains how to maintain the CSSOM parser repository, including updating specifications, web platform tests, and generating fixtures.
The maintenance workflow typically involves three steps:
- Update Submodules: Pull the latest changes from the W3C CSSWG drafts and Web Platform Tests.
- Generate Fixtures: Extract test cases from the updated WPT files.
- Run Tests: Verify that the parser still works and passes the tests.
We provide npm scripts to make this process straightforward.
To run all steps (update submodules, generate fixtures, and run tests) in one go:
pnpm run maintainIf you want to run the steps individually:
1. Update Submodules:
pnpm run submodules:updateThis runs git submodule update --init --recursive --remote.
2. Generate Fixtures:
pnpm run fixtures:generateThis runs node scripts/extract_external_suites.ts.
3. Run Tests:
pnpm testOr run the full preflight check (typecheck and test):
pnpm run preflightWhen specifications are updated in the submodules, we need to ensure our implementation remains compliant and that the reference comments in the code are up to date.
- Diff Specs: Run
git diffon thesubmodules/csswg-draftsdirectory to see what changed in the relevant specs (e.g.,css-syntax-3,css-nesting-1,cssom-1) since the last update. - Update Comments: If section numbers or anchors changed, update the comments in
src/tokenizer.tsandsrc/parser.tsto reflect the new spec locations. - Implement Changes: If the spec introduced new parsing rules or modified existing ones, update the implementation accordingly.
- Verify: Run tests to ensure no regressions.
To maintain high compliance at scale, we use specialized AI subagents to audit the codebase against the specifications. This process should be run periodically or when significant spec updates occur.
When initiating an audit, spawn the following subagents with their specific roles and prompts:
- CSSOM Spec Auditor: Reads
cssom-1/Overview.bsand compares withsrc/types.tsandsrc/CSSOM.ts. Focuses on rule interfaces and inheritance. - CSS Syntax Spec Auditor: Reads
css-syntax-3/Overview.bsand compares withsrc/tokenizer.tsandsrc/parser.ts. Focuses on low-level tokenization and parsing algorithms. - CSS Nesting & Variables Auditor: Reads
css-nesting-1/Overview.bsandcss-variables-1/Overview.bs. Focuses on interleaved declarations and custom property handling. - Media Queries Auditor: Reads
mediaqueries-4/Overview.bs. Focuses on media query list parsing and evaluation. - CSS Logical Auditor: Reads
css-logical-1/Overview.bs. Focuses on logical properties shorthand serialization incssText. - CSS Values & Typed OM Auditor: Reads
css-values-4/Overview.bsandcss-typed-om-1/Overview.bs. Focuses on value representation and serialization.
- CSS Spec Tricky Case Researcher: Reads specs to identify complex error recovery scenarios or easily overlooked rules (e.g., EOF handling, unclosed constructs).
- WPT Tricky Case Researcher: Searches through
tests/web-platform-teststo find specific tests that cover edge cases that might fail in naive implementations.
Every auditor should:
- Read the relevant spec in the submodule.
- Compare with the current implementation in the corresponding file.
- Identify non-compliance, missing features, or technical debt.
- Report findings with specific spec references and actionable recommendations.
The scripts/external_suites/extract_wpt.ts script reads from the submodules and generates JSON fixtures used by the tests. If you add new test files to WPT or need to support new properties, you may need to update this script or run it to include the new data.
Note: We rely on Node's ability to run .ts files directly (supported in Node 24.11.0+), so no build step is needed for scripts.