Skip to content

Commit 9df2243

Browse files
committed
Merge branch 'master' into gh-7
2 parents 4fa7765 + 8e87c68 commit 9df2243

File tree

11 files changed

+63
-7
lines changed

11 files changed

+63
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Svelte changelog
22

3+
## 1.18.1
4+
5+
* Allow `destroy()` in event handlers ([#523](https://github.com/sveltejs/svelte/issues/523))
6+
* Fix bug with `{{yield}}` blocks following elements ([#524](https://github.com/sveltejs/svelte/issues/524))
7+
38
## 1.18.0
49

510
* Visit `<select>` attributes after children, to ensure options are in the right state ([#521](https://github.com/sveltejs/svelte/pull/521))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte",
3-
"version": "1.18.0",
3+
"version": "1.18.1",
44
"description": "The magical disappearing UI framework",
55
"main": "compiler/svelte.js",
66
"files": [

src/generators/dom/preprocess.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function preprocessChildren ( generator, block, state, node, isTopLevel ) {
264264

265265
if ( lastChild ) {
266266
lastChild.next = child;
267-
lastChild.needsAnchor = !child._state.name;
267+
lastChild.needsAnchor = !child._state || !child._state.name;
268268
}
269269

270270
lastChild = child;

src/validate/html/validateElement.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import flattenReference from '../../utils/flattenReference.js';
22

3+
const validBuiltins = new Set([
4+
'set',
5+
'fire',
6+
'destroy'
7+
]);
8+
39
export default function validateElement ( validator, node ) {
410
const isComponent = node.name === ':Self' || validator.components.has( node.name );
511

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

5864
if ( name === 'this' || name === 'event' ) return;
59-
if ( callee.type === 'Identifier' && callee.name === 'set' || callee.name === 'fire' || validator.methods.has( callee.name ) ) return;
65+
if ( callee.type === 'Identifier' && validBuiltins.has( callee.name ) || validator.methods.has( callee.name ) ) return;
66+
67+
const validCallees = [ 'this.*', 'event.*' ]
68+
.concat(
69+
Array.from( validBuiltins ),
70+
Array.from( validator.methods.keys() )
71+
);
6072

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

6475
if ( callee.type === 'Identifier' && validator.helpers.has( callee.name ) ) {
6576
message += `. '${callee.name}' exists on 'helpers', did you put it in the wrong place?`;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<div>before</div>
2+
{{yield}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
html: `
3+
<div>before</div>
4+
test
5+
`
6+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Foo>test</Foo>
2+
3+
<script>
4+
import Foo from './Foo.html';
5+
6+
export default {
7+
components: {
8+
Foo
9+
}
10+
};
11+
</script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
html: `
3+
<button>destroy</button>
4+
`,
5+
6+
test ( assert, component, target, window ) {
7+
const button = target.querySelector( 'button' );
8+
const event = new window.MouseEvent( 'click' );
9+
10+
let destroyed = false;
11+
component.on( 'destroy', () => {
12+
destroyed = true;
13+
});
14+
15+
button.dispatchEvent( event );
16+
assert.htmlEqual( target.innerHTML, `` );
17+
18+
assert.ok( destroyed );
19+
}
20+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button on:click='destroy()'>destroy</button>

test/validator/samples/method-nonexistent-helper/errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[{
2-
"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?",
2+
"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?",
33
"pos": 18,
44
"loc": {
55
"line": 1,

test/validator/samples/method-nonexistent/errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[{
2-
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire or bar)",
2+
"message": "'foo' is an invalid callee (should be one of this.*, event.*, set, fire, destroy or bar)",
33
"pos": 18,
44
"loc": {
55
"line": 1,

0 commit comments

Comments
 (0)