From 286ee018bd59eecd394969d3fa014f4a9f232eb1 Mon Sep 17 00:00:00 2001 From: Simon Graband Date: Mon, 21 Jun 2021 15:53:08 +0200 Subject: [PATCH] Transpile theia to es6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Transpiles theia to es6. To keep support of es5 based vscode extensions, the @es5ClassCompat tag was used. The tag was also applied to be used with theia es5 plugins. Contributed on behalf of STMicroelectronics Signed-off-by: Simon Graband Co-authored-by: Paul Maréchal --- configs/base.tsconfig.json | 2 +- .../src/generator/webpack-generator.ts | 20 ----- packages/core/src/browser/navigatable.ts | 4 +- packages/core/src/browser/saveable.ts | 4 +- .../core/src/browser/tree/tree-widget.tsx | 2 +- packages/monaco/src/typings/monaco/index.d.ts | 2 +- .../browser/plugin-contribution-handler.ts | 5 +- .../main/browser/view/tree-view-widget.tsx | 2 +- .../plugin-ext/src/plugin/command-registry.ts | 2 +- packages/plugin-ext/src/plugin/types-impl.ts | 83 ++++++++++++++++--- ...search-in-workspace-result-tree-widget.tsx | 2 +- .../browser/task-problem-matcher-registry.ts | 6 +- .../workspace-uri-contribution.spec.ts | 2 +- 13 files changed, 91 insertions(+), 45 deletions(-) diff --git a/configs/base.tsconfig.json b/configs/base.tsconfig.json index 7175a17cf0299..25840e002be94 100644 --- a/configs/base.tsconfig.json +++ b/configs/base.tsconfig.json @@ -14,7 +14,7 @@ "resolveJsonModule": true, "module": "commonjs", "moduleResolution": "node", - "target": "es5", + "target": "es6", "jsx": "react", "lib": [ "es6", diff --git a/dev-packages/application-manager/src/generator/webpack-generator.ts b/dev-packages/application-manager/src/generator/webpack-generator.ts index f10462cf47517..b6f062a32461c 100644 --- a/dev-packages/application-manager/src/generator/webpack-generator.ts +++ b/dev-packages/application-manager/src/generator/webpack-generator.ts @@ -195,26 +195,6 @@ module.exports = { { test: /\\.plist$/, type: 'asset/resource' - }, - { - test: /\\.js$/, - // include only es6 dependencies to transpile them to es5 classes - include: /vscode-ws-jsonrpc|vscode-jsonrpc|vscode-languageserver-protocol|vscode-languageserver-types/, - use: { - loader: 'babel-loader', - options: { - presets: ['@babel/preset-env'], - plugins: [ - // reuse runtime babel lib instead of generating it in each js file - '@babel/plugin-transform-runtime', - // ensure that classes are transpiled - '@babel/plugin-transform-classes' - ], - // see https://github.com/babel/babel/issues/8900#issuecomment-431240426 - sourceType: 'unambiguous', - cacheDirectory: true - } - } } ] }, diff --git a/packages/core/src/browser/navigatable.ts b/packages/core/src/browser/navigatable.ts index 49efbbadc5c42..9429dc76ee007 100644 --- a/packages/core/src/browser/navigatable.ts +++ b/packages/core/src/browser/navigatable.ts @@ -45,14 +45,14 @@ export namespace NavigatableWidget { return arg instanceof BaseWidget && Navigatable.is(arg); } export function* getAffected( - widgets: IterableIterator | ArrayLike, + widgets: Iterable, context: MaybeArray ): IterableIterator<[URI, T & NavigatableWidget]> { const uris = Array.isArray(context) ? context : [context]; return get(widgets, resourceUri => uris.some(uri => uri.isEqualOrParent(resourceUri))); } export function* get( - widgets: IterableIterator | ArrayLike, + widgets: Iterable, filter: (resourceUri: URI) => boolean = () => true ): IterableIterator<[URI, T & NavigatableWidget]> { for (const widget of widgets) { diff --git a/packages/core/src/browser/saveable.ts b/packages/core/src/browser/saveable.ts index ad4ca17f276f9..cea603bfaa8f2 100644 --- a/packages/core/src/browser/saveable.ts +++ b/packages/core/src/browser/saveable.ts @@ -161,11 +161,11 @@ export namespace SaveableWidget { export function is(widget: Widget | undefined): widget is SaveableWidget { return !!widget && 'closeWithoutSaving' in widget; } - export function getDirty(widgets: IterableIterator | ArrayLike): IterableIterator { + export function getDirty(widgets: Iterable): IterableIterator { return get(widgets, Saveable.isDirty); } export function* get( - widgets: IterableIterator | ArrayLike, + widgets: Iterable, filter: (widget: T) => boolean = () => true ): IterableIterator { for (const widget of widgets) { diff --git a/packages/core/src/browser/tree/tree-widget.tsx b/packages/core/src/browser/tree/tree-widget.tsx index 085f2a9f6df73..f510b9d73d4bb 100644 --- a/packages/core/src/browser/tree/tree-widget.tsx +++ b/packages/core/src/browser/tree/tree-widget.tsx @@ -976,7 +976,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); } diff --git a/packages/monaco/src/typings/monaco/index.d.ts b/packages/monaco/src/typings/monaco/index.d.ts index a0f65fe3e9987..938a6798827af 100644 --- a/packages/monaco/src/typings/monaco/index.d.ts +++ b/packages/monaco/src/typings/monaco/index.d.ts @@ -525,7 +525,7 @@ declare module monaco.actions { * Retrieves all the registered menu items for the given menu. * @param menuId - see https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/platform/actions/common/actions.ts#L67 */ - getMenuItems(menuId: 7 /* EditorContext */ | 8 /* EditorContextPeek */ | 25 /* MenubarSelectionMenu */): IMenuItem | ISubmenuItem[]; + getMenuItems(menuId: 7 /* EditorContext */ | 8 /* EditorContextPeek */ | 25 /* MenubarSelectionMenu */): Iterable | Iterable; } // https://github.com/theia-ide/vscode/blob/standalone/0.20.x/src/vs/platform/actions/common/actions.ts#L51 diff --git a/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts b/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts index d2abed4ee425a..3792190f5593a 100644 --- a/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts +++ b/packages/plugin-ext/src/main/browser/plugin-contribution-handler.ts @@ -299,8 +299,9 @@ export class PluginContributionHandler { } } - if (contributions.colors) { - pushContribution('colors', () => this.colors.register(...contributions.colors)); + const colors = contributions.colors; + if (colors) { + pushContribution('colors', () => this.colors.register(...colors)); } if (contributions.taskDefinitions) { diff --git a/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx b/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx index cfb5468717370..35275ea828201 100644 --- a/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx +++ b/packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx @@ -281,7 +281,7 @@ export class TreeViewWidget extends TreeViewWelcomeWidget { }); const children = this.getCaption(node); - return React.createElement('div', attrs, ...children); + return React.createElement('div', attrs, children); } protected getCaption(node: TreeNode): React.ReactNode { diff --git a/packages/plugin-ext/src/plugin/command-registry.ts b/packages/plugin-ext/src/plugin/command-registry.ts index a5e877d93256f..93d283a1762e8 100644 --- a/packages/plugin-ext/src/plugin/command-registry.ts +++ b/packages/plugin-ext/src/plugin/command-registry.ts @@ -102,7 +102,7 @@ export class CommandRegistryImpl implements CommandRegistryExt { // Using the KnownCommand exclusions, convert the commands manually return KnownCommands.map(id, args, (mappedId: string, mappedArgs: any[] | undefined, mappedResult: KnownCommands.ConversionFunction) => { const mr: KnownCommands.ConversionFunction = mappedResult; - return this.proxy.$executeCommand(mappedId, ...mappedArgs).then((result: any) => { + return this.proxy.$executeCommand(mappedId, ...mappedArgs || []).then((result: any) => { if (!result) { return undefined; } diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index bf66f68c0a84c..bb3d66e244372 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -24,7 +24,7 @@ import { UUID } from '@theia/core/shared/@phosphor/coreutils'; import { illegalArgument } from '../common/errors'; -import * as theia from '@theia/plugin'; +import type * as theia from '@theia/plugin'; import { URI as CodeURI, UriComponents } from '@theia/core/shared/vscode-uri'; import { relative } from '../common/paths-util'; import { startsWithIgnoreCase } from '@theia/core/lib/common/strings'; @@ -33,6 +33,7 @@ import { SymbolKind } from '../common/plugin-api-rpc-model'; import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from '@theia/filesystem/lib/common/files'; import * as paths from 'path'; import { ObjectsTransferrer } from '../common/rpc-protocol'; +import { es5ClassCompat } from '../common/types'; /** * A reviver that takes URI's transferred via JSON.stringify() and makes @@ -52,6 +53,7 @@ export function reviver(key: string | undefined, value: any): any { * We cannot simply upgrade the dependency, because the curent version 3.x * is not compatible with our current codebase */ +@es5ClassCompat export class URI extends CodeURI implements theia.Uri { protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean); protected constructor(components: UriComponents); @@ -114,6 +116,7 @@ export class URI extends CodeURI implements theia.Uri { } } +@es5ClassCompat export class Disposable { private disposable: undefined | (() => void); @@ -207,6 +210,7 @@ export enum SourceControlInputBoxValidationType { Information = 2 } +@es5ClassCompat export class ColorTheme implements theia.ColorTheme { constructor(public readonly kind: ColorThemeKind) { } } @@ -233,6 +237,7 @@ export namespace TextEditorSelectionChangeKind { } } +@es5ClassCompat export class Position { private _line: number; private _character: number; @@ -390,6 +395,7 @@ export class Position { } } +@es5ClassCompat export class Range { protected _start: Position; protected _end: Position; @@ -521,6 +527,7 @@ export class Range { } +@es5ClassCompat export class Selection extends Range { private _anchor: Position; private _active: Position; @@ -572,6 +579,7 @@ export enum EnvironmentVariableMutatorType { Prepend = 3 } +@es5ClassCompat export class SnippetString { static isSnippetString(thing: {}): thing is SnippetString { @@ -653,11 +661,13 @@ export class SnippetString { } } +@es5ClassCompat export class ThemeColor { constructor(public id: string) { } } +@es5ClassCompat export class ThemeIcon { static readonly File: ThemeIcon = new ThemeIcon('file'); @@ -716,6 +726,7 @@ export enum ConfigurationTarget { Memory } +@es5ClassCompat export class RelativePattern { base: string; @@ -746,6 +757,7 @@ export enum IndentAction { Outdent = 3 } +@es5ClassCompat export class TextEdit { protected _range: Range; @@ -854,6 +866,7 @@ export enum CompletionItemKind { TypeParameter = 24 } +@es5ClassCompat export class CompletionItem implements theia.CompletionItem { label: string; @@ -876,6 +889,7 @@ export class CompletionItem implements theia.CompletionItem { } } +@es5ClassCompat export class CompletionList { isIncomplete?: boolean; @@ -900,16 +914,7 @@ export enum DebugConsoleMode { MergeWithParent = 1 } -export class DiagnosticRelatedInformation { - location: Location; - message: string; - - constructor(location: Location, message: string) { - this.location = location; - this.message = message; - } -} - +@es5ClassCompat export class Location { uri: URI; range: Range; @@ -935,6 +940,17 @@ export class Location { } } +@es5ClassCompat +export class DiagnosticRelatedInformation { + location: Location; + message: string; + + constructor(location: Location, message: string) { + this.location = location; + this.message = message; + } +} + export enum DiagnosticTag { Unnecessary = 1, } @@ -943,6 +959,7 @@ export enum CompletionItemTag { Deprecated = 1, } +@es5ClassCompat export class Diagnostic { range: Range; message: string; @@ -970,6 +987,7 @@ export enum MarkerTag { Unnecessary = 1, } +@es5ClassCompat export class ParameterInformation { label: string | [number, number]; documentation?: string | MarkdownString; @@ -980,6 +998,7 @@ export class ParameterInformation { } } +@es5ClassCompat export class SignatureInformation { label: string; documentation?: string | MarkdownString; @@ -998,6 +1017,7 @@ export enum SignatureHelpTriggerKind { ContentChange = 3, } +@es5ClassCompat export class SignatureHelp { signatures: SignatureInformation[]; activeSignature: number; @@ -1008,6 +1028,7 @@ export class SignatureHelp { } } +@es5ClassCompat export class Hover { public contents: MarkdownString[] | theia.MarkedString[]; @@ -1037,6 +1058,7 @@ export enum DocumentHighlightKind { Write = 2 } +@es5ClassCompat export class DocumentHighlight { public range: Range; @@ -1053,6 +1075,7 @@ export class DocumentHighlight { export type Definition = Location | Location[]; +@es5ClassCompat export class DocumentLink { range: Range; @@ -1073,6 +1096,7 @@ export class DocumentLink { } } +@es5ClassCompat export class CodeLens { range: Range; @@ -1112,6 +1136,7 @@ export enum CodeActionTriggerKind { Automatic = 2, } +@es5ClassCompat export class CodeActionKind { private static readonly sep = '.'; @@ -1148,6 +1173,7 @@ export enum TextDocumentSaveReason { FocusOut = 3 } +@es5ClassCompat export class CodeAction { title: string; @@ -1200,6 +1226,7 @@ export interface FileTextEdit { metadata?: WorkspaceEditMetadata; } +@es5ClassCompat export class WorkspaceEdit implements theia.WorkspaceEdit { private _edits = new Array(); @@ -1312,6 +1339,7 @@ export class WorkspaceEdit implements theia.WorkspaceEdit { } } +@es5ClassCompat export class TreeItem { label?: string | theia.TreeItemLabel; @@ -1349,6 +1377,7 @@ export enum SymbolTag { Deprecated = 1 } +@es5ClassCompat export class SymbolInformation { static validate(candidate: SymbolInformation): void { @@ -1393,6 +1422,7 @@ export class SymbolInformation { } } +@es5ClassCompat export class DocumentSymbol { static validate(candidate: DocumentSymbol): void { @@ -1437,6 +1467,7 @@ export interface QuickInputButton { readonly tooltip?: string | undefined; } +@es5ClassCompat export class QuickInputButtons { static readonly Back: QuickInputButton = { iconPath: { @@ -1446,6 +1477,7 @@ export class QuickInputButtons { }; } +@es5ClassCompat export class FileDecoration { static validate(d: FileDecoration): void { @@ -1483,6 +1515,7 @@ export enum FileChangeType { Deleted = 3, } +@es5ClassCompat export class FileSystemError extends Error { static FileExists(messageOrUri?: string | URI): FileSystemError { @@ -1544,6 +1577,7 @@ export interface FileStat { readonly size: number; } +@es5ClassCompat export class ProgressOptions { /** * The location at which progress should show. @@ -1565,6 +1599,8 @@ export class ProgressOptions { this.location = location; } } + +@es5ClassCompat export class Progress { /** * Report a progress update. @@ -1590,6 +1626,7 @@ export enum ProgressLocation { Notification = 15 } +@es5ClassCompat export class ProcessExecution { private executionProcess: string; private arguments: string[]; @@ -1669,6 +1706,7 @@ export enum TaskRevealKind { Never = 3 } +@es5ClassCompat export class ShellExecution { private shellCommandLine: string; private shellCommand: string | theia.ShellQuotedString; @@ -1742,6 +1780,7 @@ export class ShellExecution { } } +@es5ClassCompat export class CustomExecution { private _callback: (resolvedDefintion: theia.TaskDefinition) => Thenable; constructor(callback: (resolvedDefintion: theia.TaskDefinition) => Thenable) { @@ -1762,6 +1801,7 @@ export class CustomExecution { } } +@es5ClassCompat export class TaskGroup { private groupId: string; @@ -1805,6 +1845,7 @@ export enum TaskScope { Workspace = 2 } +@es5ClassCompat export class Task { private taskDefinition: theia.TaskDefinition; private taskScope: theia.TaskScope.Global | theia.TaskScope.Workspace | theia.WorkspaceFolder | undefined; @@ -1990,10 +2031,12 @@ export class Task { } } +@es5ClassCompat export class Task2 extends Task { detail?: string; } +@es5ClassCompat export class DebugAdapterExecutable { /** * The command or path of the debug adapter executable. @@ -2030,6 +2073,7 @@ export class DebugAdapterExecutable { /** * Represents a debug adapter running as a socket based server. */ +@es5ClassCompat export class DebugAdapterServer { /** @@ -2064,6 +2108,7 @@ export enum LogLevel { /** * The base class of all breakpoint types. */ +@es5ClassCompat export class Breakpoint { /** * Is breakpoint enabled. @@ -2105,6 +2150,7 @@ export class Breakpoint { /** * A breakpoint specified by a source location. */ +@es5ClassCompat export class SourceBreakpoint extends Breakpoint { /** * The source and line position of this breakpoint. @@ -2123,6 +2169,7 @@ export class SourceBreakpoint extends Breakpoint { /** * A breakpoint specified by a function name. */ +@es5ClassCompat export class FunctionBreakpoint extends Breakpoint { /** * The name of the function to which this breakpoint is attached. @@ -2138,6 +2185,7 @@ export class FunctionBreakpoint extends Breakpoint { } } +@es5ClassCompat export class Color { readonly red: number; readonly green: number; @@ -2152,6 +2200,7 @@ export class Color { } } +@es5ClassCompat export class ColorInformation { range: Range; color: Color; @@ -2168,6 +2217,7 @@ export class ColorInformation { } } +@es5ClassCompat export class ColorPresentation { label: string; textEdit?: TextEdit; @@ -2187,6 +2237,7 @@ export enum ColorFormat { HSL = 2 } +@es5ClassCompat export class FoldingRange { start: number; end: number; @@ -2205,6 +2256,7 @@ export enum FoldingRangeKind { Region = 3 } +@es5ClassCompat export class SelectionRange { range: Range; @@ -2253,6 +2305,7 @@ export enum UIKind { Web = 2 } +@es5ClassCompat export class CallHierarchyItem { _sessionId?: string; _itemId?: string; @@ -2288,6 +2341,7 @@ export class CallHierarchyItem { } } +@es5ClassCompat export class CallHierarchyIncomingCall { from: theia.CallHierarchyItem; @@ -2299,6 +2353,7 @@ export class CallHierarchyIncomingCall { } } +@es5ClassCompat export class CallHierarchyOutgoingCall { to: theia.CallHierarchyItem; @@ -2310,6 +2365,7 @@ export class CallHierarchyOutgoingCall { } } +@es5ClassCompat export class TimelineItem { timestamp: number; label: string; @@ -2327,6 +2383,7 @@ export class TimelineItem { // #region Semantic Coloring +@es5ClassCompat export class SemanticTokensLegend { public readonly tokenTypes: string[]; public readonly tokenModifiers: string[]; @@ -2341,6 +2398,7 @@ function isStrArrayOrUndefined(arg: any): arg is string[] | undefined { return ((typeof arg === 'undefined') || (Array.isArray(arg) && arg.every(e => typeof e === 'string'))); } +@es5ClassCompat export class SemanticTokensBuilder { private _prevLine: number; @@ -2520,6 +2578,7 @@ export class SemanticTokensBuilder { } } +@es5ClassCompat export class SemanticTokens { readonly resultId?: string; readonly data: Uint32Array; @@ -2530,6 +2589,7 @@ export class SemanticTokens { } } +@es5ClassCompat export class SemanticTokensEdit { readonly start: number; readonly deleteCount: number; @@ -2542,6 +2602,7 @@ export class SemanticTokensEdit { } } +@es5ClassCompat export class SemanticTokensEdits { readonly resultId?: string; readonly edits: SemanticTokensEdit[]; diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx b/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx index 772067f8d2c49..a039597c26e13 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx +++ b/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx @@ -1074,7 +1074,7 @@ export class SearchInWorkspaceResultTreeWidget extends TreeWidget { protected getExcludeGlobs(excludeOptions?: string[]): string[] { const excludePreferences = this.filesystemPreferences['files.exclude']; const excludePreferencesGlobs = Object.keys(excludePreferences).filter(key => !!excludePreferences[key]); - return [...new Set([...excludePreferencesGlobs, ...excludeOptions])]; + return [...new Set([...excludePreferencesGlobs, ...excludeOptions || []])]; } /** diff --git a/packages/task/src/browser/task-problem-matcher-registry.ts b/packages/task/src/browser/task-problem-matcher-registry.ts index 179639812d496..651ad7ba60a78 100644 --- a/packages/task/src/browser/task-problem-matcher-registry.ts +++ b/packages/task/src/browser/task-problem-matcher-registry.ts @@ -144,7 +144,11 @@ export class ProblemMatcherRegistry { patterns.push(ProblemPattern.fromProblemPatternContribution(matcher.pattern)); } } else if (baseMatcher) { - patterns.push(...baseMatcher.pattern); + if (Array.isArray(baseMatcher.pattern)) { + patterns.push(...baseMatcher.pattern); + } else { + patterns.push(baseMatcher.pattern); + } } let deprecated: boolean | undefined = matcher.deprecated; diff --git a/packages/workspace/src/browser/workspace-uri-contribution.spec.ts b/packages/workspace/src/browser/workspace-uri-contribution.spec.ts index 22b524d2e4cd4..46661f03372af 100644 --- a/packages/workspace/src/browser/workspace-uri-contribution.spec.ts +++ b/packages/workspace/src/browser/workspace-uri-contribution.spec.ts @@ -46,7 +46,7 @@ beforeEach(() => { container = new Container(); container.bind(ApplicationShell).toConstantValue({ currentChanged: new Signal({}), - widgets: () => [] + widgets: [] // eslint-disable-next-line @typescript-eslint/no-explicit-any } as any); container.bind(WidgetManager).toConstantValue({