Repository navigation
Conversation
…ng file The "never appears in <file>" error for `composes: x from "./other.css"` was added to the log with the imported file's Source but with the Loc of the composes declaration, which is an offset into the composing file. The reported location was therefore the other file, at whatever line that offset happened to land on. Attach it to the composing file, like the same-file variant and like esbuild.
|
Warning Review limit reached
Next review available in: 1 minute Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Comment |
|
Status: ready for review. Reproduced on bun 1.4.0 with Tests: The CodeRabbit comments above are only its rate-limit notices; nothing to address from them. |
… the composes declaration warn_non_single_class_composes took one source index and used it both for the definition note and for the composes declaration. In the cross-file arm that index is the file defining the name, while compose.loc is an offset into the composing file, so the error was reported in the wrong file at an unrelated line. Take both indices: the error goes on the composing file, the note stays on the definition.
There was a problem hiding this comment.
LGTM — the follow-up commits addressed the sibling warn_non_single_class_composes mismatch and the comment-cop notes.
What was reviewed:
validate_css_import_composes: error now attached toinput_files[id]withcompose.loc; message still namesother_source.path.pretty.warn_non_single_class_composes: split intodefinition_idx(note viarange_data) andcomposing_idx(primary viaadd_range_error_fmt_with_notes); both call sites pass the right pair.- New tests assert exact file/line/column/lineText for both errors and their notes, cross-file and same-file.
Extended reasoning...
Overview
This PR fixes two CSS modules composes diagnostics that paired a byte offset from the composing file with the imported file's Source, producing correct message text but wrong file/line/excerpt. Changes: scanImportsAndExports.rs (validate_css_import_composes — swap the Source to the composing file, keep the searched file's name in the message text), generateCodeForLazyExport.rs (warn_non_single_class_composes — take separate definition_idx/composing_idx, build the note with range_data against the defining file and the primary with add_range_error_fmt_with_notes against the composing file), and test/bundler/esbuild/css.test.ts (two existing tests moved their expected errors under /styles.module.css; two new tests assert exact position and lineText for every error and note via Bun.build).
Prior feedback addressed
My earlier review flagged that the cross-file arm of visit_composes still passed import_record.source_index.get() as the sole index to warn_non_single_class_composes, keeping the same mismatch for the "not a single class name" error. Commit a6acf80 fixes it exactly as suggested (two indices, range_data + add_range_error_fmt_with_notes, matching the shape used elsewhere in the linker for multi-file notes), and css/ImportCSSFromJSComposesNonClassNameLocation now locks the primary at styles.module.css:5:12 with the note at other.module.css:4:1. The comment-cop notes about long inline comments were addressed in 413329d — the parameter names source/other_source and definition_idx/composing_idx carry the intent.
Security risks
None. This only changes which Source a diagnostic Loc is resolved against; no parsing, allocation, or control-flow changes on the success path.
Level of scrutiny
Low-to-medium. The change is a targeted diagnostic-location fix with no effect on generated output. I confirmed add_range_error_fmt_with_notes (src/ast/lib.rs:1750) resolves the primary against its source argument while each note carries its own Location via range_data (src/ast/lib.rs:2753), so the two-source split is sound. add_error_fmt returns (), so dropping the old let _ = is harmless. visit_composes is always entered with idx = the file whose ast.composes is being iterated, so compose.loc is always an offset into all_sources[idx] and the same-file arm passing idx, idx is unchanged in behavior.
Other factors
The new tests use backend: "api" + onAfterApiBundle to inspect build.logs positions directly, cover two names in one declaration, and include a same-file control for each cross-file case. The author verified the four affected tests fail on 1.4.0 and pass with the change, and that the rest of css.test.ts and css-modules.test.ts still pass.
|
Closing this PR because it has been inactive for more than 90 days. |
Problem
composes: name from "./other.css"errors are located in the wrong file. The message text is right, but the file, line and excerpt are those ofother.css, at whatever line a byte offset taken from the composing file happens to land on (clamped to the end ofother.csswhen it is shorter):The name "zzz" never appears in "other.css" as a CSS modules locally scoped class name...whenother.csshas no localzzz(src/bundler/linker_context/scanImportsAndExports.rs,validate_css_import_composes).The composes property cannot be used with "zzz", because it is not a single class name.whenother.cssdefineszzzas something other than a class, e.g.#zzz(src/bundler/linker_context/generateCodeForLazyExport.rs,warn_non_single_class_composes). ItsThe definition of "zzz" is here.note was already correct.Sourceandcompose.loc, which is an offset into the composing file. In the second site this happened because the function took one source index and used it for both the note (definition, other file) and the error (declaration, composing file).composes: zzz;), locate these errors on thecomposesdeclaration. The mismatch dates back to the CSS modules implementation; two existing tests encoded the wrong file.Fix
validate_css_import_composes: attach the error to the composing file'sSource(input_files[id]); the message still names the file that was searched.warn_non_single_class_composes: take the composing file's index alongside the defining file's. The error is attached to the composing file atcompose.loc; the note is built withrange_dataagainst the defining file, the same way the linker builds its other multi-file notes (add_range_error_fmt_with_notes). The same-file arm passes the same index twice and is unchanged in behavior.compose.locis recorded by thecomposesvalue parser as a position in the file being parsed, so it can only be resolved against that file's contents; every other composes diagnostic in these two functions already pairs sources and offsets this way.css/ImportCSSFromJSComposesFromMissingImportandcss/ImportCSSFromJSComposesImportedNonClassnow expect the errors understyles.module.css(they expected the imported file, including the case where it is a plain, non-module stylesheet).css/ImportCSSFromJSComposesFromMissingImportLocationandcss/ImportCSSFromJSComposesNonClassNameLocationcheck file, line, column and line text of every error and note reported byBun.build: two names in one cross-filecomposes, a cross-file non-class name, and a same-file case of each for comparison. The notes still point at the definitions in the other file.USE_SYSTEM_BUN=1 bun test) and pass withbun bd test; the rest of css.test.ts and test/bundler/css/css-modules.test.ts pass.Background
composesis the CSS modules property that makes one class's exported name also include other classes.composes: a from "./x.css"looksaup amongx.css's locally scoped names. The linker validates that lookup twice:validate_css_import_composeswhile scanning imports (is the name there at all), andgenerate_code_for_lazy_exportwhile building the file's export object (is it a class that can be composed).Source(one input file) and aLoc(byte offset). Line, column and excerpt are computed by resolving the offset against thatSource's contents, so theSourcehas to be the file the offset was taken from. A note is a second such (text,Source, offset) triple attached to the message and may point into a different file.Before / after with
bun build entry.js --outdir outstyles.module.csshas a ~200 byte comment before.foo { composes: zzz from "./file.module.css"; };file.module.cssis the one-line.x{color:red}.Before (1.4.0):
After:
esbuild reports the same thing as
styles.module.css:4:12: ERROR: The name "zzz" never appears in "file.module.css" ....Same layout, but
other.module.cssis#bar {\n color: blue;\n}and the declaration iscomposes: bar from "./other.module.css". Before:After: