Skip to content

Commit f0e1fd9

Browse files
author
Andy Hanson
committed
Merge branch 'master' into map5
2 parents a0641b2 + d7160c7 commit f0e1fd9

File tree

104 files changed

+2255
-1661
lines changed

Some content is hidden

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

104 files changed

+2255
-1661
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"gulp-insert": "latest",
6161
"gulp-newer": "latest",
6262
"gulp-sourcemaps": "latest",
63-
"gulp-typescript": "latest",
63+
"gulp-typescript": "3.1.3",
6464
"into-stream": "latest",
6565
"istanbul": "latest",
6666
"jake": "latest",

src/compiler/checker.ts

Lines changed: 159 additions & 138 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ namespace ts {
212212
shortName: "p",
213213
type: "string",
214214
isFilePath: true,
215-
description: Diagnostics.Compile_the_project_in_the_given_directory,
216-
paramType: Diagnostics.DIRECTORY
215+
description: Diagnostics.Compile_the_project_given_the_path_to_its_configuration_file_or_to_a_folder_with_a_tsconfig_json,
216+
paramType: Diagnostics.FILE_OR_DIRECTORY
217217
},
218218
{
219219
name: "removeComments",
@@ -517,7 +517,7 @@ namespace ts {
517517
include: typeAcquisition.include || [],
518518
exclude: typeAcquisition.exclude || []
519519
};
520-
return result;
520+
return result;
521521
}
522522
return typeAcquisition;
523523
}

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace ts {
126126
}
127127

128128
entries() {
129-
return new MapIterator(this.data, (data, key) => [key, data[key]]);
129+
return new MapIterator(this.data, (data, key) => [key, data[key]] as [string, T]);
130130
}
131131

