Skip to content

Commit 669797a

Browse files
committed
Merge branch 'master' into fix36604
2 parents f902f8a + b481dd4 commit 669797a

File tree

59 files changed

+996
-292
lines changed

Some content is hidden

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

59 files changed

+996
-292
lines changed

src/compiler/checker.ts

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,15 @@ namespace ts {
26792679
return links.target;
26802680
}
26812681

2682+
function tryResolveAlias(symbol: Symbol): Symbol | undefined {
2683+
const links = getSymbolLinks(symbol);
2684+
if (links.target !== resolvingSymbol) {
2685+
return resolveAlias(symbol);
2686+
}
2687+
2688+
return undefined;
2689+
}
2690+
26822691
/**
26832692
* Marks a symbol as type-only if its declaration is syntactically type-only.
26842693
* If it is not itself marked type-only, but resolves to a type-only alias
@@ -4049,6 +4058,7 @@ namespace ts {
40494058
getSourceFiles: () => host.getSourceFiles(),
40504059
getCurrentDirectory: maybeBind(host, host.getCurrentDirectory),
40514060
getProbableSymlinks: maybeBind(host, host.getProbableSymlinks),
4061+
useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames)
40524062
} : undefined },
40534063
encounteredError: false,
40544064
visitedTypes: undefined,
@@ -6330,7 +6340,8 @@ namespace ts {
63306340
return result;
63316341

63326342
function visitExistingNodeTreeSymbols<T extends Node>(node: T): Node {
6333-
if (isJSDocAllType(node)) {
6343+
// We don't _actually_ support jsdoc namepath types, emit `any` instead
6344+
if (isJSDocAllType(node) || node.kind === SyntaxKind.JSDocNamepathType) {
63346345
return createKeywordTypeNode(SyntaxKind.AnyKeyword);
63356346
}
63366347
if (isJSDocUnknownType(node)) {
@@ -11058,8 +11069,18 @@ namespace ts {
1105811069
}
1105911070
else {
1106011071
const constraintDeclaration = getConstraintDeclaration(typeParameter);
11061-
typeParameter.constraint = constraintDeclaration ? getTypeFromTypeNode(constraintDeclaration) :
11062-
getInferredTypeParameterConstraint(typeParameter) || noConstraintType;
11072+
if (!constraintDeclaration) {
11073+
typeParameter.constraint = getInferredTypeParameterConstraint(typeParameter) || noConstraintType;
11074+
}
11075+
else {
11076+
let type = getTypeFromTypeNode(constraintDeclaration);
11077+
if (type.flags & TypeFlags.Any && type !== errorType) { // Allow errorType to propegate to keep downstream errors suppressed
11078+
// use keyofConstraintType as the base constraint for mapped type key constraints (unknown isn;t assignable to that, but `any` was),
11079+
// use unknown otherwise
11080+
type = constraintDeclaration.parent.parent.kind === SyntaxKind.MappedType ? keyofConstraintType : unknownType;
11081+
}
11082+
typeParameter.constraint = type;
11083+
}
1106311084
}
1106411085
}
1106511086
return typeParameter.constraint === noConstraintType ? undefined : typeParameter.constraint;
@@ -13154,7 +13175,7 @@ namespace ts {
1315413175
* this function should be called in a left folding style, with left = previous result of getSpreadType
1315513176
* and right = the new element to be spread.
1315613177
*/
13157-
function getSpreadType(left: Type, right: Type, symbol: Symbol | undefined, objectFlags: ObjectFlags, readonly: boolean, isParentTypeNullable?: boolean): Type {
13178+
function getSpreadType(left: Type, right: Type, symbol: Symbol | undefined, objectFlags: ObjectFlags, readonly: boolean): Type {
1315813179
if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) {
1315913180
return anyType;
1316013181
}
@@ -13170,16 +13191,16 @@ namespace ts {
1317013191
if (left.flags & TypeFlags.Union) {
1317113192
const merged = tryMergeUnionOfObjectTypeAndEmptyObject(left as UnionType, readonly);
1317213193
if (merged) {
13173-
return getSpreadType(merged, right, symbol, objectFlags, readonly, isParentTypeNullable);
13194+
return getSpreadType(merged, right, symbol, objectFlags, readonly);
1317413195
}
13175-
return mapType(left, t => getSpreadType(t, right, symbol, objectFlags, readonly, isParentTypeNullable));
13196+
return mapType(left, t => getSpreadType(t, right, symbol, objectFlags, readonly));
1317613197
}
1317713198
if (right.flags & TypeFlags.Union) {
1317813199
const merged = tryMergeUnionOfObjectTypeAndEmptyObject(right as UnionType, readonly);
1317913200
if (merged) {
13180-
return getSpreadType(left, merged, symbol, objectFlags, readonly, maybeTypeOfKind(right, TypeFlags.Nullable));
13201+
return getSpreadType(left, merged, symbol, objectFlags, readonly);
1318113202
}
13182-
return mapType(right, t => getSpreadType(left, t, symbol, objectFlags, readonly, maybeTypeOfKind(right, TypeFlags.Nullable)));
13203+
return mapType(right, t => getSpreadType(left, t, symbol, objectFlags, readonly));
1318313204
}
1318413205
if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.BigIntLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive | TypeFlags.Index)) {
1318513206
return left;
@@ -13243,14 +13264,6 @@ namespace ts {
1324313264
result.nameType = getSymbolLinks(leftProp).nameType;
1324413265
members.set(leftProp.escapedName, result);
1324513266
}
13246-
else if (strictNullChecks &&
13247-
!isParentTypeNullable &&
13248-
symbol &&
13249-
!isFromSpreadAssignment(leftProp, symbol) &&
13250-
isFromSpreadAssignment(rightProp, symbol) &&
13251-
!maybeTypeOfKind(rightType, TypeFlags.Nullable)) {
13252-
error(leftProp.valueDeclaration, Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, unescapeLeadingUnderscores(leftProp.escapedName));
13253-
}
1325413267
}
1325513268
else {
1325613269
members.set(leftProp.escapedName, getSpreadSymbol(leftProp, readonly));
@@ -16783,10 +16796,6 @@ namespace ts {
1678316796
return match === -1 || discriminable.indexOf(/*searchElement*/ true, match + 1) !== -1 ? defaultValue : target.types[match];
1678416797
}
1678516798

16786-
function isFromSpreadAssignment(prop: Symbol, container: Symbol) {
16787-
return prop.valueDeclaration?.parent !== container.valueDeclaration;
16788-
}
16789-
1679016799
/**
1679116800
* A type is 'weak' if it is an object type with at least one optional property
1679216801
* and no required properties, call/construct signatures or index signatures
@@ -22547,6 +22556,7 @@ namespace ts {
2254722556
checkGrammarObjectLiteralExpression(node, inDestructuringPattern);
2254822557

2254922558
let propertiesTable: SymbolTable;
22559+
const allPropertiesTable = createSymbolTable();
2255022560
let propertiesArray: Symbol[] = [];
2255122561
let spread: Type = emptyObjectType;
2255222562

@@ -22628,6 +22638,7 @@ namespace ts {
2262822638
prop.type = type;
2262922639
prop.target = member;
2263022640
member = prop;
22641+
allPropertiesTable.set(prop.escapedName, prop);
2263122642
}
2263222643
else if (memberDecl.kind === SyntaxKind.SpreadAssignment) {
2263322644
if (languageVersion < ScriptTarget.ES2015) {
@@ -22645,6 +22656,16 @@ namespace ts {
2264522656
error(memberDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
2264622657
return errorType;
2264722658
}
22659+
for (const right of getPropertiesOfType(type)) {
22660+
const rightType = getTypeOfSymbol(right);
22661+
const left = allPropertiesTable.get(right.escapedName);
22662+
if (strictNullChecks &&
22663+
left &&
22664+
!maybeTypeOfKind(rightType, TypeFlags.Nullable)) {
22665+
error(left.valueDeclaration, Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, unescapeLeadingUnderscores(left.escapedName));
22666+
}
22667+
}
22668+
2264822669
spread = getSpreadType(spread, type, node.symbol, objectFlags, inConstContext);
2264922670
offset = i + 1;
2265022671
continue;
@@ -23924,12 +23945,26 @@ namespace ts {
2392423945
return getSpellingSuggestion(name, symbols, getCandidateName);
2392523946
function getCandidateName(candidate: Symbol) {
2392623947
const candidateName = symbolName(candidate);
23927-
return !startsWith(candidateName, "\"") && candidate.flags & meaning ? candidateName : undefined;
23948+
if (startsWith(candidateName, "\"")) {
23949+
return undefined;
23950+
}
23951+
23952+
if (candidate.flags & meaning) {
23953+
return candidateName;
23954+
}
23955+
23956+
if (candidate.flags & SymbolFlags.Alias) {
23957+
const alias = tryResolveAlias(candidate);
23958+
if (alias && alias.flags & meaning) {
23959+
return candidateName;
23960+
}
23961+
}
23962+
23963+
return undefined;
2392823964
}
2392923965
}
2393023966

2393123967
function markPropertyAsReferenced(prop: Symbol, nodeForCheckWriteOnly: Node | undefined, isThisAccess: boolean) {
23932-
2393323968
const valueDeclaration = prop && (prop.flags & SymbolFlags.ClassMember) && prop.valueDeclaration;
2393423969
if (!valueDeclaration) {
2393523970
return;
@@ -28754,6 +28789,9 @@ namespace ts {
2875428789
if (func.kind === SyntaxKind.ArrowFunction) {
2875528790
error(node, Diagnostics.An_arrow_function_cannot_have_a_this_parameter);
2875628791
}
28792+
if (func.kind === SyntaxKind.GetAccessor || func.kind === SyntaxKind.SetAccessor) {
28793+
error(node, Diagnostics.get_and_set_accessors_cannot_declare_this_parameters);
28794+
}
2875728795
}
2875828796

2875928797
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,6 +2899,10 @@
28992899
"category": "Error",
29002900
"code": 2783
29012901
},
2902+
"'get' and 'set' accessors cannot declare 'this' parameters.": {
2903+
"category": "Error",
2904+
"code": 2784
2905+
},
29022906

29032907
"Import declaration '{0}' is using private name '{1}'.": {
29042908
"category": "Error",

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ namespace ts {
968968
forEachResolvedProjectReference,
969969
isSourceOfProjectReferenceRedirect,
970970
emitBuildInfo,
971-
getProbableSymlinks
971+
getProbableSymlinks,
972+
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
972973
};
973974

974975
verifyCompilerOptions();

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,8 +3174,8 @@ namespace ts {
31743174
}
31753175

31763176
// TODO: This should implement TypeCheckerHost but that's an internal type.
3177-
export interface Program extends ScriptReferenceHost {
3178-
3177+
export interface Program extends ScriptReferenceHost, ModuleSpecifierResolutionHost {
3178+
getCurrentDirectory(): string;
31793179
/**
31803180
* Get a list of root file names that were passed to a 'createProgram'
31813181
*/

src/compiler/utilitiesPublic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ namespace ts {
18151815
export function isPropertyName(node: Node): node is PropertyName {
18161816
const kind = node.kind;
18171817
return kind === SyntaxKind.Identifier
1818+
|| kind === SyntaxKind.PrivateIdentifier
18181819
|| kind === SyntaxKind.StringLiteral
18191820
|| kind === SyntaxKind.NumericLiteral
18201821
|| kind === SyntaxKind.ComputedPropertyName;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7011,6 +7011,9 @@
70117011
<Item ItemId=";Only_named_exports_may_use_export_type_1383" ItemType="0" PsrId="306" Leaf="true">
70127012
<Str Cat="Text">
70137013
<Val><![CDATA[Only named exports may use 'export type'.]]></Val>
7014+
<Tgt Cat="Text" Stat="Loc" Orig="New">
7015+
<Val><![CDATA[只有已命名的导出可使用“导出类型”。]]></Val>
7016+
</Tgt>
70147017
</Str>
70157018
<Disp Icon="Str" />
70167019
</Item>
@@ -10878,6 +10881,9 @@
1087810881
<Item ItemId=";Type_of_property_0_circularly_references_itself_in_mapped_type_1_2615" ItemType="0" PsrId="306" Leaf="true">
1087910882
<Str Cat="Text">
1088010883
<Val><![CDATA[Type of property '{0}' circularly references itself in mapped type '{1}'.]]></Val>
10884+
<Tgt Cat="Text" Stat="Loc" Orig="New">
10885+
<Val><![CDATA[属性“{0}”的类型在已映射的类型“{1}”中循环引用其自身。]]></Val>
10886+
</Tgt>
1088110887
</Str>
1088210888
<Disp Icon="Str" />
1088310889
</Item>

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7008,6 +7008,12 @@
70087008
</Str>
70097009
<Disp Icon="Str" />
70107010
</Item>
7011+
<Item ItemId=";Only_named_exports_may_use_export_type_1383" ItemType="0" PsrId="306" Leaf="true">
7012+
<Str Cat="Text">
7013+
<Val><![CDATA[Only named exports may use 'export type'.]]></Val>
7014+
</Str>
7015+
<Disp Icon="Str" />
7016+
</Item>
70117017
<Item ItemId=";Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword_2340" ItemType="0" PsrId="306" Leaf="true">
70127018
<Str Cat="Text">
70137019
<Val><![CDATA[Only public and protected methods of the base class are accessible via the 'super' keyword.]]></Val>
@@ -7035,11 +7041,20 @@
70357041
</Str>
70367042
<Disp Icon="Str" />
70377043
</Item>
7038-
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_6064" ItemType="0" PsrId="306" Leaf="true">
7044+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line_6230" ItemType="0" PsrId="306" Leaf="true">
7045+
<Str Cat="Text">
7046+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'false' or 'null' on command line.]]></Val>
7047+
<Tgt Cat="Text" Stat="Loc" Orig="New">
7048+
<Val><![CDATA[只能在 'tsconfig.json' 檔案中指定 '{0}' 選項,或在命令列上將其設定為 'false' 或 'null'。]]></Val>
7049+
</Tgt>
7050+
</Str>
7051+
<Disp Icon="Str" />
7052+
</Item>
7053+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line_6064" ItemType="0" PsrId="306" Leaf="true">
70397054
<Str Cat="Text">
7040-
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file.]]></Val>
7055+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'null' on command line.]]></Val>
70417056
<Tgt Cat="Text" Stat="Loc" Orig="New">
7042-
<Val><![CDATA[只能在 'tsconfig.json' 檔案中指定選項 '{0}'。]]></Val>
7057+
<Val><![CDATA[只能在 'tsconfig.json' 檔案中指定 '{0}' 選項,或在命令列上將其設定為 'null'。]]></Val>
70437058
</Tgt>
70447059
</Str>
70457060
<Disp Icon="Str" />
@@ -9531,6 +9546,9 @@
95319546
<Item ItemId=";Tag_0_expects_at_least_1_arguments_but_the_JSX_factory_2_provides_at_most_3_6229" ItemType="0" PsrId="306" Leaf="true">
95329547
<Str Cat="Text">
95339548
<Val><![CDATA[Tag '{0}' expects at least '{1}' arguments, but the JSX factory '{2}' provides at most '{3}'.]]></Val>
9549+
<Tgt Cat="Text" Stat="Loc" Orig="New">
9550+
<Val><![CDATA[標籤 '{0}' 至少需要 '{1}' 個引數,但 JSX factory '{2}' 最多只提供 '{3}' 個。]]></Val>
9551+
</Tgt>
95349552
</Str>
95359553
<Disp Icon="Str" />
95369554
</Item>
@@ -10857,6 +10875,12 @@
1085710875
</Str>
1085810876
<Disp Icon="Str" />
1085910877
</Item>
10878+
<Item ItemId=";Type_of_property_0_circularly_references_itself_in_mapped_type_1_2615" ItemType="0" PsrId="306" Leaf="true">
10879+
<Str Cat="Text">
10880+
<Val><![CDATA[Type of property '{0}' circularly references itself in mapped type '{1}'.]]></Val>
10881+
</Str>
10882+
<Disp Icon="Str" />
10883+
</Item>
1086010884
<Item ItemId=";Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_cal_1321" ItemType="0" PsrId="306" Leaf="true">
1086110885
<Str Cat="Text">
1086210886
<Val><![CDATA[Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.]]></Val>

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7017,6 +7017,12 @@
70177017
</Str>
70187018
<Disp Icon="Str" />
70197019
</Item>
7020+
<Item ItemId=";Only_named_exports_may_use_export_type_1383" ItemType="0" PsrId="306" Leaf="true">
7021+
<Str Cat="Text">
7022+
<Val><![CDATA[Only named exports may use 'export type'.]]></Val>
7023+
</Str>
7024+
<Disp Icon="Str" />
7025+
</Item>
70207026
<Item ItemId=";Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword_2340" ItemType="0" PsrId="306" Leaf="true">
70217027
<Str Cat="Text">
70227028
<Val><![CDATA[Only public and protected methods of the base class are accessible via the 'super' keyword.]]></Val>
@@ -7044,11 +7050,20 @@
70447050
</Str>
70457051
<Disp Icon="Str" />
70467052
</Item>
7047-
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_6064" ItemType="0" PsrId="306" Leaf="true">
7053+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line_6230" ItemType="0" PsrId="306" Leaf="true">
7054+
<Str Cat="Text">
7055+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'false' or 'null' on command line.]]></Val>
7056+
<Tgt Cat="Text" Stat="Loc" Orig="New">
7057+
<Val><![CDATA[Možnost {0} jde zadat jenom v souboru tsconfig.json nebo nastavit na příkazovém řádku na hodnotu false nebo null.]]></Val>
7058+
</Tgt>
7059+
</Str>
7060+
<Disp Icon="Str" />
7061+
</Item>
7062+
<Item ItemId=";Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line_6064" ItemType="0" PsrId="306" Leaf="true">
70487063
<Str Cat="Text">
7049-
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file.]]></Val>
7064+
<Val><![CDATA[Option '{0}' can only be specified in 'tsconfig.json' file or set to 'null' on command line.]]></Val>
70507065
<Tgt Cat="Text" Stat="Loc" Orig="New">
7051-
<Val><![CDATA[Možnost {0} je možné zadat jenom v souboru tsconfig.json.]]></Val>
7066+
<Val><![CDATA[Možnost {0} jde zadat jenom v souboru tsconfig.json nebo nastavit na příkazovém řádku na hodnotu null.]]></Val>
70527067
</Tgt>
70537068
</Str>
70547069
<Disp Icon="Str" />
@@ -9540,6 +9555,9 @@
95409555
<Item ItemId=";Tag_0_expects_at_least_1_arguments_but_the_JSX_factory_2_provides_at_most_3_6229" ItemType="0" PsrId="306" Leaf="true">
95419556
<Str Cat="Text">
95429557
<Val><![CDATA[Tag '{0}' expects at least '{1}' arguments, but the JSX factory '{2}' provides at most '{3}'.]]></Val>
9558+
<Tgt Cat="Text" Stat="Loc" Orig="New">
9559+
<Val><![CDATA[Značka {0} očekává nejmíň {1} argumentů, ale objekt pro vytváření JSX {2} poskytuje maximálně {3}.]]></Val>
9560+
</Tgt>
95439561
</Str>
95449562
<Disp Icon="Str" />
95459563
</Item>
@@ -10866,6 +10884,12 @@
1086610884
</Str>
1086710885
<Disp Icon="Str" />
1086810886
</Item>
10887+
<Item ItemId=";Type_of_property_0_circularly_references_itself_in_mapped_type_1_2615" ItemType="0" PsrId="306" Leaf="true">
10888+
<Str Cat="Text">
10889+
<Val><![CDATA[Type of property '{0}' circularly references itself in mapped type '{1}'.]]></Val>
10890+
</Str>
10891+
<Disp Icon="Str" />
10892+
</Item>
1086910893
<Item ItemId=";Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_cal_1321" ItemType="0" PsrId="306" Leaf="true">
1087010894
<Str Cat="Text">
1087110895
<Val><![CDATA[Type of 'yield' operand in an async generator must either be a valid promise or must not contain a callable 'then' member.]]></Val>

0 commit comments

Comments
 (0)