diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component/Component.js similarity index 97% rename from src/generators/dom/visitors/Component.js rename to src/generators/dom/visitors/Component/Component.js index d4c5a86dc6..577a78fa1a 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component/Component.js @@ -1,6 +1,6 @@ -import deindent from '../../../utils/deindent.js'; -import CodeBuilder from '../../../utils/CodeBuilder.js'; -import visit from '../visit.js'; +import deindent from '../../../../utils/deindent.js'; +import CodeBuilder from '../../../../utils/CodeBuilder.js'; +import visit from '../../visit.js'; import addComponentAttributes from './attributes/addComponentAttributes.js'; function capDown ( name ) { diff --git a/src/generators/dom/visitors/attributes/addComponentAttributes.js b/src/generators/dom/visitors/Component/attributes/addComponentAttributes.js similarity index 98% rename from src/generators/dom/visitors/attributes/addComponentAttributes.js rename to src/generators/dom/visitors/Component/attributes/addComponentAttributes.js index b659592d52..0bc983c2f7 100644 --- a/src/generators/dom/visitors/attributes/addComponentAttributes.js +++ b/src/generators/dom/visitors/Component/attributes/addComponentAttributes.js @@ -1,5 +1,5 @@ import addComponentBinding from './addComponentBinding.js'; -import deindent from '../../../../utils/deindent.js'; +import deindent from '../../../../../utils/deindent.js'; export default function addComponentAttributes ( generator, block, node, local ) { local.staticAttributes = []; diff --git a/src/generators/dom/visitors/attributes/addComponentBinding.js b/src/generators/dom/visitors/Component/attributes/addComponentBinding.js similarity index 90% rename from src/generators/dom/visitors/attributes/addComponentBinding.js rename to src/generators/dom/visitors/Component/attributes/addComponentBinding.js index 10482fee5c..f9a7e035d2 100644 --- a/src/generators/dom/visitors/attributes/addComponentBinding.js +++ b/src/generators/dom/visitors/Component/attributes/addComponentBinding.js @@ -1,6 +1,6 @@ -import deindent from '../../../../utils/deindent.js'; -import flattenReference from '../../../../utils/flattenReference.js'; -import getSetter from './binding/getSetter.js'; +import deindent from '../../../../../utils/deindent.js'; +import flattenReference from '../../../../../utils/flattenReference.js'; +import getSetter from '../../shared/binding/getSetter.js'; export default function addComponentBinding ( generator, node, attribute, block, local ) { const { name, keypath } = flattenReference( attribute.value ); diff --git a/src/generators/dom/visitors/Element.js b/src/generators/dom/visitors/Element/Element.js similarity index 65% rename from src/generators/dom/visitors/Element.js rename to src/generators/dom/visitors/Element/Element.js index 01e347ef59..8f49390730 100644 --- a/src/generators/dom/visitors/Element.js +++ b/src/generators/dom/visitors/Element/Element.js @@ -1,8 +1,7 @@ -import CodeBuilder from '../../../utils/CodeBuilder.js'; -import deindent from '../../../utils/deindent.js'; -import visit from '../visit.js'; +import deindent from '../../../../utils/deindent.js'; +import visit from '../../visit.js'; import addElementAttributes from './attributes/addElementAttributes.js'; -import visitComponent from './Component.js'; +import visitComponent from '../Component/Component.js'; import visitWindow from './meta/Window.js'; const meta = { @@ -26,15 +25,20 @@ export default function visitElement ( generator, block, state, node ) { namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : state.namespace }); - const local = { - allUsedContexts: [], + block.builders.create.addLine( `var ${name} = ${getRenderStatement( generator, childState.namespace, node.name )};` ); - create: new CodeBuilder(), - update: new CodeBuilder(), - destroy: new CodeBuilder() - }; + if ( !state.parentNode ) { + block.builders.detach.addLine( `${generator.helper( 'detachNode' )}( ${name} );` ); + } - const isToplevel = !state.parentNode; + // add CSS encapsulation attribute + if ( generator.cssId && state.isTopLevel ) { + block.builders.create.addLine( `${generator.helper( 'setAttribute' )}( ${name}, '${generator.cssId}', '' );` ); + } + + const local = { + allUsedContexts: [] + }; addElementAttributes( generator, block, childState, node, local ); @@ -57,47 +61,22 @@ export default function visitElement ( generator, block, state, node ) { return `${name}.__svelte.${listName} = ${listName};\n${name}.__svelte.${indexName} = ${indexName};`; }).join( '\n' ); - local.create.addBlock( deindent` + block.builders.create.addBlock( deindent` ${name}.__svelte = { ${initialProps} }; ` ); - local.update.addBlock( updates ); - } - - let render; - - if ( childState.namespace ) { - if ( childState.namespace === 'http://www.w3.org/2000/svg' ) { - render = `var ${name} = ${generator.helper( 'createSvgElement' )}( '${node.name}' )`; - } else { - render = `var ${name} = document.createElementNS( '${childState.namespace}', '${node.name}' );`; - } - } else { - render = `var ${name} = ${generator.helper( 'createElement' )}( '${node.name}' );`; - } - - if ( generator.cssId && state.isTopLevel ) { - render += `\n${generator.helper( 'setAttribute' )}( ${name}, '${generator.cssId}', '' );`; - } - - local.create.addLineAtStart( render ); - if ( isToplevel ) { - block.builders.detach.addLine( `${generator.helper( 'detachNode' )}( ${name} );` ); + block.builders.update.addBlock( updates ); } // special case – bound