Repository navigation
Fix Input#origin() without from or with relative sourceRoot - #2179
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Relative source resolution and tests lib/input.js, test/css-syntax-error.test.ts |
Input.origin uses the map file’s directory as the base for relative sources, or the current working directory when no map file is set. Tests verify resolved paths and mapped positions. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: ai
Merge Risk: 
Minimal · up to a499d
-
The reported source-map cases are covered by the new tests. No issue introduced by this change remains identified, so it is ready for normal merge checks.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the fix and its two triggering cases: missing
fromand relativesourceRootinInput#origin(). The raw summary confirms the change in lib/input.js resolves relative sources against the map file directory or the current working directory, and the tests cover both cases. The title is specific and matches the main change.
Full details: Docstring Coverage
-
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
|
Thanks. Released in 8.5.32. |
When the input CSS has a previous source map, every
CssSyntaxErrorgoes throughInput#origin(). That method builds the URL of the original file withnew URL(from.source, sourceRoot || pathToFileURL(mapFile)), which throws in two cases. ATypeErrorthen replaces the syntax error, so the user never sees what is wrong with their CSS.fromand no map file, for example with an inline map.pathToFileURL(undefined)throwsThe "path" argument must be of type string. Received undefined. This is the crash in build failed with @parcel/optimizer-cssnano: The "path" argument must be of type string. Received undefined parcel-bundler/parcel#7522 from@parcel/optimizer-cssnano, where mischnic pointed out that the real error was a parser error that couldn't be printed becausefromis undefined.sourceRootsuch as../src.source-map-jsalready prefixesfrom.sourcewithsourceRoot, and thensourceRootis used again as the URL base, sonew URL('../src/b.css', '../src')throwsInvalid URL.Now
from.sourceis resolved against the map file, or against the current directory when there is none. This is also how map generation treats a previous map's sources withoutfrom. With a relativesourceRoot,origin()now points to the same file as the generated map does. Absolute paths and URLsourceRootvalues give the same result as before, becausefrom.sourceis already absolute in those cases.I added two tests in
test/css-syntax-error.test.ts, one for each case. Both fail onmainwith theTypeError.pnpm unit,test:lint,test:types,test:coverageandtest:sizepass.Summary by CodeRabbit