Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve regexp invalid modifiers errors #145

Merged

Conversation

JLHwung
Copy link
Collaborator

@JLHwung JLHwung commented Oct 1, 2024

Currently we generate different errors for two equivalent invalid expressions:

Invalid flags for modifiers group at position 8
    ^[a-z](?ui:[a-z])$
            ^
character at position 9: :
    ^[a-z](?iu:[a-z])$
             ^

In this PR we improve the parsing logic so that the latter case now throws the same error as the former. We also aligned the production names to the latest draft.

@nicolo-ribaudo
Copy link
Collaborator

When it comes to valid regex flags that are invalid in this position (e.g. u, or g), it would be nice to get an error pointing exactly to that flag.

parser.js Outdated
if(match("-")){
disablingFlags = matchReg(/^[sim]+/);
if(enablingFlags[2] === "-") {
disablingFlags = matchReg(/^([sim]+):/);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Aside: Here we disallows the production (?i-:foo) when the enablingFlags are non-empty and the disablingFlags are empty. The current spec draft does allow such productions and the V8 engine supports it well. I have raised a comment in the spec draft review (tc39/ecma262#3221 (comment)). If the spec is deemed no change here, I will open a new PR to fix that.

@jviereck jviereck merged commit 6ad7019 into jviereck:gh-pages Oct 3, 2024
@jviereck
Copy link
Owner

jviereck commented Oct 3, 2024

Thank you for the PR @JLHwung and @nicolo-ribaudo for the review!

@JLHwung JLHwung deleted the improve-regexp-invalid-modifiers-errors branch October 4, 2024 00:01
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.

3 participants