Skip to content

Add union of replacer function and string #34941

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib/es2015.symbol.wellknown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ interface String {
*/
replace(searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string): string;

/**
* Replaces text in a string, using an object that supports replacement within a string.
* @param searchValue A object can search for and replace matches within a string.
* @param replacer A function that returns the replacement text or a string containing the text to replace for every
* successful match of searchValue in this string.
*/
replace(
searchValue: { [Symbol.replace](string: string, replacer: string | ((substring: string, ...args: any[]) => string)): string; },
replacer: string | ((substring: string, ...args: any[]) => string)): string;

/**
* Finds the first substring match in a regular expression search.
* @param searcher An object which supports searching within a string.
Expand Down
7 changes: 7 additions & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ interface String {
*/
replace(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;

/**
* Replaces text in a string, using a regular expression or search string.
* @param searchValue A string to search for.
* @param replacer A string containing the text to replace for every successful match or a function that returns the replacement text.
*/
replace(searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string;

/**
* Finds the first substring match in a regular expression search.
* @param regexp The regular expression pattern and applicable flags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ export class HTMLtoJSX {
// wrapping newlines and sequences of two or more spaces in variables.
text = text
>text : Symbol(text, Decl(controlFlowPropertyDeclarations.ts, 113, 7))
>text .replace(/\r/g, '') .replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>text .replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>text .replace(/\r/g, '') .replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>text .replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>text : Symbol(text, Decl(controlFlowPropertyDeclarations.ts, 113, 7))

.replace(/\r/g, '')
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

.replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) {
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>whitespace : Symbol(whitespace, Decl(controlFlowPropertyDeclarations.ts, 121, 50))

return '{' + JSON.stringify(whitespace) + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,18 @@ export class HTMLtoJSX {
>text = text .replace(/\r/g, '') .replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) { return '{' + JSON.stringify(whitespace) + '}'; }) : string
>text : string
>text .replace(/\r/g, '') .replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) { return '{' + JSON.stringify(whitespace) + '}'; }) : string
>text .replace(/\r/g, '') .replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>text .replace(/\r/g, '') .replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>text .replace(/\r/g, '') : string
>text .replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>text .replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>text : string

.replace(/\r/g, '')
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>/\r/g : RegExp
>'' : ""

.replace(/( {2,}|\n|\t|\{|\})/g, function(whitespace) {
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>/( {2,}|\n|\t|\{|\})/g : RegExp
>function(whitespace) { return '{' + JSON.stringify(whitespace) + '}'; } : (whitespace: string) => string
>whitespace : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
a1(...array2); // Error parameter type is (number|string)[]
~~~~~~
!!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'?
!!! related TS2728 /.ts/lib.es5.d.ts:1385:13: 'Array' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:1392:13: 'Array' is declared here.
a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]]
~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type '[[any]]'.
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/externModule.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ tests/cases/compiler/externModule.ts(37,3): error TS2552: Cannot find name 'XDat
var d=new XDate();
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:914:13: 'Date' is declared here.
d.getDay();
d=new XDate(1978,2);
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:914:13: 'Date' is declared here.
d.getXDate();
var n=XDate.parse("3/2/2004");
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:914:13: 'Date' is declared here.
n=XDate.UTC(1964,2,1);
~~~~~
!!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'?
!!! related TS2728 /.ts/lib.es5.d.ts:907:13: 'Date' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:914:13: 'Date' is declared here.


Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.t
Math.sign(1);
~~~~
!!! error TS2551: Property 'sign' does not exist on type 'Math'. Did you mean 'sin'?
!!! related TS2728 /.ts/lib.es5.d.ts:713:5: 'sin' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:720:5: 'sin' is declared here.

// Using ES6 object
var o = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tests/cases/conformance/types/any/narrowExceptionVariableInCatchClause.ts(16,17)
err.massage; // ERROR: Property 'massage' does not exist on type 'Error'
~~~~~~~
!!! error TS2551: Property 'massage' does not exist on type 'Error'. Did you mean 'message'?
!!! related TS2728 /.ts/lib.es5.d.ts:974:5: 'message' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:981:5: 'message' is declared here.
}

else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ tests/cases/conformance/types/any/narrowFromAnyWithInstanceof.ts(22,7): error TS
x.mesage;
~~~~~~
!!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'?
!!! related TS2728 /.ts/lib.es5.d.ts:974:5: 'message' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:981:5: 'message' is declared here.
}

if (x instanceof Date) {
x.getDate();
x.getHuors();
~~~~~~~~
!!! error TS2551: Property 'getHuors' does not exist on type 'Date'. Did you mean 'getHours'?
!!! related TS2728 /.ts/lib.es5.d.ts:763:5: 'getHours' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:770:5: 'getHours' is declared here.
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ tests/cases/conformance/types/any/narrowFromAnyWithTypePredicate.ts(33,7): error
x.mesage;
~~~~~~
!!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'?
!!! related TS2728 /.ts/lib.es5.d.ts:974:5: 'message' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:981:5: 'message' is declared here.
}

if (isDate(x)) {
x.getDate();
x.getHuors();
~~~~~~~~
!!! error TS2551: Property 'getHuors' does not exist on type 'Date'. Did you mean 'getHours'?
!!! related TS2728 /.ts/lib.es5.d.ts:763:5: 'getHours' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:770:5: 'getHours' is declared here.
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ regexMatchList.forEach(match => ''.replace(match, ''));
>regexMatchList : Symbol(regexMatchList, Decl(noImplicitAnyInContextuallyTypesFunctionParamter.ts, 0, 3))
>forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
>match : Symbol(match, Decl(noImplicitAnyInContextuallyTypesFunctionParamter.ts, 1, 23))
>''.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>''.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>match : Symbol(match, Decl(noImplicitAnyInContextuallyTypesFunctionParamter.ts, 1, 23))

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ regexMatchList.forEach(match => ''.replace(match, ''));
>match => ''.replace(match, '') : (match: string) => string
>match : string
>''.replace(match, '') : string
>''.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>''.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>'' : ""
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>match : string
>'' : ""

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ module Bugs {

var result= message.replace(/\{(\d+)\}/g, function(match, ...rest) {
>result : Symbol(result, Decl(overloadResolutionOverNonCTLambdas.ts, 6, 7))
>message.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>message.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>message : Symbol(message, Decl(overloadResolutionOverNonCTLambdas.ts, 5, 16))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>match : Symbol(match, Decl(overloadResolutionOverNonCTLambdas.ts, 6, 55))
>rest : Symbol(rest, Decl(overloadResolutionOverNonCTLambdas.ts, 6, 61))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module Bugs {
var result= message.replace(/\{(\d+)\}/g, function(match, ...rest) {
>result : string
>message.replace(/\{(\d+)\}/g, function(match, ...rest) { var index= rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; }) : string
>message.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>message.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>message : string
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>/\{(\d+)\}/g : RegExp
>function(match, ...rest) { var index= rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; } : (match: string, ...rest: any[]) => any
>match : string
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserArgumentList1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export function removeClass (node:HTMLElement, className:string) {
>node.className : Symbol(Element.className, Decl(lib.dom.d.ts, --, --))
>node : Symbol(node, Decl(parserArgumentList1.ts, 0, 29))
>className : Symbol(Element.className, Decl(lib.dom.d.ts, --, --))
>node.className.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>node.className.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>node.className : Symbol(Element.className, Decl(lib.dom.d.ts, --, --))
>node : Symbol(node, Decl(parserArgumentList1.ts, 0, 29))
>className : Symbol(Element.className, Decl(lib.dom.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>className : Symbol(className, Decl(parserArgumentList1.ts, 0, 46))
>everything : Symbol(everything, Decl(parserArgumentList1.ts, 1, 80))
>leftDelimiter : Symbol(leftDelimiter, Decl(parserArgumentList1.ts, 1, 91))
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/parserArgumentList1.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export function removeClass (node:HTMLElement, className:string) {
>node : HTMLElement
>className : string
>node.className.replace(_classNameRegexp(className), function (everything, leftDelimiter, name, rightDelimiter) { return leftDelimiter.length + rightDelimiter.length === 2 ? ' ' : ''; }) : string
>node.className.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>node.className.replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>node.className : string
>node : HTMLElement
>className : string
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
>replace : { (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: string | RegExp, replacer: string | ((substring: string, ...args: any[]) => string)): string; }
>_classNameRegexp(className) : any
>_classNameRegexp : any
>className : string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ tests/cases/conformance/parser/ecmascript5/Expressions/parserMemberAccessAfterPo
!!! error TS1005: ';' expected.
~~~~~~~~
!!! error TS2552: Cannot find name 'toString'. Did you mean 'String'?
!!! related TS2728 /.ts/lib.es5.d.ts:527:13: 'String' is declared here.
!!! related TS2728 /.ts/lib.es5.d.ts:534:13: 'String' is declared here.
8 changes: 4 additions & 4 deletions tests/baselines/reference/parserRealSource11.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -7131,24 +7131,24 @@ module TypeScript {
>this : Symbol(Comment, Decl(parserRealSource11.ts, 2323, 5))
>text : Symbol(Comment.text, Decl(parserRealSource11.ts, 2325, 38))
>i : Symbol(i, Decl(parserRealSource11.ts, 2337, 28))
>this.text[i].replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>this.text[i].replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>this.text : Symbol(Comment.text, Decl(parserRealSource11.ts, 2325, 38))
>this : Symbol(Comment, Decl(parserRealSource11.ts, 2323, 5))
>text : Symbol(Comment.text, Decl(parserRealSource11.ts, 2325, 38))
>i : Symbol(i, Decl(parserRealSource11.ts, 2337, 28))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}
}
else {
this.text = [(this.content.replace(/^\s+|\s+$/g, ''))];
>this.text : Symbol(Comment.text, Decl(parserRealSource11.ts, 2325, 38))
>this : Symbol(Comment, Decl(parserRealSource11.ts, 2323, 5))
>text : Symbol(Comment.text, Decl(parserRealSource11.ts, 2325, 38))
>this.content.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>this.content.replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>this.content : Symbol(Comment.content, Decl(parserRealSource11.ts, 2329, 21))
>this : Symbol(Comment, Decl(parserRealSource11.ts, 2323, 5))
>content : Symbol(Comment.content, Decl(parserRealSource11.ts, 2329, 21))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>replace : Symbol(String.replace, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}
}

Expand Down
Loading