Skip to content

Commit 4eaec97

Browse files
committed
Merge branch 'master' of github.com:Microsoft/TypeScript into nojvek-jsx-fragment-factory
2 parents 6eaa05b + 3bb84ef commit 4eaec97

File tree

384 files changed

+3775
-2715
lines changed

Some content is hidden

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

384 files changed

+3775
-2715
lines changed

src/compiler/checker.ts

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ namespace ts {
23032303
else {
23042304
Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
23052305
if (compilerOptions.preserveConstEnums) {
2306-
diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName);
2306+
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
23072307
}
23082308
}
23092309

@@ -4155,12 +4155,16 @@ namespace ts {
41554155
let leftStr = symbolValueDeclarationIsContextSensitive(left.symbol) ? typeToString(left, left.symbol.valueDeclaration) : typeToString(left);
41564156
let rightStr = symbolValueDeclarationIsContextSensitive(right.symbol) ? typeToString(right, right.symbol.valueDeclaration) : typeToString(right);
41574157
if (leftStr === rightStr) {
4158-
leftStr = typeToString(left, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4159-
rightStr = typeToString(right, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4158+
leftStr = getTypeNameForErrorDisplay(left);
4159+
rightStr = getTypeNameForErrorDisplay(right);
41604160
}
41614161
return [leftStr, rightStr];
41624162
}
41634163

4164+
function getTypeNameForErrorDisplay(type: Type) {
4165+
return typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
4166+
}
4167+
41644168
function symbolValueDeclarationIsContextSensitive(symbol: Symbol): boolean {
41654169
return symbol && symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !isContextSensitive(symbol.valueDeclaration);
41664170
}
@@ -15742,23 +15746,30 @@ namespace ts {
1574215746
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
1574315747
if (incompatibleStack.length) reportIncompatibleStack();
1574415748
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
15749+
let generalizedSource = source;
15750+
let generalizedSourceType = sourceType;
15751+
15752+
if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
15753+
generalizedSource = getBaseTypeOfLiteralType(source);
15754+
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
15755+
}
1574515756

1574615757
if (target.flags & TypeFlags.TypeParameter) {
1574715758
const constraint = getBaseConstraintOfType(target);
15748-
const constraintElab = constraint && isTypeAssignableTo(source, constraint);
15749-
if (constraintElab) {
15759+
let needsOriginalSource;
15760+
if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
1575015761
reportError(
1575115762
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
15752-
sourceType,
15763+
needsOriginalSource ? sourceType : generalizedSourceType,
1575315764
targetType,
15754-
typeToString(constraint!),
15765+
typeToString(constraint),
1575515766
);
1575615767
}
1575715768
else {
1575815769
reportError(
1575915770
Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1,
1576015771
targetType,
15761-
sourceType
15772+
generalizedSourceType
1576215773
);
1576315774
}
1576415775
}
@@ -15775,7 +15786,7 @@ namespace ts {
1577515786
}
1577615787
}
1577715788

15778-
reportError(message, sourceType, targetType);
15789+
reportError(message, generalizedSourceType, targetType);
1577915790
}
1578015791

1578115792
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
@@ -17304,9 +17315,10 @@ namespace ts {
1730417315
return Ternary.True;
1730517316
}
1730617317
if (isGenericMappedType(source)) {
17307-
// A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U }
17308-
// if T is related to U.
17309-
return kind === IndexKind.String ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
17318+
// A generic mapped type { [P in K]: T } is related to a type with an index signature
17319+
// { [x: string]: U }, and optionally with an index signature { [x: number]: V },
17320+
// if T is related to U and V.
17321+
return getIndexTypeOfType(target, IndexKind.String) ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
1731017322
}
1731117323
const indexType = getIndexTypeOfType(source, kind) || kind === IndexKind.Number && getIndexTypeOfType(source, IndexKind.String);
1731217324
if (indexType) {
@@ -17372,6 +17384,21 @@ namespace ts {
1737217384
}
1737317385
}
1737417386

