Merge branch 'master' into gh-7

pull/525/head
Rich-Harris 9 years ago
commit 9df2243784

@ -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))

@ -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": [

@ -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;

@ -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 );
@ -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?`;

@ -0,0 +1,6 @@
export default {
html: `
<div>before</div>
test
`
};

@ -0,0 +1,11 @@
<Foo>test</Foo>
<script>
import Foo from './Foo.html';
export default {
components: {
Foo
}
};
</script>

@ -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 );
}
};

@ -0,0 +1 @@
<button on:click='destroy()'>destroy</button>

@ -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,

@ -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,

Loading…
Cancel
Save