Remove typings and replace missing methods with vscodes (#8217)

* remove typings and replace missing methods with vscodes

* fix strict-null-checks

* fix tests
This commit is contained in:
Anthony Dresser
2019-11-05 13:03:20 -08:00
committed by GitHub
parent 4645a8ba6b
commit 22a427f934
184 changed files with 634 additions and 43388 deletions

View File

@@ -0,0 +1,8 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export function entries<K>(o: Record<string, K>): [string, K][] {
return Object.keys(o).map(k => [k, o[k]]);
}

View File

@@ -1,50 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Alterable version of the vs memorize function; to unmemoize use unmemoize
*/
export function memoize(target: any, key: string, descriptor: any) {
let fnKey: string | null = null;
let fn: Function | null = null;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
if (fn!.length !== 0) {
console.warn('Memoize should only be used in functions with zero parameters');
}
} else if (typeof descriptor.get === 'function') {
fnKey = 'get';
fn = descriptor.get;
}
if (!fn) {
throw new Error('not supported');
}
const memoizeKey = `$memoize$${key}`;
descriptor[fnKey!] = function (...args: any[]) {
if (!this.hasOwnProperty(memoizeKey)) {
Object.defineProperty(this, memoizeKey, {
configurable: true,
enumerable: false,
writable: false,
value: fn!.apply(this, args)
});
}
return this[memoizeKey];
};
}
export function unmemoize(target: Object, key: string) {
const memoizeKey = `$memoize$${key}`;
if (target.hasOwnProperty(memoizeKey)) {
delete target[memoizeKey];
}
}

View File

@@ -32,11 +32,3 @@ export function mixin(destination: any, source: any, overwrite: boolean = true,
}
return destination;
}
export function entries<T>(o: { [key: string]: T }): [string, T][] {
return Object.keys(o).map(k => [k, o[k]] as [string, T]);
}
export function values<T>(o: { [key: string]: T }): T[] {
return Object.keys(o).map(k => o[k]);
}

View File

@@ -19,3 +19,20 @@ export function escape(html: string): string {
}
});
}
// gotten from https://github.com/59naga/string-raw/blob/master/src/index.js
export function raw(callSite: any, ...substitutions: any[]): string {
let template;
try {
template = Array.from(callSite.raw);
} catch (e) {
throw new TypeError('Cannot convert undefined or null to object');
}
return template.map((chunk, i) => {
if (callSite.raw.length <= i) {
return chunk;
}
return substitutions[i - 1] ? substitutions[i - 1] + chunk : chunk;
}).join('');
}