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
This commit is contained in:
Misko Hevery 2020-10-13 12:58:14 -07:00 committed by Alex Rickabaugh
parent 1b9193b3fb
commit e1f80d73a8
6 changed files with 22 additions and 22 deletions

View File

@ -434,7 +434,7 @@ const tI18n = <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: <I18nUpdateOpCodes>[
// The following OpCodes represent: `<b>{count, plural, ... }</b>">`
@ -968,7 +968,7 @@ const tI18n = <TI18n>{
],
<I18nMutateOpCodes>[ // Case: `other`: `{<7B>0<EFBFBD> <!--subICU-->}`
'', 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: [

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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<number|string|ELEMENT_MARKER|COMMENT_MARKER|null>,
export interface I18nMutateOpCodes extends Array<number|string|ELEMENT_MARKER|ICU_MARKER|null>,
I18nDebug {}
export const enum I18nUpdateOpCode {

View File

@ -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
]))