Skip to content

Commit ac1aa5d

Browse files
committed
Merge branch 'master' of https://github.com/microsoft/TypeScript into bug/33511
2 parents 06567e0 + a88957e commit ac1aa5d

File tree

361 files changed

+3528
-1466
lines changed

Some content is hidden

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

361 files changed

+3528
-1466
lines changed

.gitmodules

Whitespace-only changes.

src/compiler/checker.ts

Lines changed: 45 additions & 13 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) {
@@ -17357,6 +17368,21 @@ namespace ts {
1735717368
}
1735817369
}
1735917370

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+
1736017386
function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
1736117387
return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
1736217388
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
@@ -28743,7 +28769,14 @@ namespace ts {
2874328769
}
2874428770
case SyntaxKind.CommaToken:
2874528771
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) {
28746-
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
28772+
const sf = getSourceFileOfNode(left);
28773+
const sourceText = sf.text;
28774+
const start = skipTrivia(sourceText, left.pos);
28775+
const isInDiag2657 = sf.parseDiagnostics.some(diag => {
28776+
if (diag.code !== Diagnostics.JSX_expressions_must_have_one_parent_element.code) return false;
28777+
return textSpanContainsPosition(diag, start);
28778+
});
28779+
if (!isInDiag2657) error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
2874728780
}
2874828781
return rightType;
2874928782

@@ -33824,8 +33857,7 @@ namespace ts {
3382433857
const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
3382533858
if (basePropertyFlags && derivedPropertyFlags) {
3382633859
// property/accessor is overridden with property/accessor
33827-
if (!compilerOptions.useDefineForClassFields
33828-
|| baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
33860+
if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
3382933861
|| base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
3383033862
|| derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
3383133863
// when the base property is abstract or from an interface, base/derived flags don't need to match
@@ -33841,7 +33873,7 @@ namespace ts {
3384133873
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
3384233874
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
3384333875
}
33844-
else {
33876+
else if (compilerOptions.useDefineForClassFields) {
3384533877
const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
3384633878
if (uninitialized
3384733879
&& !(derived.flags & SymbolFlags.Transient)

src/compiler/diagnosticMessages.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5705,6 +5705,34 @@
57055705
"category": "Message",
57065706
"code": 95118
57075707
},
5708+
"Generate 'get' and 'set' accessors for all overriding properties": {
5709+
"category": "Message",
5710+
"code": 95119
5711+
},
5712+
"Wrap in JSX fragment": {
5713+
"category": "Message",
5714+
"code": 95120
5715+
},
5716+
"Wrap all unparented JSX in JSX fragment": {
5717+
"category": "Message",
5718+
"code": 95121
5719+
},
5720+
"Convert arrow function or function expression": {
5721+
"category": "Message",
5722+
"code": 95122
5723+
},
5724+
"Convert to anonymous function": {
5725+
"category": "Message",
5726+
"code": 95123
5727+
},
5728+
"Convert to named function": {
5729+
"category": "Message",
5730+
"code": 95124
5731+
},
5732+
"Convert to arrow function": {
5733+
"category": "Message",
5734+
"code": 95125
5735+
},
57085736

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

src/compiler/parser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4503,7 +4503,7 @@ namespace ts {
45034503
return finishNode(node);
45044504
}
45054505

4506-
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement | JsxFragment {
4506+
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number): JsxElement | JsxSelfClosingElement | JsxFragment {
45074507
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
45084508
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
45094509
if (opening.kind === SyntaxKind.JsxOpeningElement) {
@@ -4541,15 +4541,16 @@ namespace ts {
45414541
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
45424542
// of one sort or another.
45434543
if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
4544-
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true));
4544+
const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
4545+
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
45454546
if (invalidElement) {
4546-
parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element);
45474547
const badNode = <BinaryExpression>createNode(SyntaxKind.BinaryExpression, result.pos);
45484548
badNode.end = invalidElement.end;
45494549
badNode.left = result;
45504550
badNode.right = invalidElement;
45514551
badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false);
45524552
badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos;
4553+
parseErrorAt(skipTrivia(sourceText, topBadPos), invalidElement.end, Diagnostics.JSX_expressions_must_have_one_parent_element);
45534554
return <JsxElement><Node>badNode;
45544555
}
45554556
}

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
19141914
var __importStar = (this && this.__importStar) || function (mod) {
19151915
if (mod && mod.__esModule) return mod;
19161916
var result = {};
1917-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1917+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19181918
__setModuleDefault(result, mod);
19191919
return result;
19201920
};`

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5376,6 +5376,15 @@
53765376
</Str>
53775377
<Disp Icon="Str" />
53785378
</Item>
5379+
<Item ItemId=";Generate_get_and_set_accessors_for_all_overriding_properties_95119" ItemType="0" PsrId="306" Leaf="true">
5380+
<Str Cat="Text">
5381+
<Val><![CDATA[Generate 'get' and 'set' accessors for all overriding properties]]></Val>
5382+
<Tgt Cat="Text" Stat="Loc" Orig="New">
5383+
<Val><![CDATA[为所有重写属性生成 "get" 和 "set" 访问器]]></Val>
5384+
</Tgt>
5385+
</Str>
5386+
<Disp Icon="Str" />
5387+
</Item>
53795388
<Item ItemId=";Generates_a_CPU_profile_6223" ItemType="0" PsrId="306" Leaf="true">
53805389
<Str Cat="Text">
53815390
<Val><![CDATA[Generates a CPU profile.]]></Val>

0 commit comments

Comments
 (0)