Skip to content

Commit fc1a2aa

Browse files
committed
Merge branch 'main' into always-suggesting-spelling-correction
2 parents 5ffa9a1 + e4d9282 commit fc1a2aa

File tree

176 files changed

+2870
-202
lines changed

Some content is hidden

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

176 files changed

+2870
-202
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12041,7 +12041,7 @@ namespace ts {
1204112041
else if (type !== firstType) {
1204212042
checkFlags |= CheckFlags.HasNonUniformType;
1204312043
}
12044-
if (isLiteralType(type)) {
12044+
if (isLiteralType(type) || isPatternLiteralType(type)) {
1204512045
checkFlags |= CheckFlags.HasLiteralType;
1204612046
}
1204712047
if (type.flags & TypeFlags.Never) {
@@ -19015,6 +19015,9 @@ namespace ts {
1901519015
}
1901619016
else if (target.flags & TypeFlags.TemplateLiteral) {
1901719017
if (source.flags & TypeFlags.TemplateLiteral) {
19018+
if (relation === comparableRelation) {
19019+
return templateLiteralTypesDefinitelyUnrelated(source as TemplateLiteralType, target as TemplateLiteralType) ? Ternary.False : Ternary.True;
19020+
}
1901819021
// Report unreliable variance for type variables referenced in template literal type placeholders.
1901919022
// For example, `foo-${number}` is related to `foo-${string}` even though number isn't related to string.
1902019023
instantiateType(source, makeFunctionTypeMapper(reportUnreliableMarkers));
@@ -19054,11 +19057,10 @@ namespace ts {
1905419057
return result;
1905519058
}
1905619059
}
19057-
else if (source.flags & TypeFlags.TemplateLiteral) {
19060+
else if (source.flags & TypeFlags.TemplateLiteral && !(target.flags & TypeFlags.Object)) {
1905819061
if (!(target.flags & TypeFlags.TemplateLiteral)) {
19059-
const baseConstraint = getBaseConstraintOfType(source);
19060-
const constraint = baseConstraint && baseConstraint !== source ? baseConstraint : stringType;
19061-
if (result = isRelatedTo(constraint, target, reportErrors)) {
19062+
const constraint = getBaseConstraintOfType(source);
19063+
if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, reportErrors))) {
1906219064
resetErrorInfo(saveErrorInfo);
1906319065
return result;
1906419066
}
@@ -21429,6 +21431,18 @@ namespace ts {
2142921431
return !!(type.symbol && some(type.symbol.declarations, hasSkipDirectInferenceFlag));
2143021432
}
2143121433

21434+
function templateLiteralTypesDefinitelyUnrelated(source: TemplateLiteralType, target: TemplateLiteralType) {
21435+
// Two template literal types with diffences in their starting or ending text spans are definitely unrelated.
21436+
const sourceStart = source.texts[0];
21437+
const targetStart = target.texts[0];
21438+
const sourceEnd = source.texts[source.texts.length - 1];
21439+
const targetEnd = target.texts[target.texts.length - 1];
21440+
const startLen = Math.min(sourceStart.length, targetStart.length);
21441+
const endLen = Math.min(sourceEnd.length, targetEnd.length);
21442+
return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) ||
21443+
sourceEnd.slice(sourceEnd.length - endLen) !== targetEnd.slice(targetEnd.length - endLen);
21444+
}
21445+
2143221446
function isValidBigIntString(s: string): boolean {
2143321447
const scanner = createScanner(ScriptTarget.ESNext, /*skipTrivia*/ false);
2143421448
let success = true;
@@ -22529,7 +22543,7 @@ namespace ts {
2252922543
if ((prop as TransientSymbol).isDiscriminantProperty === undefined) {
2253022544
(prop as TransientSymbol).isDiscriminantProperty =
2253122545
((prop as TransientSymbol).checkFlags & CheckFlags.Discriminant) === CheckFlags.Discriminant &&
22532-
!maybeTypeOfKind(getTypeOfSymbol(prop), TypeFlags.Instantiable & ~TypeFlags.TemplateLiteral);
22546+
!isGenericType(getTypeOfSymbol(prop));
2253322547
}
2253422548
return !!(prop as TransientSymbol).isDiscriminantProperty;
2253522549
}
@@ -23088,15 +23102,17 @@ namespace ts {
2308823102
return filterType(type, t => (t.flags & kind) !== 0);
2308923103
}
2309023104

23091-
// Return a new type in which occurrences of the string and number primitive types in
23092-
// typeWithPrimitives have been replaced with occurrences of string literals and numeric
23093-
// literals in typeWithLiterals, respectively.
23105+
// Return a new type in which occurrences of the string, number and bigint primitives and placeholder template
23106+
// literal types in typeWithPrimitives have been replaced with occurrences of compatible and more specific types
23107+
// from typeWithLiterals. This is essentially a limited form of intersection between the two types. We avoid a
23108+
// true intersection because it is more costly and, when applied to union types, generates a large number of
23109+
// types we don't actually care about.
2309423110
function replacePrimitivesWithLiterals(typeWithPrimitives: Type, typeWithLiterals: Type) {
23095-
if (isTypeSubsetOf(stringType, typeWithPrimitives) && maybeTypeOfKind(typeWithLiterals, TypeFlags.StringLiteral) ||
23096-
isTypeSubsetOf(numberType, typeWithPrimitives) && maybeTypeOfKind(typeWithLiterals, TypeFlags.NumberLiteral) ||
23097-
isTypeSubsetOf(bigintType, typeWithPrimitives) && maybeTypeOfKind(typeWithLiterals, TypeFlags.BigIntLiteral)) {
23111+
if (maybeTypeOfKind(typeWithPrimitives, TypeFlags.String | TypeFlags.TemplateLiteral | TypeFlags.Number | TypeFlags.BigInt) &&
23112+
maybeTypeOfKind(typeWithLiterals, TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping | TypeFlags.NumberLiteral | TypeFlags.BigIntLiteral)) {
2309823113
return mapType(typeWithPrimitives, t =>
23099-
t.flags & TypeFlags.String ? extractTypesOfKind(typeWithLiterals, TypeFlags.String | TypeFlags.StringLiteral) :
23114+
t.flags & TypeFlags.String ? extractTypesOfKind(typeWithLiterals, TypeFlags.String | TypeFlags.StringLiteral | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) :
23115+
isPatternLiteralType(t) && !maybeTypeOfKind(typeWithLiterals, TypeFlags.String | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) ? extractTypesOfKind(typeWithLiterals, TypeFlags.StringLiteral) :
2310023116
t.flags & TypeFlags.Number ? extractTypesOfKind(typeWithLiterals, TypeFlags.Number | TypeFlags.NumberLiteral) :
2310123117
t.flags & TypeFlags.BigInt ? extractTypesOfKind(typeWithLiterals, TypeFlags.BigInt | TypeFlags.BigIntLiteral) : t);
2310223118
}
@@ -23939,7 +23955,7 @@ namespace ts {
2393923955
const narrowedPropType = narrowType(propType);
2394023956
return filterType(type, t => {
2394123957
const discriminantType = getTypeOfPropertyOrIndexSignature(t, propName);
23942-
return !(discriminantType.flags & TypeFlags.Never) && isTypeComparableTo(discriminantType, narrowedPropType);
23958+
return !(narrowedPropType.flags & TypeFlags.Never) && isTypeComparableTo(narrowedPropType, discriminantType);
2394323959
});
2394423960
}
2394523961

@@ -31095,16 +31111,14 @@ namespace ts {
3109531111
}
3109631112

3109731113
function checkImportMetaProperty(node: MetaProperty) {
31098-
if (moduleKind !== ModuleKind.ES2020 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) {
31099-
if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) {
31100-
if (getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.ESNext) {
31101-
error(node, Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
31102-
}
31103-
}
31104-
else {
31105-
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_esnext_system_node12_or_nodenext);
31114+
if (moduleKind === ModuleKind.Node12 || moduleKind === ModuleKind.NodeNext) {
31115+
if (getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.ESNext) {
31116+
error(node, Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output);
3110631117
}
3110731118
}
31119+
else if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System) {
31120+
error(node, Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node12_or_nodenext);
31121+
}
3110831122
const file = getSourceFileOfNode(node);
3110931123
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
3111031124
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
@@ -32126,10 +32140,10 @@ namespace ts {
3212632140
Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module);
3212732141
diagnostics.add(diagnostic);
3212832142
}
32129-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
32143+
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
3213032144
span = getSpanOfTokenAtPosition(sourceFile, node.pos);
3213132145
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
32132-
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
32146+
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher);
3213332147
diagnostics.add(diagnostic);
3213432148
}
3213532149
}
@@ -33723,7 +33737,7 @@ namespace ts {
3372333737
}
3372433738

3372533739
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
33726-
if (isJSDocTypeAssertion(node)) {
33740+
if (hasJSDocNodes(node) && isJSDocTypeAssertion(node)) {
3372733741
const type = getJSDocTypeAssertionType(node);
3372833742
return checkAssertionWorker(type, type, node.expression, checkMode);
3372933743
}
@@ -42792,9 +42806,9 @@ namespace ts {
4279242806
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
4279342807
Diagnostics.for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module));
4279442808
}
42795-
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
42809+
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(forInOrOfStatement).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) {
4279642810
diagnostics.add(createDiagnosticForNode(forInOrOfStatement.awaitModifier,
42797-
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher));
42811+
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher));
4279842812
}
4279942813
}
4280042814
}
@@ -43558,7 +43572,7 @@ namespace ts {
4355843572

4355943573
function checkGrammarImportCallExpression(node: ImportCall): boolean {
4356043574
if (moduleKind === ModuleKind.ES2015) {
43561-
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_umd_node12_or_nodenext);
43575+
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node12_or_nodenext);
4356243576
}
4356343577

