diff --git a/build/lib/standalone.js b/build/lib/standalone.js index cf921e7401c..63e16442d53 100644 --- a/build/lib/standalone.js +++ b/build/lib/standalone.js @@ -27,7 +27,7 @@ function writeFile(filePath, contents) { fs.writeFileSync(filePath, contents); } function extractEditor(options) { - const tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.json')).toString()); + const tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.monaco.json')).toString()); let compilerOptions; if (tsConfig.extends) { compilerOptions = Object.assign({}, require(path.join(options.sourcesRoot, tsConfig.extends)).compilerOptions, tsConfig.compilerOptions); @@ -36,13 +36,11 @@ function extractEditor(options) { compilerOptions = tsConfig.compilerOptions; } tsConfig.compilerOptions = compilerOptions; + compilerOptions.noEmit = false; compilerOptions.noUnusedLocals = false; compilerOptions.preserveConstEnums = false; compilerOptions.declaration = false; compilerOptions.moduleResolution = ts.ModuleResolutionKind.Classic; - delete compilerOptions.types; - delete tsConfig.extends; - tsConfig.exclude = []; options.compilerOptions = compilerOptions; let result = tss.shake(options); for (let fileName in result) { diff --git a/build/lib/standalone.ts b/build/lib/standalone.ts index b7b0fee295f..dfd3c99fe91 100644 --- a/build/lib/standalone.ts +++ b/build/lib/standalone.ts @@ -31,7 +31,7 @@ function writeFile(filePath: string, contents: Buffer | string): void { } export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: string }): void { - const tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.json')).toString()); + const tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.monaco.json')).toString()); let compilerOptions: { [key: string]: any }; if (tsConfig.extends) { compilerOptions = Object.assign({}, require(path.join(options.sourcesRoot, tsConfig.extends)).compilerOptions, tsConfig.compilerOptions); @@ -40,14 +40,12 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str } tsConfig.compilerOptions = compilerOptions; + compilerOptions.noEmit = false; compilerOptions.noUnusedLocals = false; compilerOptions.preserveConstEnums = false; compilerOptions.declaration = false; compilerOptions.moduleResolution = ts.ModuleResolutionKind.Classic; - delete compilerOptions.types; - delete tsConfig.extends; - tsConfig.exclude = []; options.compilerOptions = compilerOptions; diff --git a/src/tsconfig.json b/src/tsconfig.json index 4b9f4170455..72ae60789f9 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -4,7 +4,13 @@ "removeComments": false, "preserveConstEnums": true, "sourceMap": false, - "outDir": "../out" + "outDir": "../out", + "target": "es6", + "lib": [ + "dom", + "es5", + "es2015.iterable" + ] }, "include": [ "./typings", @@ -13,4 +19,4 @@ "exclude": [ "./typings/require-monaco.d.ts" ] -} \ No newline at end of file +} diff --git a/src/typings/lib.ie11_safe_es6.d.ts b/src/typings/lib.ie11_safe_es6.d.ts index ef2e2db7da5..43bde6f7c64 100644 --- a/src/typings/lib.ie11_safe_es6.d.ts +++ b/src/typings/lib.ie11_safe_es6.d.ts @@ -59,7 +59,7 @@ interface SetConstructor { declare var Set: SetConstructor; -interface WeakMap { +interface WeakMap { delete(key: K): boolean; get(key: K): V | undefined; has(key: K): boolean; @@ -70,9 +70,9 @@ interface WeakMap { interface WeakMapConstructor { new(): WeakMap; - new (): WeakMap; + new (): WeakMap; // new (entries?: [K, V][]): WeakMap; - readonly prototype: WeakMap; + readonly prototype: WeakMap; } declare var WeakMap: WeakMapConstructor; diff --git a/src/typings/lib.webworker.importscripts.d.ts b/src/typings/lib.webworker.importscripts.d.ts new file mode 100644 index 00000000000..e84f717c9a4 --- /dev/null +++ b/src/typings/lib.webworker.importscripts.d.ts @@ -0,0 +1,23 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + + + + +///////////////////////////// +/// WorkerGlobalScope APIs +///////////////////////////// +// These are only available in a Web Worker +declare function importScripts(...urls: string[]): void; diff --git a/src/vs/base/common/event.ts b/src/vs/base/common/event.ts index 1a77679c4ff..4438fa3db74 100644 --- a/src/vs/base/common/event.ts +++ b/src/vs/base/common/event.ts @@ -27,8 +27,8 @@ export namespace Event { return (listener, thisArgs = null, disposables?) => { // we need this, in case the event fires during the listener call let didFire = false; - - const result = event(e => { + let result: IDisposable; + result = event(e => { if (didFire) { return; } else if (result) { diff --git a/src/vs/base/common/types.ts b/src/vs/base/common/types.ts index c05da11b423..ad873be97b1 100644 --- a/src/vs/base/common/types.ts +++ b/src/vs/base/common/types.ts @@ -143,8 +143,12 @@ export function validateConstraint(arg: any, constraint: TypeConstraint | undefi throw new Error(`argument does not match constraint: typeof ${constraint}`); } } else if (isFunction(constraint)) { - if (arg instanceof constraint) { - return; + try { + if (arg instanceof constraint) { + return; + } + } catch{ + // ignore } if (!isUndefinedOrNull(arg) && arg.constructor === constraint) { return; @@ -161,8 +165,32 @@ export function validateConstraint(arg: any, constraint: TypeConstraint | undefi * any additional argument supplied. */ export function create(ctor: Function, ...args: any[]): any { - let obj = Object.create(ctor.prototype); - ctor.apply(obj, args); - - return obj; + if (isNativeClass(ctor)) { + return new (ctor as any)(...args); + } else { + let obj = Object.create(ctor.prototype); + ctor.apply(obj, args); + return obj; + } +} + +// https://stackoverflow.com/a/32235645/1499159 +function isNativeClass(thing): boolean { + return typeof thing === 'function' + && thing.hasOwnProperty('prototype') + && !thing.hasOwnProperty('arguments'); +} + +/** + * + * + */ +export function getAllPropertyNames(obj: object): string[] { + let res: string[] = []; + let proto = Object.getPrototypeOf(obj); + while (Object.prototype !== proto) { + res = res.concat(Object.getOwnPropertyNames(proto)); + proto = Object.getPrototypeOf(proto); + } + return res; } diff --git a/src/vs/base/common/worker/simpleWorker.ts b/src/vs/base/common/worker/simpleWorker.ts index fc6db66a8e4..fa19fff26e9 100644 --- a/src/vs/base/common/worker/simpleWorker.ts +++ b/src/vs/base/common/worker/simpleWorker.ts @@ -6,6 +6,7 @@ import { transformErrorForSerialization } from 'vs/base/common/errors'; import { Disposable } from 'vs/base/common/lifecycle'; import { isWeb } from 'vs/base/common/platform'; +import { getAllPropertyNames } from 'vs/base/common/types'; const INITIALIZE = '$initialize'; @@ -324,7 +325,7 @@ export class SimpleWorkerServer { if (this._requestHandler) { // static request handler let methods: string[] = []; - for (let prop in this._requestHandler) { + for (const prop of getAllPropertyNames(this._requestHandler)) { if (typeof this._requestHandler[prop] === 'function') { methods.push(prop); } @@ -360,7 +361,7 @@ export class SimpleWorkerServer { } let methods: string[] = []; - for (let prop in this._requestHandler) { + for (const prop of getAllPropertyNames(this._requestHandler)) { if (typeof this._requestHandler[prop] === 'function') { methods.push(prop); } diff --git a/src/vs/editor/common/services/editorSimpleWorker.ts b/src/vs/editor/common/services/editorSimpleWorker.ts index ed3a564f52e..4ef83f744a7 100644 --- a/src/vs/editor/common/services/editorSimpleWorker.ts +++ b/src/vs/editor/common/services/editorSimpleWorker.ts @@ -22,6 +22,7 @@ import { ILinkComputerTarget, computeLinks } from 'vs/editor/common/modes/linkCo import { BasicInplaceReplace } from 'vs/editor/common/modes/supports/inplaceReplaceSupport'; import { IDiffComputationResult } from 'vs/editor/common/services/editorWorkerService'; import { createMonacoBaseAPI } from 'vs/editor/common/standalone/standaloneBase'; +import { getAllPropertyNames } from 'vs/base/common/types'; export interface IMirrorModel { readonly uri: URI; @@ -599,7 +600,7 @@ export abstract class BaseEditorSimpleWorker { this._foreignModule = this._foreignModuleFactory(ctx, createData); // static foreing module let methods: string[] = []; - for (let prop in this._foreignModule) { + for (const prop of getAllPropertyNames(this._foreignModule)) { if (typeof this._foreignModule[prop] === 'function') { methods.push(prop); } @@ -612,7 +613,7 @@ export abstract class BaseEditorSimpleWorker { this._foreignModule = foreignModule.create(ctx, createData); let methods: string[] = []; - for (let prop in this._foreignModule) { + for (const prop of getAllPropertyNames(this._foreignModule)) { if (typeof this._foreignModule[prop] === 'function') { methods.push(prop); } diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 1e6a66f3096..4ea1942b4c1 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -16,6 +16,18 @@ import { generateUuid } from 'vs/base/common/uuid'; import * as vscode from 'vscode'; +function es5ClassCompat(target: Function): any { + ///@ts-ignore + function _() { return Reflect.construct(target, arguments, this.constructor); } + Object.defineProperty(_, 'name', Object.getOwnPropertyDescriptor(target, 'name')!); + ///@ts-ignore + Object.setPrototypeOf(_, target); + ///@ts-ignore + Object.setPrototypeOf(_.prototype, target.prototype); + return _; +} + +@es5ClassCompat export class Disposable { static from(...inDisposables: { dispose(): any }[]): Disposable { @@ -46,6 +58,7 @@ export class Disposable { } } +@es5ClassCompat export class Position { static Min(...positions: Position[]): Position { @@ -217,6 +230,7 @@ export class Position { } } +@es5ClassCompat export class Range { static isRange(thing: any): thing is vscode.Range { @@ -351,6 +365,7 @@ export class Range { } } +@es5ClassCompat export class Selection extends Range { static isSelection(thing: any): thing is Selection { @@ -421,6 +436,7 @@ export enum EndOfLine { CRLF = 2 } +@es5ClassCompat export class TextEdit { static isTextEdit(thing: any): thing is TextEdit { @@ -524,6 +540,7 @@ export interface IFileTextEdit { edit: TextEdit; } +@es5ClassCompat export class WorkspaceEdit implements vscode.WorkspaceEdit { private _edits = new Array(); @@ -627,6 +644,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { } } +@es5ClassCompat export class SnippetString { static isSnippetString(thing: any): thing is SnippetString { @@ -720,6 +738,7 @@ export enum DiagnosticSeverity { Error = 0 } +@es5ClassCompat export class Location { static isLocation(thing: any): thing is Location { @@ -758,6 +777,7 @@ export class Location { } } +@es5ClassCompat export class DiagnosticRelatedInformation { static is(thing: any): thing is DiagnosticRelatedInformation { @@ -791,6 +811,7 @@ export class DiagnosticRelatedInformation { } } +@es5ClassCompat export class Diagnostic { range: Range; @@ -835,6 +856,7 @@ export class Diagnostic { } } +@es5ClassCompat export class Hover { public contents: vscode.MarkdownString[] | vscode.MarkedString[]; @@ -864,6 +886,7 @@ export enum DocumentHighlightKind { Write = 2 } +@es5ClassCompat export class DocumentHighlight { range: Range; @@ -911,6 +934,7 @@ export enum SymbolKind { TypeParameter = 25 } +@es5ClassCompat export class SymbolInformation { static validate(candidate: SymbolInformation): void { @@ -954,6 +978,7 @@ export class SymbolInformation { } } +@es5ClassCompat export class DocumentSymbol { static validate(candidate: DocumentSymbol): void { @@ -993,6 +1018,7 @@ export enum CodeActionTrigger { Manual = 2, } +@es5ClassCompat export class CodeAction { title: string; @@ -1011,6 +1037,7 @@ export class CodeAction { } +@es5ClassCompat export class CodeActionKind { private static readonly sep = '.'; @@ -1041,6 +1068,7 @@ export class CodeActionKind { } } +@es5ClassCompat export class SelectionRangeKind { private static readonly _sep = '.'; @@ -1060,6 +1088,7 @@ export class SelectionRangeKind { } } +@es5ClassCompat export class SelectionRange { kind: SelectionRangeKind; @@ -1072,6 +1101,7 @@ export class SelectionRange { } +@es5ClassCompat export class CodeLens { range: Range; @@ -1088,6 +1118,7 @@ export class CodeLens { } } +@es5ClassCompat export class MarkdownString { value: string; @@ -1118,6 +1149,7 @@ export class MarkdownString { } } +@es5ClassCompat export class ParameterInformation { label: string | [number, number]; @@ -1129,6 +1161,7 @@ export class ParameterInformation { } } +@es5ClassCompat export class SignatureInformation { label: string; @@ -1142,6 +1175,7 @@ export class SignatureInformation { } } +@es5ClassCompat export class SignatureHelp { signatures: SignatureInformation[]; @@ -1198,6 +1232,7 @@ export enum CompletionItemKind { TypeParameter = 24 } +@es5ClassCompat export class CompletionItem implements vscode.CompletionItem { label: string; @@ -1235,6 +1270,7 @@ export class CompletionItem implements vscode.CompletionItem { } } +@es5ClassCompat export class CompletionList { isIncomplete?: boolean; @@ -1324,6 +1360,7 @@ export namespace TextEditorSelectionChangeKind { } } +@es5ClassCompat export class DocumentLink { range: Range; @@ -1342,6 +1379,7 @@ export class DocumentLink { } } +@es5ClassCompat export class Color { readonly red: number; readonly green: number; @@ -1358,6 +1396,7 @@ export class Color { export type IColorFormat = string | { opaque: string, transparent: string }; +@es5ClassCompat export class ColorInformation { range: Range; @@ -1375,6 +1414,7 @@ export class ColorInformation { } } +@es5ClassCompat export class ColorPresentation { label: string; textEdit?: TextEdit; @@ -1416,6 +1456,7 @@ export enum TaskPanelKind { New = 3 } +@es5ClassCompat export class TaskGroup implements vscode.TaskGroup { private _id: string; @@ -1458,6 +1499,7 @@ export class TaskGroup implements vscode.TaskGroup { } } +@es5ClassCompat export class ProcessExecution implements vscode.ProcessExecution { private _process: string; @@ -1530,6 +1572,7 @@ export class ProcessExecution implements vscode.ProcessExecution { } } +@es5ClassCompat export class ShellExecution implements vscode.ShellExecution { private _commandLine: string; @@ -1626,6 +1669,7 @@ export enum TaskScope { Workspace = 2 } +@es5ClassCompat export class Task implements vscode.Task { private static ProcessType: string = 'process'; @@ -1858,6 +1902,7 @@ export enum ProgressLocation { Notification = 15 } +@es5ClassCompat export class TreeItem { label?: string | vscode.TreeItemLabel; @@ -1885,6 +1930,7 @@ export enum TreeItemCollapsibleState { Expanded = 2 } +@es5ClassCompat export class ThemeIcon { static readonly File = new ThemeIcon('file'); @@ -1897,6 +1943,7 @@ export class ThemeIcon { } } +@es5ClassCompat export class ThemeColor { id: string; constructor(id: string) { @@ -1912,6 +1959,7 @@ export enum ConfigurationTarget { WorkspaceFolder = 3 } +@es5ClassCompat export class RelativePattern implements IRelativePattern { base: string; baseFolder?: URI; @@ -1944,6 +1992,7 @@ export class RelativePattern implements IRelativePattern { } } +@es5ClassCompat export class Breakpoint { private _id: string | undefined; @@ -1974,6 +2023,7 @@ export class Breakpoint { } } +@es5ClassCompat export class SourceBreakpoint extends Breakpoint { readonly location: Location; @@ -1986,6 +2036,7 @@ export class SourceBreakpoint extends Breakpoint { } } +@es5ClassCompat export class FunctionBreakpoint extends Breakpoint { readonly functionName: string; @@ -1998,6 +2049,7 @@ export class FunctionBreakpoint extends Breakpoint { } } +@es5ClassCompat export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable { readonly command: string; readonly args: string[]; @@ -2010,6 +2062,7 @@ export class DebugAdapterExecutable implements vscode.DebugAdapterExecutable { } } +@es5ClassCompat export class DebugAdapterServer implements vscode.DebugAdapterServer { readonly port: number; readonly host?: string; @@ -2021,6 +2074,7 @@ export class DebugAdapterServer implements vscode.DebugAdapterServer { } /* +@es5ClassCompat export class DebugAdapterImplementation implements vscode.DebugAdapterImplementation { readonly implementation: any; @@ -2048,6 +2102,7 @@ export enum FileChangeType { Deleted = 3, } +@es5ClassCompat export class FileSystemError extends Error { static FileExists(messageOrUri?: string | URI): FileSystemError { @@ -2090,6 +2145,7 @@ export class FileSystemError extends Error { //#region folding api +@es5ClassCompat export class FoldingRange { start: number; @@ -2125,6 +2181,7 @@ export enum CommentThreadCollapsibleState { Expanded = 1 } +@es5ClassCompat export class QuickInputButtons { static readonly Back: vscode.QuickInputButton = { iconPath: 'back.svg' }; diff --git a/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts b/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts index 3142782ef07..7248d076a02 100644 --- a/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts +++ b/src/vs/workbench/services/textMate/electron-browser/TMSyntax.ts @@ -257,7 +257,7 @@ export class TextMateService extends Disposable implements ITextMateService { let injections: string[] = []; for (let i = 1; i <= scopeParts.length; i++) { const subScopeName = scopeParts.slice(0, i).join('.'); - injections = [...injections, ...this._injections[subScopeName]]; + injections = [...injections, ...(this._injections[subScopeName] || [])]; } return injections; }