From e1f80d73a8906b852f547ba36a251e1c32c4997b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 13 Oct 2020 12:58:14 -0700 Subject: [PATCH] refactor(core): rename `COMMENT_MARKER` to `ICU_MARKER` (#39233) `COMMENT_MARKER` is a generic name which does not make it obvious that it is used for ICU use case. `ICU_MARKER` is more explicit as it is used exclusively with ICUs. PR Close #39233 --- packages/core/src/render3/i18n/i18n.md | 4 ++-- packages/core/src/render3/i18n/i18n_apply.ts | 5 +++-- packages/core/src/render3/i18n/i18n_debug.ts | 10 +++++----- packages/core/src/render3/i18n/i18n_parse.ts | 6 +++--- packages/core/src/render3/interfaces/i18n.ts | 15 +++++++-------- packages/core/test/render3/i18n_debug_spec.ts | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/core/src/render3/i18n/i18n.md b/packages/core/src/render3/i18n/i18n.md index 05669f0dd5..e476df408d 100644 --- a/packages/core/src/render3/i18n/i18n.md +++ b/packages/core/src/render3/i18n/i18n.md @@ -434,7 +434,7 @@ const tI18n = { // // Assume expandoIndex = 200; // const node = lView[expandoIndex++] = document.createComment(''); // lView[1].appendChild(node); - COMMENT_MARKER, '', 1 << SHIFT_PARENT | AppendChild, + ICU_MARKER, '', 1 << SHIFT_PARENT | AppendChild, ], update: [ // The following OpCodes represent: `{count, plural, ... }">` @@ -968,7 +968,7 @@ const tI18n = { ], [ // Case: `other`: `{�0� }` '', 1 << SHIFT_PARENT | AppendChild, // Expando location: 100 - COMMENT_MARKER, '', 0 << SHIFT_PARENT | AppendChild, // Expando location: 101 + ICU_MARKER, '', 0 << SHIFT_PARENT | AppendChild, // Expando location: 101 ], ], remove: [ diff --git a/packages/core/src/render3/i18n/i18n_apply.ts b/packages/core/src/render3/i18n/i18n_apply.ts index e123460211..499a399da5 100644 --- a/packages/core/src/render3/i18n/i18n_apply.ts +++ b/packages/core/src/render3/i18n/i18n_apply.ts @@ -11,7 +11,7 @@ import {assertDefined, assertDomNode, assertEqual, assertGreaterThan, assertInde import {assertIndexInExpandoRange, assertTIcu} from '../assert'; import {attachPatchData} from '../context_discovery'; import {elementPropertyInternal, setElementAttribute} from '../instructions/shared'; -import {COMMENT_MARKER, ELEMENT_MARKER, getCurrentICUCaseIndex, getParentFromI18nMutateOpCode, getRefFromI18nMutateOpCode, I18nCreateOpCode, I18nCreateOpCodes, I18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, IcuType, TI18n, TIcu} from '../interfaces/i18n'; +import {ELEMENT_MARKER, getCurrentICUCaseIndex, getParentFromI18nMutateOpCode, getRefFromI18nMutateOpCode, I18nCreateOpCode, I18nCreateOpCodes, I18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, ICU_MARKER, IcuType, TI18n, TIcu} from '../interfaces/i18n'; import {TNode} from '../interfaces/node'; import {RElement, RNode, RText} from '../interfaces/renderer'; import {SanitizerFn} from '../interfaces/sanitization'; @@ -20,6 +20,7 @@ import {createCommentNode, createElementNode, createTextNode, nativeInsertBefore import {getBindingIndex} from '../state'; import {renderStringify} from '../util/misc_utils'; import {getNativeByIndex, unwrapRNode} from '../util/view_utils'; + import {getLocaleId} from './i18n_locale_id'; import {getTIcu} from './i18n_util'; @@ -202,7 +203,7 @@ export function applyMutableOpCodes( } } else { switch (opCode) { - case COMMENT_MARKER: + case ICU_MARKER: const commentValue = mutableOpCodes[++i] as string; const commentNodeIndex = mutableOpCodes[++i] as number; if (lView[commentNodeIndex] === null) { diff --git a/packages/core/src/render3/i18n/i18n_debug.ts b/packages/core/src/render3/i18n/i18n_debug.ts index 1c0b6c6fc5..c048e9ee2b 100644 --- a/packages/core/src/render3/i18n/i18n_debug.ts +++ b/packages/core/src/render3/i18n/i18n_debug.ts @@ -7,7 +7,7 @@ */ import {assertNumber, assertString} from '../../util/assert'; -import {COMMENT_MARKER, ELEMENT_MARKER, getInstructionFromI18nMutateOpCode, getParentFromI18nMutateOpCode, getRefFromI18nMutateOpCode, I18nCreateOpCode, I18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes} from '../interfaces/i18n'; +import {ELEMENT_MARKER, getInstructionFromI18nMutateOpCode, getParentFromI18nMutateOpCode, getRefFromI18nMutateOpCode, I18nCreateOpCode, I18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, ICU_MARKER} from '../interfaces/i18n'; /** @@ -137,7 +137,7 @@ export function i18nMutateOpCodesToString( let lastRef = -1; while (parser.hasMore()) { let value = parser.consumeNumberStringOrMarker(); - if (value === COMMENT_MARKER) { + if (value === ICU_MARKER) { const text = parser.consumeString(); lastRef = parser.consumeNumber(); lines.push(`lView[${lastRef}] = document.createComment("${text}")`); @@ -201,13 +201,13 @@ class OpCodeParser { return value; } - consumeNumberStringOrMarker(): number|string|COMMENT_MARKER|ELEMENT_MARKER { + consumeNumberStringOrMarker(): number|string|ICU_MARKER|ELEMENT_MARKER { let value = this.codes[this.i++]; - if (typeof value === 'string' || typeof value === 'number' || value == COMMENT_MARKER || + if (typeof value === 'string' || typeof value === 'number' || value == ICU_MARKER || value == ELEMENT_MARKER) { return value; } - assertNumber(value, 'expecting number, string, COMMENT_MARKER or ELEMENT_MARKER in OpCode'); + assertNumber(value, 'expecting number, string, ICU_MARKER or ELEMENT_MARKER in OpCode'); return value; } } diff --git a/packages/core/src/render3/i18n/i18n_parse.ts b/packages/core/src/render3/i18n/i18n_parse.ts index 5f20adde86..11be9980e9 100644 --- a/packages/core/src/render3/i18n/i18n_parse.ts +++ b/packages/core/src/render3/i18n/i18n_parse.ts @@ -16,7 +16,7 @@ import {CharCode} from '../../util/char_code'; import {loadIcuContainerVisitor} from '../instructions/i18n_icu_container_visitor'; import {allocExpando, createTNodeAtIndex, elementAttributeInternal, setInputsForProperty, setNgReflectProperties} from '../instructions/shared'; import {getDocument} from '../interfaces/document'; -import {COMMENT_MARKER, ELEMENT_MARKER, ensureIcuContainerVisitorLoaded, I18nCreateOpCode, I18nCreateOpCodes, I18nMutateOpCode, i18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, IcuExpression, IcuType, TI18n, TIcu} from '../interfaces/i18n'; +import {ELEMENT_MARKER, ensureIcuContainerVisitorLoaded, I18nCreateOpCode, I18nCreateOpCodes, I18nMutateOpCode, i18nMutateOpCode, I18nMutateOpCodes, I18nUpdateOpCode, I18nUpdateOpCodes, ICU_MARKER, IcuExpression, IcuType, TI18n, TIcu} from '../interfaces/i18n'; import {TNode, TNodeType} from '../interfaces/node'; import {RComment, RElement} from '../interfaces/renderer'; import {SanitizerFn} from '../interfaces/sanitization'; @@ -678,7 +678,7 @@ function walkIcuTree( const icuExpression: IcuExpression = nestedIcus[nestedIcuIndex]; // Create the comment node that will anchor the ICU expression addCreateNodeAndAppend( - create, COMMENT_MARKER, ngDevMode ? `nested ICU ${nestedIcuIndex}` : '', parentIdx, + create, ICU_MARKER, ngDevMode ? `nested ICU ${nestedIcuIndex}` : '', parentIdx, newIndex); icuStart(tView, lView, sharedUpdateOpCodes, parentIdx, icuExpression, newIndex); addRemoveNestedIcu(remove, newIndex, depth); @@ -714,7 +714,7 @@ function addUpdateIcuUpdate(update: I18nUpdateOpCodes, bindingMask: number, inde } function addCreateNodeAndAppend( - create: I18nMutateOpCodes, marker: null|COMMENT_MARKER|ELEMENT_MARKER, text: string, + create: I18nMutateOpCodes, marker: null|ICU_MARKER|ELEMENT_MARKER, text: string, appendToParentIdx: number, createAtIdx: number) { if (marker !== null) { create.push(marker); diff --git a/packages/core/src/render3/interfaces/i18n.ts b/packages/core/src/render3/interfaces/i18n.ts index 3b93b1b055..4ae81e8e49 100644 --- a/packages/core/src/render3/interfaces/i18n.ts +++ b/packages/core/src/render3/interfaces/i18n.ts @@ -117,17 +117,16 @@ export interface ELEMENT_MARKER { } /** - * Marks that the next string is comment text. + * Marks that the next string is comment text need for ICU. * * See `I18nMutateOpCodes` documentation. */ -// FIXME(misko): Rename to ICU marker -export const COMMENT_MARKER: COMMENT_MARKER = { - marker: 'comment' +export const ICU_MARKER: ICU_MARKER = { + marker: 'ICU' }; -export interface COMMENT_MARKER { - marker: 'comment'; +export interface ICU_MARKER { + marker: 'ICU'; } export interface I18nDebug { @@ -220,7 +219,7 @@ export enum I18nCreateOpCode { * // --------------------- * // Equivalent to: * // lView[1].appendChild(lView[0] = document.createComment('')); - * COMMENT_MARKER, '', 0, 1 << SHIFT_PARENT | 0 << SHIFT_REF | AppendChild, + * ICU_MARKER, '', 0, 1 << SHIFT_PARENT | 0 << SHIFT_REF | AppendChild, * * // For moving existing nodes to a different location * // -------------------------------------------------- @@ -245,7 +244,7 @@ export enum I18nCreateOpCode { * * See: `applyI18nCreateOpCodes`; */ -export interface I18nMutateOpCodes extends Array, +export interface I18nMutateOpCodes extends Array, I18nDebug {} export const enum I18nUpdateOpCode { diff --git a/packages/core/test/render3/i18n_debug_spec.ts b/packages/core/test/render3/i18n_debug_spec.ts index 68a8cb9306..9a05808680 100644 --- a/packages/core/test/render3/i18n_debug_spec.ts +++ b/packages/core/test/render3/i18n_debug_spec.ts @@ -7,7 +7,7 @@ */ import {i18nCreateOpCodesToString, i18nMutateOpCodesToString, i18nUpdateOpCodesToString} from '@angular/core/src/render3/i18n/i18n_debug'; -import {COMMENT_MARKER, ELEMENT_MARKER, I18nCreateOpCode, I18nMutateOpCode, I18nUpdateOpCode} from '@angular/core/src/render3/interfaces/i18n'; +import {ELEMENT_MARKER, I18nCreateOpCode, I18nMutateOpCode, I18nUpdateOpCode, ICU_MARKER} from '@angular/core/src/render3/interfaces/i18n'; describe('i18n debug', () => { describe('i18nUpdateOpCodesToString', () => { @@ -92,7 +92,7 @@ describe('i18n debug', () => { it('should print comment AppendChild', () => { expect(i18nMutateOpCodesToString([ - COMMENT_MARKER, 'xyz', 0, + ICU_MARKER, 'xyz', 0, 1 << I18nMutateOpCode.SHIFT_PARENT | 0 << I18nMutateOpCode.SHIFT_REF | I18nMutateOpCode.AppendChild ]))