Skip to content

feat: create_analyzer().add() for many inputs (stacked on #647) - #652

Draft
bartveneman wants to merge 25 commits into
claude/sleepy-tesla-tu72wqfrom
claude/incremental-analyzer
Draft

bartveneman wants to merge 25 commits into
claude/sleepy-tesla-tu72wqfrom
claude/incremental-analyzer

Conversation

@bartveneman

Copy link
Copy Markdown
Member

Stacked on #647. Re-adds the incremental multi-input API that was split off to keep #647 small: create_analyzer(collectors).add(css, { source }).result() and analyzer.parse_options. In #647, analyze(input, collectors, options?) is the only entry point.

The branch is #647 plus a revert of the removal commit, so merging it later is a clean re-add.


Generated by Claude Code

claude added 21 commits November 7, 2026 18:49
Adds the new engine next to the legacy analyze(), exposed as the
temporary `./next` subpath until the old code is removed:

- adapter/css-parser: the only module that talks to the parser
- define_collector, create_analyzer, analyze and merge
- one count shape (create_counter, merge_counts, summarize) with
  opt-in locations
- declarative dispatch table: parse options follow subscriptions,
  one shared value walk, lazy memoized declaration facts
- incremental add() with per-file `source` on locations
- oxlint overrides (prefer-const, function declarations, adapter-only
  parser imports) for the new code, plus a pkg.pr.new preview workflow

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Reworks the public utils on the /selectors, /values and /atrules
subpaths to one contract: input is `string | node`, output is plain
data. No callbacks, no parser nodes in results.

- get_specificity, compare_specificity, get_complexity (number[]),
  get_vendor_prefixes, get_accessibility_selectors, get_combinators
- analyze_animation, destructure_font_shorthand, is_value_reset,
  get_prefixed_values, get_value_browserhacks
- get_supports_browserhacks, get_media_browserhacks
- colour keyword sets renamed to snake_case
- remove deprecated is_ie9_hack

The legacy analyze() is adapted to the new utils and its output is
unchanged. Adds contract tests (text vs node parity) for each util.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ports the nine collectors css-design-tokens reads onto the new engine:
colors (+ formats, per-property counts), font_sizes, font_families,
line_heights, gradients, box_shadows, border_radiuses, durations and
timing_functions, exposed on the new ./collectors subpath. The
./presets subpath adds analyze_design_tokens and design_tokens_collectors.

Engine additions the collectors needed:
- value handlers receive the node kind
- lazy, shared ctx facts: clean_value_text and font_shorthand
- context counters track contexts only with `contexts: true`

Output matches the 9.x analyzer on a fixture covering all nine
(parity test). Deliberate differences: contexts are keyed by the
normalized property, and values are lowercased consistently.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Covers the stylelint use cases next to colors: max-unique-z-indexes,
max-unique-colors and max-average-selector-specificity.

- z_indexes counts z-index values
- specificity counts every selector as "a,b,c"; summarize_specificity
  derives min, max, sum, mean and mode and matches the 9.x analyzer
- summarize_numbers/summarize_frequencies derive min, max, range, sum,
  mean, mode and median from counted values, so averages stay mergeable
  across files and runs
- the engine no longer descends into selectors nested in :is()/:not(),
  so each selector is dispatched once

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds the collectors for every other group of the 9.x report, so the
full report can now be built from collectors:

- stylesheet (size, lines, comments, embedded content)
- atrules (all at-rules incl. font-face, import, media, supports,
  keyframes, container, layer, property, function, scope)
- rules, selectors, declarations, properties
- text_shadows, displays, units, keywords, resets, value_prefixes,
  value_browserhacks, value_complexity, animation_names

Names that are defined and used (keyframes, containers, layers,
custom properties, anchor names) are tracked per collector and merge
across files. Numeric series are stored as counted values so min, max,
mean, mode and median stay derivable and mergeable.

Every group has a parity test against the 9.x analyzer on one fixture.
The engine now skips @supports conditions, so they are no longer
mistaken for declarations.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- analyze_all: every collector in one call, flat snake_case result
  (one key per collector), mergeable with merge()
- analyze_compat: the 9.x report (nested, camelCase, same numbers),
  built from the collectors; `useLocations` and `__meta__` are gone
- opt-in `sequence: true` on the counting collectors keeps numeric
  series in source order (9.x `items`, used for charts); compat turns
  it on
- context collectors take `property: 'as_written'` for 9.x-style
  per-property keys; compat uses it
- `pnpm test:compat` runs the existing 9.x topic tests against
  analyze_compat (tests about useLocations are skipped); CI runs it
- shared fixtures, preset tests and a knip config that treats every
  test file as an entry

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…alyzer

The new API now lives at `.`: analyze, create_analyzer, merge,
define_collector, the counters and summaries. The 9.x analyze() is
gone; `analyze_compat` from `/presets` returns the same report.

- delete the monolithic analyze(), useLocations, Collection,
  ContextCollection and AggregateCollection, plus deprecated exports
  (hasVendorPrefix, isIe9Hack)
- freeze the 9.9.6 output as golden JSON; analyze_compat must match it
- run the 9.x topic tests against analyze_compat; port the
  useLocations tests to collectors
- apply prefer-const and function declarations to all of src, rename
  the remaining camelCase helpers
- drop the temporary `./next` subpath and the compat test config
- rewrite the readme for pnpm and the collector API; add MIGRATION.md

BREAKING CHANGE: see MIGRATION.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… selectors); rename remaining camelCase locals to snake_case

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 9.x topic tests ran the whole analyzer for every case. They are now
unit tests that live next to the code they test:

