Skip to content

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

Open
apoorva-01 wants to merge 1 commit into
python-babel:masterfrom
apoorva-01:fix/770-crlf-jslexer-line-numbers
Open

Fix JS extractor line numbers being off on CRLF files#1288
apoorva-01 wants to merge 1 commit 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

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.

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.
@apoorva-01 apoorva-01 force-pushed the fix/770-crlf-jslexer-line-numbers branch from 23bcec7 to c1e2875 Compare July 2, 2026 02:51
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

1 participant