Skip to content

Commit d78247a

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 244db70 + 88c6825 commit d78247a

File tree

176 files changed

+1741
-249
lines changed

Some content is hidden

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

176 files changed

+1741
-249
lines changed

Jakefile.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ var servicesSources = [
151151
"signatureHelp.ts",
152152
"symbolDisplay.ts",
153153
"transpile.ts",
154+
// Formatting
154155
"formatting/formatting.ts",
155156
"formatting/formattingContext.ts",
156157
"formatting/formattingRequestKind.ts",
@@ -166,7 +167,18 @@ var servicesSources = [
166167
"formatting/rulesMap.ts",
167168
"formatting/rulesProvider.ts",
168169
"formatting/smartIndenter.ts",
169-
"formatting/tokenRange.ts"
170+
"formatting/tokenRange.ts",
171+
// CodeFixes
172+
"codeFixProvider.ts",
173+
"codefixes/fixes.ts",
174+
"codefixes/fixExtendsInterfaceBecomesImplements.ts",
175+
"codefixes/fixClassIncorrectlyImplementsInterface.ts",
176+
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
177+
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
178+
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
179+
"codefixes/helpers.ts",
180+
"codefixes/importFixes.ts",
181+
"codefixes/unusedIdentifierFixes.ts"
170182
].map(function (f) {
171183
return path.join(servicesDirectory, f);
172184
}));

src/compiler/checker.ts

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ namespace ts {
7979
getDeclaredTypeOfSymbol,
8080
getPropertiesOfType,
8181
getPropertyOfType,
82+
getIndexInfoOfType,
8283
getSignaturesOfType,
8384
getIndexTypeOfType,
8485
getBaseTypes,
86+
getTypeFromTypeNode,
8587
getReturnTypeOfSignature,
8688
getNonNullableType,
8789
getSymbolsInScope,
@@ -90,6 +92,7 @@ namespace ts {
9092
getExportSpecifierLocalTargetSymbol,
9193
getTypeAtLocation: getTypeOfNode,
9294
getPropertySymbolOfDestructuringAssignment,
95+
signatureToString,
9396
typeToString,
9497
getSymbolDisplayBuilder,
9598
symbolToString,
@@ -114,7 +117,8 @@ namespace ts {
114117
// we deliberately exclude augmentations
115118
// since we are only interested in declarations of the module itself
116119
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
117-
}
120+
},
121+
getApparentType
118122
};
119123

120124
const tupleTypes: GenericType[] = [];
@@ -1368,7 +1372,9 @@ namespace ts {
13681372
return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
13691373
}
13701374

