mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 01:25:38 -05:00
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:
8
src/sql/base/common/collections.ts
Normal file
8
src/sql/base/common/collections.ts
Normal 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]]);
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user