132132
forEach(action: (value: T, key: string) => void): void {

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,7 @@
25132513
"category": "Message",
25142514
"code": 6019
25152515
},
2516-
"Compile the project in the given directory.": {
2516+
"Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'": {
25172517
"category": "Message",
25182518
"code": 6020
25192519
},
@@ -2573,6 +2573,10 @@
25732573
"category": "Message",
25742574
"code": 6039
25752575
},
2576+
"FILE OR DIRECTORY": {
2577+
"category": "Message",
2578+
"code": 6040
2579+
},
25762580
"Compilation complete. Watching for file changes.": {
25772581
"category": "Message",
25782582
"code": 6042

src/compiler/moduleNameResolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace ts {
1515
}
1616

1717
/** Array that is only intended to be pushed to, never read. */
18-
interface Push<T> {
18+
export interface Push<T> {
1919
push(value: T): void;
2020
}
2121

@@ -358,7 +358,7 @@ namespace ts {
358358
* Then it computes the set of parent folders for 'directory' that should have the same module resolution result
359359
* and for every parent folder in set it adds entry: parent -> module resolution. .
360360
* Lets say we first directory name: /a/b/c/d/e and resolution result is: /a/b/bar.ts.
361-
* Set of parent folders that should have the same result will be:
361+
* Set of parent folders that should have the same result will be:
362362
* [
363363
* /a/b/c/d, /a/b/c, /a/b
364364
* ]
@@ -1023,7 +1023,7 @@ namespace ts {
10231023

10241024
/**
10251025
* Represents result of search. Normally when searching among several alternatives we treat value `undefined` as indicator
1026-
* that search fails and we should try another option.
1026+
* that search fails and we should try another option.
10271027
* However this does not allow us to represent final result that should be used instead of further searching (i.e. a final result that was found in cache).
10281028
* SearchResult is used to deal with this issue, its values represents following outcomes:
10291029
* - undefined - not found, continue searching

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@
28252825
EnumLike = Enum | EnumLiteral,
28262826
UnionOrIntersection = Union | Intersection,
28272827
StructuredType = Object | Union | Intersection,
2828-
StructuredOrTypeParameter = StructuredType | TypeParameter | Index,
2828+
StructuredOrTypeVariable = StructuredType | TypeParameter | Index | IndexedAccess,
28292829
TypeVariable = TypeParameter | IndexedAccess,
28302830

28312831
// 'Narrowable' types are types where narrowing actually narrows.

src/harness/fourslash.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -536,53 +536,66 @@ namespace FourSlash {
536536
}
537537

538538
public verifyGoToDefinitionIs(endMarker: string | string[]) {
539-
this.verifyGoToDefinitionWorker(endMarker instanceof Array ? endMarker : [endMarker]);
539+
this.verifyGoToXWorker(endMarker instanceof Array ? endMarker : [endMarker], () => this.getGoToDefinition());
540540
}
541541

542542
public verifyGoToDefinition(arg0: any, endMarkerNames?: string | string[]) {
543+
this.verifyGoToX(arg0, endMarkerNames, () => this.getGoToDefinition());
544+
}
545+
546+
private getGoToDefinition(): ts.DefinitionInfo[] {
547+
return this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition)
548+
}
549+
550+
public verifyGoToType(arg0: any, endMarkerNames?: string | string[]) {
551+
this.verifyGoToX(arg0, endMarkerNames, () =>
552+
this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition));
553+
}
554+
555+
private verifyGoToX(arg0: any, endMarkerNames: string | string[] | undefined, getDefs: () => ts.DefinitionInfo[] | undefined) {
543556
if (endMarkerNames) {
544-
this.verifyGoToDefinitionPlain(arg0, endMarkerNames);
557+
this.verifyGoToXPlain(arg0, endMarkerNames, getDefs);
545558
}
546559
else if (arg0 instanceof Array) {
547560
const pairs: [string | string[], string | string[]][] = arg0;
548561
for (const [start, end] of pairs) {
549-
this.verifyGoToDefinitionPlain(start, end);
562+
this.verifyGoToXPlain(start, end, getDefs);
550563
}
551564
}
552565
else {
553566
const obj: { [startMarkerName: string]: string | string[] } = arg0;
554567
for (const startMarkerName in obj) {
555568
if (ts.hasProperty(obj, startMarkerName)) {
556-
this.verifyGoToDefinitionPlain(startMarkerName, obj[startMarkerName]);
569+
this.verifyGoToXPlain(startMarkerName, obj[startMarkerName], getDefs);
557570
}
558571
}
559572
}
560573
}
561574

562-
private verifyGoToDefinitionPlain(startMarkerNames: string | string[], endMarkerNames: string | string[]) {
575+
private verifyGoToXPlain(startMarkerNames: string | string[], endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | undefined) {
563576
if (startMarkerNames instanceof Array) {
564577
for (const start of startMarkerNames) {
565-
this.verifyGoToDefinitionSingle(start, endMarkerNames);
578+
this.verifyGoToXSingle(start, endMarkerNames, getDefs);
566579
}
567580
}
568581
else {
569-
this.verifyGoToDefinitionSingle(startMarkerNames, endMarkerNames);
582+
this.verifyGoToXSingle(startMarkerNames, endMarkerNames, getDefs);
570583
}
571584
}
572585

573586
public verifyGoToDefinitionForMarkers(markerNames: string[]) {
574587
for (const markerName of markerNames) {
575-
this.verifyGoToDefinitionSingle(`${markerName}Reference`, `${markerName}Definition`);
588+
this.verifyGoToXSingle(`${markerName}Reference`, `${markerName}Definition`, () => this.getGoToDefinition());
576589
}
577590
}
578591

579-
private verifyGoToDefinitionSingle(startMarkerName: string, endMarkerNames: string | string[]) {
592+
private verifyGoToXSingle(startMarkerName: string, endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | undefined) {
580593
this.goToMarker(startMarkerName);
581-
this.verifyGoToDefinitionWorker(endMarkerNames instanceof Array ? endMarkerNames : [endMarkerNames]);
594+
this.verifyGoToXWorker(endMarkerNames instanceof Array ? endMarkerNames : [endMarkerNames], getDefs);
582595
}
583596

584-
private verifyGoToDefinitionWorker(endMarkers: string[]) {
585-
const definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition) || [];
597+
private verifyGoToXWorker(endMarkers: string[], getDefs: () => ts.DefinitionInfo[] | undefined) {
598+
const definitions = getDefs() || [];
586599

587600
if (endMarkers.length !== definitions.length) {
588601
this.raiseError(`goToDefinitions failed - expected to find ${endMarkers.length} definitions but got ${definitions.length}`);
@@ -3038,10 +3051,6 @@ namespace FourSlashInterface {
30383051
this.state.goToEOF();
30393052
}
30403053

3041-
public type(definitionIndex = 0) {
3042-
this.state.goToTypeDefinition(definitionIndex);
3043-
}
3044-
30453054
public implementation() {
30463055
this.state.goToImplementation();
30473056
}
@@ -3209,6 +3218,13 @@ namespace FourSlashInterface {
32093218
this.state.verifyGoToDefinition(arg0, endMarkerName);
32103219
}
32113220

3221+
public goToType(startMarkerName: string | string[], endMarkerName: string | string[]): void;
3222+
public goToType(startsAndEnds: [string | string[], string | string[]][]): void;
3223+
public goToType(startsAndEnds: { [startMarkerName: string]: string | string[] }): void;
3224+
public goToType(arg0: any, endMarkerName?: string | string[]) {
3225+
this.state.verifyGoToType(arg0, endMarkerName);
3226+
}
3227+
32123228
public goToDefinitionForMarkers(...markerNames: string[]) {
32133229
this.state.verifyGoToDefinitionForMarkers(markerNames);
32143230
}

src/services/completions.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
/// <reference path='../compiler/utilities.ts' />
2-
31
/* @internal */
42
namespace ts.Completions {
5-
export function getCompletionsAtPosition(host: LanguageServiceHost, typeChecker: TypeChecker, log: (message: string) => void, compilerOptions: CompilerOptions, sourceFile: SourceFile, position: number): CompletionInfo {
3+
export function getCompletionsAtPosition(host: LanguageServiceHost, typeChecker: TypeChecker, log: (message: string) => void, compilerOptions: CompilerOptions, sourceFile: SourceFile, position: number): CompletionInfo | undefined {
64
if (isInReferenceComment(sourceFile, position)) {
75
return getTripleSlashReferenceCompletion(sourceFile, position);
86
}
@@ -134,7 +132,7 @@ namespace ts.Completions {
134132
return uniqueNames;
135133
}
136134

137-
function getStringLiteralCompletionEntries(sourceFile: SourceFile, position: number) {
135+
function getStringLiteralCompletionEntries(sourceFile: SourceFile, position: number): CompletionInfo | undefined {
138136
const node = findPrecedingToken(position, sourceFile);
139137
if (!node || node.kind !== SyntaxKind.StringLiteral) {
140138
return undefined;
@@ -174,7 +172,7 @@ namespace ts.Completions {
174172
return getStringLiteralCompletionEntriesFromModuleNames(<StringLiteral>node);
175173
}
176174
else {
177-
const argumentInfo = SignatureHelp.getContainingArgumentInfo(node, position, sourceFile);
175+
const argumentInfo = SignatureHelp.getImmediatelyContainingArgumentInfo(node, position, sourceFile);
178176
if (argumentInfo) {
179177
// Get string literal completions from specialized signatures of the target
180178
// i.e. declare function f(a: 'A');
@@ -188,7 +186,7 @@ namespace ts.Completions {
188186
}
189187
}
190188

191-
function getStringLiteralCompletionEntriesFromPropertyAssignment(element: ObjectLiteralElement) {
189+
function getStringLiteralCompletionEntriesFromPropertyAssignment(element: ObjectLiteralElement): CompletionInfo | undefined {
192190
const type = typeChecker.getContextualType((<ObjectLiteralExpression>element.parent));
193191
const entries: CompletionEntry[] = [];
194192
if (type) {
@@ -199,7 +197,7 @@ namespace ts.Completions {
199197
}
200198
}
201199

202-
function getStringLiteralCompletionEntriesFromCallExpression(argumentInfo: SignatureHelp.ArgumentListInfo) {
200+
function getStringLiteralCompletionEntriesFromCallExpression(argumentInfo: SignatureHelp.ArgumentListInfo): CompletionInfo | undefined {
203201
const candidates: Signature[] = [];
204202
const entries: CompletionEntry[] = [];
205203

@@ -219,7 +217,7 @@ namespace ts.Completions {
219217
return undefined;
220218
}
221219

222-
function getStringLiteralCompletionEntriesFromElementAccess(node: ElementAccessExpression) {
220+
function getStringLiteralCompletionEntriesFromElementAccess(node: ElementAccessExpression): CompletionInfo | undefined {
223221
const type = typeChecker.getTypeAtLocation(node.expression);
224222
const entries: CompletionEntry[] = [];
225223
if (type) {
@@ -231,7 +229,7 @@ namespace ts.Completions {
231229
return undefined;
232230
}
233231

234-
function getStringLiteralCompletionEntriesFromContextualType(node: StringLiteral) {
232+
function getStringLiteralCompletionEntriesFromContextualType(node: StringLiteral): CompletionInfo | undefined {
235233
const type = typeChecker.getContextualType(node);
236234
if (type) {
237235
const entries: CompletionEntry[] = [];
@@ -243,26 +241,26 @@ namespace ts.Completions {
243241
return undefined;
244242
}
245243

246-
function addStringLiteralCompletionsFromType(type: Type, result: CompletionEntry[]): void {
244+
function addStringLiteralCompletionsFromType(type: Type, result: Push<CompletionEntry>): void {
247245
if (type && type.flags & TypeFlags.TypeParameter) {
248246
type = typeChecker.getApparentType(type);
249247
}
250248
if (!type) {
251249
return;
252250
}
253251
if (type.flags & TypeFlags.Union) {
254-
forEach((<UnionType>type).types, t => addStringLiteralCompletionsFromType(t, result));
255-
}
256-
else {
257-
if (type.flags & TypeFlags.StringLiteral) {
258-
result.push({
259-
name: (<LiteralType>type).text,
260-
kindModifiers: ScriptElementKindModifier.none,
261-
kind: ScriptElementKind.variableElement,
262-
sortText: "0"
263-
});
252+
for (const t of (<UnionType>type).types) {
253+
addStringLiteralCompletionsFromType(t, result);
264254
}
265255
}
256+
else if (type.flags & TypeFlags.StringLiteral) {
257+
result.push({
258+
name: (<LiteralType>type).text,
259+
kindModifiers: ScriptElementKindModifier.none,
260+
kind: ScriptElementKind.variableElement,
261+
sortText: "0"
262+
});
263+
}
266264
}
267265

268266
function getStringLiteralCompletionEntriesFromModuleNames(node: StringLiteral): CompletionInfo {

src/services/findAllReferences.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ namespace ts.FindAllReferences {
325325
fileName: targetLabel.getSourceFile().fileName,
326326
kind: ScriptElementKind.label,
327327
name: labelName,
328-
textSpan: createTextSpanFromBounds(targetLabel.getStart(), targetLabel.getEnd()),
328+
textSpan: createTextSpanFromNode(targetLabel, sourceFile),
329329
displayParts: [displayPart(labelName, SymbolDisplayPartKind.text)]
330330
};
331331

@@ -872,7 +872,7 @@ namespace ts.FindAllReferences {
872872
fileName: node.getSourceFile().fileName,
873873
kind: ScriptElementKind.variableElement,
874874
name: "this",
875-
textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()),
875+
textSpan: createTextSpanFromNode(node),
876876
displayParts
877877
},
878878
references: references
@@ -943,7 +943,7 @@ namespace ts.FindAllReferences {
943943
fileName: node.getSourceFile().fileName,
944944
kind: ScriptElementKind.variableElement,
945945
name: type.text,
946-
textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()),
946+
textSpan: createTextSpanFromNode(node),
947947
displayParts: [displayPart(getTextOfNode(node), SymbolDisplayPartKind.stringLiteral)]
948948
},
949949
references: references

0 commit comments

Comments
 (0)