mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Refactor navigation bar
This commit is contained in:
@@ -138,6 +138,17 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function filterMutate<T>(array: T[], f: (x: T) => boolean): void {
|
||||
let outIndex = 0;
|
||||
for (const item of array) {
|
||||
if (f(item)) {
|
||||
array[outIndex] = item;
|
||||
outIndex++;
|
||||
}
|
||||
}
|
||||
array.length = outIndex;
|
||||
}
|
||||
|
||||
export function map<T, U>(array: T[], f: (x: T) => U): U[] {
|
||||
let result: U[];
|
||||
if (array) {
|
||||
|
||||
@@ -17,19 +17,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
|
||||
if (node) {
|
||||
if (node !== void 0) {
|
||||
return cbNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
function visitNodeArray<T>(cbNodes: (nodes: Node[]) => T, nodes: Node[]) {
|
||||
if (nodes) {
|
||||
if (nodes !== void 0) {
|
||||
return cbNodes(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
function visitEachNode<T>(cbNode: (node: Node) => T, nodes: Node[]) {
|
||||
if (nodes) {
|
||||
if (nodes !== void 0) {
|
||||
for (const node of nodes) {
|
||||
const result = cbNode(node);
|
||||
if (result) {
|
||||
@@ -44,7 +44,7 @@ namespace ts {
|
||||
// embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
|
||||
// a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned.
|
||||
export function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T {
|
||||
if (!node) {
|
||||
if (node === void 0) {
|
||||
return;
|
||||
}
|
||||
// The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray
|
||||
|
||||
Reference in New Issue
Block a user