Skip to content

Commit

Permalink
refactor(core): simplify array flatten logic (#48358)
Browse files Browse the repository at this point in the history
We can now use modern Javascript to get the same result.

PR Close #48358
  • Loading branch information
alan-agius4 authored and AndrewKushnir committed Dec 6, 2022
1 parent 5e2cd07 commit c0d0417
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/core/src/di/create_injector.ts
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

import {flatten} from '../util/array_utils';
import {EMPTY_ARRAY} from '../util/empty';
import {stringify} from '../util/stringify';

Expand Down
20 changes: 2 additions & 18 deletions packages/core/src/util/array_utils.ts
Expand Up @@ -32,27 +32,11 @@ export function arrayEquals<T>(a: T[], b: T[], identityAccessor?: (value: T) =>
return true;
}


/**
* Flattens an array.
*/
export function flatten(list: any[], dst?: any[]): any[] {
if (dst === undefined) dst = list;
for (let i = 0; i < list.length; i++) {
let item = list[i];
if (Array.isArray(item)) {
// we need to inline it.
if (dst === list) {
// Our assumption that the list was already flat was wrong and
// we need to clone flat since we need to write to it.
dst = list.slice(0, i);
}
flatten(item, dst);
} else if (dst !== list) {
dst.push(item);
}
}
return dst;
export function flatten(list: any[]): any[] {
return list.flat(Number.POSITIVE_INFINITY);
}

export function deepForEach<T>(input: (T|any[])[], fn: (value: T) => void): void {
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Expand Up @@ -1016,9 +1016,6 @@
{
"name": "first"
},
{
"name": "flatten"
},
{
"name": "flatten2"
},
Expand Down

0 comments on commit c0d0417

Please sign in to comment.