Repository navigation
css: require the import record list in StyleSheet::parse and an ImportInfo in StyleSheet::to_css - #47990
css: require the import record list in StyleSheet::parse and an ImportInfo in StyleSheet::to_css#47990robobun wants to merge 2 commits into
Conversation
…tInfo in to_css StyleSheet::parse took Option<&mut Vec<ImportRecord>>. StyleSheet::to_css and StyleAttribute::to_css took Option<ImportInfo>. No caller has a reason to pass None: a style sheet can hold a url(), the parser rejects a url() when there is no list, and the printer cannot print one with no table. Two callers passed None by mistake: build_css_output (both arguments, #38528) and bun pm diff (the print side, #45307). The three signatures now take the value itself, as parse_bundler and StyleAttribute::parse already do. A caller that leaves the list out does not compile. parse_with takes the NonNull that both of its callers already have. The callers drop their Some(..). No behaviour change. Parser::new and to_css_with_writer keep the Option: a parser of one value (An+B, a color) and the linker's url-free blocks have no list.
|
Updated 8:06 PM PT - Nov 8th, 2026
❌ @robobun, your commit 2bd274a has some failures in 🧪 To try this PR locally: bunx bun-pr 47990That installs a local version of the PR into your bun-47990 --bun |
|
This PR changes three signatures and no behaviour, so there is no failing input to reproduce. What it prevents: with Before this PR that code compiles, and This PR (#47990) is stacked on #38528. CI on 2bd274a (build 138973): no test failed. Each test lane that ran passed all of its shards: Linux (alpine, debian, debian with ASAN, ubuntu, on x64 and aarch64), Windows (x64 and aarch64) and macOS aarch64. The four macOS x64 test shards did not run. Each one waited in the queue without an agent until it expired, four times in a row. |
…css-require-import-records
Stacked on #38528.
Behaviour change: none
Problem
StyleSheet::parsetakesOption<&mut Vec<ImportRecord>>.StyleSheet::to_cssandStyleAttribute::to_csstakeOption<ImportInfo>(src/css/css_parser.rs). A caller that passesNonecompiles.None, the parser rejects eachurl()withUnexpected token: url(...)and the printer fails withNo import records found. Two callers did that:build_css_output(bun build --no-bundle: keep css url() references instead of failing to parse #38528) andnormalize_cssofbun pm diff(install: fix regressions and older bugs found after the package manager consolidation #45307).Fix
&mut Vec<ImportRecord>andImportInfo, asparse_bundlerandStyleAttribute::parsealready do. The 8 callers drop theirSome(..).Noneafter bun build --no-bundle: keep css url() references instead of failing to parse #38528.Parser::newandto_css_with_writerkeep theOption: An+B,Bun.colorand the linker's url-free blocks have no list.Noneput back inbuild_css_output,cargo check -p bun_bundlergives twoE0308errors.test/bundler/css/,test/js/bun/css/,test/bundler/cli.test.tsandbun-pm-diff.test.tspass.Background
bun_ast::ImportRecordperurl(). The printer reads theurl()back from it throughImportInfo(src/css/printer.rs).url()as text with no list: the tests of bun build --no-bundle: keep css url() references instead of failing to parse #38528 pass, but a bundler caller that forgets its table then prints unresolved urls. Considered one parse-and-print entry point inbun_css: a new API, which needs a maintainer's decision.Downsides
StyleSheet::parse_with, whichparseandparse_bundlercall, is 16 bytes smaller. The binary keeps its size.Notes
Why a separate PR
The base of this PR is the branch of #38528. The repair of
bun build --no-bundleis two arguments in one function and is in that PR. This change reaches no user, so it can wait or be dropped without an effect on that repair.parse_withis the shared body ofparseandparse_bundler. It now takes theNonNullpointer to the list that both of them already have, and no longer anOptionof it.Callers
StyleSheet::parse:src/bundler/transpiler.rs(build_css_output),src/runtime/cli/pm_diff_normalize.rs(normalize_css),src/css_jsc/css_internals.rs(testing_impl).StyleSheet::to_css: the same three, andsrc/bundler/linker_context/prepareCssAstsForChunk.rs.StyleAttribute::to_css:src/css_jsc/css_internals.rs(attr_test).What keeps the
OptionParser::new(.., None, ..): the An+B parser insrc/css/css_parser.rsandBun.colorinsrc/css_jsc/color_js.rs. These grammars have nourl().to_css_with_writer(.., None, ..): the linker prints url-free blocks with it insrc/bundler/linker_context/generateCompileResultForCssChunk.rs.Printer::new(.., None, ..):Bun.color.What this does not guard
build_css_outputis a short copy of the bundler's CSS step. css: export view-transition pseudo-element classes from CSS modules #42729 repaired its symbol table and source index. The types here do not cover those.The text fallback, built and run
Parser::add_import_recordreturns a sentinel index when there is no list, andUrl::to_cssprints the text of theUrlfor that index (4 files insrc/css).build_css_outputkeeps its twoNones.@container style(composes: b from "./f.css")in a CSS module witherror: No import records found while printing.composes .. fromholds only an index.url()unresolved and exits 0. Today that caller fails.Open PRs that edit the same lines
with { type: "css" }as a module that exports a CSSStyleSheet in browser builds #41959 adds a callersheet.to_css(.., Some(ImportInfo::init_outside_of_bundler(..)), ..)insrc/bundler/css_module_script.rs. It must drop theSome(..)after this merges.src/css/css_parser.rs.Self-review
Parser::newchanges by one line.Measurements (release builds of #38528 and of this branch, linux x64)
bunis 140,478,752 bytes on both..textis 110,627,497 bytes on both.llvm-nm -S), 1 differs:StyleSheet::parse_with::<BundlerAtRuleParser>, 9,143 to 9,127 bytes and 1,719 to 1,715 instructions. It no longer tests theOption.StyleSheet::parse(282 bytes),parse_bundler(282),to_css_with_writer(1,535),StyleAttribute::to_css(1,231) andTranspiler::build_css_output(2,566) are equal on both.Noneput back at the two arguments inbuild_css_output,cargo check -p bun_bundlerprintserror[E0308]: mismatched types: expected &mut Vec<ImportRecord<'_>>, found Option<_>anderror[E0308]: mismatched types: expected ImportInfo<'_>, found Option<_>.--no-bundleprint the same bytes on both debug builds.Suites run on the debug build of this branch
test/bundler/cli.test.ts,test/bundler/css/,test/js/bun/css/,test/bundler/esbuild/css.test.ts,test/cli/install/bun-pm-diff.test.ts,test/bundler/bundler_loader.test.ts,test/bundler/bundler_html.test.ts: 3,956 pass, 48 skip, 4 todo, 0 fail.no test proof · iteration 2 · the description declares no behaviour change, so there is no failing test to prove; the existing suite in CI is the check