(
node: T,
context: any,
)
| 293 | } |
| 294 | |
| 295 | private _visitElementLike<T extends html.Element | html.Component>( |
| 296 | node: T, |
| 297 | context: any, |
| 298 | ): T | null { |
| 299 | this._mayBeAddBlockChildren(node); |
| 300 | this._depth++; |
| 301 | const wasInI18nNode = this._inI18nNode; |
| 302 | const wasInImplicitNode = this._inImplicitNode; |
| 303 | let childNodes: html.Node[] = []; |
| 304 | let translatedChildNodes: html.Node[] = undefined!; |
| 305 | |
| 306 | // Extract: |
| 307 | // - top level nodes with the (implicit) "i18n" attribute if not already in a section |
| 308 | // - ICU messages |
| 309 | const nodeName = node instanceof html.Component ? node.tagName : node.name; |
| 310 | const i18nAttr = _getI18nAttr(node); |
| 311 | const i18nMeta = i18nAttr ? i18nAttr.value : ''; |
| 312 | const isImplicit = |
| 313 | this._implicitTags.some((tag) => nodeName === tag) && |
| 314 | !this._inIcu && |
| 315 | !this._isInTranslatableSection; |
| 316 | const isTopLevelImplicit = !wasInImplicitNode && isImplicit; |
| 317 | this._inImplicitNode = wasInImplicitNode || isImplicit; |
| 318 | |
| 319 | if (!this._isInTranslatableSection && !this._inIcu) { |
| 320 | if (i18nAttr || isTopLevelImplicit) { |
| 321 | this._inI18nNode = true; |
| 322 | const message = this._addMessage(node.children, i18nMeta)!; |
| 323 | translatedChildNodes = this._translateMessage(node, message); |
| 324 | } |
| 325 | |
| 326 | if (this._mode == _VisitorMode.Extract) { |
| 327 | const isTranslatable = i18nAttr || isTopLevelImplicit; |
| 328 | if (isTranslatable) this._openTranslatableSection(node); |
| 329 | html.visitAll(this, node.children); |
| 330 | if (isTranslatable) this._closeTranslatableSection(node, node.children); |
| 331 | } |
| 332 | } else { |
| 333 | if (i18nAttr || isTopLevelImplicit) { |
| 334 | this._reportError( |
| 335 | node, |
| 336 | 'Could not mark an element as translatable inside a translatable section', |
| 337 | ); |
| 338 | } |
| 339 | |
| 340 | if (this._mode == _VisitorMode.Extract) { |
| 341 | // Descend into child nodes for extraction |
| 342 | html.visitAll(this, node.children); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | if (this._mode === _VisitorMode.Merge) { |
| 347 | const visitNodes = translatedChildNodes || node.children; |
| 348 | visitNodes.forEach((child) => { |
| 349 | const visited = child.visit(this, context); |
| 350 | if (visited && !this._isInTranslatableSection) { |
| 351 | // Do not add the children from translatable sections (= i18n blocks here) |
| 352 | // They will be added later in this loop when the block closes (i.e. on `<!-- /i18n -->`) |
no test coverage detected