From cede99d68bb27c8ede641f113a9cc877f17013c0 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 17 Mar 2017 23:22:40 -0400 Subject: [PATCH] use direct references to components that have been imported --- src/generators/dom/index.js | 11 +++++++++++ src/generators/dom/visitors/Component.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index 2872a948c1..e066a6c48e 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -191,6 +191,17 @@ export default function dom ( parsed, source, options, names ) { // TODO remove the namespace property from the generated code, it's unused past this point } + if ( templateProperties.components ) { + generator.importedComponents = {}; + 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; + } + }); + } + generator.push({ name: generator.alias( 'renderMainFragment' ), namespace, diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index 990b947f7c..7165a8a7c2 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -106,7 +106,7 @@ export default { componentInitProperties.push(`data: ${name}_initialData`); } - const expression = node.name === ':Self' ? generator.name : `template.components.${node.name}`; + const expression = node.name === ':Self' ? generator.name : generator.importedComponents[ node.name ] || `template.components.${node.name}`; local.init.addBlockAtStart( deindent` ${statements.join( '\n\n' )}