Skip to content

Fix JS extractor line numbers being off on CRLF files - #1288

Merged
akx merged 2 commits into
python-babel:masterfrom
apoorva-01:fix/770-crlf-jslexer-line-numbers
Oct 30, 2026
Merged

akx merged 2 commits into
python-babel:masterfrom
apoorva-01:fix/770-crlf-jslexer-line-numbers

Conversation

@apoorva-01

@apoorva-01 apoorva-01 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #770.

The JS extractor reports different line numbers by line ending: a call after three comment lines shows on line 4 with LF but line 7 with CRLF.

It's the // and <!-- comment rules in jslexer. They match with .*, and . eats the \r of a CRLF, so the comment token keeps a trailing \r that gets counted as a newline, then the \n is counted again, two lines per comment. Switching both to [^\r\n]* stops the comment before the newline so the \r\n counts once. Added tests that LF and CRLF line numbers match.

Left CHANGES.rst alone since that's filled in at release, happy to add an entry.

@apoorva-01
apoorva-01 force-pushed the fix/770-crlf-jslexer-line-numbers branch from 23bcec7 to c1e2875 Compare July 2, 2026 02:51
The // and <!-- comment rules matched with .*, which eats the \r of a
CRLF, so the comment kept a trailing \r counted as a newline (and the \n
again). Restrict both to [^\r\n] so the pair counts once.
@akx
akx force-pushed the fix/770-crlf-jslexer-line-numbers branch from c1e2875 to 9e49025 Compare October 30, 2026 09:15
@akx
akx self-requested a review October 30, 2026 09:15
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.54%. Comparing base (3fd4be9) to head (ada27e4).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1288      +/-   ##
==========================================
+ Coverage   93.53%   93.54%   +0.01%     
==========================================
  Files          27       27              
  Lines        4931     4930       -1     
==========================================
  Hits         4612     4612              
+ Misses        319      318       -1     
Flag Coverage Δ
macos-14-3.10 92.63% <ø> (+0.01%) ⬆️
macos-14-3.11 92.57% <ø> (+0.01%) ⬆️
macos-14-3.12 92.77% <ø> (+0.01%) ⬆️
macos-14-3.13 92.77% <ø> (+0.01%) ⬆️
macos-14-3.14 92.75% <ø> (+0.01%) ⬆️
macos-14-3.15 92.75% <ø> (+0.01%) ⬆️
macos-14-3.8 92.51% <ø> (+0.01%) ⬆️
macos-14-3.9 92.57% <ø> (+0.01%) ⬆️
macos-14-pypy3.10 92.63% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.10 92.65% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.11 92.59% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.12 92.79% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.13 92.79% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.14 92.77% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.15 92.77% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.8 92.53% <ø> (+0.01%) ⬆️
ubuntu-24.04-3.9 92.59% <ø> (+0.01%) ⬆️
ubuntu-24.04-pypy3.10 92.65% <ø> (+0.01%) ⬆️
windows-2022-3.10 92.64% <ø> (+0.01%) ⬆️
windows-2022-3.11 92.58% <ø> (+0.01%) ⬆️
windows-2022-3.12 92.79% <ø> (+0.01%) ⬆️
windows-2022-3.13 92.79% <ø> (+0.01%) ⬆️
windows-2022-3.14 92.77% <ø> (+0.01%) ⬆️
windows-2022-3.15 92.77% <ø> (+0.01%) ⬆️
windows-2022-3.8 92.62% <ø> (+0.01%) ⬆️
windows-2022-3.9 92.58% <ø> (+0.01%) ⬆️
windows-2022-pypy3.10 92.64% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing apoorva-01:fix/770-crlf-jslexer-line-numbers (ada27e4) with master (e01a236)

Open in CodSpeed

@akx

akx commented Oct 30, 2026

Copy link
Copy Markdown
Member

Could you rebase this to fix conflicts?

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the test cases a bit. Thank you.

@akx
akx enabled auto-merge (squash) October 30, 2026 10:48
@akx
akx merged commit 1208865 into python-babel:master Oct 30, 2026
36 checks passed
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.

Line number discrepancy with JavaScript extractor

2 participants