1371-
// Resolves a qualified name and any involved aliases
1375+
/**
1376+
* Resolves a qualified name and any involved aliases.
1377+
*/
13721378
function resolveEntityName(name: EntityNameOrEntityNameExpression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean, location?: Node): Symbol | undefined {
13731379
if (nodeIsMissing(name)) {
13741380
return undefined;
@@ -2109,7 +2115,7 @@ namespace ts {
21092115
return result || types;
21102116
}
21112117

2112-
function visibilityToString(flags: ModifierFlags) {
2118+
function visibilityToString(flags: ModifierFlags): string | undefined {
21132119
if (flags === ModifierFlags.Private) {
21142120
return "private";
21152121
}
@@ -2488,26 +2494,6 @@ namespace ts {
24882494
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags);
24892495
}
24902496

2491-
function writeIndexSignature(info: IndexInfo, keyword: SyntaxKind) {
2492-
if (info) {
2493-
if (info.isReadonly) {
2494-
writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2495-
writeSpace(writer);
2496-
}
2497-
writePunctuation(writer, SyntaxKind.OpenBracketToken);
2498-
writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2499-
writePunctuation(writer, SyntaxKind.ColonToken);
2500-
writeSpace(writer);
2501-
writeKeyword(writer, keyword);
2502-
writePunctuation(writer, SyntaxKind.CloseBracketToken);
2503-
writePunctuation(writer, SyntaxKind.ColonToken);
2504-
writeSpace(writer);
2505-
writeType(info.type, TypeFormatFlags.None);
2506-
writePunctuation(writer, SyntaxKind.SemicolonToken);
2507-
writer.writeLine();
2508-
}
2509-
}
2510-
25112497
function writePropertyWithModifiers(prop: Symbol) {
25122498
if (isReadonlySymbol(prop)) {
25132499
writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
@@ -2595,8 +2581,8 @@ namespace ts {
25952581
writePunctuation(writer, SyntaxKind.SemicolonToken);
25962582
writer.writeLine();
25972583
}
2598-
writeIndexSignature(resolved.stringIndexInfo, SyntaxKind.StringKeyword);
2599-
writeIndexSignature(resolved.numberIndexInfo, SyntaxKind.NumberKeyword);
2584+
buildIndexSignatureDisplay(resolved.stringIndexInfo, writer, IndexKind.String, enclosingDeclaration, globalFlags, symbolStack);
2585+
buildIndexSignatureDisplay(resolved.numberIndexInfo, writer, IndexKind.Number, enclosingDeclaration, globalFlags, symbolStack);
26002586
for (const p of resolved.properties) {
26012587
const t = getTypeOfSymbol(p);
26022588
if (p.flags & (SymbolFlags.Function | SymbolFlags.Method) && !getPropertiesOfObjectType(t).length) {
@@ -2787,6 +2773,11 @@ namespace ts {
27872773
}
27882774

27892775
function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2776+
const returnType = getReturnTypeOfSignature(signature);
2777+
if (flags & TypeFormatFlags.SuppressAnyReturnType && isTypeAny(returnType)) {
2778+
return;
2779+
}
2780+
27902781
if (flags & TypeFormatFlags.WriteArrowStyleSignature) {
27912782
writeSpace(writer);
27922783
writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken);
@@ -2800,7 +2791,6 @@ namespace ts {
28002791
buildTypePredicateDisplay(signature.typePredicate, writer, enclosingDeclaration, flags, symbolStack);
28012792
}
28022793
else {
2803-
const returnType = getReturnTypeOfSignature(signature);
28042794
buildTypeDisplay(returnType, writer, enclosingDeclaration, flags, symbolStack);
28052795
}
28062796
}
@@ -2825,6 +2815,34 @@ namespace ts {
28252815
buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack);
28262816
}
28272817

2818+
function buildIndexSignatureDisplay(info: IndexInfo, writer: SymbolWriter, kind: IndexKind, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2819+
if (info) {
2820+
if (info.isReadonly) {
2821+
writeKeyword(writer, SyntaxKind.ReadonlyKeyword);
2822+
writeSpace(writer);
2823+
}
2824+
writePunctuation(writer, SyntaxKind.OpenBracketToken);
2825+
writer.writeParameter(info.declaration ? declarationNameToString(info.declaration.parameters[0].name) : "x");
2826+
writePunctuation(writer, SyntaxKind.ColonToken);
2827+
writeSpace(writer);
2828+
switch (kind) {
2829+
case IndexKind.Number:
2830+
writeKeyword(writer, SyntaxKind.NumberKeyword);
2831+
break;
2832+
case IndexKind.String:
2833+
writeKeyword(writer, SyntaxKind.StringKeyword);
2834+
break;
2835+
}
2836+
2837+
writePunctuation(writer, SyntaxKind.CloseBracketToken);
2838+
writePunctuation(writer, SyntaxKind.ColonToken);
2839+
writeSpace(writer);
2840+
buildTypeDisplay(info.type, writer, enclosingDeclaration, globalFlags, symbolStack);
2841+
writePunctuation(writer, SyntaxKind.SemicolonToken);
2842+
writer.writeLine();
2843+
}
2844+
}
2845+
28282846
return _displayBuilder || (_displayBuilder = {
28292847
buildSymbolDisplay,
28302848
buildTypeDisplay,
@@ -2835,6 +2853,7 @@ namespace ts {
28352853
buildDisplayForTypeParametersAndDelimiters,
28362854
buildTypeParameterDisplayFromSymbol,
28372855
buildSignatureDisplay,
2856+
buildIndexSignatureDisplay,
28382857
buildReturnTypeDisplay
28392858
});
28402859
}
@@ -3786,11 +3805,13 @@ namespace ts {
37863805
return signatures;
37873806
}
37883807

3789-
// The base constructor of a class can resolve to
3790-
// undefinedType if the class has no extends clause,
3791-
// unknownType if an error occurred during resolution of the extends expression,
3792-
// nullType if the extends expression is the null value, or
3793-
// an object type with at least one construct signature.
3808+
/**
3809+
* The base constructor of a class can resolve to
3810+
* * undefinedType if the class has no extends clause,
3811+
* * unknownType if an error occurred during resolution of the extends expression,
3812+
* * nullType if the extends expression is the null value, or
3813+
* * an object type with at least one construct signature.
3814+
*/
37943815
function getBaseConstructorTypeOfClass(type: InterfaceType): Type {
37953816
if (!type.resolvedBaseConstructorType) {
37963817
const baseTypeNode = getBaseTypeNodeOfClass(type);
@@ -4271,7 +4292,7 @@ namespace ts {
42714292
return <InterfaceTypeWithDeclaredMembers>type;
42724293
}
42734294

4274-
function getTypeWithThisArgument(type: Type, thisArgument?: Type) {
4295+
function getTypeWithThisArgument(type: Type, thisArgument?: Type): Type {
42754296
if (getObjectFlags(type) & ObjectFlags.Reference) {
42764297
return createTypeReference((<TypeReference>type).target,
42774298
concatenate((<TypeReference>type).typeArguments, [thisArgument || (<TypeReference>type).target.thisType]));
@@ -4497,6 +4518,9 @@ namespace ts {
44974518
setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo);
44984519
}
44994520

4521+
/**
4522+
* Converts an AnonymousType to a ResolvedType.
4523+
*/
45004524
function resolveAnonymousTypeMembers(type: AnonymousType) {
45014525
const symbol = type.symbol;
45024526
if (type.target) {
@@ -6629,17 +6653,19 @@ namespace ts {
66296653
const constraintType = getConstraintTypeFromMappedType(type);
66306654
if (constraintType.flags & TypeFlags.Index) {
66316655
const typeVariable = (<IndexType>constraintType).type;
6632-
const mappedTypeVariable = instantiateType(typeVariable, mapper);
6633-
if (typeVariable !== mappedTypeVariable) {
6634-
return mapType(mappedTypeVariable, t => {
6635-
if (isMappableType(t)) {
6636-
const replacementMapper = createUnaryTypeMapper(typeVariable, t);
6637-
const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper);
6638-
combinedMapper.mappedTypes = mapper.mappedTypes;
6639-
return instantiateMappedObjectType(type, combinedMapper);
6640-
}
6641-
return t;
6642-
});
6656+
if (typeVariable.flags & TypeFlags.TypeParameter) {
6657+
const mappedTypeVariable = instantiateType(typeVariable, mapper);
6658+
if (typeVariable !== mappedTypeVariable) {
6659+
return mapType(mappedTypeVariable, t => {
6660+
if (isMappableType(t)) {
6661+
const replacementMapper = createUnaryTypeMapper(typeVariable, t);
6662+
const combinedMapper = mapper.mappedTypes && mapper.mappedTypes.length === 1 ? replacementMapper : combineTypeMappers(replacementMapper, mapper);
6663+
combinedMapper.mappedTypes = mapper.mappedTypes;
6664+
return instantiateMappedObjectType(type, combinedMapper);
6665+
}
6666+
return t;
6667+
});
6668+
}
66436669
}
66446670
}
66456671
return instantiateMappedObjectType(type, mapper);
@@ -7278,10 +7304,12 @@ namespace ts {
72787304
return false;
72797305
}
72807306

7281-
// Compare two types and return
7282-
// Ternary.True if they are related with no assumptions,
7283-
// Ternary.Maybe if they are related with assumptions of other relationships, or
7284-
// Ternary.False if they are not related.
7307+
/**
7308+
* Compare two types and return
7309+
* * Ternary.True if they are related with no assumptions,
7310+
* * Ternary.Maybe if they are related with assumptions of other relationships, or
7311+
* * Ternary.False if they are not related.
7312+
*/
72857313
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
72867314
let result: Ternary;
72877315
if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) {

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ namespace ts {
10601060
}
10611061
}
10621062

1063-
function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
1063+
export function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
10641064
baseIndex = baseIndex || 0;
10651065

10661066
return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]);

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,23 +3243,19 @@
32433243
"category": "Message",
32443244
"code": 90002
32453245
},
3246-
"Change 'extends' to 'implements'": {
3246+
"Change 'extends' to 'implements'.": {
32473247
"category": "Message",
32483248
"code": 90003
32493249
},
3250-
"Remove unused identifiers": {
3250+
"Remove unused identifiers.": {
32513251
"category": "Message",
32523252
"code": 90004
32533253
},
3254-
"Implement interface on reference": {
3255-
"category": "Message",
3256-
"code": 90005
3257-
},
3258-
"Implement interface on class": {
3254+
"Implement interface '{0}'.": {
32593255
"category": "Message",
32603256
"code": 90006
32613257
},
3262-
"Implement inherited abstract class": {
3258+
"Implement inherited abstract class.": {
32633259
"category": "Message",
32643260
"code": 90007
32653261
},

0 commit comments

Comments
 (0)