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

es6 compile #68121

Merged
merged 15 commits into from
Feb 11, 2019
6 changes: 2 additions & 4 deletions build/lib/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions build/lib/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down
10 changes: 8 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": false,
"outDir": "../out"
"outDir": "../out",
"target": "es6",
"lib": [
"dom",
"es5",
"es2015.iterable"
]
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't in the schema but exactly what we want 🤓

},
"include": [
"./typings",
Expand All @@ -13,4 +19,4 @@
"exclude": [
"./typings/require-monaco.d.ts"
]
}
}
6 changes: 3 additions & 3 deletions src/typings/lib.ie11_safe_es6.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
23 changes: 23 additions & 0 deletions src/typings/lib.webworker.importscripts.d.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions src/vs/base/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 33 additions & 5 deletions src/vs/base/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
5 changes: 3 additions & 2 deletions src/vs/base/common/worker/simpleWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/common/services/editorSimpleWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down