@@ -438,17 +438,20 @@ function replaceHtmlWithPlaceholders(
438438 const components : Array < string | Placeholder > = [ ] ;
439439
440440 const traverse = ( node : parse5 . DefaultTreeNode ) : void => {
441- const text =
442- node . nodeName === '#text'
443- ? ( node as parse5 . DefaultTreeTextNode ) . value
444- : null ;
445- if ( text !== null ) {
441+ if ( node . nodeName === '#text' ) {
442+ const text = ( node as parse5 . DefaultTreeTextNode ) . value ;
446443 components . push ( text ) ;
444+ } else if ( node . nodeName === '#comment' ) {
445+ components . push ( {
446+ untranslatable : serializeComment ( node as parse5 . DefaultTreeCommentNode ) ,
447+ } ) ;
447448 } else {
448449 const { open, close} = serializeOpenCloseTags ( node ) ;
449450 components . push ( { untranslatable : open } ) ;
450- for ( const child of ( node as parse5 . DefaultTreeParentNode ) . childNodes ) {
451- traverse ( child ) ;
451+ if ( 'childNodes' in node ) {
452+ for ( const child of ( node as parse5 . DefaultTreeParentNode ) . childNodes ) {
453+ traverse ( child ) ;
454+ }
452455 }
453456 components . push ( { untranslatable : close } ) ;
454457 }
@@ -481,6 +484,17 @@ function serializeOpenCloseTags(
481484 return { open, close} ;
482485}
483486
487+ /**
488+ * Serialize an HTML comment node.
489+ *
490+ * Example:
491+ *
492+ * {data: "foo"} --> "<!-- foo -->"
493+ */
494+ function serializeComment ( comment : parse5 . DefaultTreeCommentNode ) : string {
495+ return parse5 . serialize ( { childNodes : [ comment ] } ) ;
496+ }
497+
484498/**
485499 * E.g. "foo", 'foo', or `foo`, but not `foo${bar}`.
486500 */
0 commit comments