-
Notifications
You must be signed in to change notification settings - Fork 12
Flag implication: v
implies u
?
#23
Comments
FWIW I don't have any strong opinion here. I totally defer to you + stage 3 reviewers. |
It doesn't have to be an early error; due to Another con of option 2 there is that |
If we were to throw errors (which for the record, I hope we don't!) I think it would need to be an early error in the regular expression literal case:
Great point; added to the original post. Thanks! |
Also, personally I don't find "requires more typing" an issue; code is read more often than it's written, so clarity/readability should be weighed more highly. I also think that it would be very unfortunate if all code that currently checks |
Previous issue: #14 I personally would be happy with requiring |
I'd rather avoid this option. There is no precedent for introducing a new flag that cannot be used by itself. |
In email I asked:
Mathias replied:
|
Copied from #14 (comment) where I wrote: Crazy idea: Could we change the "unicode" getter to return numeric value 2 instead of boolean false/true, when |
In email, Waldemar wrote: There are two reasonable alternatives: A. Flags as they are now. This has the disadvantage that user code checking for unicode mode must be modified to also look for the v flag. B. Setting the v flag actually sets the u flag as well, with us picking whatever the most reasonable semantics are to achieve that. I want to note that we have discussed another option as well: Require setting (Waldemar’s option B is Mathias’ original option 2. Waldemar’s option A is what we have in the current draft spec changes.) Mathias responded about Waldemar’s option A: I see this as an advantage; any existing code checking for The mental model is that Note that if |
Discussed in today's meeting with @mathiasbynens @macchiati @sffc -- We realized that to say “ In addition, in issue #30 we propose resolving CharacterClasses with top-level Shane was wondering whether implementers that test As for code that parses regular expression pattern strings, we think that adding the Cc stage 3 reviewers @waldemarhorwat @gibson042 @msaboff |
ftr, "v implies u" to me does not mean that the same syntax will be used, it means "u is for unicode semantics, v implies the same unicode semantics". I suspect most cases of people checking |
Follow-up from our meeting notes: Since we don't quite have “ |
The only examples I know of, and which I was referring to during the TC39 meetings, are used for the latter purpose. I share them below, but first, some background: any JS parser technically has to check each regular expression’s flags and parse accordingly, since invalid patterns result in early errors per spec, which are parse-time errors. A JS parser which is lenient in the face of an invalid regular expression literal is technically in violation of the spec. And of course, patterns exist that are only valid with or without the
With that out of the way, here are the JS-parser-in-JS examples which I referred do during the TC39 meetings.
(Note that Babel doesn’t bother implementing (or emulating) proper regular expression parsing, and happily accepts invalid patterns: https://github.com/babel/babel/blob/e498bee10f0123bb208baa228ce6417542a2c3c4/packages/babel-parser/src/tokenizer/index.js#L924-L973 It does check whether each flag is a known one, but it has no flag-specific code paths, not even for These are the only examples I’m aware of. All of the above implementations (incl. Babel) would need to be updated to support I’m not aware of any real-world examples of library code checking |
There are three options:
I would like to resolve this issue with option 3, because it’s simplest. The mental model then becomes: Let’s discuss this during this week’s meeting. |
I agree with your logic for |
Even with the smaller scope of just the set notation the committee favored a new flag, and with the incompatibilities within the combined-so-far scope /u and /v are really separate modes. |
During yesterday’s weekly sync we decided to proceed with “option 3”. Closing this issue to mark its resolution. We’ll update the spec draft later. |
v
implies u
v
implies u
?
The current draft spec says that the
v
flag implies theu
behavior, but it doesn't make that explicit in that/./v.unicode === false
. This was a conscious choice that I pushed for: I wanted to preserve the invariant that 1 flag affects exactly 1 getter.v
andu
are two distinct modes; it's just thatv
syntax + functionality happen to be a superset ofu
.During the TC39 meeting, @waldemarhorwat and @msaboff brought up alternate options, and we should reconsider if we should change anything here.
u
flag wheneverv
is used..unicode
might now break, sincev
is parsed differently/./v.unicode === true
..unicode === true
to behave based on theu
-only (non-v
) behavior..unicode === true
would not correspond to.flags.includes('u')
. (pointed out by Jordan)The text was updated successfully, but these errors were encountered: