remove the component references in the export that we will be referring to directly

pull/390/head
Conduitry 8 years ago
parent 77321f8356
commit 25a26613b3

@ -18,6 +18,8 @@ class DomGenerator extends Generator {
// Svelte's builtin `import { get, ... } from 'svelte/shared.js'`; // Svelte's builtin `import { get, ... } from 'svelte/shared.js'`;
this.importedNames = {}; this.importedNames = {};
this.aliases = {}; this.aliases = {};
this.importedComponents = {};
} }
addElement ( name, renderStatement, needsIdentifier = false ) { addElement ( name, renderStatement, needsIdentifier = false ) {
@ -193,14 +195,25 @@ export default function dom ( parsed, source, options, names ) {
} }
if ( templateProperties.components ) { if ( templateProperties.components ) {
generator.importedComponents = {}; let hasNonImportedComponent = false;
templateProperties.components.value.properties.forEach( property => { templateProperties.components.value.properties.forEach( property => {
const key = property.key.name; const key = property.key.name;
const value = source.slice( property.value.start, property.value.end ); const value = source.slice( property.value.start, property.value.end );
if ( generator.importedNames[ value ] ) { if ( generator.importedNames[ value ] ) {
generator.importedComponents[ key ] = 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({ generator.push({

Loading…
Cancel
Save