fix: avoid hoisting error by using 'let' instead of 'var' (#11291)

Fixes #11284
pull/11292/head
Craig Jennings 7 months ago committed by GitHub
parent 05ac8f4322
commit fe6e4e2b05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: avoid hoisting error by using 'let' instead of 'var'

@ -111,7 +111,8 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
var events = []; var events = [];
for (key in next) { for (key in next) {
var value = next[key]; // let instead of var because referenced in a closure
let value = next[key];
if (value === prev?.[key]) continue; if (value === prev?.[key]) continue;
var prefix = key[0] + key[1]; // this is faster than key.slice(0, 2) var prefix = key[0] + key[1]; // this is faster than key.slice(0, 2)
@ -119,8 +120,8 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
if (prefix === 'on') { if (prefix === 'on') {
/** @type {{ capture?: true }} */ /** @type {{ capture?: true }} */
var opts = {}; const opts = {};
var event_name = key.slice(2); let event_name = key.slice(2);
var delegated = DelegatedEvents.includes(event_name); var delegated = DelegatedEvents.includes(event_name);
if ( if (

@ -0,0 +1,13 @@
import { test } from '../../test';
export default test({
async test({ assert, target }) {
const input = target.querySelector('input');
input?.dispatchEvent(new Event('input', { bubbles: true }));
await Promise.resolve();
assert.htmlEqual(target.innerHTML, 'true <input class="hello">');
}
});

@ -0,0 +1,7 @@
<script lang="ts">
const props = {};
let changed = $state(false);
</script>
{changed}
<input {...props} oninput={() => (changed = true)} class="hello" />
Loading…
Cancel
Save