From 92f19a0a7432a39192ee19158b0b97df2f4af229 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 4 Apr 2017 06:47:55 -0400 Subject: [PATCH] better prototype assignment --- src/generators/dom/index.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index 32b9ec793d..1aad7df481 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -393,18 +393,17 @@ export default function dom ( parsed, source, options ) { const sharedPath = options.shared === true ? 'svelte/shared.js' : options.shared; - if ( sharedPath ) { - const base = templateProperties.methods ? `{}, ${generator.alias( 'template' )}.methods` : `{}`; - builders.main.addBlock( `${name}.prototype = ${generator.helper( 'assign' )}( ${base}, ${generator.helper( 'proto' )} );` ); - } else { - if ( templateProperties.methods ) { - builders.main.addBlock( `${name}.prototype = ${generator.alias( 'template' )}.methods;` ); - } + const prototypeBase = `${name}.prototype` + ( templateProperties.methods ? `, ${generator.alias( 'template' )}.methods` : '' ); + const proto = sharedPath ? generator.helper( 'proto ' ) : deindent` + { + ${ + [ 'get', 'fire', 'observe', 'on', 'set', '_flush' ] + .map( n => `${n}: ${generator.helper( n )}` ) + .join( ',\n' ) + } + }`; - [ 'get', 'fire', 'observe', 'on', 'set', '_flush' ].forEach( methodName => { - builders.main.addLine( `${name}.prototype.${methodName} = ${generator.helper( methodName )};` ); - }); - } + builders.main.addBlock( `${generator.helper( 'assign' )}( ${prototypeBase}, ${proto});` ); // TODO deprecate component.teardown() builders.main.addBlock( deindent`