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({