( this: I18nCreateOpCodes | void, opcodes?: I18nCreateOpCodes, )
| 36 | * @param opcodes `I18nCreateOpCodes` if invoked as a function. |
| 37 | */ |
| 38 | export function i18nCreateOpCodesToString( |
| 39 | this: I18nCreateOpCodes | void, |
| 40 | opcodes?: I18nCreateOpCodes, |
| 41 | ): string[] { |
| 42 | const createOpCodes: I18nCreateOpCodes = opcodes || (Array.isArray(this) ? this : ([] as any)); |
| 43 | let lines: string[] = []; |
| 44 | for (let i = 0; i < createOpCodes.length; i++) { |
| 45 | const opCode = createOpCodes[i++] as any; |
| 46 | const text = createOpCodes[i] as string; |
| 47 | const isComment = (opCode & I18nCreateOpCode.COMMENT) === I18nCreateOpCode.COMMENT; |
| 48 | const appendNow = |
| 49 | (opCode & I18nCreateOpCode.APPEND_EAGERLY) === I18nCreateOpCode.APPEND_EAGERLY; |
| 50 | const index = opCode >>> I18nCreateOpCode.SHIFT; |
| 51 | lines.push( |
| 52 | `lView[${index}] = document.${isComment ? 'createComment' : 'createText'}(${JSON.stringify( |
| 53 | text, |
| 54 | )});`, |
| 55 | ); |
| 56 | if (appendNow) { |
| 57 | lines.push(`parent.appendChild(lView[${index}]);`); |
| 58 | } |
| 59 | } |
| 60 | return lines; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Converts `I18nUpdateOpCodes` array into a human readable format. |
no test coverage detected
searching dependent graphs…