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

Function icuCreateOpCodesToString

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

Source from the content-addressed store, hash-verified

134 * @param opcodes `I18nCreateOpCodes` if invoked as a function.
135 */
136export function icuCreateOpCodesToString(
137 this: IcuCreateOpCodes | void,
138 opcodes?: IcuCreateOpCodes,
139): string[] {
140 const parser = new OpCodeParser(opcodes || (Array.isArray(this) ? this : []));
141 let lines: string[] = [];
142
143 function consumeOpCode(opCode: number): string {
144 const parent = getParentFromIcuCreateOpCode(opCode);
145 const ref = getRefFromIcuCreateOpCode(opCode);
146 switch (getInstructionFromIcuCreateOpCode(opCode)) {
147 case IcuCreateOpCode.AppendChild:
148 return `(lView[${parent}] as Element).appendChild(lView[${lastRef}])`;
149 case IcuCreateOpCode.Attr:
150 return `(lView[${ref}] as Element).setAttribute("${parser.consumeString()}", "${parser.consumeString()}")`;
151 }
152 throw new Error('Unexpected OpCode: ' + getInstructionFromIcuCreateOpCode(opCode));
153 }
154
155 let lastRef = -1;
156 while (parser.hasMore()) {
157 let value = parser.consumeNumberStringOrMarker();
158 if (value === ICU_MARKER) {
159 const text = parser.consumeString();
160 lastRef = parser.consumeNumber();
161 lines.push(`lView[${lastRef}] = document.createComment("${text}")`);
162 } else if (value === ELEMENT_MARKER) {
163 const text = parser.consumeString();
164 lastRef = parser.consumeNumber();
165 lines.push(`lView[${lastRef}] = document.createElement("${text}")`);
166 } else if (typeof value === 'string') {
167 lastRef = parser.consumeNumber();
168 lines.push(`lView[${lastRef}] = document.createTextNode("${value}")`);
169 } else if (typeof value === 'number') {
170 const line = consumeOpCode(value);
171 line && lines.push(line);
172 } else {
173 throw new Error('Unexpected value');
174 }
175 }
176
177 return lines;
178}
179
180/**
181 * Converts `I18nRemoveOpCodes` array into a human readable format.

Callers 1

i18n_debug_spec.tsFile · 0.90

Calls 7

hasMoreMethod · 0.95
consumeStringMethod · 0.95
consumeNumberMethod · 0.95
consumeOpCodeFunction · 0.85
isArrayMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…