From 25a26613b3f11e244b18c26e8f6789d9bfd3a592 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 18 Mar 2017 17:39:30 -0400 Subject: [PATCH] remove the component references in the export that we will be referring to directly --- src/generators/dom/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index 0a4036c355..91c1085082 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -18,6 +18,8 @@ class DomGenerator extends Generator { // Svelte's builtin `import { get, ... } from 'svelte/shared.js'`; this.importedNames = {}; this.aliases = {}; + + this.importedComponents = {}; } addElement ( name, renderStatement, needsIdentifier = false ) { @@ -193,14 +195,25 @@ export default function dom ( parsed, source, options, names ) { } if ( templateProperties.components ) { - generator.importedComponents = {}; + let hasNonImportedComponent = false; templateProperties.components.value.properties.forEach( property => { const key = property.key.name; const value = source.slice( property.value.start, property.value.end ); if ( generator.importedNames[ value ] ) { generator.importedComponents[ key ] = value; + } else { + hasNonImportedComponent = true; } }); + if ( hasNonImportedComponent ) { + // remove the specific components which were imported, as we'll refer to them directly + Object.keys( generator.importedComponents ).forEach ( key => { + removeObjectKey( generator.code, templateProperties.components.value, key ); + }); + } else { + // remove the entire components portion of the export + removeObjectKey( generator.code, defaultExport.declaration, 'components' ); + } } generator.push({