mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 09:35:40 -05:00
Initial VS Code 1.19 source merge (#571)
* Initial 1.19 xcopy * Fix yarn build * Fix numerous build breaks * Next batch of build break fixes * More build break fixes * Runtime breaks * Additional post merge fixes * Fix windows setup file * Fix test failures. * Update license header blocks to refer to source eula
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
import { isObject, isUndefinedOrNull, isArray } from 'vs/base/common/types';
|
||||
|
||||
export function clone<T>(obj: T): T {
|
||||
export function deepClone<T>(obj: T): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
@@ -15,23 +15,8 @@ export function clone<T>(obj: T): T {
|
||||
// See https://github.com/Microsoft/TypeScript/issues/10990
|
||||
return obj as any;
|
||||
}
|
||||
const result = (Array.isArray(obj)) ? <any>[] : <any>{};
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (obj[key] && typeof obj[key] === 'object') {
|
||||
result[key] = clone(obj[key]);
|
||||
} else {
|
||||
result[key] = obj[key];
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export function deepClone<T>(obj: T): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
const result = (Array.isArray(obj)) ? <any>[] : <any>{};
|
||||
Object.getOwnPropertyNames(obj).forEach(key => {
|
||||
const result: any = Array.isArray(obj) ? [] : {};
|
||||
Object.keys(obj).forEach((key: keyof T) => {
|
||||
if (obj[key] && typeof obj[key] === 'object') {
|
||||
result[key] = deepClone(obj[key]);
|
||||
} else {
|
||||
@@ -41,7 +26,27 @@ export function deepClone<T>(obj: T): T {
|
||||
return result;
|
||||
}
|
||||
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
export function deepFreeze<T>(obj: T): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
const stack: any[] = [obj];
|
||||
while (stack.length > 0) {
|
||||
let obj = stack.shift();
|
||||
Object.freeze(obj);
|
||||
for (const key in obj) {
|
||||
if (_hasOwnProperty.call(obj, key)) {
|
||||
let prop = obj[key];
|
||||
if (typeof prop === 'object' && !Object.isFrozen(prop)) {
|
||||
stack.push(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
export function cloneAndChange(obj: any, changer: (orig: any) => any): any {
|
||||
return _cloneAndChange(obj, changer, []);
|
||||
@@ -72,8 +77,8 @@ function _cloneAndChange(obj: any, changer: (orig: any) => any, encounteredObjec
|
||||
encounteredObjects.push(obj);
|
||||
const r2 = {};
|
||||
for (let i2 in obj) {
|
||||
if (hasOwnProperty.call(obj, i2)) {
|
||||
r2[i2] = _cloneAndChange(obj[i2], changer, encounteredObjects);
|
||||
if (_hasOwnProperty.call(obj, i2)) {
|
||||
(r2 as any)[i2] = _cloneAndChange(obj[i2], changer, encounteredObjects);
|
||||
}
|
||||
}
|
||||
encounteredObjects.pop();
|
||||
@@ -115,10 +120,6 @@ export function assign(destination: any, ...sources: any[]): any {
|
||||
return destination;
|
||||
}
|
||||
|
||||
export function toObject<T>(arr: T[], keyMap: (t: T) => string): { [key: string]: T } {
|
||||
return arr.reduce((o, d) => assign(o, { [keyMap(d)]: d }), Object.create(null));
|
||||
}
|
||||
|
||||
export function equals(one: any, other: any): boolean {
|
||||
if (one === other) {
|
||||
return true;
|
||||
@@ -172,12 +173,6 @@ export function equals(one: any, other: any): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function ensureProperty(obj: any, property: string, defaultValue: any) {
|
||||
if (typeof obj[property] === 'undefined') {
|
||||
obj[property] = defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function arrayToHash(array: any[]) {
|
||||
const result: any = {};
|
||||
for (let i = 0; i < array.length; ++i) {
|
||||
@@ -206,34 +201,6 @@ export function createKeywordMatcher(arr: string[], caseInsensitive: boolean = f
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Started from TypeScript's __extends function to make a type a subclass of a specific class.
|
||||
* Modified to work with properties already defined on the derivedClass, since we can't get TS
|
||||
* to call this method before the constructor definition.
|
||||
*/
|
||||
export function derive(baseClass: any, derivedClass: any): void {
|
||||
for (let prop in baseClass) {
|
||||
if (baseClass.hasOwnProperty(prop)) {
|
||||
derivedClass[prop] = baseClass[prop];
|
||||
}
|
||||
}
|
||||
|
||||
derivedClass = derivedClass || function () { };
|
||||
const basePrototype = baseClass.prototype;
|
||||
const derivedPrototype = derivedClass.prototype;
|
||||
derivedClass.prototype = Object.create(basePrototype);
|
||||
|
||||
for (let prop in derivedPrototype) {
|
||||
if (derivedPrototype.hasOwnProperty(prop)) {
|
||||
// handle getters and setters properly
|
||||
Object.defineProperty(derivedClass.prototype, prop, Object.getOwnPropertyDescriptor(derivedPrototype, prop));
|
||||
}
|
||||
}
|
||||
|
||||
// Cast to any due to Bug 16188:PropertyDescriptor set and get function should be optional.
|
||||
Object.defineProperty(derivedClass.prototype, 'constructor', <any>{ value: derivedClass, writable: true, configurable: true, enumerable: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls JSON.Stringify with a replacer to break apart any circular references.
|
||||
* This prevents JSON.stringify from throwing the exception
|
||||
@@ -287,4 +254,4 @@ export function distinct(base: obj, target: obj): obj {
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user