Skip to content

Commit b09e93d

Browse files
authoredSep 28, 2022
Merge pull request #50041 from microsoft/fix/47969
Fix(47969): String.prototypr.replace docs fix
2 parents 0ac12bb + 8e71f42 commit b09e93d

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed
 

‎src/lib/es2015.symbol.wellknown.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ interface String {
219219
match(matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null;
220220

221221
/**
222-
* Replaces first match with string or all matches with RegExp.
223-
* @param searchValue A string or RegExp search value.
224-
* @param replaceValue A string containing the text to replace for match.
222+
* Passes a string and {@linkcode replaceValue} to the `[Symbol.replace]` method on {@linkcode searchValue}. This method is expected to implement its own replacement algorithm.
223+
* @param searchValue An object that supports searching for and replacing matches within a string.
224+
* @param replaceValue The replacement text.
225225
*/
226226
replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;
227227

‎src/lib/es5.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ interface String {
423423

424424
/**
425425
* Replaces text in a string, using a regular expression or search string.
426-
* @param searchValue A string to search for.
427-
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
426+
* @param searchValue A string or regular expression to search for.
427+
* @param replaceValue A string containing the text to replace. When the {@linkcode searchValue} is a `RegExp`, all matches are replaced if the `g` flag is set (or only those matches at the beginning, if the `y` flag is also present). Otherwise, only the first match of {@linkcode searchValue} is replaced.
428428
*/
429429
replace(searchValue: string | RegExp, replaceValue: string): string;
430430

‎tests/baselines/reference/completionsStringMethods.baseline

+48-2
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@
10481048
"kind": "space"
10491049
},
10501050
{
1051-
"text": "A string to search for.",
1051+
"text": "A string or regular expression to search for.",
10521052
"kind": "text"
10531053
}
10541054
]
@@ -1065,7 +1065,53 @@
10651065
"kind": "space"
10661066
},
10671067
{
1068-
"text": "A string containing the text to replace for every successful match of searchValue in this string.",
1068+
"text": "A string containing the text to replace. When the ",
1069+
"kind": "text"
1070+
},
1071+
{
1072+
"text": "{@linkcode ",
1073+
"kind": "link"
1074+
},
1075+
{
1076+
"text": "searchValue",
1077+
"kind": "linkName",
1078+
"target": {
1079+
"fileName": "lib.d.ts",
1080+
"textSpan": {
1081+
"start": 18880,
1082+
"length": 28
1083+
}
1084+
}
1085+
},
1086+
{
1087+
"text": "}",
1088+
"kind": "link"
1089+
},
1090+
{
1091+
"text": " is a `RegExp`, all matches are replaced if the `g` flag is set (or only those matches at the beginning, if the `y` flag is also present). Otherwise, only the first match of ",
1092+
"kind": "text"
1093+
},
1094+
{
1095+
"text": "{@linkcode ",
1096+
"kind": "link"
1097+
},
1098+
{
1099+
"text": "searchValue",
1100+
"kind": "linkName",
1101+
"target": {
1102+
"fileName": "lib.d.ts",
1103+
"textSpan": {
1104+
"start": 18880,
1105+
"length": 28
1106+
}
1107+
}
1108+
},
1109+
{
1110+
"text": "}",
1111+
"kind": "link"
1112+
},
1113+
{
1114+
"text": " is replaced.",
10691115
"kind": "text"
10701116
}
10711117
]

0 commit comments

Comments
 (0)
Please sign in to comment.