Skip to content

fix(parser): preserve regex literals ending in an escaped slash - #738

Closed
nagahara-naoki wants to merge 1 commit into
voidzero-dev:mainfrom
nagahara-naoki:fix/regex-comment-parsing
Closed

nagahara-naoki wants to merge 1 commit into
voidzero-dev:mainfrom
nagahara-naoki:fix/regex-comment-parsing

Conversation

@nagahara-naoki

Copy link
Copy Markdown
Contributor

Fix regex literals ending in an escaped slash

This Angular template removes one leading slash when the button is clicked:

<button (click)="result = path.replace(/^\//, '') // normalize path">
  Normalize path
</button>

Before: Oxc treated the last two slashes in /^\// as a comment and failed to compile the template with Unterminated regular expression.

After: Oxc parses the regex and ignores the trailing // normalize path comment. Clicking the button produces:

path before click result after click
"/docs" "docs"
"//docs" "/docs"
"docs" "docs"

Event source ranges

The event handler’s source range now extends through // normalize path. The parsed assignment’s range starts at result and ends at ). Regression tests check both positions and cover event attributes that contain HTML character references such as &quot;.

Tests

  • Both upstream regex cases now pass. Angular conformance improved from 1,430 to 1,432 of 1,456, with no new failures.
  • All 1,656 tests in the local compiler, parser, transform, and conformance-runner suites that were run passed.

@Brooooooklyn

Copy link
Copy Markdown
Member

Thanks a lot for this fix, @nagahara-naoki!

This PR doesn't allow edits from maintainers, so I couldn't push the follow-up changes to your branch. That means I have to close it here.

Your commit is kept as is, with you as the author, in #740. That PR adds 3 commits on top:

  • the conformance runner keeps checking event spans
  • the same escaped-slash fix for {{ }} interpolations
  • more tests (Angular's spec cases, escaped quotes, handler spans for every event kind)

Next time, please tick "Allow edits by maintainers" so we can update the PR directly. Thanks again!

@nagahara-naoki

Copy link
Copy Markdown
Contributor Author

@Brooooooklyn
Thanks for carrying this into #740 and preserving my authorship.
I appreciate the extra checks on event spans and interpolations.

I’ll make sure maintainer edits are enabled on my next PR!

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.

2 participants