Skip to content

refactor(regular_expression): Refactor regexp-modifiers support#11142

Merged
leaysgur merged 3 commits intomainfrom
r/regexp-modifiers
May 19, 2025
Merged

refactor(regular_expression): Refactor regexp-modifiers support#11142
leaysgur merged 3 commits intomainfrom
r/regexp-modifiers

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented May 19, 2025

When I first implemented this proposal, it was Stage 3 and the specs were not even fixed.
But for now, this spec is in Stage 4 and has been cleared up, so I've updated it.

In the process, I have done some refactoring.

  • Shorten code by bitflags like RegExpFlags
    • This requires some lines to make ast_tools works
  • Update readme

NOTE: The basic behavior remains unchanged.

Copilot AI review requested due to automatic review settings May 19, 2025 07:55
@graphite-app
Copy link
Contributor

graphite-app bot commented May 19, 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.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label May 19, 2025
Copy link
Contributor

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 refactors regex modifier support to use bitflags, simplifies modifier parsing logic, and updates related AST tooling and documentation.

  • Switches from arrays to bitflags for representing modifiers in Modifiers
  • Refactors parse_modifiers to detect duplicates and overlaps via flag operations
  • Adds allocator/ContentEq support for Modifier and updates display logic
  • Updates README stage and adds bitflags dependency

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/oxc_regular_expression/src/parser/pattern_parser/pattern_parser_impl.rs Replaced enabling/disabling arrays with bitflags, simplified error checks in parse_modifiers
crates/oxc_regular_expression/src/ast_impl/span.rs Added ContentEq impl for Modifier
crates/oxc_regular_expression/src/ast_impl/mod.rs Introduced allocator module
crates/oxc_regular_expression/src/ast_impl/display.rs Updated Display impl to use Modifier::contains
crates/oxc_regular_expression/src/ast_impl/allocator.rs Implemented CloneIn for Modifier
crates/oxc_regular_expression/src/ast.rs Defined Modifier via bitflags! and added alias for ast_tools
crates/oxc_regular_expression/README.md Changed proposal stage from 3 to 4
crates/oxc_regular_expression/Cargo.toml Added bitflags dependency
Comments suppressed due to low confidence (3)

crates/oxc_regular_expression/src/parser/pattern_parser/pattern_parser_impl.rs:1583

  • [nitpick] The variable name duplicate is ambiguous; consider renaming it to has_duplicate_flag or duplicate_flag_detected for clarity.
let mut duplicate = false;

crates/oxc_regular_expression/src/parser/pattern_parser/pattern_parser_impl.rs:1651

  • [nitpick] This compound if condition combines multiple checks; consider extracting each check into well-named helper functions or separate if statements to improve readability and maintainability.
if enabling.is_empty() && disabling.is_empty() || duplicate || [ast::Modifier::I, ast::Modifier::M, ast::Modifier::S].iter().any(|&modifier| enabling.contains(modifier) && disabling.contains(modifier))

crates/oxc_regular_expression/src/parser/pattern_parser/pattern_parser_impl.rs:1578

  • Consider adding unit tests for scenarios such as duplicate modifier flags and overlapping enabling/disabling flags to verify the new error conditions.
fn parse_modifiers(&mut self) -> Result<Option<ast::Modifiers>> {

@codspeed-hq
Copy link

codspeed-hq bot commented May 19, 2025

CodSpeed Instrumentation Performance Report

Merging #11142 will not alter performance

Comparing r/regexp-modifiers (21bc19d) with main (240bcf3)

Summary

✅ 38 untouched benchmarks

@leaysgur

This comment was marked as resolved.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 19, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented May 19, 2025

Merge activity

  • May 19, 8:50 AM UTC: @leaysgur we removed the merge queue label because we could not find a Graphite account associated with your GitHub profile.

You must have a Graphite account in order to use the merge queue. Create an account and try again using this link

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 19, 2025
@Boshen
Copy link
Member

Boshen commented May 19, 2025

Nice!

@leaysgur leaysgur merged commit 9775585 into main May 19, 2025
25 checks passed
@leaysgur leaysgur deleted the r/regexp-modifiers branch May 19, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants