Skip to content

Commit

Permalink
refactor(core): move attachDebugGetter to i18n specifc code (#48549)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pkozlowski-opensource authored and alxhub committed Jan 4, 2023
1 parent 1085e5c commit dacfe43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
18 changes: 17 additions & 1 deletion packages/core/src/render3/i18n/i18n_parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<T>(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.
*
Expand Down
24 changes: 0 additions & 24 deletions packages/core/src/render3/util/debug_utils.ts

This file was deleted.

0 comments on commit dacfe43

Please sign in to comment.