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

Merge pull request #393 from sveltejs/removeobjectkey-fix

Fix removing last key in object when it has a trailing comma
This commit is contained in:
Rich Harris 2017-03-19 08:45:51 -04:00 committed by GitHub
commit b5c971cba4
3 changed files with 4 additions and 4 deletions

View File

@ -206,8 +206,8 @@ export default function dom ( parsed, source, options, names ) {
}
});
if ( hasNonImportedComponent ) {
// remove the specific components which were imported, as we'll refer to them directly
Object.keys( generator.importedComponents ).forEach ( key => {
// remove the specific components that were imported, as we'll refer to them directly
Object.keys( generator.importedComponents ).forEach( key => {
removeObjectKey( generator, templateProperties.components.value, key );
});
} else {

View File

@ -4,6 +4,6 @@ export default function removeObjectKey ( generator, node, key ) {
const index = properties.findIndex( property => property.key.type === 'Identifier' && property.key.name === key );
if ( index === -1 ) return;
const a = properties[ index ].start;
const b = index < properties.length - 1 ? properties[ index + 1 ].start : properties[ index ].end;
const b = index < properties.length - 1 ? properties[ index + 1 ].start : node.end - 1;
generator.code.remove( a, b );
}

View File

@ -5,6 +5,6 @@
import ComponentTwo from './ComponentTwo.html';
export default {
components: { RenamedComponentOne: ComponentOne, RenamedComponentTwo: ComponentTwo }
components: { RenamedComponentOne: ComponentOne, RenamedComponentTwo: ComponentTwo },
};
</script>