0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

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

This commit is contained in:
Conduitry 2017-03-18 17:39:30 -04:00
parent 77321f8356
commit 25a26613b3

View File

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