Skip to content

Commit 7b9d7f0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix-accidental-accessor-call
2 parents ac9d57c + d45f0d0 commit 7b9d7f0

File tree

278 files changed

+2711
-1388
lines changed

Some content is hidden

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

278 files changed

+2711
-1388
lines changed

.gitmodules

Whitespace-only changes.

src/compiler/checker.ts

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ namespace ts {
22872287
else {
22882288
Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
22892289
if (compilerOptions.preserveConstEnums) {
2290-
diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName);
2290+
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
22912291
}
22922292
}
22932293

@@ -4139,12 +4139,16 @@ namespace ts {
41394139
let leftStr = symbolValueDeclarationIsContextSensitive(left.symbol) ? typeToString(left, left.symbol.valueDeclaration) : typeToString(left);
41404140
let rightStr = symbolValueDeclarationIsContextSensitive(right.symbol) ? typeToString(right, right.symbol.valueDeclaration) : typeToString(right);
41414141
if (leftStr === rightStr) {
4142-
leftStr = typeToString(left, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4143-
rightStr = typeToString(right, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4142+
leftStr = getTypeNameForErrorDisplay(left);
4143+
rightStr = getTypeNameForErrorDisplay(right);
41444144
}
41454145
return [leftStr, rightStr];
41464146
}
41474147

4148+
function getTypeNameForErrorDisplay(type: Type) {
4149+
return typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4150+
}
4151+
41484152
function symbolValueDeclarationIsContextSensitive(symbol: Symbol): boolean {
41494153
return symbol && symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !isContextSensitive(symbol.valueDeclaration);
41504154
}
@@ -15726,23 +15730,30 @@ namespace ts {
1572615730
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
1572715731
if (incompatibleStack.length) reportIncompatibleStack();
1572815732
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
15733+
let generalizedSource = source;
15734+
let generalizedSourceType = sourceType;
15735+
15736+
if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
15737+
generalizedSource = getBaseTypeOfLiteralType(source);
15738+
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
15739+
}
1572915740

1573015741
if (target.flags & TypeFlags.TypeParameter) {
1573115742
const constraint = getBaseConstraintOfType(target);
15732-
const constraintElab = constraint && isTypeAssignableTo(source, constraint);
15733-
if (constraintElab) {
15743+
let needsOriginalSource;
15744+
if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
1573415745
reportError(
1573515746
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
15736-
sourceType,
15747+
needsOriginalSource ? sourceType : generalizedSourceType,
1573715748
targetType,
15738-
typeToString(constraint!),
15749+
typeToString(constraint),
1573915750
);
1574015751
}
1574115752
else {
1574215753
reportError(
1574315754
Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1,
1574415755
targetType,
15745-
sourceType
15756+
generalizedSourceType
1574615757
);
1574715758
}
1574815759
}
@@ -15759,7 +15770,7 @@ namespace ts {
1575915770
}
1576015771
}
1576115772

15762-
reportError(message, sourceType, targetType);
15773+
reportError(message, generalizedSourceType, targetType);
1576315774
}
1576415775

1576515776
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
@@ -17288,9 +17299,10 @@ namespace ts {
1728817299
return Ternary.True;
1728917300
}
1729017301
if (isGenericMappedType(source)) {
17291-
// A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U }
17292-
// if T is related to U.
17293-
return kind === IndexKind.String ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
17302+
// A generic mapped type { [P in K]: T } is related to a type with an index signature
17303+
// { [x: string]: U }, and optionally with an index signature { [x: number]: V },
17304+
// if T is related to U and V.
17305+
return getIndexTypeOfType(target, IndexKind.String) ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
1729417306
}
1729517307
const indexType = getIndexTypeOfType(source, kind) || kind === IndexKind.Number && getIndexTypeOfType(source, IndexKind.String);
1729617308
if (indexType) {
@@ -17356,6 +17368,21 @@ namespace ts {
1735617368
}
1735717369
}
1735817370

