Skip to content

Commit 2a12c9a

Browse files
committed
add es6 deprecation messages to some utils, remove duplicated utils, microsoft#90676
1 parent 4f2ea53 commit 2a12c9a

6 files changed

Lines changed: 33 additions & 20 deletions

File tree

src/vs/base/browser/ui/tree/abstractTree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
1414
import { ITreeModel, ITreeNode, ITreeRenderer, ITreeEvent, ITreeMouseEvent, ITreeContextMenuEvent, ITreeFilter, ITreeNavigator, ICollapseStateChangeEvent, ITreeDragAndDrop, TreeDragOverBubble, TreeVisibility, TreeFilterResult, ITreeModelSpliceEvent, TreeMouseEventTarget } from 'vs/base/browser/ui/tree/tree';
1515
import { ISpliceable } from 'vs/base/common/sequence';
1616
import { IDragAndDropData, StaticDND, DragAndDropData } from 'vs/base/browser/dnd';
17-
import { range, equals, distinctES6, fromSet } from 'vs/base/common/arrays';
17+
import { range, equals, distinctES6 } from 'vs/base/common/arrays';
1818
import { ElementsDragAndDropData } from 'vs/base/browser/ui/list/listView';
1919
import { domEvent } from 'vs/base/browser/event';
2020
import { fuzzyScore, FuzzyScore } from 'vs/base/common/filters';
@@ -1320,7 +1320,7 @@ export abstract class AbstractTree<T, TFilterData, TRef> implements IDisposable
13201320
set.add(node);
13211321
}
13221322

1323-
return fromSet(set);
1323+
return values(set);
13241324
}).event;
13251325

13261326
if (_options.keyboardSupport !== false) {

src/vs/base/common/arrays.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,6 @@ export function distinctES6<T>(array: ReadonlyArray<T>): T[] {
372372
});
373373
}
374374

375-
export function fromSet<T>(set: Set<T>): T[] {
376-
const result: T[] = [];
377-
set.forEach(o => result.push(o));
378-
return result;
379-
}
380-
381375
export function uniqueFilter<T>(keyFn: (t: T) => string): (t: T) => boolean {
382376
const seen: { [key: string]: boolean; } = Object.create(null);
383377

@@ -405,6 +399,9 @@ export function lastIndex<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean):
405399
return -1;
406400
}
407401

402+
/**
403+
* @deprecated ES6: use `Array.findIndex`
404+
*/
408405
export function firstIndex<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): number {
409406
for (let i = 0; i < array.length; i++) {
410407
const element = array[i];
@@ -417,6 +414,10 @@ export function firstIndex<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean)
417414
return -1;
418415
}
419416

