Skip to content

Commit

Permalink
Merge branch 'master' into gh-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Apr 25, 2017
2 parents a0284a4 + 09b1635 commit 11cf3f9
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 25 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Svelte changelog

## 1.17.2

* Replace bad characters when creating variable names based on element names ([#516](https://github.com/sveltejs/svelte/issues/516))

## 1.17.1

* Fixes for static each-else and yield blocks ([#509](https://github.com/sveltejs/svelte/issues/509)), ([#514](https://github.com/sveltejs/svelte/issues/514))
* Code generation tweaks ([#504](https://github.com/sveltejs/svelte/issues/504)), ([#507](https://github.com/sveltejs/svelte/issues/507))

## 1.17.0

* Add `currentTime`, `duration` and `paused` bindings for media elements ([#406](https://github.com/sveltejs/svelte/issues/406))
Expand Down Expand Up @@ -43,7 +52,7 @@
* Add `bind:online` to window ([#404](https://github.com/sveltejs/svelte/issues/404))
* In dev mode, throw if read-only properties are set ([#404](https://github.com/sveltejs/svelte/issues/404))
* Prevent conflicts with component name ([#464](https://github.com/sveltejs/svelte/pull/464))
* Ensure event handler names are deconflicted ([#466https://github.com/sveltejs/svelte/issues/466
* Ensure event handler names are deconflicted ([#466](https://github.com/sveltejs/svelte/issues/466))

## 1.13.7

Expand Down Expand Up @@ -279,7 +288,7 @@

## 1.2.4

* SSR compiler: Implement `{{{tripes}}}` ([#197](https://github.com/sveltejs/svelte/issues/197))
* SSR compiler: Implement `{{{triples}}}` ([#197](https://github.com/sveltejs/svelte/issues/197))
* SSR compiler: Escape HTML in tags ([#197](https://github.com/sveltejs/svelte/issues/197))

## 1.2.3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte",
"version": "1.17.0",
"version": "1.17.2",
"description": "The magical disappearing UI framework",
"main": "compiler/svelte.js",
"files": [
Expand Down
10 changes: 6 additions & 4 deletions src/generators/dom/visitors/Component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ export default function visitComponent ( generator, block, state, node ) {
`var ${yieldFragment} = ${childBlock.name}( ${params}, ${block.component} );`
);

block.builders.update.addLine(
`${yieldFragment}.update( changed, ${params} );`
);
if ( childBlock.hasUpdateMethod ) {
block.builders.update.addLine(
`${yieldFragment}.update( changed, ${params} );`
);
}

componentInitProperties.push( `_yield: ${yieldFragment}`);
}
Expand Down Expand Up @@ -181,4 +183,4 @@ export default function visitComponent ( generator, block, state, node ) {

block.builders.create.addBlock( local.create );
if ( !local.update.isEmpty() ) block.builders.update.addBlock( local.update );
}
}
34 changes: 16 additions & 18 deletions src/generators/dom/visitors/Element/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,19 @@ export default function visitElement ( generator, block, state, node ) {
block.builders.create.addLine( `${generator.helper( 'setAttribute' )}( ${name}, '${generator.cssId}', '' );` );
}

let selectValueAttribute;

node.attributes
.sort( ( a, b ) => order[ a.type ] - order[ b.type ] )
.forEach( attribute => {
// <select> value attributes are an annoying special case — it must be handled
// *after* its children have been updated
if ( ( attribute.type === 'Attribute' || attribute.type === 'Binding' ) && attribute.name === 'value' && node.name === 'select' ) {
selectValueAttribute = attribute;
return;
}

visitors[ attribute.type ]( generator, block, childState, node, attribute );
});
function visitAttributes () {
node.attributes
.sort( ( a, b ) => order[ a.type ] - order[ b.type ] )
.forEach( attribute => {
visitors[ attribute.type ]( generator, block, childState, node, attribute );
});
}

if ( node.name !== 'select' ) {
// <select> value attributes are an annoying special case — it must be handled
// *after* its children have been updated
visitAttributes();
}

// special case – bound <option> without a value attribute
if ( node.name === 'option' && !node.attributes.find( attribute => attribute.type === 'Attribute' && attribute.name === 'value' ) ) { // TODO check it's bound
Expand Down Expand Up @@ -109,9 +108,8 @@ export default function visitElement ( generator, block, state, node ) {
block.builders.update.addLine( node.lateUpdate );
}

if ( selectValueAttribute ) {
const visitor = selectValueAttribute.type === 'Attribute' ? visitAttribute : visitBinding;
visitor( generator, block, childState, node, selectValueAttribute );
if ( node.name === 'select' ) {
visitAttributes();
}

if ( node.initialUpdate ) {
Expand All @@ -129,4 +127,4 @@ function getRenderStatement ( generator, namespace, name ) {
}

return `${generator.helper( 'createElement' )}( '${name}' )`;
}
}
1 change: 1 addition & 0 deletions test/runtime/samples/component-yield-static/Widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<b>{{yield}}</b>
12 changes: 12 additions & 0 deletions test/runtime/samples/component-yield-static/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
html: `
<b>Hello</b>
`,

test ( assert, component, target ) {
component.set( { name: 'World' } );
assert.htmlEqual( target.innerHTML, `
<b>Hello</b> World
` );
}
};
12 changes: 12 additions & 0 deletions test/runtime/samples/component-yield-static/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Widget>Hello</Widget> {{name}}

<script>
import Widget from './Widget.html';

export default {
components: { Widget },
data() {
return { name: '' };
}
};
</script>
5 changes: 5 additions & 0 deletions test/runtime/samples/element-invalid-name/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
html: `
<foo-bar>Hello</foo-bar>
`
}
1 change: 1 addition & 0 deletions test/runtime/samples/element-invalid-name/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<foo-bar>Hello</foo-bar>
24 changes: 24 additions & 0 deletions test/runtime/samples/select-change-handler/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
skip: true, // JSDOM

data: {
options: [ { id: 'a' }, { id: 'b' }, { id: 'c' } ],
selected: 'b'
},

test ( assert, component, target, window ) {
const select = target.querySelector( 'select' );
assert.equal( select.value, 'b' );

const event = new window.Event( 'change' );

select.value = 'c';
select.dispatchEvent( event );

assert.equal( select.value, 'c' );
assert.equal( component.get( 'lastChangedTo' ), 'c' );
assert.equal( component.get( 'selected' ), 'c' );

component.destroy();
}
};
15 changes: 15 additions & 0 deletions test/runtime/samples/select-change-handler/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<select bind:value="selected" on:change="updateLastChangedTo(selected)">
{{#each options as option}}
<option value="{{option.id}}">{{option.id}}</option>
{{/each}}
</select>

<script>
export default {
methods: {
updateLastChangedTo(result) {
this.set({ lastChangedTo: result });
}
}
};
</script>

0 comments on commit 11cf3f9

Please sign in to comment.