-
Notifications
You must be signed in to change notification settings - Fork 12
Respect [absence of] flags semantics of regular expression #6
Comments
My initial thought was that "match all" implied that you wanted all the matches for the pattern, regardless of the global/sticky flags. However, it also makes sense to me to respect the |
@ljharb if you respect I think the name should state clear enough that the method returns an In my opinion this method should be exposed as |
Yay! To summarize related comment from parallel thread - #5 (comment) - what I propose is:
P.S. Note that I'm not proposing anything new here - all the described situations just match existing behavior of |
@abozhilov There's no convention in the language for what returns an iterator and doesn't - and all the prototype keys/values/entries methods don't convey it either. The committee does not want to use a naming convention for this purpose. |
@RReverser You have four items there. (1) and (3) I think I'm convinced by, and (2) is already in the proposal. As for (4) - when i do
I think it makes the most sense to be consistent with all four of these, and I think I am indeed convinced that this will make for the most useful, coherent, and consistent method, and I think the committee will be convinced by these arguments. I'll leave this open until I've made the changes (which will take time since I'm still making the changes for |
@ljharb I agree, but the name tends to confusion.
Please reconsider the name, at least to be discussed with the committee, thanks. |
@abozhilov I believe name could be raise as a separate issue here in order not to pollute discussion thread. Personally, I agree that |
The concern there is that Please do file a new issue about the naming, as this issue is solely about the |
OK, is the conclusion here to respect the original values for both g and y then? Personally, I would've expected that g is added and y doesn't take effect--it's just a little hard for me to see a use case otherwise, and it feels more like something to trip up on than a feature. |
#6 (comment) is the conclusion we'd come to. |
To restate the conclusion: just like |
I'm not really a fan of the resolution here. It just seems like the proposal here, and the recently merged spec text, will make the result harder to use. String.prototype.split is a good model for always adding the y flag; I could go either way on the g flag given the precedent there. |
[Continuation of Twitter discussion]
I'd propose to always respect
g
and/ory
flags, including inmatchAll
method in order to preserve existing semantics, as otherwise implicit addition of "global" flag specifically in this method might be pretty surprising for users. Also, this will reduce implementation complexity, as neither polyfill nor engine will need to reconstruct RegExp, but reuse existing one.That is, I propose to yield all matches when
g
ory
flag is present (same behavior as withexec
loop) but yield only first match when it's not. This way behavior will be consistent withexec
,match
andreplace
calls, and it will make it possible to use same preconstructed regular expression object and expect same behavior in any of given methods.The text was updated successfully, but these errors were encountered: