diff --git a/src/generators/dom/visitors/Text.js b/src/generators/dom/visitors/Text.js index aae2dae3e50c..923175e5ab67 100644 --- a/src/generators/dom/visitors/Text.js +++ b/src/generators/dom/visitors/Text.js @@ -1,6 +1,21 @@ +// Whitespace inside one of these elements will not result in +// a whitespace node being created in any circumstances. (This +// list is almost certainly very incomplete) +const elementsWithoutText = new Set([ + 'audio', + 'datalist', + 'dl', + 'ol', + 'optgroup', + 'select', + 'ul', + 'video' +]); + export default function visitText ( generator, block, state, node ) { - if ( state.namespace && !/\S/.test( node.data ) ) { - return; + if ( !/\S/.test( node.data ) ) { + if ( state.namespace ) return; + if ( elementsWithoutText.has( state.parentNodeName) ) return; } const name = block.getUniqueName( `text` ); diff --git a/test/runtime/samples/select-no-whitespace/_config.js b/test/runtime/samples/select-no-whitespace/_config.js new file mode 100644 index 000000000000..dabd1a54006d --- /dev/null +++ b/test/runtime/samples/select-no-whitespace/_config.js @@ -0,0 +1,6 @@ +export default { + test ( assert, component, target ) { + const select = target.querySelector( 'select' ); + assert.equal( select.childNodes.length, 3 ); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/select-no-whitespace/main.html b/test/runtime/samples/select-no-whitespace/main.html new file mode 100644 index 000000000000..1a91345534dd --- /dev/null +++ b/test/runtime/samples/select-no-whitespace/main.html @@ -0,0 +1,5 @@ + \ No newline at end of file