Skip to content

Commit 68cc8fa

Browse files
committed
Merge branch 'master' into ownJsonParsing
2 parents 3dbfecd + 1418fd1 commit 68cc8fa

File tree

63 files changed

+3885
-791
lines changed

Some content is hidden

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

63 files changed

+3885
-791
lines changed

src/compiler/checker.ts

+162-71
Large diffs are not rendered by default.

src/compiler/parser.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2591,6 +2591,8 @@ namespace ts {
25912591
case SyntaxKind.OpenBraceToken:
25922592
case SyntaxKind.OpenBracketToken:
25932593
case SyntaxKind.LessThanToken:
2594+
case SyntaxKind.BarToken:
2595+
case SyntaxKind.AmpersandToken:
25942596
case SyntaxKind.NewKeyword:
25952597
case SyntaxKind.StringLiteral:
25962598
case SyntaxKind.NumericLiteral:
@@ -2650,6 +2652,7 @@ namespace ts {
26502652
}
26512653

26522654
function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode {
2655+
parseOptional(operator);
26532656
let type = parseConstituentType();
26542657
if (token() === operator) {
26552658
const types = createNodeArray<TypeNode>([type], type.pos);

src/compiler/transformers/ts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1353,13 +1353,13 @@ namespace ts {
13531353
// __metadata("design:type", Function),
13541354
// __metadata("design:paramtypes", [Object]),
13551355
// __metadata("design:returntype", void 0)
1356-
// ], C.prototype, "method", undefined);
1356+
// ], C.prototype, "method", null);
13571357
//
13581358
// The emit for an accessor is:
13591359
//
13601360
// __decorate([
13611361
// dec
1362-
// ], C.prototype, "accessor", undefined);
1362+
// ], C.prototype, "accessor", null);
13631363
//
13641364
// The emit for a property is:
13651365
//

src/harness/unittests/tsserverProjectSystem.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ namespace ts.projectSystem {
5151
throttleLimit: number,
5252
installTypingHost: server.ServerHost,
5353
readonly typesRegistry = createMap<void>(),
54-
telemetryEnabled?: boolean,
5554
log?: TI.Log) {
56-
super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, telemetryEnabled, log);
55+
super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, log);
5756
}
5857

5958
safeFileList = safeList.path;

src/harness/unittests/typingsInstaller.ts

+107-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ namespace ts.projectSystem {
2020
}
2121

2222
class Installer extends TestTypingsInstaller {
23-
constructor(host: server.ServerHost, p?: InstallerParams, telemetryEnabled?: boolean, log?: TI.Log) {
23+
constructor(host: server.ServerHost, p?: InstallerParams, log?: TI.Log) {
2424
super(
2525
(p && p.globalTypingsCacheLocation) || "/a/data",
2626
(p && p.throttleLimit) || 5,
2727
host,
2828
(p && p.typesRegistry),
29-
telemetryEnabled,
3029
log);
3130
}
3231

@@ -36,7 +35,7 @@ namespace ts.projectSystem {
3635
}
3736
}
3837

39-
function executeCommand(self: Installer, host: TestServerHost, installedTypings: string[], typingFiles: FileOrFolder[], cb: TI.RequestCompletedAction): void {
38+
function executeCommand(self: Installer, host: TestServerHost, installedTypings: string[] | string, typingFiles: FileOrFolder[], cb: TI.RequestCompletedAction): void {
4039
self.addPostExecAction(installedTypings, success => {
4140
for (const file of typingFiles) {
4241
host.createFileOrFolder(file, /*createParentDirectory*/ true);
@@ -907,7 +906,7 @@ namespace ts.projectSystem {
907906
const host = createServerHost([f1, packageJson]);
908907
const installer = new (class extends Installer {
909908
constructor() {
910-
super(host, { globalTypingsCacheLocation: "/tmp" }, /*telemetryEnabled*/ false, { isEnabled: () => true, writeLine: msg => messages.push(msg) });
909+
super(host, { globalTypingsCacheLocation: "/tmp" }, { isEnabled: () => true, writeLine: msg => messages.push(msg) });
911910
}
912911
installWorker(_requestId: number, _args: string[], _cwd: string, _cb: server.typingsInstaller.RequestCompletedAction) {
913912
assert(false, "runCommand should not be invoked");
@@ -971,15 +970,18 @@ namespace ts.projectSystem {
971970
let seenTelemetryEvent = false;
972971
const installer = new (class extends Installer {
973972
constructor() {
974-
super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") }, /*telemetryEnabled*/ true);
973+
super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") });
975974
}
976975
installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
977976
const installedTypings = ["@types/commander"];
978977
const typingFiles = [commander];
979978
executeCommand(this, host, installedTypings, typingFiles, cb);
980979
}
981-
sendResponse(response: server.SetTypings | server.InvalidateCachedTypings | server.TypingsInstallEvent) {
982-
if (response.kind === server.EventInstall) {
980+
sendResponse(response: server.SetTypings | server.InvalidateCachedTypings | server.BeginInstallTypes | server.EndInstallTypes) {
981+
if (response.kind === server.EventBeginInstallTypes) {
982+
return;
983+
}
984+
if (response.kind === server.EventEndInstallTypes) {
983985
assert.deepEqual(response.packagesToInstall, ["@types/commander"]);
984986
seenTelemetryEvent = true;
985987
return;
@@ -997,4 +999,102 @@ namespace ts.projectSystem {
997999
checkProjectActualFiles(projectService.inferredProjects[0], [f1.path, commander.path]);
9981000
});
9991001
});
1002+
1003+
describe("progress notifications", () => {
1004+
it ("should be sent for success", () => {
1005+
const f1 = {
1006+
path: "/a/app.js",
1007+
content: ""
1008+
};
1009+
const package = {
1010+
path: "/a/package.json",
1011+
content: JSON.stringify({ dependencies: { "commander": "1.0.0" } })
1012+
};
1013+
const cachePath = "/a/cache/";
1014+
const commander = {
1015+
path: cachePath + "node_modules/@types/commander/index.d.ts",
1016+
content: "export let x: number"
1017+
};
1018+
const host = createServerHost([f1, package]);
1019+
let beginEvent: server.BeginInstallTypes;
1020+
let endEvent: server.EndInstallTypes;
1021+
const installer = new (class extends Installer {
1022+
constructor() {
1023+
super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") });
1024+
}
1025+
installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
1026+
const installedTypings = ["@types/commander"];
1027+
const typingFiles = [commander];
1028+
executeCommand(this, host, installedTypings, typingFiles, cb);
1029+
}
1030+
sendResponse(response: server.SetTypings | server.InvalidateCachedTypings | server.BeginInstallTypes | server.EndInstallTypes) {
1031+
if (response.kind === server.EventBeginInstallTypes) {
1032+
beginEvent = response;
1033+
return;
1034+
}
1035+
if (response.kind === server.EventEndInstallTypes) {
1036+
endEvent = response;
1037+
return;
1038+
}
1039+
super.sendResponse(response);
1040+
}
1041+
})();
1042+
const projectService = createProjectService(host, { typingsInstaller: installer });
1043+
projectService.openClientFile(f1.path);
1044+
1045+
installer.installAll(/*expectedCount*/ 1);
1046+
1047+
assert.isTrue(!!beginEvent);
1048+
assert.isTrue(!!endEvent);
1049+
assert.isTrue(beginEvent.eventId === endEvent.eventId);
1050+
assert.isTrue(endEvent.installSuccess);
1051+
checkNumberOfProjects(projectService, { inferredProjects: 1 });
1052+
checkProjectActualFiles(projectService.inferredProjects[0], [f1.path, commander.path]);
1053+
});
1054+
1055+
it ("should be sent for error", () => {
1056+
const f1 = {
1057+
path: "/a/app.js",
1058+
content: ""
1059+
};
1060+
const package = {
1061+
path: "/a/package.json",
1062+
content: JSON.stringify({ dependencies: { "commander": "1.0.0" } })
1063+
};
1064+
const cachePath = "/a/cache/";
1065+
const host = createServerHost([f1, package]);
1066+
let beginEvent: server.BeginInstallTypes;
1067+
let endEvent: server.EndInstallTypes;
1068+
const installer = new (class extends Installer {
1069+
constructor() {
1070+
super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") });
1071+
}
1072+
installWorker(_requestId: number, _args: string[], _cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
1073+
executeCommand(this, host, "", [], cb);
1074+
}
1075+
sendResponse(response: server.SetTypings | server.InvalidateCachedTypings | server.BeginInstallTypes | server.EndInstallTypes) {
1076+
if (response.kind === server.EventBeginInstallTypes) {
1077+
beginEvent = response;
1078+
return;
1079+
}
1080+
if (response.kind === server.EventEndInstallTypes) {
1081+
endEvent = response;
1082+
return;
1083+
}
1084+
super.sendResponse(response);
1085+
}
1086+
})();
1087+
const projectService = createProjectService(host, { typingsInstaller: installer });
1088+
projectService.openClientFile(f1.path);
1089+
1090+
installer.installAll(/*expectedCount*/ 1);
1091+
1092+
assert.isTrue(!!beginEvent);
1093+
assert.isTrue(!!endEvent);
1094+
assert.isTrue(beginEvent.eventId === endEvent.eventId);
1095+
assert.isFalse(endEvent.installSuccess);
1096+
checkNumberOfProjects(projectService, { inferredProjects: 1 });
1097+
checkProjectActualFiles(projectService.inferredProjects[0], [f1.path]);
1098+
});
1099+
});
10001100
}

src/lib/es2017.object.d.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ interface ObjectConstructor {
44
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
55
*/
66
values<T>(o: { [s: string]: T }): T[];
7+
8+
/**
9+
* Returns an array of values of the enumerable properties of an object
10+
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
11+
*/
712
values(o: any): any[];
13+
14+
/**
15+
* Returns an array of key/values of the enumerable properties of an object
16+
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
17+
*/
18+
entries<T>(o: { [s: string]: T }): [string, T][];
19+
820
/**
921
* Returns an array of key/values of the enumerable properties of an object
1022
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
1123
*/
12-
entries<T extends { [key: string]: any }, K extends keyof T>(o: T): [keyof T, T[K]][];
1324
entries(o: any): [string, any][];
1425
}

src/server/protocol.ts

+34
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,40 @@ namespace ts.server.protocol {
21172117
typingsInstallerVersion: string;
21182118
}
21192119

2120+
export type BeginInstallTypesEventName = "beginInstallTypes";
2121+
export type EndInstallTypesEventName = "endInstallTypes";
2122+
2123+
export interface BeginInstallTypesEvent extends Event {
2124+
event: BeginInstallTypesEventName;
2125+
body: BeginInstallTypesEventBody;
2126+
}
2127+
2128+
export interface EndInstallTypesEvent extends Event {
2129+
event: EndInstallTypesEventName;
2130+
body: EndInstallTypesEventBody;
2131+
}
2132+
2133+
export interface InstallTypesEventBody {
2134+
/**
2135+
* correlation id to match begin and end events
2136+
*/
2137+
eventId: number;
2138+
/**
2139+
* list of packages to install
2140+
*/
2141+
packages: ReadonlyArray<string>;
2142+
}
2143+
2144+
export interface BeginInstallTypesEventBody extends InstallTypesEventBody {
2145+
}
2146+
2147+
export interface EndInstallTypesEventBody extends InstallTypesEventBody {
2148+
/**
2149+
* true if installation succeeded, otherwise false
2150+
*/
2151+
success: boolean;
2152+
}
2153+
21202154
export interface NavBarResponse extends Response {
21212155
body?: NavigationBarItem[];
21222156
}

src/server/server.ts

+33-6
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ namespace ts.server {
198198
private socket: NodeSocket;
199199
private projectService: ProjectService;
200200
private throttledOperations: ThrottledOperations;
201-
private telemetrySender: EventSender;
201+
private eventSender: EventSender;
202202

203203
constructor(
204204
private readonly telemetryEnabled: boolean,
@@ -231,7 +231,7 @@ namespace ts.server {
231231
}
232232

233233
setTelemetrySender(telemetrySender: EventSender) {
234-
this.telemetrySender = telemetrySender;
234+
this.eventSender = telemetrySender;
235235
}
236236

237237
attach(projectService: ProjectService) {
@@ -291,12 +291,30 @@ namespace ts.server {
291291
});
292292
}
293293

294-
private handleMessage(response: SetTypings | InvalidateCachedTypings | TypingsInstallEvent) {
294+
private handleMessage(response: SetTypings | InvalidateCachedTypings | BeginInstallTypes | EndInstallTypes) {
295295
if (this.logger.hasLevel(LogLevel.verbose)) {
296296
this.logger.info(`Received response: ${JSON.stringify(response)}`);
297297
}
298-
if (response.kind === EventInstall) {
299-
if (this.telemetrySender) {
298+
299+
if (response.kind === EventBeginInstallTypes) {
300+
if (!this.eventSender) {
301+
return;
302+
}
303+
const body: protocol.BeginInstallTypesEventBody = {
304+
eventId: response.eventId,
305+
packages: response.packagesToInstall,
306+
};
307+
const eventName: protocol.BeginInstallTypesEventName = "beginInstallTypes";
308+
this.eventSender.event(body, eventName);
309+
310+
return;
311+
}
312+
313+
if (response.kind === EventEndInstallTypes) {
314+
if (!this.eventSender) {
315+
return;
316+
}
317+
if (this.telemetryEnabled) {
300318
const body: protocol.TypingsInstalledTelemetryEventBody = {
301319
telemetryEventName: "typingsInstalled",
302320
payload: {
@@ -306,10 +324,19 @@ namespace ts.server {
306324
}
307325
};
308326
const eventName: protocol.TelemetryEventName = "telemetry";
309-
this.telemetrySender.event(body, eventName);
327+
this.eventSender.event(body, eventName);
310328
}
329+
330+
const body: protocol.EndInstallTypesEventBody = {
331+
eventId: response.eventId,
332+
packages: response.packagesToInstall,
333+
success: response.installSuccess,
334+
};
335+
const eventName: protocol.EndInstallTypesEventName = "endInstallTypes";
336+
this.eventSender.event(body, eventName);
311337
return;
312338
}
339+
313340
this.projectService.updateTypingsForProject(response);
314341
if (response.kind == ActionSet && this.socket) {
315342
this.sendEvent(0, "setTypings", response);

src/server/shared.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace ts.server {
44
export const ActionSet: ActionSet = "action::set";
55
export const ActionInvalidate: ActionInvalidate = "action::invalidate";
6-
export const EventInstall: EventInstall = "event::install";
6+
export const EventBeginInstallTypes: EventBeginInstallTypes = "event::beginInstallTypes";
7+
export const EventEndInstallTypes: EventEndInstallTypes = "event::endInstallTypes";
78

89
export namespace Arguments {
910
export const GlobalCacheLocation = "--globalTypingsCacheLocation";

src/server/types.d.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ declare namespace ts.server {
4343

4444
export type ActionSet = "action::set";
4545
export type ActionInvalidate = "action::invalidate";
46-
export type EventInstall = "event::install";
46+
export type EventBeginInstallTypes = "event::beginInstallTypes";
47+
export type EventEndInstallTypes = "event::endInstallTypes";
4748

4849
export interface TypingInstallerResponse {
49-
readonly kind: ActionSet | ActionInvalidate | EventInstall;
50+
readonly kind: ActionSet | ActionInvalidate | EventBeginInstallTypes | EventEndInstallTypes;
5051
}
5152

5253
export interface ProjectResponse extends TypingInstallerResponse {
@@ -65,11 +66,20 @@ declare namespace ts.server {
6566
readonly kind: ActionInvalidate;
6667
}
6768

68-
export interface TypingsInstallEvent extends TypingInstallerResponse {
69+
export interface InstallTypes extends ProjectResponse {
70+
readonly kind: EventBeginInstallTypes | EventEndInstallTypes;
71+
readonly eventId: number;
72+
readonly typingsInstallerVersion: string;
6973
readonly packagesToInstall: ReadonlyArray<string>;
70-
readonly kind: EventInstall;
74+
}
75+
76+
export interface BeginInstallTypes extends InstallTypes {
77+
readonly kind: EventBeginInstallTypes;
78+
}
79+
80+
export interface EndInstallTypes extends InstallTypes {
81+
readonly kind: EventEndInstallTypes;
7182
readonly installSuccess: boolean;
72-
readonly typingsInstallerVersion: string;
7383
}
7484

7585
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {

0 commit comments

Comments
 (0)