4356443578
if (node.typeArguments) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ namespace ts {
394394
es6: ModuleKind.ES2015,
395395
es2015: ModuleKind.ES2015,
396396
es2020: ModuleKind.ES2020,
397+
es2022: ModuleKind.ES2022,
397398
esnext: ModuleKind.ESNext,
398399
node12: ModuleKind.Node12,
399400
nodenext: ModuleKind.NodeNext,

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@
920920
"category": "Error",
921921
"code": 1322
922922
},
923-
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node12', or 'nodenext'.": {
923+
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node12', or 'nodenext'.": {
924924
"category": "Error",
925925
"code": 1323
926926
},
@@ -992,7 +992,7 @@
992992
"category": "Error",
993993
"code": 1342
994994
},
995-
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'esnext', 'system', 'node12', or 'nodenext'.": {
995+
"The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'.": {
996996
"category": "Error",
997997
"code": 1343
998998
},
@@ -1116,7 +1116,7 @@
11161116
"category": "Message",
11171117
"code": 1377
11181118
},
1119-
"Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
1119+
"Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
11201120
"category": "Error",
11211121
"code": 1378
11221122
},
@@ -1324,7 +1324,7 @@
13241324
"category": "Error",
13251325
"code": 1431
13261326
},
1327-
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
1327+
"Top-level 'for await' loops are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.": {
13281328
"category": "Error",
13291329
"code": 1432
13301330
},

