Merge pull request #393 from sveltejs/removeobjectkey-fix

Fix removing last key in object when it has a trailing comma
pull/402/head
Rich Harris 8 years ago committed by GitHub
commit b5c971cba4

@ -206,7 +206,7 @@ export default function dom ( parsed, source, options, names ) {
}
});
if ( hasNonImportedComponent ) {
// remove the specific components which were imported, as we'll refer to them directly
// 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 );
});

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

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

Loading…
Cancel
Save