Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig: transpile to es6 #6060

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configs/base.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"resolveJsonModule": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"target": "es6",
"jsx": "react",
"lib": [
"es6",
"dom"
],
"sourceMap": true
}
}
}
4 changes: 2 additions & 2 deletions packages/core/src/browser/navigatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ export namespace NavigatableWidget {
return arg instanceof BaseWidget && Navigatable.is(arg);
}
export function* getAffected<T extends Widget>(
widgets: IterableIterator<T> | ArrayLike<T>,
widgets: Iterable<T>,
context: MaybeArray<URI>
): IterableIterator<[URI, T & NavigatableWidget]> {
const uris = Array.isArray(context) ? context : [context];
return get(widgets, resourceUri => uris.some(uri => uri.isEqualOrParent(resourceUri)));
}
export function* get<T extends Widget>(
widgets: IterableIterator<T> | ArrayLike<T>,
widgets: Iterable<T>,
filter: (resourceUri: URI) => boolean = () => true
): IterableIterator<[URI, T & NavigatableWidget]> {
for (const widget of widgets) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/browser/saveable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export namespace SaveableWidget {
export function is(widget: Widget | undefined): widget is SaveableWidget {
return !!widget && 'closeWithoutSaving' in widget;
}
export function getDirty<T extends Widget>(widgets: IterableIterator<T> | ArrayLike<T>): IterableIterator<SaveableWidget & T> {
export function getDirty<T extends Widget>(widgets: Iterable<T>): IterableIterator<SaveableWidget & T> {
return get(widgets, Saveable.isDirty);
}
export function* get<T extends Widget>(
widgets: IterableIterator<T> | ArrayLike<T>,
widgets: Iterable<T>,
filter: (widget: T) => boolean = () => true
): IterableIterator<SaveableWidget & T> {
for (const widget of widgets) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class TabBarRenderer extends TabBar.Renderer {
if (this.tabBar && this.decoratorService) {
const allDecorations = this.decoratorService.getDecorations([...this.tabBar.titles]);
if (allDecorations.has(tab)) {
tabDecorations.push(...allDecorations.get(tab));
tabDecorations.push(...allDecorations.get(tab)!);
}
}
return tabDecorations;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/tree/tree-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export class TreeWidget extends ReactWidget implements StatefulWidget {
decorations.push(node.decorationData);
}
if (this.decorations.has(node.id)) {
decorations.push(...this.decorations.get(node.id));
decorations.push(...this.decorations.get(node.id)!);
}
return decorations.sort(TreeDecoration.Data.comparePriority);
}
Expand Down
30 changes: 17 additions & 13 deletions packages/core/src/common/messaging/proxy-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ class NoTransform extends stream.Transform {
}
}

class TestServer {
requests: string[] = [];
doStuff(arg: string): Promise<string> {
this.requests.push(arg);
return Promise.resolve(`done: ${arg}`);
}

class BaseTestServer1 {
fails(arg: string, otherArg: string): Promise<string> {
throw new Error('fails failed');
}
}

class BaseTestServer2 extends BaseTestServer1 {
fails2(arg: string, otherArg: string): Promise<string> {
return Promise.reject(new Error('fails2 failed'));
}
}

class TestServer extends BaseTestServer2 {
requests: string[] = [];
doStuff(arg: string): Promise<string> {
this.requests.push(arg);
return Promise.resolve(`done: ${arg}`);
}
}

class TestClient {
notifications: string[] = [];
notifyThat(arg: string): void {
Expand Down Expand Up @@ -74,18 +78,18 @@ describe('Proxy-Factory', () => {
});
it('Rejected Promise should result in rejected Promise.', done => {
const it = getSetup();
const handle = setTimeout(() => done('timeout'), 500);
it.serverProxy.fails('a', 'b').catch(err => {
expect(<Error>err.message).to.contain('fails failed');
const handle = setTimeout(() => done(new Error('timeout')), 500);
it.serverProxy.fails('a', 'b').catch((err: Error) => {
expect(err.message).to.contain('fails failed');
clearTimeout(handle);
done();
});
});
it('Remote Exceptions should result in rejected Promise.', done => {
const { serverProxy } = getSetup();
const handle = setTimeout(() => done('timeout'), 500);
serverProxy.fails2('a', 'b').catch(err => {
expect(<Error>err.message).to.contain('fails2 failed');
const handle = setTimeout(() => done(new Error('timeout')), 500);
serverProxy.fails2('a', 'b').catch((err: Error) => {
expect(err.message).to.contain('fails2 failed');
clearTimeout(handle);
done();
});
Expand Down
28 changes: 23 additions & 5 deletions packages/core/src/common/messaging/proxy-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
});
}

/**
* In ECMAScript 6, `Object.keys()` does not automatically parse the
* prototype chain when looking for properties. This method must implement
* the algorithm of choice for looking up such functions from a given object.
*/
protected collectFunctionNames(object: any): Iterable<string> {
const functions = new Set<string>();
let prototype = Object.getPrototypeOf(object);
while (prototype) {
for (const property of Object.getOwnPropertyNames(prototype)) {
const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
if (descriptor && typeof descriptor.value === 'function' && property !== 'constructor') {
functions.add(property);
}
}
prototype = Object.getPrototypeOf(prototype);
}
return functions;
}

/**
* Connect a MessageConnection to the factory.
*
Expand All @@ -131,11 +151,9 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
*/
listen(connection: MessageConnection): void {
if (this.target) {
for (const prop in this.target) {
if (typeof this.target[prop] === 'function') {
connection.onRequest(prop, (...args) => this.onRequest(prop, ...args));
connection.onNotification(prop, (...args) => this.onNotification(prop, ...args));
}
for (const prop of this.collectFunctionNames(this.target)) {
connection.onRequest(prop, (...args) => this.onRequest(prop, ...args));
connection.onNotification(prop, (...args) => this.onNotification(prop, ...args));
}
}
connection.onDispose(() => this.waitForConnection());
Expand Down
2 changes: 1 addition & 1 deletion packages/java/src/browser/java-client-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class JavaClientContribution extends BaseLanguageClientContribution {
protected onReady(languageClient: ILanguageClient): void {
languageClient.onNotification(ActionableNotification.type, this.showActionableMessage.bind(this));
languageClient.onNotification(StatusNotification.type, this.showStatusMessage.bind(this));
languageClient.onRequest(ExecuteClientCommand.type, params => this.commandService.executeCommand(params.command, ...params.arguments));
languageClient.onRequest(ExecuteClientCommand.type, params => this.commandService.executeCommand(params.command, ...params.arguments || []));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to change it? Does it mean a breaking change for all JSON-RPC using varargs? Could we avoid it?

Copy link
Member Author

@paul-marechal paul-marechal Aug 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching compilation target to ES6 made TypeScript detect that params.arguments can be undefined meaning that it could not be unwrapped. It wouldn't let me build.

It is breaking if we try to unwrap undefined values in other places.

super.onReady(languageClient);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-bulk-edit-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class MonacoBulkEditService implements monaco.editor.IBulkEditService {
protected readonly workspace: MonacoWorkspace;

apply(edit: monaco.languages.WorkspaceEdit): monaco.Promise<monaco.editor.IBulkEditResult> {
return this.workspace.applyBulkEdit(edit);
return monaco.Promise.wrap(this.workspace.applyBulkEdit(edit));
}

}
8 changes: 4 additions & 4 deletions packages/monaco/src/browser/monaco-quick-open-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,10 @@ export class MonacoQuickOpenActionProvider implements monaco.quickOpen.IActionPr
}

// tslint:disable-next-line:no-any
async getActions(element: any, entry: QuickOpenEntry | QuickOpenEntryGroup): monaco.Promise<monaco.quickOpen.IAction[]> {
const actions = await this.provider.getActions(entry.item);
const monacoActions = actions.map(action => new MonacoQuickOpenAction(action));
return monaco.Promise.wrap(monacoActions);
getActions(element: any, entry: QuickOpenEntry | QuickOpenEntryGroup): monaco.Promise<monaco.quickOpen.IAction[]> {
return monaco.Promise.wrap(
this.provider.getActions(entry.item)
.then(actions => actions.map(action => new MonacoQuickOpenAction(action))));
}

hasSecondaryActions(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco/src/browser/monaco-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class MonacoWorkspace implements lang.Workspace {
return true;
}

async applyBulkEdit(workspaceEdit: monaco.languages.WorkspaceEdit, options?: EditorOpenerOptions): monaco.Promise<monaco.editor.IBulkEditResult> {
async applyBulkEdit(workspaceEdit: monaco.languages.WorkspaceEdit, options?: EditorOpenerOptions): Promise<monaco.editor.IBulkEditResult> {
try {
const unresolvedEditorEdits = this.groupEdits(workspaceEdit);
const editorEdits = await this.openEditors(unresolvedEditorEdits, options);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class CommandRegistryImpl implements CommandRegistryExt {
return this.executeLocalCommand(id, ...args);
} else {
return KnownCommands.map(id, args, (mappedId: string, mappedArgs: any[] | undefined) =>
this.proxy.$executeCommand(mappedId, ...mappedArgs));
this.proxy.$executeCommand(mappedId, ...mappedArgs || []));
}
}
// tslint:enable:no-any
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class SourceControlResourceGroupImpl implements theia.SourceControlResourceGroup
if (state && state.command) {
const command = state.command;
if (command.command) {
await this.commands.$executeCommand(command.command, ...command.arguments);
await this.commands.$executeCommand(command.command, ...command.arguments || []);
}
}
}
Expand Down