src/compiler/transformer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace ts {
33
function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory<SourceFile | Bundle> {
44
switch (moduleKind) {
55
case ModuleKind.ESNext:
6+
case ModuleKind.ES2022:
67
case ModuleKind.ES2020:
78
case ModuleKind.ES2015:
89
return transformECMAScriptModule;

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,7 @@ namespace ts {
25072507
|| (isExternalModuleExport(node)
25082508
&& moduleKind !== ModuleKind.ES2015
25092509
&& moduleKind !== ModuleKind.ES2020
2510+
&& moduleKind !== ModuleKind.ES2022
25102511
&& moduleKind !== ModuleKind.ESNext
25112512
&& moduleKind !== ModuleKind.System);
25122513
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,6 +6192,7 @@ namespace ts {
61926192
// module kind).
61936193
ES2015 = 5,
61946194
ES2020 = 6,
6195+
ES2022 = 7,
61956196
ESNext = 99,
61966197

61976198
// Node12+ is an amalgam of commonjs (albeit updated) and es2020+, and represents a distinct module system from es2020/esnext

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6166,6 +6166,7 @@ namespace ts {
61666166
case ModuleKind.AMD:
61676167
case ModuleKind.ES2015:
61686168
case ModuleKind.ES2020:
6169+
case ModuleKind.ES2022:
61696170
case ModuleKind.ESNext:
61706171
return true;
61716172
default:

src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13044,12 +13044,18 @@
1304413044
<Item ItemId=";The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement_2207" ItemType="0" PsrId="306" Leaf="true">
1304513045
<Str Cat="Text">
1304613046
<Val><![CDATA[The 'type' modifier cannot be used on a named export when 'export type' is used on its export statement.]]></Val>
13047+
<Tgt Cat="Text" Stat="Loc" Orig="New">
13048+
<Val><![CDATA[Pokud se v příkazu k exportu používá „export type“, nemůžete v pojmenovaném exportu použít modifikátor „type“.]]></Val>
13049+
</Tgt>
1304713050
</Str>
1304813051
<Disp Icon="Str" />
1304913052
</Item>
1305013053
<Item ItemId=";The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement_2206" ItemType="0" PsrId="306" Leaf="true">
1305113054
<Str Cat="Text">
1305213055
<Val><![CDATA[The 'type' modifier cannot be used on a named import when 'import type' is used on its import statement.]]></Val>
13056+
<Tgt Cat="Text" Stat="Loc" Orig="New">
13057+
<Val><![CDATA[Pokud se v příkazu k importu používá „import type“, nemůžete v pojmenovaném importu použít modifikátor „type“.]]></Val>
13058+
</Tgt>
1305313059
</Str>
1305413060
<Disp Icon="Str" />
1305513061
</Item>

0 commit comments

Comments
 (0)