17371+
function typeCouldHaveTopLevelSingletonTypes(type: Type): boolean {
17372+
if (type.flags & TypeFlags.UnionOrIntersection) {
17373+
return !!forEach((type as IntersectionType).types, typeCouldHaveTopLevelSingletonTypes);
17374+
}
17375+
17376+
if (type.flags & TypeFlags.Instantiable) {
17377+
const constraint = getConstraintOfType(type);
17378+
if (constraint) {
17379+
return typeCouldHaveTopLevelSingletonTypes(constraint);
17380+
}
17381+
}
17382+
17383+
return isUnitType(type);
17384+
}
17385+
1735917386
function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
1736017387
return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
1736117388
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
@@ -33823,8 +33850,7 @@ namespace ts {
3382333850
const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
3382433851
if (basePropertyFlags && derivedPropertyFlags) {
3382533852
// property/accessor is overridden with property/accessor
33826-
if (!compilerOptions.useDefineForClassFields
33827-
|| baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
33853+
if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
3382833854
|| base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
3382933855
|| derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
3383033856
// when the base property is abstract or from an interface, base/derived flags don't need to match
@@ -33840,7 +33866,7 @@ namespace ts {
3384033866
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
3384133867
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
3384233868
}
33843-
else {
33869+
else if (compilerOptions.useDefineForClassFields) {
3384433870
const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
3384533871
if (uninitialized
3384633872
&& !(derived.flags & SymbolFlags.Transient)

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5705,10 +5705,14 @@
57055705
"category": "Message",
57065706
"code": 95118
57075707
},
5708-
"Remove parentheses": {
5708+
"Generate 'get' and 'set' accessors for all overriding properties": {
57095709
"category": "Message",
57105710
"code": 95119
57115711
},
5712+
"Remove parentheses": {
5713+
"category": "Message",
5714+
"code": 95120
5715+
},
57125716

57135717
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
57145718
"category": "Error",

src/lib/es2015.core.d.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -434,48 +434,48 @@ interface String {
434434
startsWith(searchString: string, position?: number): boolean;
435435

436436
/**
437-
* Returns an <a> HTML anchor element and sets the name attribute to the text value
437+
* Returns an `<a>` HTML anchor element and sets the name attribute to the text value
438438
* @param name
439439
*/
440440
anchor(name: string): string;
441441

442-
/** Returns a <big> HTML element */
442+
/** Returns a `<big>` HTML element */
443443
big(): string;
444444

445-
/** Returns a <blink> HTML element */
445+
/** Returns a `<blink>` HTML element */
446446
blink(): string;
447447

448-
/** Returns a <b> HTML element */
448+
/** Returns a `<b>` HTML element */
449449
bold(): string;
450450

451-
/** Returns a <tt> HTML element */
451+
/** Returns a `<tt>` HTML element */
452452
fixed(): string;
453453

454-
/** Returns a <font> HTML element and sets the color attribute value */
454+
/** Returns a `<font>` HTML element and sets the color attribute value */
455455
fontcolor(color: string): string;
456456

457-
/** Returns a <font> HTML element and sets the size attribute value */
457+
/** Returns a `<font>` HTML element and sets the size attribute value */
458458
fontsize(size: number): string;
459459

460-
/** Returns a <font> HTML element and sets the size attribute value */
460+
/** Returns a `<font>` HTML element and sets the size attribute value */
461461
fontsize(size: string): string;
462462

463-
/** Returns an <i> HTML element */
463+
/** Returns an `<i>` HTML element */
464464
italics(): string;
465465

466-
/** Returns an <a> HTML element and sets the href attribute value */
466+
/** Returns an `<a>` HTML element and sets the href attribute value */
467467
link(url: string): string;
468468

469-
/** Returns a <small> HTML element */
469+
/** Returns a `<small>` HTML element */
470470
small(): string;
471471

472-
/** Returns a <strike> HTML element */
472+
/** Returns a `<strike>` HTML element */
473473
strike(): string;
474474

475-
/** Returns a <sub> HTML element */
475+
/** Returns a `<sub>` HTML element */
476476
sub(): string;
477477

478-
/** Returns a <sup> HTML element */
478+
/** Returns a `<sup>` HTML element */
479479
sup(): string;
480480
}
481481

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

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,24 @@
450450
</Str>
451451
<Disp Icon="Str" />
452452
</Item>
453+
<Item ItemId=";A_labeled_tuple_element_is_declared_as_optional_with_a_question_mark_after_the_name_and_before_the_c_5086" ItemType="0" PsrId="306" Leaf="true">
454+
<Str Cat="Text">
455+
<Val><![CDATA[A labeled tuple element is declared as optional with a question mark after the name and before the colon, rather than after the type.]]></Val>
456+
<Tgt Cat="Text" Stat="Loc" Orig="New">
457+
<Val><![CDATA[标记的元组元素被声明为可选,并且问号位于名称之后、冒号之前,而不是位于类型之后。]]></Val>
458+
</Tgt>
459+
</Str>
460+
<Disp Icon="Str" />
461+
</Item>
462+
<Item ItemId=";A_labeled_tuple_element_is_declared_as_rest_with_a_before_the_name_rather_than_before_the_type_5087" ItemType="0" PsrId="306" Leaf="true">
463+
<Str Cat="Text">
464+
<Val><![CDATA[A labeled tuple element is declared as rest with a `...` before the name, rather than before the type.]]></Val>
465+
<Tgt Cat="Text" Stat="Loc" Orig="New">
466+
<Val><![CDATA[标记的元组元素在名称之前(而不是类型之前)以 "…" 声明为 rest。]]></Val>
467+
</Tgt>
468+
</Str>
469+
<Disp Icon="Str" />
470+
</Item>
453471
<Item ItemId=";A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_memb_2651" ItemType="0" PsrId="306" Leaf="true">
454472
<Str Cat="Text">
455473
<Val><![CDATA[A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.]]></Val>
@@ -867,6 +885,15 @@
867885
</Str>
868886
<Disp Icon="Str" />
869887
</Item>
888+
<Item ItemId=";A_tuple_member_cannot_be_both_optional_and_rest_5085" ItemType="0" PsrId="306" Leaf="true">
889+
<Str Cat="Text">
890+
<Val><![CDATA[A tuple member cannot be both optional and rest.]]></Val>
891+
<Tgt Cat="Text" Stat="Loc" Orig="New">
892+
<Val><![CDATA[元组成员不能既是可选的又是 rest。]]></Val>
893+
</Tgt>
894+
</Str>
895+
<Disp Icon="Str" />
896+
</Item>
870897
<Item ItemId=";A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Con_17007" ItemType="0" PsrId="306" Leaf="true">
871898
<Str Cat="Text">
872899
<Val><![CDATA[A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.]]></Val>
@@ -3522,6 +3549,15 @@
35223549
</Str>
35233550
<Disp Icon="Str" />
35243551
</Item>
3552+
<Item ItemId=";Convert_overload_list_to_single_signature_95118" ItemType="0" PsrId="306" Leaf="true">
3553+
<Str Cat="Text">
3554+
<Val><![CDATA[Convert overload list to single signature]]></Val>
3555+
<Tgt Cat="Text" Stat="Loc" Orig="New">
3556+
<Val><![CDATA[将重载列表转换为单一签名]]></Val>
3557+
</Tgt>
3558+
</Str>
3559+
<Disp Icon="Str" />
3560+
</Item>
35253561
<Item ItemId=";Convert_parameters_to_destructured_object_95075" ItemType="0" PsrId="306" Leaf="true">
35263562
<Str Cat="Text">
35273563
<Val><![CDATA[Convert parameters to destructured object]]></Val>
@@ -6055,7 +6091,7 @@
60556091
<Str Cat="Text">
60566092
<Val><![CDATA[Its element type '{0}' is not a valid JSX element.]]></Val>
60576093
<Tgt Cat="Text" Stat="Loc" Orig="New">
6058-
<Val><![CDATA[其元素类型{0}不是有效的 JSX 元素。]]></Val>
6094+
<Val><![CDATA[其元素类型 "{0}" 不是有效的 JSX 元素。]]></Val>
60596095
</Tgt>
60606096
</Str>
60616097
<Disp Icon="Str" />
@@ -6064,7 +6100,7 @@
60646100
<Str Cat="Text">
60656101
<Val><![CDATA[Its instance type '{0}' is not a valid JSX element.]]></Val>
60666102
<Tgt Cat="Text" Stat="Loc" Orig="New">
6067-
<Val><![CDATA[其实例类型{0}不是有效的 JSX 元素。]]></Val>
6103+
<Val><![CDATA[其实例类型 "{0}" 不是有效的 JSX 元素。]]></Val>
60686104
</Tgt>
60696105
</Str>
60706106
<Disp Icon="Str" />
@@ -6073,7 +6109,7 @@
60736109
<Str Cat="Text">
60746110
<Val><![CDATA[Its return type '{0}' is not a valid JSX element.]]></Val>
60756111
<Tgt Cat="Text" Stat="Loc" Orig="New">
6076-
<Val><![CDATA[其返回类型{0}不是有效的 JSX 元素。]]></Val>
6112+
<Val><![CDATA[其返回类型 "{0}" 不是有效的 JSX 元素。]]></Val>
60776113
</Tgt>
60786114
</Str>
60796115
<Disp Icon="Str" />
@@ -6807,6 +6843,15 @@
68076843
</Str>
68086844
<Disp Icon="Str" />
68096845
</Item>
6846+
<Item ItemId=";Move_labeled_tuple_element_modifiers_to_labels_95117" ItemType="0" PsrId="306" Leaf="true">
6847+
<Str Cat="Text">
6848+
<Val><![CDATA[Move labeled tuple element modifiers to labels]]></Val>
6849+
<Tgt Cat="Text" Stat="Loc" Orig="New">
6850+
<Val><![CDATA[将已标记的元组元素修饰符移至标签]]></Val>
6851+
</Tgt>
6852+
</Str>
6853+
<Disp Icon="Str" />
6854+
</Item>
68106855
<Item ItemId=";Move_to_a_new_file_95049" ItemType="0" PsrId="306" Leaf="true">
68116856
<Str Cat="Text">
68126857
<Val><![CDATA[Move to a new file]]></Val>
@@ -8761,7 +8806,7 @@
87618806
<Str Cat="Text">
87628807
<Val><![CDATA[Replace '{0}' with 'Promise<{1}>']]></Val>
87638808
<Tgt Cat="Text" Stat="Loc" Orig="New">
8764-
<Val><![CDATA[将{0}替换为 "Promise<{1}>"]]></Val>
8809+
<Val><![CDATA[将 "{0}" 替换为 "Promise<{1}>"]]></Val>
87658810
</Tgt>
87668811
</Str>
87678812
<Disp Icon="Str" />
@@ -10599,6 +10644,15 @@
1059910644
</Str>
1060010645
<Disp Icon="Str" />
1060110646
</Item>
10647+
<Item ItemId=";This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without_6234" ItemType="0" PsrId="306" Leaf="true">
10648+
<Str Cat="Text">
10649+
<Val><![CDATA[This expression is not callable because it is a 'get' accessor. Did you mean to use it without '()'?]]></Val>
10650+
<Tgt Cat="Text" Stat="Loc" Orig="New">
10651+
<Val><![CDATA[此表达式是 "get" 访问器,因此不可调用。你想在不使用 "()" 的情况下使用它吗?]]></Val>
10652+
</Tgt>
10653+
</Str>
10654+
<Disp Icon="Str" />
10655+
</Item>
1060210656
<Item ItemId=";This_expression_is_not_constructable_2351" ItemType="0" PsrId="306" Leaf="true">
1060310657
<Str Cat="Text">
1060410658
<Val><![CDATA[This expression is not constructable.]]></Val>
@@ -10764,6 +10818,15 @@
1076410818
</Str>
1076510819
<Disp Icon="Str" />
1076610820
</Item>
10821+
<Item ItemId=";Tuple_members_must_all_have_names_or_all_not_have_names_5084" ItemType="0" PsrId="306" Leaf="true">
10822+
<Str Cat="Text">
10823+
<Val><![CDATA[Tuple members must all have names or all not have names.]]></Val>
10824+
<Tgt Cat="Text" Stat="Loc" Orig="New">
10825+
<Val><![CDATA[元组成员必须全部具有或全部不具有名称。]]></Val>
10826+
</Tgt>
10827+
</Str>
10828+
<Disp Icon="Str" />
10829+
</Item>
1076710830
<Item ItemId=";Tuple_type_0_of_length_1_has_no_element_at_index_2_2493" ItemType="0" PsrId="306" Leaf="true">
1076810831
<Str Cat="Text">
1076910832
<Val><![CDATA[Tuple type '{0}' of length '{1}' has no element at index '{2}'.]]></Val>

0 commit comments

Comments
 (0)