Switch to std library Object functions (#152128)

- `fromMap` -> `Object.fromEntries`

- `values` -> `Object.values`
This commit is contained in:
Matt Bierner 2022-06-15 09:34:32 -07:00 committed by GitHub
parent 001d52cf6b
commit 98ad4c15b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 36 deletions

View file

@ -9,29 +9,12 @@
*/
export type IStringDictionary<V> = Record<string, V>;
/**
* An interface for a JavaScript object that
* acts a dictionary. The keys are numbers.
*/
export type INumberDictionary<V> = Record<number, V>;
const hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Returns an array which contains all values that reside
* in the given dictionary.
*/
export function values<T>(from: IStringDictionary<T> | INumberDictionary<T>): T[] {
const result: T[] = [];
for (const key in from) {
if (hasOwnProperty.call(from, key)) {
result.push((from as any)[key]);
}
}
return result;
}
/**
* Iterates over each entry in the provided dictionary. The iterator will stop when the callback returns `false`.
*
@ -63,16 +46,6 @@ export function groupBy<K extends string | number | symbol, V>(data: V[], groupF
return result;
}
export function fromMap<T>(original: Map<string, T>): IStringDictionary<T> {
const result: IStringDictionary<T> = Object.create(null);
if (original) {
original.forEach((value, key) => {
result[key] = value;
});
}
return result;
}
export function diffSets<T>(before: Set<T>, after: Set<T>): { removed: T[]; added: T[] } {
const removed: T[] = [];
const added: T[] = [];

View file

@ -51,7 +51,6 @@ import { ProxyIdentifier } from 'vs/workbench/services/extensions/common/proxyId
import { ExtensionDescriptionRegistry } from 'vs/workbench/services/extensions/common/extensionDescriptionRegistry';
import type * as vscode from 'vscode';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { values } from 'vs/base/common/collections';
import { ExtHostEditorInsets } from 'vs/workbench/api/common/extHostCodeInsets';
import { ExtHostLabelService } from 'vs/workbench/api/common/extHostLabelService';
import { getRemoteName } from 'vs/platform/remote/common/remoteHosts';
@ -186,7 +185,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
rpcProtocol.set(ExtHostContext.ExtHostInteractive, new ExtHostInteractive(rpcProtocol, extHostNotebook, extHostDocumentsAndEditors, extHostCommands));
// Check that no named customers are missing
const expected: ProxyIdentifier<any>[] = values(ExtHostContext);
const expected = Object.values<ProxyIdentifier<any>>(ExtHostContext);
rpcProtocol.assertRegistered(expected);
// Other instances

View file

@ -10,7 +10,7 @@ import * as Types from 'vs/base/common/types';
import * as Platform from 'vs/base/common/platform';
import * as Async from 'vs/base/common/async';
import * as resources from 'vs/base/common/resources';
import { IStringDictionary, values } from 'vs/base/common/collections';
import { IStringDictionary } from 'vs/base/common/collections';
import { LinkedMap, Touch } from 'vs/base/common/map';
import Severity from 'vs/base/common/severity';
import { Event, Emitter } from 'vs/base/common/event';
@ -1217,7 +1217,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
if (group) {
// Try to find an existing terminal to split.
// Even if an existing terminal is found, the split can fail if the terminal width is too small.
for (const terminal of values(this._terminals)) {
for (const terminal of Object.values(this._terminals)) {
if (terminal.group === group) {
this._logService.trace(`Found terminal to split for group ${group}`);
const originalInstance = terminal.terminal;

View file

@ -7,7 +7,7 @@ import * as nls from 'vs/nls';
import * as Types from 'vs/base/common/types';
import { Schemas } from 'vs/base/common/network';
import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor';
import { IStringDictionary, forEach, fromMap } from 'vs/base/common/collections';
import { IStringDictionary, forEach } from 'vs/base/common/collections';
import { IConfigurationService, IConfigurationOverrides, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IWorkspaceFolder, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
@ -128,7 +128,7 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
if (!mapping) {
return null;
} else if (mapping.size > 0) {
return this.resolveAnyAsync(folder, config, fromMap(mapping));
return this.resolveAnyAsync(folder, config, Object.fromEntries(mapping));
} else {
return config;
}

View file

@ -14,7 +14,6 @@ import { IMessage } from 'vs/workbench/services/extensions/common/extensions';
import { ExtensionIdentifier, IExtensionDescription, EXTENSION_CATEGORIES } from 'vs/platform/extensions/common/extensions';
import { ExtensionKind } from 'vs/platform/environment/common/environment';
import { allApiProposals } from 'vs/workbench/services/extensions/common/extensionsApiProposals';
import { values } from 'vs/base/common/collections';
import { productSchemaId } from 'vs/platform/product/common/productService';
const schemaRegistry = Registry.as<IJSONContributionRegistry>(Extensions.JSONContribution);
@ -236,7 +235,7 @@ export const schema: IJSONSchema = {
items: {
type: 'string',
enum: Object.keys(allApiProposals),
markdownEnumDescriptions: values(allApiProposals)
markdownEnumDescriptions: Object.values(allApiProposals)
}
},
activationEvents: {
@ -601,7 +600,7 @@ schemaRegistry.registerSchema(productSchemaId, {
items: {
type: 'string',
enum: Object.keys(allApiProposals),
markdownEnumDescriptions: values(allApiProposals)
markdownEnumDescriptions: Object.values(allApiProposals)
}
}]
}