From dacfe4372ed75faa72ff23d7d8b967bdecc41ce7 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Tue, 20 Dec 2022 10:33:20 +0100 Subject: [PATCH] refactor(core): move attachDebugGetter to i18n specifc code (#48549) The attachDebugGetter function is only used in the i18n specific code so could be moved closer to the sole usage site instead of being exported to the entire framework code. It also lets us remove the entire packages/core/src/render3/util/debug_utils.ts file. PR Close #48549 --- packages/core/src/render3/i18n/i18n_parse.ts | 18 +++++++++++++- packages/core/src/render3/util/debug_utils.ts | 24 ------------------- 2 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 packages/core/src/render3/util/debug_utils.ts diff --git a/packages/core/src/render3/i18n/i18n_parse.ts b/packages/core/src/render3/i18n/i18n_parse.ts index 854408c1e0a..f4203b953a6 100644 --- a/packages/core/src/render3/i18n/i18n_parse.ts +++ b/packages/core/src/render3/i18n/i18n_parse.ts @@ -22,7 +22,6 @@ import {TNode, TNodeType} from '../interfaces/node'; import {SanitizerFn} from '../interfaces/sanitization'; import {HEADER_OFFSET, LView, TView} from '../interfaces/view'; import {getCurrentParentTNode, getCurrentTNode, setCurrentTNode} from '../state'; -import {attachDebugGetter} from '../util/debug_utils'; import {i18nCreateOpCodesToString, i18nRemoveOpCodesToString, i18nUpdateOpCodesToString, icuCreateOpCodesToString} from './i18n_debug'; import {addTNodeAndUpdateInsertBeforeIndex} from './i18n_insert_before_index'; @@ -52,6 +51,23 @@ function replaceNgsp(value: string): string { return value.replace(NGSP_UNICODE_REGEXP, ' '); } +/** + * Patch a `debug` property getter on top of the existing object. + * + * NOTE: always call this method with `ngDevMode && attachDebugObject(...)` + * + * @param obj Object to patch + * @param debugGetter Getter returning a value to patch + */ +function attachDebugGetter(obj: T, debugGetter: (this: T) => any): void { + if (ngDevMode) { + Object.defineProperty(obj, 'debug', {get: debugGetter, enumerable: false}); + } else { + throw new Error( + 'This method should be guarded with `ngDevMode` so that it can be tree shaken in production!'); + } +} + /** * Create dynamic nodes from i18n translation block. * diff --git a/packages/core/src/render3/util/debug_utils.ts b/packages/core/src/render3/util/debug_utils.ts deleted file mode 100644 index 00e66e0ace7..00000000000 --- a/packages/core/src/render3/util/debug_utils.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -/** - * Patch a `debug` property getter on top of the existing object. - * - * NOTE: always call this method with `ngDevMode && attachDebugObject(...)` - * - * @param obj Object to patch - * @param debugGetter Getter returning a value to patch - */ -export function attachDebugGetter(obj: T, debugGetter: (this: T) => any): void { - if (ngDevMode) { - Object.defineProperty(obj, 'debug', {get: debugGetter, enumerable: false}); - } else { - throw new Error( - 'This method should be guarded with `ngDevMode` so that it can be tree shaken in production!'); - } -}