Bun bounds CSS nesting expansion in two places. Home has neither. I ported one and it is not shippable alone — recording the full picture so the next attempt starts from here.
The two budgets
1. Printer stage — nesting_expansions on Printer, MAX_NESTING_EXPANSIONS = 65_536, checked in serialize_nesting, reset per prelude in StyleRule::to_css_base and ScopeRule::to_css. Raises PrinterErrorKind::maximum_nesting_expansion → "Maximum nesting expansion exceeded when compiling CSS nesting for the configured targets".
~/Code/bun/src/css/selectors/selector.rs:1322-1336~/Code/bun/src/css/printer.rs:155-160,:349~/Code/bun/src/css/rules/style.rs:181,~/Code/bun/src/css/rules/scope.rs:32~/Code/bun/src/css/error.rs:235,:262
2. Minify stage — selector_expansion_total / selector_expansion_multiplier on MinifyContext, MAX_SELECTOR_EXPANSION = 65_536, charged in StyleRule::charge_selector_expansion with the multiplier bumped by minify_nested_rules. Raises MinifyErrorKind::selector_expansion_limit_exceeded → "Nested CSS rules expand to more than {} selectors when compiled for the configured browser targets…".
~/Code/bun/src/css/rules/mod.rs:1227(constant),:1263(field)~/Code/bun/src/css/rules/style.rs:380-407~/Code/bun/src/css/error.rs:516,:538-542
They are not interchangeable. nested-selector-list-expansion.test.ts asserts the minify-stage message specifically.
What I tried, and why it was reverted
Porting budget 1 alone:
- Fixes
js/bun/css/nested-selector-expansion.test.ts: 2 pass / 2 fail → 4 pass / 0 fail, exact parity with pinned Bun.css.test.tsunchanged at 1064/29, runtime regressions 68/69. - But
js/bun/css/nested-selector-list-expansion.test.tsstarts exiting 133 (SIGTRAP). Its test results are unchanged (5 pass / 19 fail before and after, "Ran 24 tests" printed in full) — the abort happens at teardown, after the summary. Exit code went 1 → 133.
Printer.newError opens with bun.debugAssert(this.error_kind == null), so my first hypothesis was the budget firing twice on one printer. Guarding that (if (dest.error_kind != null) return PrintErr.CSSPrintError;) did not fix it, so the abort is elsewhere on the path a recorded-but-unconsumed printer error takes.
Reverted rather than shipped: a broken invariant is worse than one test at 2/2. The work is stashed locally as nesting-expansion port: fixes nested-selector-expansion 2/2->4/0 but introduces a teardown SIGTRAP in nested-selector-list-expansion.
Suggested order for the next attempt
- Port budget 2 (minify stage) first — it is what
nested-selector-list-expansionactually wants, and it may prevent the deep expansion from ever reaching the printer. - Then re-apply budget 1 and re-check the teardown exit code.
- Find who swallows a recorded
Printer.error_kindwithout consuming it; that is the latent bug the abort exposed, and it predates both budgets.
Refs #66