Skip to content

Deprecate the public functions of babel.messages.jslexer - #1459

Open
akx wants to merge 1 commit into
masterfrom
deprecate-jslexer-internals
Open

akx wants to merge 1 commit into
masterfrom
deprecate-jslexer-internals

Conversation

@akx

@akx akx commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

The lexer is an implementation detail of the JavaScript message extractor and has never been documented.

This renames functions there to underscore-prefixed names with wrappers under the old names that emit a DeprecationWarning.


Given how many bugs and corner cases there seem to be in the JS extractor, I have a grand plan to replace it outright with something better, probably in Babel 2.20. However, this has still been a public if undocumented module.

@akx akx added this to the Babel 2.19 milestone Nov 11, 2026
@akx
akx requested review from tomasr8 and a lite review from Copilot November 11, 2026 14:33
@akx akx added area/messages area/javascript JavaScript extractor labels Nov 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported, and the change preserves compatibility while covering the deprecated wrappers and internal helper usage in the reviewed updates.

No open issues 🎉

What changed in this PR

This PR deprecates the public JavaScript lexer helpers while preserving backward compatibility through warning-emitting wrappers. Internal extraction and lexer tests now use underscore-prefixed implementations.

Changes:

  • Renames tokenize, get_rules, and indicates_division to internal underscore-prefixed functions.
  • Adds deprecated compatibility wrappers that emit DeprecationWarning.
  • Updates JavaScript extraction and lexer tests to use internal helpers and verify deprecation behavior.
File Description
tests/​messages/​test_jslexer.py Updates lexer tests to use private helpers and verifies that deprecated wrappers emit warnings.
babel/​messages/​jslexer.py Adds underscore-prefixed lexer implementations and backward-compatible deprecation wrappers.
babel/​messages/​extract.py Updates JavaScript message extraction to use the private tokenizer.

Review effort: Lite

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.93%. Comparing base (3072a70) to head (dcd9458).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1459      +/-   ##
==========================================
- Coverage   93.67%   92.93%   -0.75%     
==========================================
  Files          27       27              
  Lines        4983     4994      +11     
==========================================
- Hits         4668     4641      -27     
- Misses        315      353      +38     
Flag Coverage Δ
macos-15-3.10 ?
macos-15-3.11 ?
macos-15-3.12 ?
macos-15-3.13 ?
macos-15-3.14 ?
macos-15-3.15 ?
macos-15-3.9 ?
macos-15-pypy3.10 ?
ubuntu-24.04-3.10 92.85% <100.00%> (+0.07%) ⬆️
ubuntu-24.04-3.11 92.79% <100.00%> (+0.07%) ⬆️
ubuntu-24.04-3.12 ?
ubuntu-24.04-3.13 ?
ubuntu-24.04-3.14 ?
ubuntu-24.04-3.15 ?
ubuntu-24.04-3.9 92.78% <100.00%> (+0.07%) ⬆️
ubuntu-24.04-pypy3.10 ?
windows-2022-3.10 ?
windows-2022-3.11 ?
windows-2022-3.12 ?
windows-2022-3.13 ?
windows-2022-3.14 ?
windows-2022-3.15 ?
windows-2022-3.9 ?
windows-2022-pypy3.10 ?

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.

@akx
akx force-pushed the deprecate-jslexer-internals branch from dcd9458 to 0a032f6 Compare November 11, 2026 14:37
The lexer is an implementation detail of the JavaScript message extractor
and has never been documented.

This renames methods there to underscore-prefixed names,
and leaves wrappers under the old names that emit a DeprecationWarning.
@akx
akx force-pushed the deprecate-jslexer-internals branch from 0a032f6 to 0ebcb83 Compare November 11, 2026 14:49

@tomasr8 tomasr8 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.

Looks good :)

I have a grand plan to replace it outright with something better

Looking forward to it 👍

Comment thread babel/messages/jslexer.py
def _warn_deprecated(name: str) -> None:
warnings.warn(
f"`babel.messages.jslexer.{name}` is an implementation detail of the JavaScript "
f"message extractor; it is deprecated and will be removed in a future version of Babel.",

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.

Super nitpicky, but this does not strictly need to be an f-string, but fine to leave as is if you prefer to keep the alignment:

Suggested change
f"message extractor; it is deprecated and will be removed in a future version of Babel.",
"message extractor; it is deprecated and will be removed in a future version of Babel.",

@akx
akx enabled auto-merge (squash) November 12, 2026 14:59
@codspeed

codspeed Bot commented Nov 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 88 untouched benchmarks


Comparing deprecate-jslexer-internals (0ebcb83) with master (3072a70)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (19d490d) during the generation of this report, so 3072a70 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants