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:
parent
1b9193b3fb
commit
e1f80d73a8
@ -434,7 +434,7 @@ const tI18n = <TI18n>{
|
|||||||
// // Assume expandoIndex = 200;
|
// // Assume expandoIndex = 200;
|
||||||
// const node = lView[expandoIndex++] = document.createComment('');
|
// const node = lView[expandoIndex++] = document.createComment('');
|
||||||
// lView[1].appendChild(node);
|
// lView[1].appendChild(node);
|
||||||
COMMENT_MARKER, '', 1 << SHIFT_PARENT | AppendChild,
|
ICU_MARKER, '', 1 << SHIFT_PARENT | AppendChild,
|
||||||
],
|
],
|
||||||
update: <I18nUpdateOpCodes>[
|
update: <I18nUpdateOpCodes>[
|
||||||
// The following OpCodes represent: `<b>{count, plural, ... }</b>">`
|
// The following OpCodes represent: `<b>{count, plural, ... }</b>">`
|
||||||
@ -968,7 +968,7 @@ const tI18n = <TI18n>{
|
|||||||
],
|
],
|
||||||
<I18nMutateOpCodes>[ // Case: `other`: `{<7B>0<EFBFBD> <!--subICU-->}`
|
<I18nMutateOpCodes>[ // Case: `other`: `{<7B>0<EFBFBD> <!--subICU-->}`
|
||||||
'', 1 << SHIFT_PARENT | AppendChild, // Expando location: 100
|
'', 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: [
|
remove: [
|
||||||
|
@ -11,7 +11,7 @@ import {assertDefined, assertDomNode, assertEqual, assertGreaterThan, assertInde
|
|||||||
import {assertIndexInExpandoRange, assertTIcu} from '../assert';
|
import {assertIndexInExpandoRange, assertTIcu} from '../assert';
|
||||||
import {attachPatchData} from '../context_discovery';
|
import {attachPatchData} from '../context_discovery';
|
||||||
import {elementPropertyInternal, setElementAttribute} from '../instructions/shared';
|
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 {TNode} from '../interfaces/node';
|
||||||
import {RElement, RNode, RText} from '../interfaces/renderer';
|
import {RElement, RNode, RText} from '../interfaces/renderer';
|
||||||
import {SanitizerFn} from '../interfaces/sanitization';
|
import {SanitizerFn} from '../interfaces/sanitization';
|
||||||
@ -20,6 +20,7 @@ import {createCommentNode, createElementNode, createTextNode, nativeInsertBefore
|
|||||||
import {getBindingIndex} from '../state';
|
import {getBindingIndex} from '../state';
|
||||||
import {renderStringify} from '../util/misc_utils';
|
import {renderStringify} from '../util/misc_utils';
|
||||||
import {getNativeByIndex, unwrapRNode} from '../util/view_utils';
|
import {getNativeByIndex, unwrapRNode} from '../util/view_utils';
|
||||||
|
|
||||||
import {getLocaleId} from './i18n_locale_id';
|
import {getLocaleId} from './i18n_locale_id';
|
||||||
import {getTIcu} from './i18n_util';
|
import {getTIcu} from './i18n_util';
|
||||||
|
|
||||||
@ -202,7 +203,7 @@ export function applyMutableOpCodes(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (opCode) {
|
switch (opCode) {
|
||||||
case COMMENT_MARKER:
|
case ICU_MARKER:
|
||||||
const commentValue = mutableOpCodes[++i] as string;
|
const commentValue = mutableOpCodes[++i] as string;
|
||||||
const commentNodeIndex = mutableOpCodes[++i] as number;
|
const commentNodeIndex = mutableOpCodes[++i] as number;
|
||||||
if (lView[commentNodeIndex] === null) {
|
if (lView[commentNodeIndex] === null) {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {assertNumber, assertString} from '../../util/assert';
|
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;
|
let lastRef = -1;
|
||||||
while (parser.hasMore()) {
|
while (parser.hasMore()) {
|
||||||
let value = parser.consumeNumberStringOrMarker();
|
let value = parser.consumeNumberStringOrMarker();
|
||||||
if (value === COMMENT_MARKER) {
|
if (value === ICU_MARKER) {
|
||||||
const text = parser.consumeString();
|
const text = parser.consumeString();
|
||||||
lastRef = parser.consumeNumber();
|
lastRef = parser.consumeNumber();
|
||||||
lines.push(`lView[${lastRef}] = document.createComment("${text}")`);
|
lines.push(`lView[${lastRef}] = document.createComment("${text}")`);
|
||||||
@ -201,13 +201,13 @@ class OpCodeParser {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeNumberStringOrMarker(): number|string|COMMENT_MARKER|ELEMENT_MARKER {
|
consumeNumberStringOrMarker(): number|string|ICU_MARKER|ELEMENT_MARKER {
|
||||||
let value = this.codes[this.i++];
|
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) {
|
value == ELEMENT_MARKER) {
|
||||||
return value;
|
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;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import {CharCode} from '../../util/char_code';
|
|||||||
import {loadIcuContainerVisitor} from '../instructions/i18n_icu_container_visitor';
|
import {loadIcuContainerVisitor} from '../instructions/i18n_icu_container_visitor';
|
||||||
import {allocExpando, createTNodeAtIndex, elementAttributeInternal, setInputsForProperty, setNgReflectProperties} from '../instructions/shared';
|
import {allocExpando, createTNodeAtIndex, elementAttributeInternal, setInputsForProperty, setNgReflectProperties} from '../instructions/shared';
|
||||||
import {getDocument} from '../interfaces/document';
|
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 {TNode, TNodeType} from '../interfaces/node';
|
||||||
import {RComment, RElement} from '../interfaces/renderer';
|
import {RComment, RElement} from '../interfaces/renderer';
|
||||||
import {SanitizerFn} from '../interfaces/sanitization';
|
import {SanitizerFn} from '../interfaces/sanitization';
|
||||||
@ -678,7 +678,7 @@ function walkIcuTree(
|
|||||||
const icuExpression: IcuExpression = nestedIcus[nestedIcuIndex];
|
const icuExpression: IcuExpression = nestedIcus[nestedIcuIndex];
|
||||||
// Create the comment node that will anchor the ICU expression
|
// Create the comment node that will anchor the ICU expression
|
||||||
addCreateNodeAndAppend(
|
addCreateNodeAndAppend(
|
||||||
create, COMMENT_MARKER, ngDevMode ? `nested ICU ${nestedIcuIndex}` : '', parentIdx,
|
create, ICU_MARKER, ngDevMode ? `nested ICU ${nestedIcuIndex}` : '', parentIdx,
|
||||||
newIndex);
|
newIndex);
|
||||||
icuStart(tView, lView, sharedUpdateOpCodes, parentIdx, icuExpression, newIndex);
|
icuStart(tView, lView, sharedUpdateOpCodes, parentIdx, icuExpression, newIndex);
|
||||||
addRemoveNestedIcu(remove, newIndex, depth);
|
addRemoveNestedIcu(remove, newIndex, depth);
|
||||||
@ -714,7 +714,7 @@ function addUpdateIcuUpdate(update: I18nUpdateOpCodes, bindingMask: number, inde
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addCreateNodeAndAppend(
|
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) {
|
appendToParentIdx: number, createAtIdx: number) {
|
||||||
if (marker !== null) {
|
if (marker !== null) {
|
||||||
create.push(marker);
|
create.push(marker);
|
||||||
|
@ -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.
|
* See `I18nMutateOpCodes` documentation.
|
||||||
*/
|
*/
|
||||||
// FIXME(misko): Rename to ICU marker
|
export const ICU_MARKER: ICU_MARKER = {
|
||||||
export const COMMENT_MARKER: COMMENT_MARKER = {
|
marker: 'ICU'
|
||||||
marker: 'comment'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface COMMENT_MARKER {
|
export interface ICU_MARKER {
|
||||||
marker: 'comment';
|
marker: 'ICU';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface I18nDebug {
|
export interface I18nDebug {
|
||||||
@ -220,7 +219,7 @@ export enum I18nCreateOpCode {
|
|||||||
* // ---------------------
|
* // ---------------------
|
||||||
* // Equivalent to:
|
* // Equivalent to:
|
||||||
* // lView[1].appendChild(lView[0] = document.createComment(''));
|
* // 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
|
* // For moving existing nodes to a different location
|
||||||
* // --------------------------------------------------
|
* // --------------------------------------------------
|
||||||
@ -245,7 +244,7 @@ export enum I18nCreateOpCode {
|
|||||||
*
|
*
|
||||||
* See: `applyI18nCreateOpCodes`;
|
* 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 {}
|
I18nDebug {}
|
||||||
|
|
||||||
export const enum I18nUpdateOpCode {
|
export const enum I18nUpdateOpCode {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {i18nCreateOpCodesToString, i18nMutateOpCodesToString, i18nUpdateOpCodesToString} from '@angular/core/src/render3/i18n/i18n_debug';
|
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('i18n debug', () => {
|
||||||
describe('i18nUpdateOpCodesToString', () => {
|
describe('i18nUpdateOpCodesToString', () => {
|
||||||
@ -92,7 +92,7 @@ describe('i18n debug', () => {
|
|||||||
|
|
||||||
it('should print comment AppendChild', () => {
|
it('should print comment AppendChild', () => {
|
||||||
expect(i18nMutateOpCodesToString([
|
expect(i18nMutateOpCodesToString([
|
||||||
COMMENT_MARKER, 'xyz', 0,
|
ICU_MARKER, 'xyz', 0,
|
||||||
1 << I18nMutateOpCode.SHIFT_PARENT | 0 << I18nMutateOpCode.SHIFT_REF |
|
1 << I18nMutateOpCode.SHIFT_PARENT | 0 << I18nMutateOpCode.SHIFT_REF |
|
||||||
I18nMutateOpCode.AppendChild
|
I18nMutateOpCode.AppendChild
|
||||||
]))
|
]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user