diff --git a/compiler/generate/index.js b/compiler/generate/index.js index 3bfca90e0a..c611c4c8c9 100644 --- a/compiler/generate/index.js +++ b/compiler/generate/index.js @@ -1,332 +1,274 @@ import { getLocator } from 'locate-character'; import deindent from './utils/deindent.js'; import walkHtml from './utils/walkHtml.js'; +import flattenReference from './utils/flattenReference.js'; -const ROOT = 'options.target'; +function createRenderer ( fragment ) { + return deindent` + function ${fragment.name} ( target${fragment.useAnchor ? ', anchor' : ''} ) { + ${fragment.initStatements.join( '\n\n' )} + + return { + update: function ( ${fragment.contextChain.join( ', ' )} ) { + ${fragment.updateStatements.join( '\n\n' )} + }, + + teardown: function () { + ${fragment.teardownStatements.join( '\n\n' )} + } + } + } + `; +} export default function generate ( parsed, template ) { + const locator = getLocator( template ); + const renderers = []; + const counters = { - fragment: 0, - element: 0, - text: 0, - anchor: 0, if: 0, - each: 0, - loop: 0 + each: 0 }; - const initStatements = []; - const setStatements = [ deindent` - const oldState = state; - state = Object.assign( {}, oldState, newState ); - ` ]; - const teardownStatements = []; - // TODO add contents of