Skip to content

Commit 7393433

Browse files
committed
Merge branch 'master' into defer-inference-for-recursive-mapped-types
2 parents dd941e5 + e0f2033 commit 7393433

285 files changed

Lines changed: 6410 additions & 4525 deletions

File tree

Some content is hidden

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

package-lock.json

Lines changed: 264 additions & 161 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"devDependencies": {
3232
"@types/browserify": "latest",
3333
"@types/chai": "latest",
34-
"@types/colors": "latest",
3534
"@types/convert-source-map": "latest",
3635
"@types/del": "latest",
3736
"@types/glob": "latest",
@@ -80,7 +79,7 @@
8079
"ts-node": "latest",
8180
"tslint": "latest",
8281
"vinyl": "latest",
83-
"colors": "latest",
82+
"chalk": "latest",
8483
"typescript": "next"
8584
},
8685
"scripts": {

scripts/tslint/formatters/autolinkableStylishFormatter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Lint from "tslint";
2-
import * as colors from "colors";
2+
import chalk from "chalk";
33
import { sep } from "path";
44
function groupBy<T>(array: ReadonlyArray<T> | undefined, getGroupId: (elem: T, index: number) => number | string): T[][] {
55
if (!array) {
@@ -52,7 +52,7 @@ function getLink(failure: Lint.RuleFailure, color: boolean): string {
5252
if (path.indexOf("/") === -1 && path.indexOf("\\") === -1) {
5353
path = `.${sep}${path}`;
5454
}
55-
return `${color ? (sev === "WARNING" ? colors.blue(sev) : colors.red(sev)) : sev}: ${path}:${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`;
55+
return `${color ? (sev === "WARNING" ? chalk.blue(sev) : chalk.red(sev)) : sev}: ${path}:${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`;
5656
}
5757

5858
function getLinkMaxSize(failures: Lint.RuleFailure[]): number {
@@ -91,7 +91,7 @@ export class Formatter extends Lint.Formatters.AbstractFormatter {
9191
const nameMaxSize = getNameMaxSize(group);
9292
return `
9393
${currentFile}
94-
${group.map(f => `${pad(getLink(f, /*color*/ true), getLink(f, /*color*/ false).length, linkMaxSize)} ${colors.grey(pad(f.getRuleName(), f.getRuleName().length, nameMaxSize))} ${colors.yellow(f.getFailure())}`).join("\n")}`;
94+
${group.map(f => `${pad(getLink(f, /*color*/ true), getLink(f, /*color*/ false).length, linkMaxSize)} ${chalk.grey(pad(f.getRuleName(), f.getRuleName().length, nameMaxSize))} ${chalk.yellow(f.getFailure())}`).join("\n")}`;
9595
}).join("\n");
9696
}
9797
}

src/compiler/checker.ts

Lines changed: 238 additions & 161 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,8 @@ namespace ts {
14191419
return Array.isArray ? Array.isArray(value) : value instanceof Array;
14201420
}
14211421

1422-
export function toArray<T>(value: T | ReadonlyArray<T>): ReadonlyArray<T>;
14231422
export function toArray<T>(value: T | T[]): T[];
1423+
export function toArray<T>(value: T | ReadonlyArray<T>): ReadonlyArray<T>;
14241424
export function toArray<T>(value: T | T[]): T[] {
14251425
return isArray(value) ? value : [value];
14261426
}
@@ -3257,4 +3257,8 @@ namespace ts {
32573257
cachedReadDirectoryResult.clear();
32583258
}
32593259
}
3260+
3261+
export function singleElementArray<T>(t: T | undefined): T[] | undefined {
3262+
return t === undefined ? undefined : [t];
3263+
}
32603264
}

src/compiler/declarationEmitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace ts {
6464
let currentIdentifiers: Map<string>;
6565
let isCurrentFileExternalModule: boolean;
6666
let reportedDeclarationError = false;
67-
let errorNameNode: DeclarationName;
67+
let errorNameNode: DeclarationName | QualifiedName;
6868
const emitJsDocComments = compilerOptions.removeComments ? noop : writeJsDocComments;
6969
const emit = compilerOptions.stripInternal ? stripInternal : emitNode;
7070
let needsDeclare = true;
@@ -1372,7 +1372,7 @@ namespace ts {
13721372
// if this is property of type literal,
13731373
// or is parameter of method/call/construct/index signature of type literal
13741374
// emit only if type is specified
1375-
if (node.type) {
1375+
if (hasType(node)) {
13761376
write(": ");
13771377
emitType(node.type);
13781378
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,10 @@
22762276
"category": "Error",
22772277
"code": 2719
22782278
},
2279+
"Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?": {
2280+
"category": "Error",
2281+
"code": 2720
2282+
},
22792283

22802284
"Import declaration '{0}' is using private name '{1}'.": {
22812285
"category": "Error",

src/compiler/parser.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,48 @@ namespace ts {
8888
case SyntaxKind.SpreadAssignment:
8989
return visitNode(cbNode, (<SpreadAssignment>node).expression);
9090
case SyntaxKind.Parameter:
91+
return visitNodes(cbNode, cbNodes, node.decorators) ||
92+
visitNodes(cbNode, cbNodes, node.modifiers) ||
93+
visitNode(cbNode, (<ParameterDeclaration>node).dotDotDotToken) ||
94+
visitNode(cbNode, (<ParameterDeclaration>node).name) ||
95+
visitNode(cbNode, (<ParameterDeclaration>node).questionToken) ||
96+
visitNode(cbNode, (<ParameterDeclaration>node).type) ||
97+
visitNode(cbNode, (<ParameterDeclaration>node).initializer);
9198
case SyntaxKind.PropertyDeclaration:
99+
return visitNodes(cbNode, cbNodes, node.decorators) ||
100+
visitNodes(cbNode, cbNodes, node.modifiers) ||
101+
visitNode(cbNode, (<PropertyDeclaration>node).name) ||
102+
visitNode(cbNode, (<PropertyDeclaration>node).questionToken) ||
103+
visitNode(cbNode, (<PropertyDeclaration>node).exclamationToken) ||
104+
visitNode(cbNode, (<PropertyDeclaration>node).type) ||
105+
visitNode(cbNode, (<PropertyDeclaration>node).initializer);
92106
case SyntaxKind.PropertySignature:
107+
return visitNodes(cbNode, cbNodes, node.decorators) ||
108+
visitNodes(cbNode, cbNodes, node.modifiers) ||
109+
visitNode(cbNode, (<PropertySignature>node).name) ||
110+
visitNode(cbNode, (<PropertySignature>node).questionToken) ||
111+
visitNode(cbNode, (<PropertySignature>node).type) ||
112+
visitNode(cbNode, (<PropertySignature>node).initializer);
93113
case SyntaxKind.PropertyAssignment:
114+
return visitNodes(cbNode, cbNodes, node.decorators) ||
115+
visitNodes(cbNode, cbNodes, node.modifiers) ||
116+
visitNode(cbNode, (<PropertyAssignment>node).name) ||
117+
visitNode(cbNode, (<PropertyAssignment>node).questionToken) ||
118+
visitNode(cbNode, (<PropertyAssignment>node).initializer);
94119
case SyntaxKind.VariableDeclaration:
120+
return visitNodes(cbNode, cbNodes, node.decorators) ||
121+
visitNodes(cbNode, cbNodes, node.modifiers) ||
122+
visitNode(cbNode, (<VariableDeclaration>node).name) ||
123+
visitNode(cbNode, (<VariableDeclaration>node).exclamationToken) ||
124+
visitNode(cbNode, (<VariableDeclaration>node).type) ||
125+
visitNode(cbNode, (<VariableDeclaration>node).initializer);
95126
case SyntaxKind.BindingElement:
96127
return visitNodes(cbNode, cbNodes, node.decorators) ||
97128
visitNodes(cbNode, cbNodes, node.modifiers) ||
98-
visitNode(cbNode, (<VariableLikeDeclaration>node).propertyName) ||
99-
visitNode(cbNode, (<VariableLikeDeclaration>node).dotDotDotToken) ||
100-
visitNode(cbNode, (<VariableLikeDeclaration>node).name) ||
101-
visitNode(cbNode, (<VariableLikeDeclaration>node).questionToken) ||
102-
visitNode(cbNode, (<VariableLikeDeclaration>node).exclamationToken) ||
103-
visitNode(cbNode, (<VariableLikeDeclaration>node).type) ||
104-
visitNode(cbNode, (<VariableLikeDeclaration>node).initializer);
129+
visitNode(cbNode, (<BindingElement>node).propertyName) ||
130+
visitNode(cbNode, (<BindingElement>node).dotDotDotToken) ||
131+
visitNode(cbNode, (<BindingElement>node).name) ||
132+
visitNode(cbNode, (<BindingElement>node).initializer);
105133
case SyntaxKind.FunctionType:
106134
case SyntaxKind.ConstructorType:
107135
case SyntaxKind.CallSignature:

src/compiler/program.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,28 @@ namespace ts {
241241
return errorMessage;
242242
}
243243

244-
const redForegroundEscapeSequence = "\u001b[91m";
245-
const yellowForegroundEscapeSequence = "\u001b[93m";
246-
const blueForegroundEscapeSequence = "\u001b[93m";
244+
/** @internal */
245+
export enum ForegroundColorEscapeSequences {
246+
Grey = "\u001b[90m",
247+
Red = "\u001b[91m",
248+
Yellow = "\u001b[93m",
249+
Blue = "\u001b[94m",
250+
Cyan = "\u001b[96m"
251+
}
247252
const gutterStyleSequence = "\u001b[30;47m";
248253
const gutterSeparator = " ";
249254
const resetEscapeSequence = "\u001b[0m";
250255
const ellipsis = "...";
251256
function getCategoryFormat(category: DiagnosticCategory): string {
252257
switch (category) {
253-
case DiagnosticCategory.Warning: return yellowForegroundEscapeSequence;
254-
case DiagnosticCategory.Error: return redForegroundEscapeSequence;
255-
case DiagnosticCategory.Message: return blueForegroundEscapeSequence;
258+
case DiagnosticCategory.Warning: return ForegroundColorEscapeSequences.Yellow;
259+
case DiagnosticCategory.Error: return ForegroundColorEscapeSequences.Red;
260+
case DiagnosticCategory.Message: return ForegroundColorEscapeSequences.Blue;
256261
}
257262
}
258263

259-
function formatAndReset(text: string, formatStyle: string) {
264+
/** @internal */
265+
export function formatColorAndReset(text: string, formatStyle: string) {
260266
return formatStyle + text + resetEscapeSequence;
261267
}
262268

@@ -289,7 +295,7 @@ namespace ts {
289295
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
290296
// so we'll skip ahead to the second-to-last line.
291297
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
292-
context += formatAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
298+
context += formatColorAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
293299
i = lastLine - 1;
294300
}
295301

@@ -300,12 +306,12 @@ namespace ts {
300306
lineContent = lineContent.replace("\t", " "); // convert tabs to single spaces
301307

302308
// Output the gutter and the actual contents of the line.
303-
context += formatAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
309+
context += formatColorAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
304310
context += lineContent + host.getNewLine();
305311

306312
// Output the gutter and the error span for the line using tildes.
307-
context += formatAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
308-
context += redForegroundEscapeSequence;
313+
context += formatColorAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
314+
context += ForegroundColorEscapeSequences.Red;
309315
if (i === firstLine) {
310316
// If we're on the last line, then limit it to the last character of the last line.
311317
// Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
@@ -324,13 +330,19 @@ namespace ts {
324330
context += resetEscapeSequence;
325331
}
326332

327-
output += host.getNewLine();
328-
output += `${ relativeFileName }(${ firstLine + 1 },${ firstLineChar + 1 }): `;
333+
output += formatColorAndReset(relativeFileName, ForegroundColorEscapeSequences.Cyan);
334+
output += "(";
335+
output += formatColorAndReset(`${ firstLine + 1 }`, ForegroundColorEscapeSequences.Yellow);
336+
output += ",";
337+
output += formatColorAndReset(`${ firstLineChar + 1 }`, ForegroundColorEscapeSequences.Yellow);
338+
output += "): ";
329339
}
330340

331341
const categoryColor = getCategoryFormat(diagnostic.category);
332342
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
333-
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }`;
343+
output += formatColorAndReset(category, categoryColor);
344+
output += formatColorAndReset(` TS${ diagnostic.code }: `, ForegroundColorEscapeSequences.Grey);
345+
output += flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine());
334346

335347
if (diagnostic.file) {
336348
output += host.getNewLine();
@@ -339,7 +351,7 @@ namespace ts {
339351

340352
output += host.getNewLine();
341353
}
342-
return output;
354+
return output + host.getNewLine();
343355
}
344356

345357
export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string {

src/compiler/types.ts

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,40 @@ namespace ts {
584584
| JSDocFunctionType
585585
| EndOfFileToken;
586586

587+
export type HasType =
588+
| SignatureDeclaration
589+
| VariableDeclaration
590+
| ParameterDeclaration
591+
| PropertySignature
592+
| PropertyDeclaration
593+
| TypePredicateNode
594+
| ParenthesizedTypeNode
595+
| TypeOperatorNode
596+
| MappedTypeNode
597+
| AssertionExpression
598+
| TypeAliasDeclaration
599+
| JSDocTypeExpression
600+
| JSDocNonNullableType
601+
| JSDocNullableType
602+
| JSDocOptionalType
603+
| JSDocVariadicType;
604+
605+
export type HasInitializer =
606+
| HasExpressionInitializer
607+
| ForStatement
608+
| ForInStatement
609+
| ForOfStatement
610+
| JsxAttribute;
611+
612+
export type HasExpressionInitializer =
613+
| VariableDeclaration
614+
| ParameterDeclaration
615+
| BindingElement
616+
| PropertySignature
617+
| PropertyDeclaration
618+
| PropertyAssignment
619+
| EnumMember;
620+
587621
/* @internal */
588622
export type MutableNodeArray<T extends Node> = NodeArray<T> & T[];
589623

@@ -793,6 +827,9 @@ namespace ts {
793827
initializer?: Expression; // Optional initializer
794828
}
795829

830+
/*@internal*/
831+
export type BindingElementGrandparent = BindingElement["parent"]["parent"];
832+
796833
export interface PropertySignature extends TypeElement, JSDocContainer {
797834
kind: SyntaxKind.PropertySignature;
798835
name: PropertyName; // Declared property name
@@ -848,25 +885,18 @@ namespace ts {
848885
expression: Expression;
849886
}
850887

851-
// SyntaxKind.VariableDeclaration
852-
// SyntaxKind.Parameter
853-
// SyntaxKind.BindingElement
854-
// SyntaxKind.Property
855-
// SyntaxKind.PropertyAssignment
856-
// SyntaxKind.JsxAttribute
857-
// SyntaxKind.ShorthandPropertyAssignment
858-
// SyntaxKind.EnumMember
859-
// SyntaxKind.JSDocPropertyTag
860-
// SyntaxKind.JSDocParameterTag
861-
export interface VariableLikeDeclaration extends NamedDeclaration {
862-
propertyName?: PropertyName;
863-
dotDotDotToken?: DotDotDotToken;
864-
name: DeclarationName;
865-
questionToken?: QuestionToken;
866-
exclamationToken?: ExclamationToken;
867-
type?: TypeNode;
868-
initializer?: Expression;
869-
}
888+
export type VariableLikeDeclaration =
889+
| VariableDeclaration
890+
| ParameterDeclaration
891+
| BindingElement
892+
| PropertyDeclaration
893+
| PropertyAssignment
894+
| PropertySignature
895+
| JsxAttribute
896+
| ShorthandPropertyAssignment
897+
| EnumMember
898+
| JSDocPropertyTag
899+
| JSDocParameterTag;
870900

871901
export interface PropertyLikeDeclaration extends NamedDeclaration {
872902
name: PropertyName;
@@ -2739,6 +2769,8 @@ namespace ts {
27392769
getAugmentedPropertiesOfType(type: Type): Symbol[];
27402770
getRootSymbols(symbol: Symbol): Symbol[];
27412771
getContextualType(node: Expression): Type | undefined;
2772+
/* @internal */ isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike): boolean;
2773+
27422774
/**
27432775
* returns unknownSignature in the case of an error.
27442776
* @param argumentCount Apparent number of arguments, passed in case of a possibly incomplete call. This should come from an ArgumentListInfo. See `signatureHelp.ts`.
@@ -2753,6 +2785,8 @@ namespace ts {
27532785

27542786
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
27552787
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
2788+
/** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */
2789+
/* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression, type: Type, property: Symbol): boolean;
27562790
/** Follow all aliases to get the original symbol. */
27572791
getAliasedSymbol(symbol: Symbol): Symbol;
27582792
/** Follow a *single* alias to get the immediately aliased symbol. */

0 commit comments

Comments
 (0)