417+
418+
/**
419+
* @deprecated ES6: use `Array.find`
420+
*/
420421
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T): T;
421422
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean): T | undefined;
422423
export function first<T>(array: ReadonlyArray<T>, fn: (item: T) => boolean, notFoundValue: T | undefined = undefined): T | undefined {
@@ -471,6 +472,9 @@ export function range(arg: number, to?: number): number[] {
471472
return result;
472473
}
473474

475+
/**
476+
* @deprecated ES6: use `Array.fill`
477+
*/
474478
export function fill<T>(num: number, value: T, arr: T[] = []): T[] {
475479
for (let i = 0; i < num; i++) {
476480
arr[i] = value;
@@ -564,6 +568,10 @@ export function pushToEnd<T>(arr: T[], value: T): void {
564568
}
565569
}
566570

571+
572+
/**
573+
* @deprecated ES6: use `Array.find`
574+
*/
567575
export function find<T>(arr: ArrayLike<T>, predicate: (value: T, index: number, arr: ArrayLike<T>) => any): T | undefined {
568576
for (let i = 0; i < arr.length; i++) {
569577
const element = arr[i];

src/vs/base/common/collections.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ export function fromMap<T>(original: Map<string, T>): IStringDictionary<T> {
9595
return result;
9696
}
9797

98-
export function mapValues<V>(map: Map<any, V>): V[] {
99-
const result: V[] = [];
100-
map.forEach(v => result.push(v));
101-
return result;
102-
}
10398

10499
export class SetMap<K, V> {
105100

src/vs/base/common/map.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { URI } from 'vs/base/common/uri';
77
import { CharCode } from 'vs/base/common/charCode';
88
import { Iterator, IteratorResult, FIN } from './iterator';
99

10-
10+
/**
11+
* @deprecated ES6: use `[...SetOrMap.values()]`
12+
*/
1113
export function values<V = any>(set: Set<V>): V[];
1214
export function values<K = any, V = any>(map: Map<K, V>): V[];
1315
export function values<V>(forEachable: { forEach(callback: (value: V, ...more: any[]) => any): void }): V[] {
@@ -16,6 +18,9 @@ export function values<V>(forEachable: { forEach(callback: (value: V, ...more: a
1618
return result;
1719
}
1820

21+
/**
22+
* @deprecated ES6: use `[...map.keys()]`
23+
*/
1924
export function keys<K, V>(map: Map<K, V>): K[] {
2025
const result: K[] = [];
2126
map.forEach((_value, key) => result.push(key));
@@ -51,6 +56,9 @@ export function setToString<K>(set: Set<K>): string {
5156
return `Set(${set.size}) {${entries.join(', ')}}`;
5257
}
5358

59+
/**
60+
* @deprecated ES6: use `...Map.entries()`
61+
*/
5462
export function mapToSerializable(map: Map<string, string>): [string, string][] {
5563
const serializable: [string, string][] = [];
5664

@@ -61,6 +69,9 @@ export function mapToSerializable(map: Map<string, string>): [string, string][]
6169
return serializable;
6270
}
6371

72+
/**
73+
* @deprecated ES6: use `new Map([[key1, value1],[key2, value2]])`
74+
*/
6475
export function serializableToMap(serializable: [string, string][]): Map<string, string> {
6576
const items = new Map<string, string>();
6677

src/vs/base/common/resourceTree.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import * as paths from 'vs/base/common/path';
88
import { Iterator } from 'vs/base/common/iterator';
99
import { relativePath, joinPath } from 'vs/base/common/resources';
1010
import { URI } from 'vs/base/common/uri';
11-
import { mapValues } from 'vs/base/common/collections';
12-
import { PathIterator } from 'vs/base/common/map';
11+
import { PathIterator, values } from 'vs/base/common/map';
1312

1413
export interface IResourceNode<T, C = void> {
1514
readonly uri: URI;
@@ -32,7 +31,7 @@ class Node<T, C> implements IResourceNode<T, C> {
3231
}
3332

3433
get children(): Iterator<Node<T, C>> {
35-
return Iterator.fromArray(mapValues(this._children));
34+
return Iterator.fromArray(values(this._children));
3635
}
3736

3837
@memoize

src/vs/base/common/strings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function isFalsyOrWhitespace(str: string | undefined): boolean {
1515
}
1616

1717
/**
18-
* @returns the provided number with the given number of preceding zeros.
18+
* @deprecated ES6: use `String.padStart`
1919
*/
2020
export function pad(n: number, l: number, char: string = '0'): string {
2121
const str = '' + n;
@@ -146,7 +146,7 @@ export function stripWildcards(pattern: string): string {
146146
}
147147

148148
/**
149-
* Determines if haystack starts with needle.
149+
* @deprecated ES6: use `String.startsWith`
150150
*/
151151
export function startsWith(haystack: string, needle: string): boolean {
152152
if (haystack.length < needle.length) {
@@ -167,7 +167,7 @@ export function startsWith(haystack: string, needle: string): boolean {
167167
}
168168

169169
/**
170-
* Determines if haystack ends with needle.
170+
* @deprecated ES6: use `String.endsWith`
171171
*/
172172
export function endsWith(haystack: string, needle: string): boolean {
173173
const diff = haystack.length - needle.length;

0 commit comments

Comments
 (0)