Skip to content

Commit

Permalink
refactor(core): rename COMMENT_MARKER to ICU_MARKER (angular#39233)
Browse files Browse the repository at this point in the history
`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 angular#39233
  • Loading branch information
mhevery authored and alxhub committed Oct 22, 2020
1 parent 1b9193b commit e1f80d7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/render3/i18n/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>">`
Expand Down Expand Up @@ -968,7 +968,7 @@ const tI18n = <TI18n>{
],
<I18nMutateOpCodes>[ // Case: `other`: `{�0� <!--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: [
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/render3/i18n/i18n_apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/render3/i18n/i18n_debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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}")`);
Expand Down Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions packages/core/src/render3/i18n/i18n_parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/render3/interfaces/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
* // --------------------------------------------------
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/render3/i18n_debug_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
]))
Expand Down

0 comments on commit e1f80d7

Please sign in to comment.