MCPcopy Index your code
hub / github.com/angular/angular / i18nUpdateOpCodesToString

Function i18nUpdateOpCodesToString

packages/core/src/render3/i18n/i18n_debug.ts:73–124  ·  view source on GitHub ↗
(
  this: I18nUpdateOpCodes | void,
  opcodes?: I18nUpdateOpCodes,
)

Source from the content-addressed store, hash-verified

71 * @param opcodes `I18nUpdateOpCodes` if invoked as a function.
72 */
73export function i18nUpdateOpCodesToString(
74 this: I18nUpdateOpCodes | void,
75 opcodes?: I18nUpdateOpCodes,
76): string[] {
77 const parser = new OpCodeParser(opcodes || (Array.isArray(this) ? this : []));
78 let lines: string[] = [];
79
80 function consumeOpCode(value: number): string {
81 const ref = value >>> I18nUpdateOpCode.SHIFT_REF;
82 const opCode = value & I18nUpdateOpCode.MASK_OPCODE;
83 switch (opCode) {
84 case I18nUpdateOpCode.Text:
85 return `(lView[${ref}] as Text).textContent = $$$`;
86 case I18nUpdateOpCode.Attr:
87 const attrName = parser.consumeString();
88 const sanitizationFn = parser.consumeFunction();
89 const value = sanitizationFn ? `(${sanitizationFn})($$$)` : '$$$';
90 return `(lView[${ref}] as Element).setAttribute('${attrName}', ${value})`;
91 case I18nUpdateOpCode.IcuSwitch:
92 return `icuSwitchCase(${ref}, $$$)`;
93 case I18nUpdateOpCode.IcuUpdate:
94 return `icuUpdateCase(${ref})`;
95 }
96 throw new Error('unexpected OpCode');
97 }
98
99 while (parser.hasMore()) {
100 let mask = parser.consumeNumber();
101 let size = parser.consumeNumber();
102 const end = parser.i + size;
103 const statements: string[] = [];
104 let statement = '';
105 while (parser.i < end) {
106 let value = parser.consumeNumberOrString();
107 if (typeof value === 'string') {
108 statement += value;
109 } else if (value < 0) {
110 // Negative numbers are ref indexes
111 // Here `i` refers to current binding index. It is to signify that the value is relative,
112 // rather than absolute.
113 statement += '${lView[i' + value + ']}';
114 } else {
115 // Positive numbers are operations.
116 const opCodeText = consumeOpCode(value);
117 statements.push(opCodeText.replace('$$$', '`' + statement + '`') + ';');
118 statement = '';
119 }
120 }
121 lines.push(`if (mask & 0b${mask.toString(2)}) { ${statements.join(' ')} }`);
122 }
123 return lines;
124}
125
126/**
127 * Converts `I18nCreateOpCodes` array into a human readable format.

Callers 1

i18n_debug_spec.tsFile · 0.90

Calls 9

hasMoreMethod · 0.95
consumeNumberMethod · 0.95
consumeNumberOrStringMethod · 0.95
consumeOpCodeFunction · 0.85
isArrayMethod · 0.80
toStringMethod · 0.65
joinMethod · 0.65
pushMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…