Skip to content

Commit 59a3320

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: (78 commits) LEGO: check in for master to temporary branch. Skip default when initially iterating exports in __importStar, same as __exportStar (microsoft#38808) fix line endings Improve error range for ts2657 (jsx expr must have parent element), add code fix for it (microsoft#37917) fix(32341): add prefix name for module exports properties (microsoft#38541) fix(19385): add space after brace in the multiline string template (microsoft#38742) fix(38815): dive in arrow functions to check only this usage instead of checking all statements (microsoft#38865) LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. Convert HTML tags in doc-comments into markdown fix linting error LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. fix(38722): change error message for use-before-declaration on const enum (microsoft#38728) ...
2 parents 7e748f4 + 1d1c167 commit 59a3320

File tree

363 files changed

+3773
-1474
lines changed

Some content is hidden

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

363 files changed

+3773
-1474
lines changed

.gitmodules

Whitespace-only changes.

src/compiler/checker.ts

+45-13
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ namespace ts {
22902290
else {
22912291
Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
22922292
if (compilerOptions.preserveConstEnums) {
2293-
diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName);
2293+
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
22942294
}
22952295
}
22962296

@@ -4142,12 +4142,16 @@ namespace ts {
41424142
let leftStr = symbolValueDeclarationIsContextSensitive(left.symbol) ? typeToString(left, left.symbol.valueDeclaration) : typeToString(left);
41434143
let rightStr = symbolValueDeclarationIsContextSensitive(right.symbol) ? typeToString(right, right.symbol.valueDeclaration) : typeToString(right);
41444144
if (leftStr === rightStr) {
4145-
leftStr = typeToString(left, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4146-
rightStr = typeToString(right, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4145+
leftStr = getTypeNameForErrorDisplay(left);
4146+
rightStr = getTypeNameForErrorDisplay(right);
41474147
}
41484148
return [leftStr, rightStr];
41494149
}
41504150

4151+
function getTypeNameForErrorDisplay(type: Type) {
4152+
return typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4153+
}
4154+
41514155
function symbolValueDeclarationIsContextSensitive(symbol: Symbol): boolean {
41524156
return symbol && symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !isContextSensitive(symbol.valueDeclaration);
41534157
}
@@ -15729,23 +15733,30 @@ namespace ts {
1572915733
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
1573015734
if (incompatibleStack.length) reportIncompatibleStack();
1573115735
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
15736+
let generalizedSource = source;
15737+
let generalizedSourceType = sourceType;
15738+
15739+
if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
15740+
generalizedSource = getBaseTypeOfLiteralType(source);
15741+
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
15742+
}
1573215743

1573315744
if (target.flags & TypeFlags.TypeParameter) {
1573415745
const constraint = getBaseConstraintOfType(target);
15735-
const constraintElab = constraint && isTypeAssignableTo(source, constraint);
15736-
if (constraintElab) {
15746+
let needsOriginalSource;
15747+
if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
1573715748
reportError(
1573815749
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
15739-
sourceType,
15750+
needsOriginalSource ? sourceType : generalizedSourceType,
1574015751
targetType,
15741-
typeToString(constraint!),
15752+
typeToString(constraint),
1574215753
);
1574315754
}
1574415755
else {
1574515756
reportError(
1574615757
Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1,
1574715758
targetType,
15748-
sourceType
15759+
generalizedSourceType
1574915760
);
1575015761
}
1575115762
}
@@ -15762,7 +15773,7 @@ namespace ts {
1576215773
}
1576315774
}
1576415775

15765-
reportError(message, sourceType, targetType);
15776+
reportError(message, generalizedSourceType, targetType);
1576615777
}
1576715778

1576815779
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
@@ -17360,6 +17371,21 @@ namespace ts {
1736017371
}
1736117372
}
1736217373

17374+
function typeCouldHaveTopLevelSingletonTypes(type: Type): boolean {
17375+
if (type.flags & TypeFlags.UnionOrIntersection) {
17376+
return !!forEach((type as IntersectionType).types, typeCouldHaveTopLevelSingletonTypes);
17377+
}
17378+
17379+
if (type.flags & TypeFlags.Instantiable) {
17380+
const constraint = getConstraintOfType(type);
17381+
if (constraint) {
17382+
return typeCouldHaveTopLevelSingletonTypes(constraint);
17383+
}
17384+
}
17385+
17386+
return isUnitType(type);
17387+
}
17388+
1736317389
function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
1736417390
return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
1736517391
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
@@ -28746,7 +28772,14 @@ namespace ts {
2874628772
}
2874728773
case SyntaxKind.CommaToken:
2874828774
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) {
28749-
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
28775+
const sf = getSourceFileOfNode(left);
28776+
const sourceText = sf.text;
28777+
const start = skipTrivia(sourceText, left.pos);
28778+
const isInDiag2657 = sf.parseDiagnostics.some(diag => {
28779+
if (diag.code !== Diagnostics.JSX_expressions_must_have_one_parent_element.code) return false;
28780+
return textSpanContainsPosition(diag, start);
28781+
});
28782+
if (!isInDiag2657) error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
2875028783
}
2875128784
return rightType;
2875228785

@@ -33827,8 +33860,7 @@ namespace ts {
3382733860
const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
3382833861
if (basePropertyFlags && derivedPropertyFlags) {
3382933862
// property/accessor is overridden with property/accessor
33830-
if (!compilerOptions.useDefineForClassFields
33831-
|| baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
33863+
if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
3383233864
|| base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
3383333865
|| derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
3383433866
// when the base property is abstract or from an interface, base/derived flags don't need to match
@@ -33844,7 +33876,7 @@ namespace ts {
3384433876
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
3384533877
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
3384633878
}
33847-
else {
33879+
else if (compilerOptions.useDefineForClassFields) {
3384833880
const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
3384933881
if (uninitialized
3385033882
&& !(derived.flags & SymbolFlags.Transient)

src/compiler/diagnosticMessages.json

+28
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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4519,7 +4519,7 @@ namespace ts {
45194519
return finishNode(node);
45204520
}
45214521

4522-
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean): JsxElement | JsxSelfClosingElement | JsxFragment {
4522+
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number): JsxElement | JsxSelfClosingElement | JsxFragment {
45234523
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
45244524
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
45254525
if (opening.kind === SyntaxKind.JsxOpeningElement) {
@@ -4557,15 +4557,16 @@ namespace ts {
45574557
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
45584558
// of one sort or another.
45594559
if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
4560-
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true));
4560+
const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
4561+
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
45614562
if (invalidElement) {
4562-
parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element);
45634563
const badNode = <BinaryExpression>createNode(SyntaxKind.BinaryExpression, result.pos);
45644564
badNode.end = invalidElement.end;
45654565
badNode.left = result;
45664566
badNode.right = invalidElement;
45674567
badNode.operatorToken = createMissingNode(SyntaxKind.CommaToken, /*reportAtCurrentPosition*/ false);
45684568
badNode.operatorToken.pos = badNode.operatorToken.end = badNode.right.pos;
4569+
parseErrorAt(skipTrivia(sourceText, topBadPos), invalidElement.end, Diagnostics.JSX_expressions_must_have_one_parent_element);
45694570
return <JsxElement><Node>badNode;
45704571
}
45714572
}

src/compiler/transformers/module/module.ts

+1-1
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

+14-14
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

0 commit comments

Comments
 (0)