From cf51690341a3d1b4fecfa950814db4ea426794cb Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 5 Dec 2022 13:35:02 +0000 Subject: [PATCH] refactor(core): remove several private utils and APIs (#48357) These APIs are no longer used. PR Close #48357 --- packages/core/src/render3/assert.ts | 6 --- packages/core/src/render3/namespaces.ts | 8 --- packages/core/src/render3/state.ts | 3 -- packages/core/src/render3/util/view_utils.ts | 14 ----- packages/core/src/util/array_utils.ts | 54 ------------------- packages/core/test/util/array_utils_spec.ts | 55 +------------------- 6 files changed, 1 insertion(+), 139 deletions(-) diff --git a/packages/core/src/render3/assert.ts b/packages/core/src/render3/assert.ts index 23cf7db30d5..a812882cdd5 100644 --- a/packages/core/src/render3/assert.ts +++ b/packages/core/src/render3/assert.ts @@ -73,12 +73,6 @@ export function assertHasParent(tNode: TNode|null) { assertDefined(tNode!.parent, 'currentTNode should have a parent'); } -export function assertDataNext(lView: LView, index: number, arr?: any[]) { - if (arr == null) arr = lView; - assertEqual( - arr.length, index, `index ${index} expected to be at the end of arr (length ${arr.length})`); -} - export function assertLContainer(value: any): asserts value is LContainer { assertDefined(value, 'LContainer must be defined'); assertEqual(isLContainer(value), true, 'Expecting LContainer'); diff --git a/packages/core/src/render3/namespaces.ts b/packages/core/src/render3/namespaces.ts index b1e9744aa19..22ee2465b07 100644 --- a/packages/core/src/render3/namespaces.ts +++ b/packages/core/src/render3/namespaces.ts @@ -7,12 +7,4 @@ */ export const SVG_NAMESPACE = 'svg'; -export const SVG_NAMESPACE_URI = 'http://www.w3.org/2000/svg'; export const MATH_ML_NAMESPACE = 'math'; -export const MATH_ML_NAMESPACE_URI = 'http://www.w3.org/1998/MathML/'; - -export function getNamespaceUri(namespace: string): string|null { - const name = namespace.toLowerCase(); - return name === SVG_NAMESPACE ? SVG_NAMESPACE_URI : - (name === MATH_ML_NAMESPACE ? MATH_ML_NAMESPACE_URI : null); -} diff --git a/packages/core/src/render3/state.ts b/packages/core/src/render3/state.ts index 5420b0b50c4..48d6d5e24ba 100644 --- a/packages/core/src/render3/state.ts +++ b/packages/core/src/render3/state.ts @@ -338,9 +338,6 @@ export function isCurrentTNodeParent(): boolean { export function setCurrentTNodeAsNotParent(): void { instructionState.lFrame.isParent = false; } -export function setCurrentTNodeAsParent(): void { - instructionState.lFrame.isParent = true; -} export function getContextLView(): LView { const contextLView = instructionState.lFrame.contextLView; diff --git a/packages/core/src/render3/util/view_utils.ts b/packages/core/src/render3/util/view_utils.ts index 468f3177bc4..e1ff9df1706 100644 --- a/packages/core/src/render3/util/view_utils.ts +++ b/packages/core/src/render3/util/view_utils.ts @@ -58,20 +58,6 @@ export function unwrapLView(value: RNode|LView|LContainer): LView|null { return null; } -/** - * Returns `LContainer` or `null` if not found. - * @param value wrapped value of `RNode`, `LView`, `LContainer` - */ -export function unwrapLContainer(value: RNode|LView|LContainer): LContainer|null { - while (Array.isArray(value)) { - // This check is same as `isLContainer()` but we don't call at as we don't want to call - // `Array.isArray()` twice and give JITer more work for inlining. - if (value[TYPE] === true) return value as LContainer; - value = value[HOST] as any; - } - return null; -} - /** * Retrieves an element value from the provided `viewData`, by unwrapping * from any containers, component views, or style contexts. diff --git a/packages/core/src/util/array_utils.ts b/packages/core/src/util/array_utils.ts index 747f476977d..4c1ed40a47a 100644 --- a/packages/core/src/util/array_utils.ts +++ b/packages/core/src/util/array_utils.ts @@ -8,18 +8,6 @@ import {assertEqual, assertLessThanOrEqual} from './assert'; -/** - * Equivalent to ES6 spread, add each item to an array. - * - * @param items The items to add - * @param arr The array to which you want to add the items - */ -export function addAllToArray(items: any[], arr: any[]) { - for (let i = 0; i < items.length; i++) { - arr.push(items[i]); - } -} - /** * Determines if the contents of two arrays is identical * @@ -180,48 +168,6 @@ export function arrayInsert2(array: any[], index: number, value1: any, value2: a } } -/** - * Insert a `value` into an `array` so that the array remains sorted. - * - * NOTE: - * - Duplicates are not allowed, and are ignored. - * - This uses binary search algorithm for fast inserts. - * - * @param array A sorted array to insert into. - * @param value The value to insert. - * @returns index of the inserted value. - */ -export function arrayInsertSorted(array: string[], value: string): number { - let index = arrayIndexOfSorted(array, value); - if (index < 0) { - // if we did not find it insert it. - index = ~index; - arrayInsert(array, index, value); - } - return index; -} - -/** - * Remove `value` from a sorted `array`. - * - * NOTE: - * - This uses binary search algorithm for fast removals. - * - * @param array A sorted array to remove from. - * @param value The value to remove. - * @returns index of the removed value. - * - positive index if value found and removed. - * - negative index if value not found. (`~index` to get the value where it should have been - * inserted) - */ -export function arrayRemoveSorted(array: string[], value: string): number { - const index = arrayIndexOfSorted(array, value); - if (index >= 0) { - arraySplice(array, index, 1); - } - return index; -} - /** * Get an index of an `value` in a sorted `array`. diff --git a/packages/core/test/util/array_utils_spec.ts b/packages/core/test/util/array_utils_spec.ts index e46270c914a..a9707cffbe5 100644 --- a/packages/core/test/util/array_utils_spec.ts +++ b/packages/core/test/util/array_utils_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {arrayIndexOfSorted, arrayInsert, arrayInsert2, arrayInsertSorted, arrayRemoveSorted, arraySplice, flatten, KeyValueArray, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils'; +import {arrayIndexOfSorted, arrayInsert, arrayInsert2, arraySplice, flatten, KeyValueArray, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils'; describe('array_utils', () => { describe('flatten', () => { @@ -76,59 +76,6 @@ describe('array_utils', () => { }); }); - describe('arrayInsertSorted', () => { - it('should insert items don\'t allow duplicates', () => { - let a; - a = ['a', 'c', 'e', 'g', 'i']; - expect(arrayInsertSorted(a, 'a')).toEqual(0); - expect(a).toEqual(['a', 'c', 'e', 'g', 'i']); - - a = ['a', 'c', 'e', 'g', 'i']; - expect(arrayInsertSorted(a, 'b')).toEqual(1); - expect(a).toEqual(['a', 'b', 'c', 'e', 'g', 'i']); - - a = ['a', 'c', 'e', 'g', 'i']; - expect(arrayInsertSorted(a, 'c')).toEqual(1); - expect(a).toEqual(['a', 'c', 'e', 'g', 'i']); - - a = ['a', 'c', 'e', 'g', 'i']; - expect(arrayInsertSorted(a, 'd')).toEqual(2); - expect(a).toEqual(['a', 'c', 'd', 'e', 'g', 'i']); - - a = ['a', 'c', 'e', 'g', 'i']; - expect(arrayInsertSorted(a, 'e')).toEqual(2); - expect(a).toEqual(['a', 'c', 'e', 'g', 'i']); - }); - }); - - - - describe('arrayRemoveSorted', () => { - it('should remove items', () => { - let a; - a = ['a', 'b', 'c', 'd', 'e']; - expect(arrayRemoveSorted(a, 'a')).toEqual(0); - expect(a).toEqual(['b', 'c', 'd', 'e']); - - a = ['a', 'b', 'c', 'd', 'e']; - expect(arrayRemoveSorted(a, 'b')).toEqual(1); - expect(a).toEqual(['a', 'c', 'd', 'e']); - - a = ['a', 'b', 'c', 'd', 'e']; - expect(arrayRemoveSorted(a, 'c')).toEqual(2); - expect(a).toEqual(['a', 'b', 'd', 'e']); - - a = ['a', 'b', 'c', 'd', 'e']; - expect(arrayRemoveSorted(a, 'd')).toEqual(3); - expect(a).toEqual(['a', 'b', 'c', 'e']); - - a = ['a', 'b', 'c', 'd', 'e']; - expect(arrayRemoveSorted(a, 'e')).toEqual(4); - expect(a).toEqual(['a', 'b', 'c', 'd']); - }); - }); - - describe('arrayIndexOfSorted', () => { it('should get index of', () => { const a = ['a', 'b', 'c', 'd', 'e'];