mirror of https://github.com/sveltejs/svelte
fix hoisting of functions that reference imported values - fixes #1933
parent
cc9a172d7c
commit
d6552025e4
@ -0,0 +1,56 @@
|
||||
export default {
|
||||
props: {
|
||||
things: [
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 2, name: 'b' },
|
||||
{ id: 3, name: 'c' },
|
||||
{ id: 4, name: 'd' },
|
||||
{ id: 5, name: 'e' }
|
||||
]
|
||||
},
|
||||
|
||||
html: `
|
||||
<div>a</div>
|
||||
<div>b</div>
|
||||
<div>c</div>
|
||||
<div>d</div>
|
||||
<div>e</div>
|
||||
`,
|
||||
|
||||
test({ assert, component, target, window, raf }) {
|
||||
let divs = document.querySelectorAll('div');
|
||||
divs.forEach(div => {
|
||||
div.getBoundingClientRect = function() {
|
||||
const index = [...this.parentNode.children].indexOf(this);
|
||||
const top = index * 30;
|
||||
|
||||
return {
|
||||
left: 0,
|
||||
right: 100,
|
||||
top,
|
||||
bottom: top + 20
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
component.things = [
|
||||
{ id: 5, name: 'e' },
|
||||
{ id: 2, name: 'b' },
|
||||
{ id: 3, name: 'c' },
|
||||
{ id: 4, name: 'd' },
|
||||
{ id: 1, name: 'a' }
|
||||
];
|
||||
|
||||
divs = document.querySelectorAll('div');
|
||||
assert.equal(divs[0].dy, 120);
|
||||
assert.equal(divs[4].dy, -120);
|
||||
|
||||
raf.tick(50);
|
||||
assert.equal(divs[0].dy, 60);
|
||||
assert.equal(divs[4].dy, -60);
|
||||
|
||||
raf.tick(100);
|
||||
assert.equal(divs[0].dy, 0);
|
||||
assert.equal(divs[4].dy, 0);
|
||||
}
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
export function linear(t) {
|
||||
return t;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
import { linear } from './easing.js';
|
||||
export let things;
|
||||
|
||||
function flip(node, animation, params) {
|
||||
const dx = animation.from.left - animation.to.left;
|
||||
const dy = animation.from.top - animation.to.top;
|
||||
|
||||
return {
|
||||
duration: 100,
|
||||
easing: linear,
|
||||
tick: (t, u) => {
|
||||
node.dx = u * dx;
|
||||
node.dy = u * dy;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
{#each things as thing (thing.id)}
|
||||
<div animate:flip>{thing.name}</div>
|
||||
{/each}
|
Loading…
Reference in new issue