0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

handle empty attributes in elements and components. fixes #63

This commit is contained in:
Rich Harris 2016-11-30 16:38:17 -05:00
parent 8a3f81363d
commit 7b15ff93ac
7 changed files with 38 additions and 0 deletions

View File

@ -16,6 +16,13 @@ export default function addComponentAttributes ( generator, node, local ) {
});
}
else if ( attribute.value.length === 0 ) {
local.staticAttributes.push({
name: attribute.name,
value: `''`
});
}
else if ( attribute.value.length === 1 ) {
const value = attribute.value[0];

View File

@ -31,6 +31,18 @@ export default function addElementAttributes ( generator, node, local ) {
}
}
else if ( attribute.value.length === 0 ) {
if ( propertyName ) {
local.init.push( deindent`
${local.name}.${propertyName} = '';
` );
} else {
local.init.push( deindent`
${local.name}.setAttribute( '${attribute.name}', '' );
` );
}
}
else if ( attribute.value.length === 1 ) {
const value = attribute.value[0];

View File

@ -0,0 +1,3 @@
export default {
html: `<div class=""></div>`
};

View File

@ -0,0 +1 @@
<div class=''></div>

View File

@ -0,0 +1 @@
<p>foo: '{{foo}}'</p>

View File

@ -0,0 +1,3 @@
export default {
html: `<div><p>foo: ''</p></div>`
};

View File

@ -0,0 +1,11 @@
<div>
<Widget foo=''/>
</div>
<script>
import Widget from './Widget.html';
export default {
components: { Widget }
};
</script>