Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't create whitespace nodes inside elements like <select> #459

Merged
merged 1 commit into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>