Skip to content

Commit 8df5bef

Browse files
committed
Merge branch 'main' into gabritto/issue46609
2 parents 74cd7a5 + a05d851 commit 8df5bef

File tree

88 files changed

+1430
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1430
-116
lines changed

src/compiler/checker.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16013,7 +16013,7 @@ namespace ts {
1601316013
const declarations = concatenate(leftProp.declarations, rightProp.declarations);
1601416014
const flags = SymbolFlags.Property | (leftProp.flags & SymbolFlags.Optional);
1601516015
const result = createSymbol(flags, leftProp.escapedName);
16016-
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)]);
16016+
result.type = getUnionType([getTypeOfSymbol(leftProp), removeMissingOrUndefinedType(rightType)], UnionReduction.Subtype);
1601716017
result.leftSpread = leftProp;
1601816018
result.rightSpread = rightProp;
1601916019
result.declarations = declarations;
@@ -21221,9 +21221,10 @@ namespace ts {
2122121221
(isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) &&
2122221222
param.parent.parameters.indexOf(param) > -1 &&
2122321223
(resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) ||
21224-
param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) {
21224+
param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) {
2122521225
const newName = "arg" + param.parent.parameters.indexOf(param);
21226-
errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, declarationNameToString(param.name));
21226+
const typeName = declarationNameToString(param.name) + (param.dotDotDotToken ? "[]" : "");
21227+
errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, typeName);
2122721228
return;
2122821229
}
2122921230
diagnostic = (declaration as ParameterDeclaration).dotDotDotToken ?

src/compiler/commandLineParser.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace ts {
2929
["es2019", "lib.es2019.d.ts"],
3030
["es2020", "lib.es2020.d.ts"],
3131
["es2021", "lib.es2021.d.ts"],
32+
["es2022", "lib.es2022.d.ts"],
3233
["esnext", "lib.esnext.d.ts"],
3334
// Host only
3435
["dom", "lib.dom.d.ts"],
@@ -72,12 +73,16 @@ namespace ts {
7273
["es2021.string", "lib.es2021.string.d.ts"],
7374
["es2021.weakref", "lib.es2021.weakref.d.ts"],
7475
["es2021.intl", "lib.es2021.intl.d.ts"],
75-
["esnext.array", "lib.es2019.array.d.ts"],
76+
["es2022.array", "lib.es2022.array.d.ts"],
77+
["es2022.error", "lib.es2022.error.d.ts"],
78+
["es2022.object", "lib.es2022.object.d.ts"],
79+
["es2022.string", "lib.es2022.string.d.ts"],
80+
["esnext.array", "lib.es2022.array.d.ts"],
7681
["esnext.symbol", "lib.es2019.symbol.d.ts"],
7782
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
7883
["esnext.intl", "lib.esnext.intl.d.ts"],
7984
["esnext.bigint", "lib.es2020.bigint.d.ts"],
80-
["esnext.string", "lib.es2021.string.d.ts"],
85+
["esnext.string", "lib.es2022.string.d.ts"],
8186
["esnext.promise", "lib.es2021.promise.d.ts"],
8287
["esnext.weakref", "lib.es2021.weakref.d.ts"]
8388
];
@@ -314,6 +319,7 @@ namespace ts {
314319
es2019: ScriptTarget.ES2019,
315320
es2020: ScriptTarget.ES2020,
316321
es2021: ScriptTarget.ES2021,
322+
es2022: ScriptTarget.ES2022,
317323
esnext: ScriptTarget.ESNext,
318324
})),
319325
affectsSourceFile: true,

