Skip to content

Conversation

Sysix
Copy link
Member

@Sysix Sysix commented Aug 22, 2025

This PR adds the function to parse TemplateLiterals.
If the new RegExp(${variable}) or new RegExp("", ${foo}) the parsing will be skipped, this is a different behavior then for StringLiterals.
https://github.com/eslint/eslint/blob/5082fc206de6946d9d4c20e57301f78839b3b9f2/tests/lib/rules/no-misleading-character-class.js#L91-L93
I would like to have a strict algo, when a regexp will be parsed and not. Currently, every rule does it by its own.

r"new RegExp('\\u{1F}', flags)", // unknown flags, we assume no 'u'

Moved some structs into the parent directory, so it can be consumed by both parsers. I guess ParserTrait could be helpful to share common methods like

  • consume_hex_digits
  • parse_unicode_escape_sequence

@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Aug 22, 2025
Copy link
Member Author

Sysix commented Aug 22, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

codspeed-hq bot commented Aug 22, 2025

CodSpeed Instrumentation Performance Report

Merging #13265 will not alter performance

Comparing 08-22-fix_regex-parser_parse_simple_templateliterals_ (9a205d1) with main (08c05df)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (9a205d1) during the generation of this report, so 08c05df was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from f146713 to ada0a39 Compare August 22, 2025 17:40
@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch 3 times, most recently from a2bde20 to e7f8ca4 Compare August 24, 2025 11:29
@Sysix Sysix changed the title fix(regex-parser): parse simple TemplateLiterals feat(regex-parser): parse simple TemplateLiterals Aug 24, 2025
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Aug 24, 2025
@Sysix Sysix added C-enhancement Category - New feature or request and removed C-bug Category - Bug C-enhancement Category - New feature or request labels Aug 24, 2025
@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from e7f8ca4 to f2c2e12 Compare August 28, 2025 18:37
@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch 2 times, most recently from c94aa23 to c2a7238 Compare August 30, 2025 14:53
@Sysix Sysix marked this pull request as ready for review September 1, 2025 18:53
@Copilot Copilot AI review requested due to automatic review settings September 1, 2025 18:53
@Sysix Sysix requested a review from camc314 as a code owner September 1, 2025 18:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements parsing of simple template literals in the regex parser, extending support beyond string literals to include template literals like new RegExp(\pattern`)`. The implementation skips parsing when template literals contain expressions/substitutions.

  • Adds a new template_literal_parser module with full template literal parsing capability
  • Refactors shared code (AST types, options, characters) to be accessible by both string and template literal parsers
  • Updates regex utility functions to handle template literal arguments in RegExp constructors

Reviewed Changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/oxc_regular_expression/src/parser/reader/template_literal_parser/parser_impl.rs Core template literal parser implementation with escape sequence handling
crates/oxc_regular_expression/src/parser/reader/template_literal_parser/mod.rs Module definition and comprehensive test cases
crates/oxc_regular_expression/src/parser/reader/template_literal_parser/diagnostics.rs Error diagnostics specific to template literal parsing
crates/oxc_regular_expression/src/parser/reader/template_literal_parser/ast.rs AST structure for template literals
crates/oxc_regular_expression/src/parser/reader/reader_impl.rs Updated reader to detect and parse template literals
crates/oxc_regular_expression/src/parser/reader/mod.rs Module restructuring to expose shared components
crates/oxc_regular_expression/src/parser/reader/ast.rs Shared CodePoint AST structure moved from string parser
crates/oxc_linter/src/utils/regex.rs Enhanced regex utilities to handle template literal arguments

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Sysix Sysix requested a review from leaysgur September 1, 2025 19:00
@camc314 camc314 marked this pull request as draft September 2, 2025 03:02
@camc314 camc314 self-assigned this Sep 2, 2025
@camc314
Copy link
Contributor

camc314 commented Sep 2, 2025

@Sysix somehow this has ended up with conflicts 🫠

@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from c2a7238 to 1774721 Compare September 2, 2025 16:23
@Sysix Sysix changed the base branch from main to graphite-base/13265 September 2, 2025 16:40
@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from 1774721 to 0eaa86f Compare September 2, 2025 16:40
@Sysix Sysix changed the base branch from graphite-base/13265 to 09-02-fix_linter_don_t_panic_when_parsing_regex_with_multiple_parentheses September 2, 2025 16:40
@graphite-app graphite-app bot changed the base branch from 09-02-fix_linter_don_t_panic_when_parsing_regex_with_multiple_parentheses to graphite-base/13265 September 2, 2025 16:51
@graphite-app graphite-app bot force-pushed the graphite-base/13265 branch from a82939e to 7e78e39 Compare September 2, 2025 16:56
@graphite-app graphite-app bot force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from 0eaa86f to 455236e Compare September 2, 2025 16:56
@graphite-app graphite-app bot changed the base branch from graphite-base/13265 to main September 2, 2025 16:56
@graphite-app graphite-app bot force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from 455236e to b7a07ca Compare September 2, 2025 16:57
@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch 2 times, most recently from d8ce816 to ca4f52f Compare September 2, 2025 19:10
@Sysix Sysix marked this pull request as ready for review September 2, 2025 19:15
@leaysgur
Copy link
Member

leaysgur commented Sep 3, 2025

Sorry for the slow response! 🙇🏻

I try to review by Saturday(during the flight), or at the latest by next Tuesday.

@Sysix
Copy link
Member Author

Sysix commented Sep 3, 2025

No need to rush, glad you're offering your help with the regex parser

Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

@Sysix Sorry for the delay!

As you noticed, there is still room for reducing duplicate lines, but I think we can address that at another time.

@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from ca4f52f to 7ae6a05 Compare September 9, 2025 17:11
@Sysix Sysix requested a review from leaysgur September 9, 2025 17:15
@Sysix Sysix force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from 7ae6a05 to 02a2ba8 Compare September 10, 2025 17:40
@leaysgur
Copy link
Member

@Sysix LGTM 👏🏻

@camc314
I've finished reviewing the regex parser part(oxc_regular_expression/*).
Would you please review the usage part(oxc_linter/*) and merge after that?

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Sep 11, 2025
Copy link
Contributor

camc314 commented Sep 11, 2025

Merge activity

@Sysix
Copy link
Member Author

Sysix commented Sep 11, 2025

@leaysgur thanks you, your approval is needed 🫶

Copy link
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

🚀

This PR adds the function to parse `TemplateLiteral`s.
If the `new RegExp(`${variable}`)` or `new RegExp("", `${foo}`)` the parsing will be skipped, this is a different behavior then for `StringLiteral`s.
https://github.com/eslint/eslint/blob/5082fc206de6946d9d4c20e57301f78839b3b9f2/tests/lib/rules/no-misleading-character-class.js#L91-L93
I would like to have a strict algo, when a regexp will be parsed and not. Currently, every rule does it by its own.
https://github.com/oxc-project/oxc/blob/2cd4c7b42cd7d4d455dd1f64ee453e05d5da26ef/crates/oxc_linter/src/rules/eslint/no_control_regex.rs#L322

Moved some structs into the parent directory, so it can be consumed by both parsers. I guess `ParserTrait` could be helpful to share common methods like
-  consume_hex_digits
- parse_unicode_escape_sequence
@graphite-app graphite-app bot force-pushed the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch from 02a2ba8 to 9a205d1 Compare September 11, 2025 23:09
@graphite-app graphite-app bot merged commit 9a205d1 into main Sep 11, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 08-22-fix_regex-parser_parse_simple_templateliterals_ branch September 11, 2025 23:15
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 11, 2025
camc314 added a commit that referenced this pull request Sep 16, 2025
## [1.16.0] - 2025-09-16

### 🚀 Features

- 97c8d06 linter: Add `preserve-caught-error` rule (#13748) (孔辉)
- 8c19b18 linter/exhaustive-deps: Implement fixer for dep in global
scope (#13783) (camc314)
- 06bce8f linter/exhaustive-deps: Implement fixer for missing dep
(#13782) (camc314)
- a8675f4 linter: Add eslint/class-methods-use-this rule (#12977) (Peter
Cardenas)
- db33196 parser: Adds typescript rule for empty argument list (#13730)
(Karan Kiri)
- 2751193 linter: Add `eslint/no-useless-computed-key` rule (#13428)
(yefan)
- 9a205d1 regex-parser: Parse simple `TemplateLiterals` (#13265) (Sysix)

### 🐛 Bug Fixes

- a2c91cd linter: Drop `rules` to allow mutable access to `ctx_host` in
`run_external_rules` (#13832) (camc314)
- 3af1e5d linter/no-unsafe-declaration-merging: Always mark first span
as primary (#13830) (camc314)
- 1c43c7c linter: Keep message when merging composite fixes (#13827)
(camc314)
- 26af302 linter/exhaustive-deps: Check stable value is on lhs of
assignment expr (#13815) (camc314)
- 4bc12d0 linter/exhaustive-deps: Remove impossible comparison with
parent kind (#13814) (camc314)
- 12baf5e linter/exhaustive-deps: Respect primary span when identifying
disable directive location (#13781) (camc314)
- fa7400a linter/no-undef: False positive with `arguments` in functions
(#13763) (camc314)
- 50e6e3c editor: Restrict servers paths for `oxc.path.server` (#13740)
(Sysix)
- b45077d editor: Strip leading slash for bin path on windows (#13738)
(Sysix)
- 8fa6227 editor: Don't allow `oxc.path.server` for untrusted workspaces
(#13734) (Sysix)
- 56da114 linter/react/jsx-handler-names: Do not detect the function
name within the inline-function's body block (#13456) (Takuji Shimokawa)
- b2bc5b4 linter/react-perf/jsx-no-new-object-as-prop: Skip as/satisfies
exprs (#13718) (camc314)
- ab51394 raw_transfer: Disable layout assertions on some 32-bit
platforms (#13716) (overlookmotel)
- 09428f6 linter/plugins: Remove outdated comment (#13691)
(overlookmotel)
- a294721 linter/plugins: Exit early if JS plugins enabled on
unsupported platforms (#13689) (overlookmotel)
- 68a2280 linter/plugins: More graceful exit for
`--experimental-js-plugins` CLI option (#13688) (overlookmotel)

### 🚜 Refactor

- 395d40d linter: Derive inmpls for `PartialEq`, `Eq` over manual ones
(#13828) (camc314)
- 8e4cd8f linter/func-names: Use `run_once` over looping over all nodes
(#13798) (camc314)
- 7f4e2fe eslint/func-names: Clean up implementation and improve
documentation (#13601) (Antoine Zanardi)
- 137896a language_server: Split options for linting and formatting
(#13627) (Sysix)
- 7346099 linter: Move `oxlint` application code into separate module
(#13745) (overlookmotel)
- 6dd4107 linter: Remove `#[cfg(test)]` attributes from `tester` module
(#13714) (overlookmotel)
- c40c6ef linter/plugins: Directory for JS plugins-related code (#13701)
(overlookmotel)
- a0022c1 linter/plugins: Improve error messages for JS plugins (#13699)
(overlookmotel)
- 1fd993f napi/oxlint: Rename `napi/oxlint2` to `napi/oxlint` (#13682)
(overlookmotel)

### ⚡ Performance

- 90c8286 linter: Detect node types from `let..else` statements (#13690)
(camchenry)
- 08c05df semantic: Make CFG construction a compile-time feature
(#13678) (Boshen)

### 🎨 Styling

- 99a7638 linter: Add comments + re-organise imports (#13715)
(overlookmotel)

### 🧪 Testing

- 18a1145 linter: Add debug assertions for skipping rules (#13724)
(camc314)
- cb080de linter/no-unused-vars: Add test for non ASCII chars in JSX
components (#13820) (camc314)
- b6eba27 linter/no-undef: Add more test cases for `arguments` (#13764)
(camc314)
- fb2d087 linter: Set CWD for tests (#13722) (overlookmotel)

Co-authored-by: camc314 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants