Skip to content

Commit 2fa229a

Browse files
committed
Merge remote-tracking branch 'origin/master' into faster-interface-check
* origin/master: (61 commits) Add release-2.7 to covered branches LEGO: check in for master to temporary branch. LEGO: check in for master to temporary branch. API: fix types to undefined union (microsoft#20909) Fix conflict between formatting rules (microsoft#21038) Switch to block-bodied lambda Better name for deferred mapped type:ReverseMapped Slightly simplify getCodeActions Make fixCannotFindModule return an empty array if there is no code action In checkAndAggregateReturnExpressionTypes, treat MethodDeclaration in an object literal same as a FunctionExpression (microsoft#20052) Return string completions for indexed access types Check for unused getter/setter in classes (microsoft#21013) Only replace `implements` with a comma if the heritage clauses are sensible Refine extends-to-implements code fix Fix version of @types/node to 8.5.5 (microsoft#21019) fix microsoft#20449, insert space between decorators (microsoft#20491) findConfigFile can return undefined (microsoft#20556) Allowed trailing commas in type parameter/argument lists (microsoft#20599) Added localization instructions to CONTRIBUTING.md (microsoft#20451) Simplify marker names ...
2 parents 92b03ec + 902d3b7 commit 2fa229a

File tree

182 files changed

+1844
-976
lines changed

Some content is hidden

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

182 files changed

+1844
-976
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ branches:
1818
- master
1919
- release-2.5
2020
- release-2.6
21+
- release-2.7
2122

2223
install:
2324
- npm uninstall typescript --no-save

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,10 @@ jake baseline-accept
183183
```
184184

185185
to establish the new baselines as the desired behavior. This will change the files in `tests\baselines\reference`, which should be included as part of your commit. It's important to carefully validate changes in the baselines.
186+
187+
## Localization
188+
189+
All strings the user may see are stored in [`diagnosticMessages.json`](./src/compiler/diagnosticMessages.json).
190+
If you make changes to it, run `jake generate-diagnostics` to push them to the `Diagnostic` interface in [`diagnosticInformationMap.generated.ts`](./src/compiler/diagnosticInformationMap.generated.ts).
191+
192+
See [coding guidelines on diagnostic messages](https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#diagnostic-messages).

Gulpfile.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ const es2018LibrarySourceMap = es2018LibrarySource.map(source =>
150150
({ target: "lib." + source, sources: ["header.d.ts", source] }));
151151

152152
const esnextLibrarySource = [
153-
"esnext.asynciterable.d.ts"
153+
"esnext.asynciterable.d.ts",
154+
"esnext.promise.d.ts"
154155
];
155156

156157
const esnextLibrarySourceMap = esnextLibrarySource.map(source =>

Jakefile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ var es2018LibrarySourceMap = es2018LibrarySource.map(function (source) {
213213
});
214214

215215
var esnextLibrarySource = [
216-
"esnext.asynciterable.d.ts"
216+
"esnext.asynciterable.d.ts",
217+
"esnext.promise.d.ts"
217218
];
218219

219220
var esnextLibrarySourceMap = esnextLibrarySource.map(function (source) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@types/minimist": "latest",
4545
"@types/mkdirp": "latest",
4646
"@types/mocha": "latest",
47-
"@types/node": "latest",
47+
"@types/node": "8.5.5",
4848
"@types/q": "latest",
4949
"@types/run-sequence": "latest",
5050
"@types/through2": "latest",

src/compiler/checker.ts

Lines changed: 194 additions & 147 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ namespace ts {
145145
"es2017.intl": "lib.es2017.intl.d.ts",
146146
"es2017.typedarrays": "lib.es2017.typedarrays.d.ts",
147147
"esnext.asynciterable": "lib.esnext.asynciterable.d.ts",
148+
"esnext.promise": "lib.esnext.promise.d.ts",
148149
}),
149150
},
150151
showInSimplifiedHelpView: true,

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/program.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace ts {
77
const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?)/;
88

9-
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string {
9+
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined {
1010
return forEachAncestorDirectory(searchPath, ancestor => {
1111
const fileName = combinePaths(ancestor, configName);
1212
return fileExists(fileName) ? fileName : undefined;
@@ -331,11 +331,11 @@ namespace ts {
331331
}
332332

333333
output += formatColorAndReset(relativeFileName, ForegroundColorEscapeSequences.Cyan);
334-
output += "(";
334+
output += ":";
335335
output += formatColorAndReset(`${ firstLine + 1 }`, ForegroundColorEscapeSequences.Yellow);
336-
output += ",";
336+
output += ":";
337337
output += formatColorAndReset(`${ firstLineChar + 1 }`, ForegroundColorEscapeSequences.Yellow);
338-
output += "): ";
338+
output += " - ";
339339
}
340340

341341
const categoryColor = getCategoryFormat(diagnostic.category);

src/compiler/transformers/esnext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ namespace ts {
968968
name: "typescript:asyncValues",
969969
scoped: false,
970970
text: `
971-
var __asyncValues = (this && this.__asyncIterator) || function (o) {
971+
var __asyncValues = (this && this.__asyncValues) || function (o) {
972972
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
973973
var m = o[Symbol.asyncIterator];
974974
return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator]();

src/compiler/types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ namespace ts {
25402540
export interface ParseConfigHost {
25412541
useCaseSensitiveFileNames: boolean;
25422542

2543-
readDirectory(rootDir: string, extensions: ReadonlyArray<string>, excludes: ReadonlyArray<string>, includes: ReadonlyArray<string>, depth: number): string[];
2543+
readDirectory(rootDir: string, extensions: ReadonlyArray<string>, excludes: ReadonlyArray<string> | undefined, includes: ReadonlyArray<string>, depth?: number): string[];
25442544

25452545
/**
25462546
* Gets a value indicating whether the specified path exists and is a file.
@@ -3251,6 +3251,7 @@ namespace ts {
32513251
ContainsPrivate = 1 << 8, // Synthetic property with private constituent(s)
32523252
ContainsStatic = 1 << 9, // Synthetic property with static constituent(s)
32533253
Late = 1 << 10, // Late-bound symbol for a computed property with a dynamic name
3254+
ReverseMapped = 1 << 11, // property of reverse-inferred homomorphic mapped type.
32543255
Synthetic = SyntheticProperty | SyntheticMethod
32553256
}
32563257

@@ -3260,6 +3261,12 @@ namespace ts {
32603261
isRestParameter?: boolean;
32613262
}
32623263

3264+
/* @internal */
3265+
export interface ReverseMappedSymbol extends TransientSymbol {
3266+
propertyType: Type;
3267+
mappedType: MappedType;
3268+
}
3269+
32633270
export const enum InternalSymbolName {
32643271
Call = "__call", // Call signatures
32653272
Constructor = "__constructor", // Constructor implementations
@@ -3494,6 +3501,7 @@ namespace ts {
34943501
EvolvingArray = 1 << 8, // Evolving array type
34953502
ObjectLiteralPatternWithComputedProperties = 1 << 9, // Object literal pattern with computed properties
34963503
ContainsSpread = 1 << 10, // Object literal contains spread operation
3504+
ReverseMapped = 1 << 11, // Object contains a property from a reverse-mapped type
34973505
ClassOrInterface = Class | Interface
34983506
}
34993507

@@ -3601,6 +3609,12 @@ namespace ts {
36013609
finalArrayType?: Type; // Final array type of evolving array type
36023610
}
36033611

3612+
/* @internal */
3613+
export interface ReverseMappedType extends ObjectType {
3614+
source: Type;
3615+
mappedType: MappedType;
3616+
}
3617+
36043618
/* @internal */
36053619
// Resolved object, union, or intersection type
36063620
export interface ResolvedType extends ObjectType, UnionOrIntersectionType {
@@ -4366,11 +4380,11 @@ namespace ts {
43664380
* If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just
43674381
* 'throw new Error("NotImplemented")'
43684382
*/
4369-
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModule[];
4383+
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): (ResolvedModule | undefined)[];
43704384
/**
43714385
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
43724386
*/
4373-
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[];
4387+
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string): (ResolvedTypeReferenceDirective | undefined)[];
43744388
getEnvironmentVariable?(name: string): string;
43754389
/* @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions): void;
43764390
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4403,7 +4403,7 @@ namespace ts {
44034403
return node.kind === SyntaxKind.RegularExpressionLiteral;
44044404
}
44054405

4406-
export function isNoSubstitutionTemplateLiteral(node: Node): node is LiteralExpression {
4406+
export function isNoSubstitutionTemplateLiteral(node: Node): node is NoSubstitutionTemplateLiteral {
44074407
return node.kind === SyntaxKind.NoSubstitutionTemplateLiteral;
44084408
}
44094409

src/harness/fourslash.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,11 @@ namespace FourSlash {
441441
this.goToPosition(marker.position);
442442
}
443443

444-
public goToEachMarker(action: () => void) {
445-
const markers = this.getMarkers();
444+
public goToEachMarker(markers: ReadonlyArray<Marker>, action: (marker: FourSlash.Marker, index: number) => void) {
446445
assert(markers.length);
447-
for (const marker of markers) {
448-
this.goToMarker(marker);
449-
action();
446+
for (let i = 0; i < markers.length; i++) {
447+
this.goToMarker(markers[i]);
448+
action(markers[i], i);
450449
}
451450
}
452451

@@ -873,7 +872,7 @@ namespace FourSlash {
873872
});
874873
}
875874

876-
public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: FourSlashInterface.VerifyCompletionListContainsOptions) {
875+
public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string | { kind?: string, kindModifiers?: string }, spanIndex?: number, hasAction?: boolean, options?: FourSlashInterface.VerifyCompletionListContainsOptions) {
877876
const completions = this.getCompletionListAtCaret(options);
878877
if (completions) {
879878
this.assertItemInCompletionList(completions.entries, entryId, text, documentation, kind, spanIndex, hasAction, options);
@@ -894,7 +893,7 @@ namespace FourSlash {
894893
* @param expectedKind the kind of symbol (see ScriptElementKind)
895894
* @param spanIndex the index of the range that the completion item's replacement text span should match
896895
*/
897-
public verifyCompletionListDoesNotContain(entryId: ts.Completions.CompletionEntryIdentifier, expectedText?: string, expectedDocumentation?: string, expectedKind?: string, spanIndex?: number, options?: FourSlashInterface.CompletionsAtOptions) {
896+
public verifyCompletionListDoesNotContain(entryId: ts.Completions.CompletionEntryIdentifier, expectedText?: string, expectedDocumentation?: string, expectedKind?: string | { kind?: string, kindModifiers?: string }, spanIndex?: number, options?: FourSlashInterface.CompletionsAtOptions) {
898897
let replacementSpan: ts.TextSpan;
899898
if (spanIndex !== undefined) {
900899
replacementSpan = this.getTextSpanForRangeAtIndex(spanIndex);
@@ -903,7 +902,7 @@ namespace FourSlash {
903902
const completions = this.getCompletionListAtCaret(options);
904903
if (completions) {
905904
let filterCompletions = completions.entries.filter(e => e.name === entryId.name && e.source === entryId.source);
906-
filterCompletions = expectedKind ? filterCompletions.filter(e => e.kind === expectedKind) : filterCompletions;
905+
filterCompletions = expectedKind ? filterCompletions.filter(e => e.kind === expectedKind || (typeof expectedKind === "object" && e.kind === expectedKind.kind)) : filterCompletions;
907906
filterCompletions = filterCompletions.filter(entry => {
908907
const details = this.getCompletionEntryDetails(entry.name);
909908
const documentation = details && ts.displayPartsToString(details.documentation);
@@ -3090,7 +3089,7 @@ Actual: ${stringify(fullActual)}`);
30903089
entryId: ts.Completions.CompletionEntryIdentifier,
30913090
text: string | undefined,
30923091
documentation: string | undefined,
3093-
kind: string | undefined,
3092+
kind: string | undefined | { kind?: string, kindModifiers?: string },
30943093
spanIndex: number | undefined,
30953094
hasAction: boolean | undefined,
30963095
options: FourSlashInterface.VerifyCompletionListContainsOptions | undefined,
@@ -3124,9 +3123,21 @@ Actual: ${stringify(fullActual)}`);
31243123
}
31253124

31263125
if (kind !== undefined) {
3127-
assert.equal(item.kind, kind, this.assertionMessageAtLastKnownMarker("completion item kind for " + entryId));
3126+
if (typeof kind === "string") {
3127+
assert.equal(item.kind, kind, this.assertionMessageAtLastKnownMarker("completion item kind for " + entryId));
3128+
}
3129+
else {
3130+
if (kind.kind) {
3131+
assert.equal(item.kind, kind.kind, this.assertionMessageAtLastKnownMarker("completion item kind for " + entryId));
3132+
}
3133+
if (kind.kindModifiers !== undefined) {
3134+
assert.equal(item.kindModifiers, kind.kindModifiers, this.assertionMessageAtLastKnownMarker("completion item kindModifiers for " + entryId));
3135+
}
3136+
}
31283137
}
31293138

3139+
3140+
31303141
if (spanIndex !== undefined) {
31313142
const span = this.getTextSpanForRangeAtIndex(spanIndex);
31323143
assert.isTrue(TestState.textSpansEqual(span, item.replacementSpan), this.assertionMessageAtLastKnownMarker(stringify(span) + " does not equal " + stringify(item.replacementSpan) + " replacement span for " + entryId));
@@ -3764,8 +3775,11 @@ namespace FourSlashInterface {
37643775
this.state.goToMarker(name);
37653776
}
37663777

3767-
public eachMarker(action: () => void) {
3768-
this.state.goToEachMarker(action);
3778+
public eachMarker(markers: ReadonlyArray<string>, action: (marker: FourSlash.Marker, index: number) => void): void;
3779+
public eachMarker(action: (marker: FourSlash.Marker, index: number) => void): void;
3780+
public eachMarker(a: ReadonlyArray<string> | ((marker: FourSlash.Marker, index: number) => void), b?: (marker: FourSlash.Marker, index: number) => void): void {
3781+
const markers = typeof a === "function" ? this.state.getMarkers() : a.map(m => this.state.getMarkerByName(m));
3782+
this.state.goToEachMarker(markers, typeof a === "function" ? a : b);
37693783
}
37703784

37713785
public rangeStart(range: FourSlash.Range) {
@@ -3840,7 +3854,7 @@ namespace FourSlashInterface {
38403854

38413855
// Verifies the completion list contains the specified symbol. The
38423856
// completion list is brought up if necessary
3843-
public completionListContains(entryId: string | ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: VerifyCompletionListContainsOptions) {
3857+
public completionListContains(entryId: string | ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string | { kind?: string, kindModifiers?: string }, spanIndex?: number, hasAction?: boolean, options?: VerifyCompletionListContainsOptions) {
38443858
if (typeof entryId === "string") {
38453859
entryId = { name: entryId, source: undefined };
38463860
}

src/harness/unittests/commandLineParsing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace ts {
6060
assertParseResult(["--lib", "es5,invalidOption", "0.ts"],
6161
{
6262
errors: [{
63-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.asynciterable'.",
63+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.asynciterable', 'esnext.promise'.",
6464
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
6565
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
6666

@@ -263,7 +263,7 @@ namespace ts {
263263
assertParseResult(["--lib", "es5,", "es7", "0.ts"],
264264
{
265265
errors: [{
266-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.asynciterable'.",
266+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.asynciterable', 'esnext.promise'.",
267267
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
268268
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
269269

@@ -283,7 +283,7 @@ namespace ts {
283283
assertParseResult(["--lib", "es5, ", "es7", "0.ts"],
284284
{
285285
errors: [{
286-
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.asynciterable'.",
286+
messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'esnext', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'esnext.asynciterable', 'esnext.promise'.",
287287
category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
288288
code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
289289

0 commit comments

Comments
 (0)