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

Normative: Add String.prototype.replaceAll #2009

Merged
merged 1 commit into from
Jun 27, 2020

Conversation

mathiasbynens
Copy link
Member

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.

@mathiasbynens mathiasbynens added needs consensus This needs committee consensus before it can be eligible to be merged. has test262 tests labels May 24, 2020
spec.html Outdated Show resolved Hide resolved
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch 2 times, most recently from 1f53ecb to 6353c08 Compare May 24, 2020 12:33
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4. and removed needs consensus This needs committee consensus before it can be eligible to be merged. labels May 24, 2020
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from 6353c08 to bf8244e Compare May 25, 2020 05:43
@mathiasbynens
Copy link
Member Author

Thanks for the reviews! I've addressed the feedback.

@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from bf8244e to fbc3b9d Compare May 25, 2020 05:44
spec.html Outdated Show resolved Hide resolved
spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@ljharb ljharb requested a review from jmdyck May 25, 2020 06:01
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch 3 times, most recently from e221f20 to 4d5efbd Compare May 25, 2020 06:32
@ljharb ljharb requested review from michaelficarra, syg, bakkot and a team May 25, 2020 06:36
spec.html Show resolved Hide resolved
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch 2 times, most recently from 4933c0e to 9c06d72 Compare May 25, 2020 15:38
@mathiasbynens mathiasbynens requested a review from jmdyck May 25, 2020 15:38
Copy link
Collaborator

@jmdyck jmdyck left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@syg syg left a 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

spec.html Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@ljharb ljharb self-assigned this May 28, 2020
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from 9c06d72 to f2286b3 Compare May 28, 2020 06:48
spec.html Outdated Show resolved Hide resolved
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from f2286b3 to a3e2f2b Compare May 29, 2020 06:07
spec.html Outdated Show resolved Hide resolved
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from a3e2f2b to e964506 Compare June 1, 2020 15:11
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).
Copy link
Contributor

Choose a reason for hiding this comment

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

Consistency suggestion (cf. #2021):

Suggested change
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).

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@michaelficarra michaelficarra Jun 2, 2020

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

spec.html Outdated Show resolved Hide resolved
spec.html Outdated Show resolved Hide resolved
@ljharb ljharb added has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. and removed pending stage 4 This proposal has not yet achieved stage 4, but may otherwise be ready to merge. labels Jun 2, 2020
@mathiasbynens mathiasbynens requested a review from bakkot June 2, 2020 15:45
@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from e964506 to 42b11de Compare June 2, 2020 16:04
@mathiasbynens mathiasbynens requested a review from gibson042 June 3, 2020 08:03
Copy link
Contributor

@gibson042 gibson042 left a 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,
Copy link
Contributor

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.

Copy link
Member Author

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.

🤷

@mathiasbynens mathiasbynens force-pushed the add-string-prototype-replaceall branch from 42b11de to 90d82a2 Compare June 3, 2020 11:10
mathiasbynens pushed a commit to tc39/proposal-string-replaceall that referenced this pull request Jun 27, 2020
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]>
@ljharb ljharb force-pushed the add-string-prototype-replaceall branch from 90d82a2 to 7ccc226 Compare June 27, 2020 21:36
@ljharb ljharb merged commit 7ccc226 into tc39:master Jun 27, 2020
jmdyck added a commit to jmdyck/ecma262 that referenced this pull request Jun 29, 2020
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.
@mathiasbynens mathiasbynens deleted the add-string-prototype-replaceall branch June 29, 2020 04:43
ljharb pushed a commit to jmdyck/ecma262 that referenced this pull request Jul 1, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has stage 4 This PR represents a proposal that has achieved stage 4, and is ready to merge. has test262 tests normative change Affects behavior required to correctly evaluate some ECMAScript source text proposal This is related to a specific proposal, and will be closed/merged when the proposal reaches stage 4.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants