未验证 提交 42f2fc97 编写于 作者: J Johannes Rieken 提交者: GitHub

Merge pull request #68121 from Microsoft/joh/es6

es6 compile
......@@ -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) {
......
......@@ -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;
......
......@@ -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
}
......@@ -59,7 +59,7 @@ interface SetConstructor {
declare var Set: SetConstructor;
interface WeakMap<K, V> {
interface WeakMap<K extends object, V> {
delete(key: K): boolean;
get(key: K): V | undefined;
has(key: K): boolean;
......@@ -70,9 +70,9 @@ interface WeakMap<K, V> {
interface WeakMapConstructor {
new(): WeakMap<any, any>;
new <K, V>(): WeakMap<K, V>;
new <K extends object, V>(): WeakMap<K, V>;
// new <K, V>(entries?: [K, V][]): WeakMap<K, V>;
readonly prototype: WeakMap<any, any>;
readonly prototype: WeakMap<object, any>;
}
declare var WeakMap: WeakMapConstructor;
......
/*! *****************************************************************************
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;
......@@ -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) {
......
......@@ -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);
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');
}
return obj;
/**
*
*
*/
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;
}
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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<IFileOperation | IFileTextEdit>();
......@@ -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' };
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册