From 8cdd4dad8a4f9203107a261254150f77b00170ba Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 10 May 2017 08:01:26 -0400 Subject: [PATCH 1/3] downgrade invalid callee error for event handlers to a warning (#579) --- src/validate/html/validateEventHandler.js | 4 ++-- .../method-nonexistent-helper/{errors.json => warnings.json} | 0 .../samples/method-nonexistent/{errors.json => warnings.json} | 0 .../window-event-invalid/{errors.json => warnings.json} | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename test/validator/samples/method-nonexistent-helper/{errors.json => warnings.json} (100%) rename test/validator/samples/method-nonexistent/{errors.json => warnings.json} (100%) rename test/validator/samples/window-event-invalid/{errors.json => warnings.json} (100%) diff --git a/src/validate/html/validateEventHandler.js b/src/validate/html/validateEventHandler.js index 3c0f1f288d..634f8729da 100644 --- a/src/validate/html/validateEventHandler.js +++ b/src/validate/html/validateEventHandler.js @@ -31,5 +31,5 @@ export default function validateEventHandlerCallee ( validator, attribute ) { message += `. '${callee.name}' exists on 'helpers', did you put it in the wrong place?`; } - validator.error( message, start ); -} \ No newline at end of file + validator.warn( message, start ); +} diff --git a/test/validator/samples/method-nonexistent-helper/errors.json b/test/validator/samples/method-nonexistent-helper/warnings.json similarity index 100% rename from test/validator/samples/method-nonexistent-helper/errors.json rename to test/validator/samples/method-nonexistent-helper/warnings.json diff --git a/test/validator/samples/method-nonexistent/errors.json b/test/validator/samples/method-nonexistent/warnings.json similarity index 100% rename from test/validator/samples/method-nonexistent/errors.json rename to test/validator/samples/method-nonexistent/warnings.json diff --git a/test/validator/samples/window-event-invalid/errors.json b/test/validator/samples/window-event-invalid/warnings.json similarity index 100% rename from test/validator/samples/window-event-invalid/errors.json rename to test/validator/samples/window-event-invalid/warnings.json From 48832ecfa836aa82b85547d8707f4ff34d8a8d39 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 18 May 2017 22:04:41 -0400 Subject: [PATCH 2/3] fix special props on `` elements, don't try to add props until after the (delayed) visiting of the attributes, as that's when we determine what the props should be. --- .../dom/visitors/Element/Element.js | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/generators/dom/visitors/Element/Element.js b/src/generators/dom/visitors/Element/Element.js index bdf408732f..37a4e58004 100644 --- a/src/generators/dom/visitors/Element/Element.js +++ b/src/generators/dom/visitors/Element/Element.js @@ -46,7 +46,7 @@ export default function visitElement ( generator, block, state, node ) { block.builders.create.addLine( `${generator.helper( 'setAttribute' )}( ${name}, '${generator.cssId}', '' );` ); } - function visitAttributes () { + function visitAttributesAndAddProps () { let intro; let outro; @@ -63,6 +63,37 @@ export default function visitElement ( generator, block, state, node ) { }); if ( intro || outro ) addTransitions( generator, block, childState, node, intro, outro ); + + if ( childState.allUsedContexts.length || childState.usesComponent ) { + const initialProps = []; + const updates = []; + + if ( childState.usesComponent ) { + initialProps.push( `component: ${block.component}` ); + } + + childState.allUsedContexts.forEach( contextName => { + if ( contextName === 'state' ) return; + + const listName = block.listNames.get( contextName ); + const indexName = block.indexNames.get( contextName ); + + initialProps.push( `${listName}: ${listName},\n${indexName}: ${indexName}` ); + updates.push( `${name}._svelte.${listName} = ${listName};\n${name}._svelte.${indexName} = ${indexName};` ); + }); + + if ( initialProps.length ) { + block.builders.create.addBlock( deindent` + ${name}._svelte = { + ${initialProps.join( ',\n' )} + }; + ` ); + } + + if ( updates.length ) { + block.builders.update.addBlock( updates.join( '\n' ) ); + } + } } if ( !state.parentNode ) { @@ -74,7 +105,7 @@ export default function visitElement ( generator, block, state, node ) { if ( node.name !== 'select' ) { // + + + +{{/each}} + +