mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
Merge pull request #71 from sveltejs/gh-63
handle empty attributes in elements and components
This commit is contained in:
commit
1de87945db
@ -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];
|
||||
|
||||
|
@ -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];
|
||||
|
||||
|
7
test/compiler/attribute-empty-svg/_config.js
Normal file
7
test/compiler/attribute-empty-svg/_config.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default {
|
||||
html: `
|
||||
<svg>
|
||||
<g class=''></g>
|
||||
</svg>
|
||||
`
|
||||
};
|
3
test/compiler/attribute-empty-svg/main.html
Normal file
3
test/compiler/attribute-empty-svg/main.html
Normal file
@ -0,0 +1,3 @@
|
||||
<svg>
|
||||
<g class=''></g>
|
||||
</svg>
|
After Width: | Height: | Size: 31 B |
3
test/compiler/attribute-empty/_config.js
Normal file
3
test/compiler/attribute-empty/_config.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: `<div class=""></div>`
|
||||
};
|
1
test/compiler/attribute-empty/main.html
Normal file
1
test/compiler/attribute-empty/main.html
Normal file
@ -0,0 +1 @@
|
||||
<div class=''></div>
|
1
test/compiler/component-data-empty/Widget.html
Normal file
1
test/compiler/component-data-empty/Widget.html
Normal file
@ -0,0 +1 @@
|
||||
<p>foo: '{{foo}}'</p>
|
3
test/compiler/component-data-empty/_config.js
Normal file
3
test/compiler/component-data-empty/_config.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: `<div><p>foo: ''</p></div>`
|
||||
};
|
11
test/compiler/component-data-empty/main.html
Normal file
11
test/compiler/component-data-empty/main.html
Normal file
@ -0,0 +1,11 @@
|
||||
<div>
|
||||
<Widget foo=''/>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import Widget from './Widget.html';
|
||||
|
||||
export default {
|
||||
components: { Widget }
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user