mirror of https://github.com/sveltejs/svelte
parent
14d7b26897
commit
1538264bd5
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't hoist function when already referenced in module scope
|
@ -1,18 +1,25 @@
|
|||||||
import { test } from '../../test';
|
import { test } from '../../test';
|
||||||
|
|
||||||
// Checks that event handlers are not hoisted when one of them is not delegateable
|
|
||||||
export default test({
|
export default test({
|
||||||
html: `<button>0</button>`,
|
html: `<button>0</button><button>x0</button><button>y0</button>`,
|
||||||
|
|
||||||
async test({ assert, target }) {
|
async test({ assert, target }) {
|
||||||
const [button] = target.querySelectorAll('button');
|
const [btn1, btn2, btn3] = target.querySelectorAll('button');
|
||||||
|
|
||||||
button.click();
|
btn1.click();
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
assert.htmlEqual(target.innerHTML, '<button>1</button>');
|
assert.htmlEqual(target.innerHTML, '<button>1</button><button>x0</button><button>y0</button>');
|
||||||
|
|
||||||
button.dispatchEvent(new MouseEvent('mouseenter'));
|
btn1.dispatchEvent(new MouseEvent('mouseenter'));
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
assert.htmlEqual(target.innerHTML, '<button>2</button>');
|
assert.htmlEqual(target.innerHTML, '<button>2</button><button>x0</button><button>y0</button>');
|
||||||
|
|
||||||
|
btn2.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>2</button><button>x1</button><button>y0</button>');
|
||||||
|
|
||||||
|
btn3.click();
|
||||||
|
await Promise.resolve();
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>2</button><button>x1</button><button>y1</button>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,36 @@
|
|||||||
|
<script context="module">
|
||||||
|
function declared_in_module_scope() {
|
||||||
|
return 'x';
|
||||||
|
}
|
||||||
|
let a = declared_in_module_scope();
|
||||||
|
|
||||||
|
let b = 'x';
|
||||||
|
try {
|
||||||
|
b = doesnt_exist();
|
||||||
|
} catch (e) {
|
||||||
|
b = 'y';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let count = $state(0)
|
let count1 = $state(0);
|
||||||
|
let count2 = $state(0);
|
||||||
|
let count3 = $state(0);
|
||||||
|
|
||||||
function increment() {
|
function increment() {
|
||||||
count += 1
|
count1 += 1;
|
||||||
|
}
|
||||||
|
function declared_in_module_scope() {
|
||||||
|
count2 += 1;
|
||||||
|
}
|
||||||
|
function doesnt_exist() {
|
||||||
|
count3 += 1;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button onclick={increment} onmouseenter={increment}>
|
<!-- Checks that event handlers are not hoisted when one of them is not delegateable -->
|
||||||
{count}
|
<button onclick={increment} onmouseenter={increment}>{count1}</button>
|
||||||
</button>
|
|
||||||
|
<!-- Checks that event handler is not hoisted if the same name is used in the module context -->
|
||||||
|
<button onclick={declared_in_module_scope}>{a}{count2}</button>
|
||||||
|
<button onclick={doesnt_exist}>{b}{count3}</button>
|
||||||
|
Loading…
Reference in new issue