Skip to content

Commit 3480321

Browse files
Add types for String#isWellFormed and String#toWellFormed (#58010)
Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 21f5f39 commit 3480321

28 files changed

+266
-8
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ const libEntries: [string, string][] = [
236236
["esnext.object", "lib.esnext.object.d.ts"],
237237
["esnext.array", "lib.esnext.array.d.ts"],
238238
["esnext.regexp", "lib.esnext.regexp.d.ts"],
239+
["esnext.string", "lib.esnext.string.d.ts"],
239240
["decorators", "lib.decorators.d.ts"],
240241
["decorators.legacy", "lib.decorators.legacy.d.ts"],
241242
];

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
15071507
es2022: [
15081508
"at",
15091509
],
1510+
esnext: [
1511+
"isWellFormed",
1512+
"toWellFormed",
1513+
],
15101514
})),
15111515
StringConstructor: new Map(Object.entries({
15121516
es2015: [

src/lib/esnext.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/// <reference lib="esnext.collection" />
88
/// <reference lib="esnext.array" />
99
/// <reference lib="esnext.regexp" />
10+
/// <reference lib="esnext.string" />

src/lib/esnext.string.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
interface String {
2+
/**
3+
* Returns true if all leading surrogates and trailing surrogates appear paired and in order.
4+
*/
5+
isWellFormed(): boolean;
6+
7+
/**
8+
* Returns a string where all lone or out-of-order surrogates have been replaced by the Unicode replacement character (U+FFFD).
9+
*/
10+
toWellFormed(): string;
11+
}

src/lib/libs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"esnext.collection",
8080
"esnext.array",
8181
"esnext.regexp",
82+
"esnext.string",
8283
"decorators",
8384
"decorators.legacy",
8485
// Default libraries

tests/baselines/reference/bundlerDirectoryModule(moduleresolution=bundler).trace.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,21 @@
10741074
"======== Module name '@typescript/lib-esnext/regexp' was not resolved. ========",
10751075
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
10761076
"File '/package.json' does not exist according to earlier cached lookups.",
1077+
"======== Resolving module '@typescript/lib-esnext/string' from '/.src/__lib_node_modules_lookup_lib.esnext.string.d.ts__.ts'. ========",
1078+
"Explicitly specified module resolution kind: 'Node10'.",
1079+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: TypeScript, Declaration.",
1080+
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
1081+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
1082+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
1083+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
1084+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
1085+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: JavaScript.",
1086+
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
1087+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
1088+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
1089+
"======== Module name '@typescript/lib-esnext/string' was not resolved. ========",
1090+
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
1091+
"File '/package.json' does not exist according to earlier cached lookups.",
10771092
"======== Resolving module '@typescript/lib-dom' from '/.src/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========",
10781093
"Explicitly specified module resolution kind: 'Node10'.",
10791094
"Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.",

tests/baselines/reference/bundlerDirectoryModule(moduleresolution=nodenext).trace.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,21 @@
10741074
"======== Module name '@typescript/lib-esnext/regexp' was not resolved. ========",
10751075
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
10761076
"File '/package.json' does not exist according to earlier cached lookups.",
1077+
"======== Resolving module '@typescript/lib-esnext/string' from '/.src/__lib_node_modules_lookup_lib.esnext.string.d.ts__.ts'. ========",
1078+
"Explicitly specified module resolution kind: 'Node10'.",
1079+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: TypeScript, Declaration.",
1080+
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
1081+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
1082+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
1083+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
1084+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
1085+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: JavaScript.",
1086+
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
1087+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
1088+
"Directory '/node_modules' does not exist, skipping all lookups in it.",
1089+
"======== Module name '@typescript/lib-esnext/string' was not resolved. ========",
1090+
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
1091+
"File '/package.json' does not exist according to earlier cached lookups.",
10771092
"======== Resolving module '@typescript/lib-dom' from '/.src/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========",
10781093
"Explicitly specified module resolution kind: 'Node10'.",
10791094
"Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.",

tests/baselines/reference/dependentDestructuredVariablesFromNestedPatterns.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async function myAllSettled<T extends readonly unknown[]>(fn: () => T) {
7070
: [undefined, new Error(String(result.reason))],
7171
>undefined : Symbol(undefined)
7272
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2022.error.d.ts, --, --))
73-
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 6 more)
73+
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --) ... and 7 more)
7474
>result.reason : Symbol(PromiseRejectedResult.reason, Decl(lib.es2020.promise.d.ts, --, --))
7575
>result : Symbol(result, Decl(dependentDestructuredVariablesFromNestedPatterns.ts, 21, 23))
7676
>reason : Symbol(PromiseRejectedResult.reason, Decl(lib.es2020.promise.d.ts, --, --))

tests/baselines/reference/modulePreserve2.trace.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,20 @@
10191019
"======== Module name '@typescript/lib-esnext/regexp' was not resolved. ========",
10201020
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
10211021
"File '/package.json' does not exist according to earlier cached lookups.",
1022+
"======== Resolving module '@typescript/lib-esnext/string' from '/.src/__lib_node_modules_lookup_lib.esnext.string.d.ts__.ts'. ========",
1023+
"Explicitly specified module resolution kind: 'Node10'.",
1024+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: TypeScript, Declaration.",
1025+
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
1026+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
1027+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
1028+
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
1029+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
1030+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: JavaScript.",
1031+
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
1032+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
1033+
"======== Module name '@typescript/lib-esnext/string' was not resolved. ========",
1034+
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
1035+
"File '/package.json' does not exist according to earlier cached lookups.",
10221036
"======== Resolving module '@typescript/lib-dom' from '/.src/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========",
10231037
"Explicitly specified module resolution kind: 'Node10'.",
10241038
"Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.",

tests/baselines/reference/modulePreserve3.trace.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,19 @@
951951
"======== Module name '@typescript/lib-esnext/regexp' was not resolved. ========",
952952
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
953953
"File '/package.json' does not exist according to earlier cached lookups.",
954+
"======== Resolving module '@typescript/lib-esnext/string' from '/.src/__lib_node_modules_lookup_lib.esnext.string.d.ts__.ts'. ========",
955+
"Explicitly specified module resolution kind: 'Node10'.",
956+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: TypeScript, Declaration.",
957+
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
958+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
959+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
960+
"Scoped package detected, looking in 'typescript__lib-esnext/string'",
961+
"Loading module '@typescript/lib-esnext/string' from 'node_modules' folder, target file types: JavaScript.",
962+
"Searching all ancestor node_modules directories for fallback extensions: JavaScript.",
963+
"Directory '/.src/node_modules' does not exist, skipping all lookups in it.",
964+
"======== Module name '@typescript/lib-esnext/string' was not resolved. ========",
965+
"File '/.ts/package.json' does not exist according to earlier cached lookups.",
966+
"File '/package.json' does not exist according to earlier cached lookups.",
954967
"======== Resolving module '@typescript/lib-dom' from '/.src/__lib_node_modules_lookup_lib.dom.d.ts__.ts'. ========",
955968
"Explicitly specified module resolution kind: 'Node10'.",
956969
"Loading module '@typescript/lib-dom' from 'node_modules' folder, target file types: TypeScript, Declaration.",

0 commit comments

Comments
 (0)