Skip to content

Fix Input#origin() without from or with relative sourceRoot - #2179

Merged
ai merged 1 commit into
postcss:mainfrom
wleeaf:origin-source-url
Oct 26, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
wleeaf:origin-source-url

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

When the input CSS has a previous source map, every CssSyntaxError goes through Input#origin(). That method builds the URL of the original file with new URL(from.source, sourceRoot || pathToFileURL(mapFile)), which throws in two cases. A TypeError then replaces the syntax error, so the user never sees what is wrong with their CSS.

  1. There is no from and no map file, for example with an inline map. pathToFileURL(undefined) throws The "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 because from is undefined.
  2. The map has a relative sourceRoot such as ../src. source-map-js already prefixes from.source with sourceRoot, and then sourceRoot is used again as the URL base, so new URL('../src/b.css', '../src') throws Invalid URL.

Now from.source is 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 without from. With a relative sourceRoot, origin() now points to the same file as the generated map does. Absolute paths and URL sourceRoot values give the same result as before, because from.source is already absolute in those cases.

I added two tests in test/css-syntax-error.test.ts, one for each case. Both fail on main with the TypeError. pnpm unit, test:lint, test:types, test:coverage and test:size pass.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed source-map paths for relative sources. They now resolve relative to the map file’s directory, or the current working directory when no map file is specified, so mapped error locations point to the expected files.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0be3052c-92da-47b0-b42a-9acf1557dd2b
Commits

Reviewing files that changed from the base of the PR and between d190857 and a499dd0.

Files selected for processing: 2
  • lib/input.js
  • test/css-syntax-error.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Input.origin resolves relative source-map sources against the map file’s directory, or the current working directory when no map file is set. Tests cover both cases and verify mapped file paths, lines, and columns.

Changes: Source Map Resolution

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: Normal

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: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix and its two triggering cases: missing from and relative sourceRoot in Input#origin(). The raw summary confirms the change in lib/input.js resolves relative sources agains…
Docstring Coverage Passed 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…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its two triggering cases: missing from and relative sourceRoot in Input#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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ai
ai merged commit f70f586 into postcss:main Oct 26, 2026
15 of 21 checks passed
@ai

ai commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thanks. Released in 8.5.32.

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