From e3055d765e0c0aa10d36dfec2b53d2f62b471130 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 19 Mar 2017 04:00:02 -0400 Subject: [PATCH] fix removeObjectKey when removing last key in object and it has a trailing comma --- src/generators/dom/index.js | 4 ++-- src/utils/removeObjectKey.js | 2 +- test/generator/samples/imported-renamed-components/main.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index ebf478f5a2..c0541b8959 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -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 { diff --git a/src/utils/removeObjectKey.js b/src/utils/removeObjectKey.js index cbd75eb1f5..a78a5b6ab2 100644 --- a/src/utils/removeObjectKey.js +++ b/src/utils/removeObjectKey.js @@ -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 ); } diff --git a/test/generator/samples/imported-renamed-components/main.html b/test/generator/samples/imported-renamed-components/main.html index 7c25eaceab..a976830378 100644 --- a/test/generator/samples/imported-renamed-components/main.html +++ b/test/generator/samples/imported-renamed-components/main.html @@ -5,6 +5,6 @@ import ComponentTwo from './ComponentTwo.html'; export default { - components: { RenamedComponentOne: ComponentOne, RenamedComponentTwo: ComponentTwo } + components: { RenamedComponentOne: ComponentOne, RenamedComponentTwo: ComponentTwo }, };