Skip to content

Commit

Permalink
Merge branch 'master' into gh-7
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 25, 2017
2 parents 4fa7765 + 8e87c68 commit 9df2243
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Svelte changelog

## 1.18.1

* Allow `destroy()` in event handlers ([#523](https://github.com/sveltejs/svelte/issues/523))
* Fix bug with `{{yield}}` blocks following elements ([#524](https://github.com/sveltejs/svelte/issues/524))

## 1.18.0

* Visit `<select>` attributes after children, to ensure options are in the right state ([#521](https://github.com/sveltejs/svelte/pull/521))
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.18.0",
"version": "1.18.1",
"description": "The magical disappearing UI framework",
"main": "compiler/svelte.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/generators/dom/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function preprocessChildren ( generator, block, state, node, isTopLevel ) {

if ( lastChild ) {
lastChild.next = child;
lastChild.needsAnchor = !child._state.name;
lastChild.needsAnchor = !child._state || !child._state.name;
}

lastChild = child;
Expand Down
17 changes: 14 additions & 3 deletions src/validate/html/validateElement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import flattenReference from '../../utils/flattenReference.js';

const validBuiltins = new Set([
'set',
'fire',
'destroy'
]);

export default function validateElement ( validator, node ) {
const isComponent = node.name === ':Self' || validator.components.has( node.name );

Expand Down Expand Up @@ -56,10 +62,15 @@ export default function validateElement ( validator, node ) {
const { name } = flattenReference( callee );

if ( name === 'this' || name === 'event' ) return;
if ( callee.type === 'Identifier' && callee.name === 'set' || callee.name === 'fire' || validator.methods.has( callee.name ) ) return;
if ( callee.type === 'Identifier' && validBuiltins.has( callee.name ) || validator.methods.has( callee.name ) ) return;

const validCallees = [ 'this.*', 'event.*' ]
.concat(
Array.from( validBuiltins ),
Array.from( validator.methods.keys() )
);

const validCallees = list( [ 'this.*', 'event.*', 'set', 'fire' ].concat( Array.from( validator.methods.keys() ) ) );
let message = `'${validator.source.slice( callee.start, callee.end )}' is an invalid callee (should be one of ${validCallees})`;
let message = `'${validator.source.slice( callee.start, callee.end )}' is an invalid callee (should be one of ${list( validCallees )})`;

if ( callee.type === 'Identifier' && validator.helpers.has( callee.name ) ) {
message += `. '${callee.name}' exists on 'helpers', did you put it in the wrong place?`;
Expand Down
2 changes: 2 additions & 0 deletions test/runtime/samples/component-yield-follows-element/Foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div>before</div>
{{yield}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
html: `
<div>before</div>
test
`
};
11 changes: 11 additions & 0 deletions test/runtime/samples/component-yield-follows-element/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Foo>test</Foo>

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

export default {
components: {
Foo
}
};
</script>
20 changes: 20 additions & 0 deletions test/runtime/samples/event-handler-destroy/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
html: `
<button>destroy</button>
`,

test ( assert, component, target, window ) {
const button = target.querySelector( 'button' );
const event = new window.MouseEvent( 'click' );

let destroyed = false;
component.on( 'destroy', () => {
destroyed = true;
});

button.dispatchEvent( event );
assert.htmlEqual( target.innerHTML, `` );

assert.ok( destroyed );
}
};
1 change: 1 addition & 0 deletions test/runtime/samples/event-handler-destroy/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button on:click='destroy()'>destroy</button>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[{
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire or bar). 'foo' exists on 'helpers', did you put it in the wrong place?",
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire, destroy or bar). 'foo' exists on 'helpers', did you put it in the wrong place?",
"pos": 18,
"loc": {
"line": 1,
Expand Down
2 changes: 1 addition & 1 deletion test/validator/samples/method-nonexistent/errors.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[{
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire or bar)",
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire, destroy or bar)",
"pos": 18,
"loc": {
"line": 1,
Expand Down

0 comments on commit 9df2243

Please sign in to comment.