src/compiler/moduleSpecifiers.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,15 @@ namespace ts.moduleSpecifiers {
707707
if (host.fileExists(packageJsonPath)) {
708708
const packageJsonContent = JSON.parse(host.readFile!(packageJsonPath)!);
709709
// TODO: Inject `require` or `import` condition based on the intended import mode
710-
const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
711-
if (fromExports) {
712-
const withJsExtension = !hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
713-
return { ...withJsExtension, verbatimFromExports: true };
714-
}
715-
if (packageJsonContent.exports) {
716-
return { moduleFileToTry: path, blockedByExports: true };
710+
if (getEmitModuleResolutionKind(options) === ModuleResolutionKind.Node12 || getEmitModuleResolutionKind(options) === ModuleResolutionKind.NodeNext) {
711+
const fromExports = packageJsonContent.exports && typeof packageJsonContent.name === "string" ? tryGetModuleNameFromExports(options, path, packageRootPath, packageJsonContent.name, packageJsonContent.exports, ["node", "types"]) : undefined;
712+
if (fromExports) {
713+
const withJsExtension = !hasTSFileExtension(fromExports.moduleFileToTry) ? fromExports : { moduleFileToTry: removeFileExtension(fromExports.moduleFileToTry) + tryGetJSExtensionForFile(fromExports.moduleFileToTry, options) };
714+
return { ...withJsExtension, verbatimFromExports: true };
715+
}
716+
if (packageJsonContent.exports) {
717+
return { moduleFileToTry: path, blockedByExports: true };
718+
}
717719
}
718720
const versionPaths = packageJsonContent.typesVersions
719721
? getPackageJsonTypesVersionsPaths(packageJsonContent.typesVersions)

src/compiler/types.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -6268,6 +6268,7 @@ namespace ts {
62686268
ES2019 = 6,
62696269
ES2020 = 7,
62706270
ES2021 = 8,
6271+
ES2022 = 9,
62716272
ESNext = 99,
62726273
JSON = 100,
62736274
Latest = ESNext,
@@ -6725,15 +6726,16 @@ namespace ts {
67256726
ContainsTypeScript = 1 << 0,
67266727
ContainsJsx = 1 << 1,
67276728
ContainsESNext = 1 << 2,
6728-
ContainsES2021 = 1 << 3,
6729-
ContainsES2020 = 1 << 4,
6730-
ContainsES2019 = 1 << 5,
6731-
ContainsES2018 = 1 << 6,
6732-
ContainsES2017 = 1 << 7,
6733-
ContainsES2016 = 1 << 8,
6734-
ContainsES2015 = 1 << 9,
6735-
ContainsGenerator = 1 << 10,
6736-
ContainsDestructuringAssignment = 1 << 11,
6729+
ContainsES2022 = 1 << 3,
6730+
ContainsES2021 = 1 << 4,
6731+
ContainsES2020 = 1 << 5,
6732+
ContainsES2019 = 1 << 6,
6733+
ContainsES2018 = 1 << 7,
6734+
ContainsES2017 = 1 << 8,
6735+
ContainsES2016 = 1 << 9,
6736+
ContainsES2015 = 1 << 10,
6737+
ContainsGenerator = 1 << 11,
6738+
ContainsDestructuringAssignment = 1 << 12,
67376739

67386740
// Markers
67396741
// - Flags used to indicate that a subtree contains a specific transformation.
@@ -6762,6 +6764,7 @@ namespace ts {
67626764
AssertTypeScript = ContainsTypeScript,
67636765
AssertJsx = ContainsJsx,
67646766
AssertESNext = ContainsESNext,
6767+
AssertES2022 = ContainsES2022,
67656768
AssertES2021 = ContainsES2021,
67666769
AssertES2020 = ContainsES2020,
67676770
AssertES2019 = ContainsES2019,

src/compiler/utilities.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ namespace ts {
606606
AsyncIterableIterator: emptyArray,
607607
AsyncGenerator: emptyArray,
608608
AsyncGeneratorFunction: emptyArray,
609+
NumberFormat: ["formatToParts"]
609610
},
610611
es2019: {
611612
Array: ["flat", "flatMap"],
@@ -627,8 +628,21 @@ namespace ts {
627628
PromiseConstructor: ["any"],
628629
String: ["replaceAll"]
629630
},
630-
esnext: {
631-
NumberFormat: ["formatToParts"]
631+
es2022: {
632+
Array: ["at"],
633+
String: ["at"],
634+
Int8Array: ["at"],
635+
Uint8Array: ["at"],
636+
Uint8ClampedArray: ["at"],
637+
Int16Array: ["at"],
638+
Uint16Array: ["at"],
639+
Int32Array: ["at"],
640+
Uint32Array: ["at"],
641+
Float32Array: ["at"],
642+
Float64Array: ["at"],
643+
BigInt64Array: ["at"],
644+
BigUint64Array: ["at"],
645+
ObjectConstructor: ["hasOwn"]
632646
}
633647
};
634648
}

src/compiler/utilitiesPublic.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace ts {
1414
switch (getEmitScriptTarget(options)) {
1515
case ScriptTarget.ESNext:
1616
return "lib.esnext.full.d.ts";
17+
case ScriptTarget.ES2022:
18+
return "lib.es2022.full.d.ts";
1719
case ScriptTarget.ES2021:
1820
return "lib.es2021.full.d.ts";
1921
case ScriptTarget.ES2020:

src/lib/es2022.array.d.ts

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
interface Array<T> {
2+
/**
3+
* Returns the item located at the specified index.
4+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5+
*/
6+
at(index: number): T | undefined;
7+
}
8+
9+
interface ReadonlyArray<T> {
10+
/**
11+
* Returns the item located at the specified index.
12+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
13+
*/
14+
at(index: number): T | undefined;
15+
}
16+
17+
interface Int8Array {
18+
/**
19+
* Returns the item located at the specified index.
20+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
21+
*/
22+
at(index: number): number | undefined;
23+
}
24+
25+
interface Uint8Array {
26+
/**
27+
* Returns the item located at the specified index.
28+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
29+
*/
30+
at(index: number): number | undefined;
31+
}
32+
33+
interface Uint8ClampedArray {
34+
/**
35+
* Returns the item located at the specified index.
36+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
37+
*/
38+
at(index: number): number | undefined;
39+
}
40+
41+
interface Int16Array {
42+
/**
43+
* Returns the item located at the specified index.
44+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
45+
*/
46+
at(index: number): number | undefined;
47+
}
48+
49+
interface Uint16Array {
50+
/**
51+
* Returns the item located at the specified index.
52+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
53+
*/
54+
at(index: number): number | undefined;
55+
}
56+
57+
interface Int32Array {
58+
/**
59+
* Returns the item located at the specified index.
60+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
61+
*/
62+
at(index: number): number | undefined;
63+
}
64+
65+
interface Uint32Array {
66+
/**
67+
* Returns the item located at the specified index.
68+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
69+
*/
70+
at(index: number): number | undefined;
71+
}
72+
73+
interface Float32Array {
74+
/**
75+
* Returns the item located at the specified index.
76+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
77+
*/
78+
at(index: number): number | undefined;
79+
}
80+
81+
interface Float64Array {
82+
/**
83+
* Returns the item located at the specified index.
84+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
85+
*/
86+
at(index: number): number | undefined;
87+
}
88+
89+
interface BigInt64Array {
90+
/**
91+
* Returns the item located at the specified index.
92+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
93+
*/
94+
at(index: number): bigint | undefined;
95+
}
96+
97+
interface BigUint64Array {
98+
/**
99+
* Returns the item located at the specified index.
100+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
101+
*/
102+
at(index: number): bigint | undefined;
103+
}

src/lib/es2022.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2021" />
2+
/// <reference lib="es2022.array" />
3+
/// <reference lib="es2022.error" />
4+
/// <reference lib="es2022.object" />
5+
/// <reference lib="es2022.string" />

src/lib/es2022.error.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface ErrorOptions {
2+
cause?: Error;
3+
}
4+
5+
interface ErrorConstructor {
6+
new(message?: string, options?: ErrorOptions): Error;
7+
(message?: string, options?: ErrorOptions): Error;
8+
}

src/lib/es2022.full.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2022" />
2+
/// <reference lib="dom" />
3+
/// <reference lib="webworker.importscripts" />
4+
/// <reference lib="scripthost" />
5+
/// <reference lib="dom.iterable" />

src/lib/es2022.object.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface Object {
2+
/**
3+
* Determines whether an object has a property with the specified name.
4+
* @param o An object.
5+
* @param v A property name.
6+
*/
7+
hasOwn(o: object, v: PropertyKey): boolean;
8+
}

src/lib/es2022.string.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface String {
2+
/**
3+
* Returns a new String consisting of the single UTF-16 code unit located at the specified index.
4+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5+
*/
6+
at(index: number): string | undefined;
7+
}

src/lib/esnext.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/// <reference lib="es2021" />
1+
/// <reference lib="es2022" />
22
/// <reference lib="esnext.intl" />

src/lib/libs.json

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"es2019",
1010
"es2020",
1111
"es2021",
12+
"es2022",
1213
"esnext",
1314
// Host only
1415
"dom.generated",
@@ -52,6 +53,10 @@
5253
"es2021.promise",
5354
"es2021.weakref",
5455
"es2021.intl",
56+
"es2022.array",
57+
"es2022.error",
58+
"es2022.object",
59+
"es2022.string",
5560
"esnext.intl",
5661
// Default libraries
5762
"es5.full",
@@ -62,6 +67,7 @@
6267
"es2019.full",
6368
"es2020.full",
6469
"es2021.full",
70+
"es2022.full",
6571
"esnext.full"
6672
],
6773
"paths": {

src/server/protocol.ts

+20
Original file line numberDiff line numberDiff line change
@@ -3199,6 +3199,25 @@ namespace ts.server.protocol {
31993199
payload: TypingsInstalledTelemetryEventPayload;
32003200
}
32013201

3202+
// A __GDPR__FRAGMENT__ has no meaning until it is ${include}d by a __GDPR__ comment, at which point
3203+
// the included properties are effectively inlined into the __GDPR__ declaration. In this case, for
3204+
// example, any __GDPR__ comment including the TypeScriptCommonProperties will be updated with an
3205+
// additional version property with the classification below. Obviously, the purpose of such a construct
3206+
// is to reduce duplication and keep multiple use sites consistent (e.g. by making sure that all reflect
3207+
// any newly added TypeScriptCommonProperties). Unfortunately, the system has limits - in particular,
3208+
// these reusable __GDPR__FRAGMENT__s are not accessible across repo boundaries. Therefore, even though
3209+
// the code for adding the common properties (i.e. version), along with the corresponding __GDPR__FRAGMENT__,
3210+
// lives in the VS Code repo (see https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/utils/telemetry.ts)
3211+
// we have to duplicate it here. It would be nice to keep them in sync, but the only likely failure mode
3212+
// is adding a property to the VS Code repro but not here and the only consequence would be having that
3213+
// property suppressed on the events (i.e. __GDPT__ comments) in this repo that reference the out-of-date
3214+
// local __GDPR__FRAGMENT__.
3215+
/* __GDPR__FRAGMENT__
3216+
"TypeScriptCommonProperties" : {
3217+
"version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
3218+
}
3219+
*/
3220+
32023221
/* __GDPR__
32033222
"typingsinstalled" : {
32043223
"${include}": ["${TypeScriptCommonProperties}"],
@@ -3515,6 +3534,7 @@ namespace ts.server.protocol {
35153534
ES2019 = "ES2019",
35163535
ES2020 = "ES2020",
35173536
ES2021 = "ES2021",
3537+
ES2022 = "ES2022",
35183538
ESNext = "ESNext"
35193539
}
35203540

src/services/codefixes/addNameToNamelessParameter.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ namespace ts.codefix {
1414

1515
function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) {
1616
const token = getTokenAtPosition(sourceFile, pos);
17-
if (!isIdentifier(token)) {
18-
return Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + Debug.formatSyntaxKind(token.kind));
19-
}
2017
const param = token.parent;
2118
if (!isParameter(param)) {
2219
return Debug.fail("Tried to add a parameter name to a non-parameter: " + Debug.formatSyntaxKind(token.kind));
2320
}
21+
2422
const i = param.parent.parameters.indexOf(param);
2523
Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
2624
Debug.assert(i > -1, "Parameter not found in parent parameter list.");
25+
26+
const typeNode = factory.createTypeReferenceNode(param.name as Identifier, /*typeArguments*/ undefined);
2727
const replacement = factory.createParameterDeclaration(
2828
/*decorators*/ undefined,
2929
param.modifiers,
3030
param.dotDotDotToken,
3131
"arg" + i,
3232
param.questionToken,
33-
factory.createTypeReferenceNode(token, /*typeArguments*/ undefined),
33+
param.dotDotDotToken ? factory.createArrayTypeNode(typeNode) : typeNode,
3434
param.initializer);
35-
changeTracker.replaceNode(sourceFile, token, replacement);
35+
changeTracker.replaceNode(sourceFile, param, replacement);
3636
}
3737
}

0 commit comments

Comments
 (0)