17387+
function typeCouldHaveTopLevelSingletonTypes(type: Type): boolean {
17388+
if (type.flags & TypeFlags.UnionOrIntersection) {
17389+
return !!forEach((type as IntersectionType).types, typeCouldHaveTopLevelSingletonTypes);
17390+
}
17391+
17392+
if (type.flags & TypeFlags.Instantiable) {
17393+
const constraint = getConstraintOfType(type);
17394+
if (constraint) {
17395+
return typeCouldHaveTopLevelSingletonTypes(constraint);
17396+
}
17397+
}
17398+
17399+
return isUnitType(type);
17400+
}
17401+
1737517402
function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
1737617403
return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
1737717404
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
@@ -33850,8 +33877,7 @@ namespace ts {
3385033877
const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
3385133878
if (basePropertyFlags && derivedPropertyFlags) {
3385233879
// property/accessor is overridden with property/accessor
33853-
if (!compilerOptions.useDefineForClassFields
33854-
|| baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
33880+
if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
3385533881
|| base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
3385633882
|| derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
3385733883
// when the base property is abstract or from an interface, base/derived flags don't need to match
@@ -33867,7 +33893,7 @@ namespace ts {
3386733893
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
3386833894
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
3386933895
}
33870-
else {
33896+
else if (compilerOptions.useDefineForClassFields) {
3387133897
const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
3387233898
if (uninitialized
3387333899
&& !(derived.flags & SymbolFlags.Transient)

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5705,6 +5705,10 @@
57055705
"category": "Message",
57065706
"code": 95118
57075707
},
5708+
"Generate 'get' and 'set' accessors for all overriding properties": {
5709+
"category": "Message",
5710+
"code": 95119
5711+
},
57085712

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

src/compiler/transformers/module/esnextAnd2015.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,36 @@ namespace ts {
1818
}
1919

2020
if (isExternalModule(node) || compilerOptions.isolatedModules) {
21-
const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(node, compilerOptions);
22-
if (externalHelpersImportDeclaration) {
23-
const statements: Statement[] = [];
24-
const statementOffset = addPrologue(statements, node.statements);
25-
append(statements, externalHelpersImportDeclaration);
26-
27-
addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
28-
return updateSourceFileNode(
29-
node,
30-
setTextRange(createNodeArray(statements), node.statements));
31-
}
32-
else {
33-
return visitEachChild(node, visitor, context);
21+
const result = updateExternalModule(node);
22+
if (!isExternalModule(node) || some(result.statements, isExternalModuleIndicator)) {
23+
return result;
3424
}
25+
return updateSourceFileNode(
26+
result,
27+
setTextRange(createNodeArray([...result.statements, createEmptyExports()]), result.statements),
28+
);
3529
}
3630

3731
return node;
3832
}
3933

34+
function updateExternalModule(node: SourceFile) {
35+
const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(node, compilerOptions);
36+
if (externalHelpersImportDeclaration) {
37+
const statements: Statement[] = [];
38+
const statementOffset = addPrologue(statements, node.statements);
39+
append(statements, externalHelpersImportDeclaration);
40+
41+
addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
42+
return updateSourceFileNode(
43+
node,
44+
setTextRange(createNodeArray(statements), node.statements));
45+
}
46+
else {
47+
return visitEachChild(node, visitor, context);
48+
}
49+
}
50+
4051
function visitor(node: Node): VisitResult<Node> {
4152
switch (node.kind) {
4253
case SyntaxKind.ImportEqualsDeclaration:

src/compiler/transformers/ts.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ namespace ts {
2323
IsNamedExternalExport = 1 << 4,
2424
IsDefaultExternalExport = 1 << 5,
2525
IsDerivedClass = 1 << 6,
26+
UseImmediatelyInvokedFunctionExpression = 1 << 7,
2627

2728
HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators,
2829
NeedsName = HasStaticInitializedProperties | HasMemberDecorators,
29-
UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
30+
MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
3031
IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport,
3132
}
3233

@@ -595,6 +596,7 @@ namespace ts {
595596
if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace;
596597
else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport;
597598
else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport;
599+
if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
598600
return facts;
599601
}
600602

@@ -665,12 +667,6 @@ namespace ts {
665667
const iife = createImmediatelyInvokedArrowFunction(statements);
666668
setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper);
667669

668-
// Class comment is already added by the ES2015 transform when targeting ES5 or below.
669-
// Only add if targetting ES2015+ to prevent duplicates
670-
if (languageVersion > ScriptTarget.ES5) {
671-
addSyntheticLeadingComment(iife, SyntaxKind.MultiLineCommentTrivia, "* @class ");
672-
}
673-
674670
const varStatement = createVariableStatement(
675671
/*modifiers*/ undefined,
676672
createVariableDeclarationList([
@@ -679,7 +675,7 @@ namespace ts {
679675
/*type*/ undefined,
680676
iife
681677
)
682-
], languageVersion > ScriptTarget.ES5 ? NodeFlags.Let : undefined)
678+
])
683679
);
684680

685681
setOriginalNode(varStatement, node);

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

0 commit comments

Comments
 (0)