-
Notifications
You must be signed in to change notification settings - Fork 12
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
Implement support for &&
and ||
in v
sets
#52
Implement support for &&
and ||
in v
sets
#52
Conversation
rewrite-pattern.js
Outdated
@@ -312,17 +402,20 @@ const regjsparserFeatures = { | |||
'unicodePropertyEscape': true, | |||
'namedGroups': true, | |||
'lookbehind': true, | |||
'unicodeSet': true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be enabled by default
ac2e643
to
665b2d8
Compare
665b2d8
to
8c26775
Compare
rewrite-pattern.js
Outdated
@@ -363,21 +462,34 @@ const rewritePattern = (pattern, flags, options) => { | |||
validateOptions(options); | |||
|
|||
config.flags.unicode = hasFlag(flags, 'u'); | |||
config.flags.unicodeSet = hasFlag(flags, 'v'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s continue matching the RegExp.prototype
getter name, which in this case is unicodeSets
.
rewrite-pattern.js
Outdated
// unicodeFlag: 'transform' implies unicodePropertyEscapes: 'transform' | ||
config.transform.unicodePropertyEscapes = config.flags.unicode && ( | ||
transform(options, 'unicodeFlag') || transform(options, 'unicodePropertyEscapes') | ||
); | ||
config.transform.namedGroups = transform(options, 'namedGroups'); | ||
|
||
const regjsparserFeatures = { | ||
'unicodeSet': Boolean(options && options.unicodeSetFlag), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps unicodeSets
here too, for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regjsparser option, so we could change it when it has a breaking release. However, it also uses unicodePropertyEscape
so it's consistent with itself.
tests/tests.js
Outdated
}, | ||
]; | ||
|
||
describe('unicode set (v) flag', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
describe('unicode set (v) flag', () => { | |
describe('unicodeSets (v) flag', () => { |
tests/tests.js
Outdated
@@ -1001,3 +1001,134 @@ describe('character classes', () => { | |||
} | |||
}); | |||
|
|||
const TRANSFORM_U = { unicodeFlag: 'transform', unicodeSetFlag: 'transform' }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m confused by this combination of settings, so just to clarify:
- The grammar for the
u
flag does not change with thev
flag proposal. - Only the
v
flag enables the new functionality. - The two flags cannot be combined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the readme, hopefully it makes it clear. By default v
is transformed to u
, but you can set unicodeFlag: 'transform'
to transform it even more. This is a sensible default, because now many browsers support u
natively.
We also do something similar in Babel, where class fields are transformed to ES6 classes and then you can choose to transform them even more to ES5.
f43e4b0
to
e6ef9a5
Compare
This adds support for
&&
and||
. It doesn't support string alternatives in sets ([\q{ab|cd}]
) or the updates to\p
: I'll open other PRs for them.I'm marking this as a wip because: