Skip to content

Commit

Permalink
Merge pull request #459 from sveltejs/gh-189
Browse files Browse the repository at this point in the history
don't create whitespace nodes inside elements like <select>
  • Loading branch information
Rich-Harris authored Apr 10, 2017
2 parents 9a3b4b1 + 182a04e commit 9c166a8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/generators/dom/visitors/Text.js
Original file line number Diff line number Diff line change
@@ -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` );
Expand Down
6 changes: 6 additions & 0 deletions test/runtime/samples/select-no-whitespace/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
test ( assert, component, target ) {
const select = target.querySelector( 'select' );
assert.equal( select.childNodes.length, 3 );
}
};
5 changes: 5 additions & 0 deletions test/runtime/samples/select-no-whitespace/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<select>
<option>a</option>
<option>b</option>
<option>c</option>
</select>

0 comments on commit 9c166a8

Please sign in to comment.