Skip to content

Fix invalid source map mapping on escaping before new line - #2169

Merged
ai merged 1 commit into
postcss:mainfrom
Rufflet:fix-escape-source-map
Oct 11, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
Rufflet:fix-escape-source-map

Conversation

@Rufflet

@Rufflet Rufflet commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fix #2168

When SafeStringifier.escapeHTML escapes the output, the whole string is passed to the builder with the node and no type. MapGenerator then adds both start and end mappings. The end mapping uses column - 2, which assumes the string ends with the node's last char. For Root, the string ends with raws.after, so \n there gives generated.column: -1, and source-map-js prints Invalid mapping.

Now only the start is mapped. The source map is already coarse in this branch.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed source-map handling when HTML characters are escaped in CSS before a newline, preventing invalid mappings and related console warnings.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bb2a5a46-9252-49ff-a575-d7c05ff98cae

📥 Commits

Reviewing files that changed from the base of the PR and between 1fd8f88 and e8f9fa7.


📒 Files selected for processing (2)
  • lib/stringify.js
  • test/map.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

Walkthrough

When HTML escaping changes CSS output, SafeStringifier.escapeHTML now marks the escaped text as a node start mapping. A regression test checks escaped CSS containing <style before a newline and verifies that no source-map warning occurs.

Changes

CSS source-map mapping

Layer / File(s) Summary
Mark escaped text as a start mapping
lib/stringify.js, test/map.test.ts
The escaping path passes the 'start' mapping type to the builder. The regression test checks the escaped output and verifies that console.warn is not called. Test cleanup restores spies.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: ai


Merge Risk: ⚪ Minimal · up to e8f9f

The change addresses the invalid source-map warning, and no concrete remaining merge-blocking issue is established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preventing invalid source-map mappings when escaping occurs before a newline.
Linked Issues check Passed Direct issue [#2168] requires removal of the generated.column: -1 / Invalid mapping warning when HTML escaping occurs before a newline. lib/stringify.js now calls `builder(escaped, node, 'start'…
Out of Scope Changes check Passed The changes remain within issue [#2168]. The production change limits source-map mapping for escaped output. The test change verifies the reported warning and restores spies during test cleanup. No un…


  • Fix all pre-merge checks with AI
✨ 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 6c9bc73 into postcss:main Oct 11, 2026
11 checks passed
@ai

ai commented Oct 11, 2026

Copy link
Copy Markdown
Member

Do you have a real issue or it is just theoretical issue from LLM?

@Rufflet

Rufflet commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Do you have a real issue or it is just theoretical issue from LLM?

It's a real one. I saw this warning in the nuxt dev console of my project (Nuxt 4.6, Vite 8.3.3, postcss 8.5.29 from Vite):

WARN  Invalid mapping: {"generated":{"column":-1,"line":18},"source":"RekaToastManager.vue%3Fvue&type=style&index=0&scoped=14957672&lang.css","original":{"column":0,"line":18},"name":null}

It was caused by a comment inside a Vue SFC <style scoped> block: /* … keep it in <style> */. The impact is small: only the console warning and one lost mapping. I already removed the comment in my project.

@ai

ai commented Oct 12, 2026

Copy link
Copy Markdown
Member

Thanks! The fix was released in 8.5.30.

pstreef added a commit to moderne-backpatch-alliance/backpatch-postcss that referenced this pull request Nov 22, 2026
Port of upstream "Fix invalid source map mapping on escaping before new line (postcss#2169)", which repairs the SafeStringifier
escaping of the previous commit.

Upstream-Commit: 6c9bc73
Co-authored-by: Alex Ershov <[email protected]>
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.

Invalid mapping (generated column -1) when CSS contains <style and HTML escaping applies

2 participants