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

Add support for named capturing groups #83

Merged
merged 2 commits into from
Jan 3, 2018

Conversation

nicolo-ribaudo
Copy link
Collaborator

https://github.com/tc39/proposal-regexp-named-groups

I started working on this feature because I needed it for implementing a babel plugin. I then decided to use another package which already transformsnamed groups in regexps (regexp-tree), but I finished this PR anyway since it will probably be useful to someone else.

@jviereck
Copy link
Owner

Hi @nicolo-ribaudo,

thanks a lot for implementing this and proving the PR - especially as you went with using a different parser in the end :)

Doing a quick look over the code, is the named-group feature enabled by default? When adding unicode parsing before (see 1), we've added a features flag to the parse(...) function. I think having a feature flag for this feature would be great as well. What do you think?

If you have any questions, let me know.

Thanks! \jv

@nicolo-ribaudo
Copy link
Collaborator Author

I enabled named groups by default because the only thing missing for the proposal to be merged to the main spec is the final approval, so it would be enabled by default[1] really soon (relevant meeting notes, tc39/ecma262#1027). If you still prefer to enable this feature using a flag, let me know 😉

[1] What I say is only valid if the features option is only meant for experimental features.

@jviereck
Copy link
Owner

f you still prefer to enable this feature using a flag, let me knowl

Yes, I prefer to have this feature enabled via a flag similar as in 1. The reasoning is to avoid people using the library to undergo possible breaking/functionality change when adding this feature.

Thanks. If there is anything, let met know. \jv

@nicolo-ribaudo
Copy link
Collaborator Author

Done!

@jviereck jviereck merged commit c6fe378 into jviereck:gh-pages Jan 3, 2018
@jviereck
Copy link
Owner

jviereck commented Jan 3, 2018

hi folks,

First: Thanks @mathiasbynens for picking this one up again and asking me for review. I dropped the todo here. This is not the way it should be. Sorry @nicolo-ribaudo for delaying the review by this.

Overall: Thanks @nicolo-ribaudo for providing this PR. The code looks very clean and I like how you managed to follow the coding style of the library.

There are a few small nits, that I am going to comment code-inline next.
@nicolo-ribaudo: Please let me know if you want to do the follow-up work yourself. Feel free to say no and I can take care of it ;)

If you have any questions, please let me know :),

All the best & thanks,
\ julian

Copy link
Owner

@jviereck jviereck left a comment

Choose a reason for hiding this comment

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

There are a few small nits, that I am going to comment code-inline next.

@nicolo-ribaudo: Please let me know if you want to do the follow-up work yourself. Feel free to say no and I can take care of it ;)

Done :)

@@ -58,6 +58,7 @@
// DecimalEscape
// CharacterEscape
// CharacterClassEscape
// k GroupName
Copy link
Owner

Choose a reason for hiding this comment

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

For understanding: the k is matching the character k here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes 👍

// _
// \ RegExpUnicodeEscapeSequence
// <ZWNJ>
// <ZWJ>
Copy link
Owner

Choose a reason for hiding this comment

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

nit: shall we move the grammar for this up at the beginning of the file?

Copy link
Owner

Choose a reason for hiding this comment

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

Looking over the code once more, other parts of the grammar are also defined locally. Therefore, leaving the grammar definition at the place introduced in this PR.

@@ -0,0 +1,60 @@
{
Copy link
Owner

Choose a reason for hiding this comment

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

Out of curiosity: Where did you/@nicolo-ribaudo get these tests from? Are these the official ECMA-262 tests for the named-groups feature?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I wrote them by myself.

});
runTests(require('./test-data-named-groups-unicode.json'), 'u', {
namedGroups: true
});
Copy link
Owner

Choose a reason for hiding this comment

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

How about adding tests for named groups & unicode-properties enabled jointly?

console.log(
'// ECMAScript 5.1/Unicode v%s NonAsciiIdentifierPartOnly:\n\n%s',
version,
result.NonAsciiIdentifierPartOnly
Copy link
Owner

Choose a reason for hiding this comment

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

Ah, strange to console.log only one of the parts. Good catch :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, the other part wasn't used yet 🙂

@jviereck
Copy link
Owner

jviereck commented Jan 3, 2018

Do you mind if I wait with releasing a new version of the library once the jointly tests for the features are there?

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