-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Normative: Add String.prototype.replaceAll #2009
Normative: Add String.prototype.replaceAll #2009
Conversation
1f53ecb
to
6353c08
Compare
6353c08
to
bf8244e
Compare
Thanks for the reviews! I've addressed the feedback. |
bf8244e
to
fbc3b9d
Compare
e221f20
to
4d5efbd
Compare
4933c0e
to
9c06d72
Compare
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.
LGTM
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.
lgtm with small nits below
9c06d72
to
f2286b3
Compare
f2286b3
to
a3e2f2b
Compare
a3e2f2b
to
e964506
Compare
spec.html
Outdated
1. Assert: Type(_replaceValue_) is String. | ||
1. Let _captures_ be a new empty List. | ||
1. Let _replacement_ be ! GetSubstitution(_searchString_, _string_, _position_, _captures_, *undefined*, _replaceValue_). | ||
1. Let _stringSlice_ be the substring of _string_ consisting of the code units from _endOfLastMatch_ (inclusive) up to _position_ (exclusive). |
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.
Consistency suggestion (cf. #2021):
1. Let _stringSlice_ be the substring of _string_ consisting of the code units from _endOfLastMatch_ (inclusive) up to _position_ (exclusive). | |
1. Let _stringSlice_ be the substring of _string_ consisting of the code units at indices _endOfLastMatch_ (inclusive) through _position_ (exclusive). |
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.
Note that the notation in #2021 is still in flux and no longer matches the suggestion.
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.
What should I do here? Happy to make any changes to get this to a land-able state.
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.
If we're going to land it before #2021, it doesn't matter what we do here.
edit: To clarify, you should just leave it as it is.
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.
Seems like this one will be able to land before #2021, but I think whichever one lands first should rebase and ensure this prose is consistent?
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.
@ljharb This PR is consistent with existing forms currently.
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.
Seems like it should stay that way then, until #2021 is merged.
e964506
to
42b11de
Compare
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.
Looks good!
1. Let _advanceBy_ be max(1, _searchLength_). | ||
1. Let _matchPositions_ be a new empty List. | ||
1. Let _position_ be ! StringIndexOf(_string_, _searchString_, 0). | ||
1. Repeat, while _position_ is not -1, |
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.
Your test in String.prototype.includes is If _index_ ≥ 0
. I don't have a preference for "≥ 0" vs. "is not -1", but I do have a preference for them to match.
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've made the change. This is a little awkward though:
If index is not -1, return true.
Return false.
In code you'd probably write it as:
If index is -1, return false.
Return true.
🤷
42b11de
to
90d82a2
Compare
The upstream spec PR (tc39/ecma262#2009) still needs to be merged, but we can already update this repository.
Proposal: https://github.com/tc39/proposal-string-replaceall Note that the changes to String.prototype.matchAll that were part of this proposal have already been merged here: tc39#1716. Co-authored-by: Jakob Gruber <[email protected]> Co-authored-by: Mathias Bynens <[email protected]>
90d82a2
to
7ccc226
Compare
PR tc39#2009 recently introduced StringIndexOf, locating its definition in a subclause of "10 ECMAScript Language: Source Code". This placement doesn't make much sense, as StringIndexOf isn't particularly related to source code. This commit relocates it to 6.1.4 The String Type.
PR tc39#2009 recently introduced StringIndexOf, locating its definition in a subclause of "10 ECMAScript Language: Source Code". This placement doesn't make much sense, as StringIndexOf isn't particularly related to source code. This commit relocates it to 6.1.4 The String Type.
Proposal: https://github.com/tc39/proposal-string-replaceall
Tests: tc39/test262#2423
Note that the changes to
String.prototype.matchAll
that were part of this proposal have already been merged here: #1716.