- one test file per collector in src/collectors, each running only that
  collector (src/test-utils.ts has plain() and series() to compare
  results)
- direct tests for the utilities (specificity, complexity, font
  shorthand, browserhacks, prefixes, resets, property helpers) and for
  the adapter, using test.each tables
- the only integration test left is the compat preset against the
  golden 9.x output
- add CONTRIBUTING.md with the style and test conventions

Also rename all remaining camelCase locals, parameters and helpers to
snake_case, and fix walk_value reporting the value node itself.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
pkg.pr.new publishes previews to its own registry, not npm, so the
trusted publishing audit does not apply.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Remove our own preview workflow; main now has pkg-pr-new.yml.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The adapter layer was 435 lines of mostly thin wrappers for a parser
swap that is not planned. Simplicity wins over flexibility:

- the engine parses and walks with css-parser directly; collector
  handlers get typed nodes (Declaration, Rule, Atrule, Selector)
- helpers that only one collector needs now live in that collector;
  the small shared ones are in collectors/shared.ts
- text-or-node input handling for the utilities moves to src/input.ts
- remove the lint rule that restricted parser imports

No behaviour change: the full suite, golden 9.x output included, still
passes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The 9.x compatibility layer (analyze_compat, compat_collectors, the
golden 9.x output and the tests that use them) moves to its own pull
request so the package stays smaller and it can be revisited later.

The core keeps what compat needed from the collectors: `sequence`,
`property: 'as_written'`, and the collectors themselves. The tests that
ran through analyze_compat now run the collectors directly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Review feedback:
- the lint rules (prefer-const, no-var, func-style) are global settings
  now instead of an override for src
- enforce `curly` and add braces to the 100+ single-line ifs
- tsdown builds the main entry and src/*/index.ts with a glob
  (the engine index stays internal)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…perty

Review feedback:
- every `.text`, `.name`, `.block`, `.prelude` read hits the parser's
  arena: read them once and reuse (at-rules, rules, selectors,
  properties, keywords, animations, browserhacks, the shared context)
- replace the `...(cond ? { x } : {})` pattern with explicit
  `undefined` (location `source`, locations of font faces and embedded
  content, sequences)
- track `@property` registrations as defined and `var()` as used, like
  keyframes, containers and layers (atrules `properties`)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merging results of separate runs (`merge()`, `merge_counts`,
`merge_context_counts`, `merge_defined_used` and the `merge` function
every collector had to provide) moves to its own pull request, to keep
this one smaller to review and the package smaller to ship.

`create_analyzer().add()` stays: it covers many inputs in one analyzer.
`define_collector(init)` now takes just the init function.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…r out of this PR

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@projectwallace/css-analyzer@c9f49a4

commit: c9f49a4

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bartveneman
bartveneman force-pushed the claude/incremental-analyzer branch from 229c7c0 to 26bf8d5 Compare November 7, 2026 19:15
…, test.each for browserhack tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bartveneman
bartveneman force-pushed the claude/incremental-analyzer branch from 26bf8d5 to c9f49a4 Compare November 7, 2026 19:25
@bartveneman
bartveneman force-pushed the claude/sleepy-tesla-tu72wq branch from b9224e1 to 4157128 Compare November 8, 2026 21:54
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