Merge pull request #459 from sveltejs/gh-189

don't create whitespace nodes inside elements like <select>
pull/464/head
Rich Harris 8 years ago committed by GitHub
commit 9c166a86f0

@ -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` );

@ -0,0 +1,6 @@
export default {
test ( assert, component, target ) {
const select = target.querySelector( 'select' );
assert.equal( select.childNodes.length, 3 );
}
};

@ -0,0 +1,5 @@
<select>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
Loading…
Cancel
Save