Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-starfishes-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: avoid hoisting error by using 'let' instead of 'var'
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
var events = [];

for (key in next) {
var value = next[key];
// let instead of var because referenced in a closure
let value = next[key];
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
if (value === prev?.[key]) continue;

var prefix = key[0] + key[1]; // this is faster than key.slice(0, 2)
if (prefix === '$$') continue;

if (prefix === 'on') {
/** @type {{ capture?: true }} */
var opts = {};
var event_name = key.slice(2);
const opts = {};
let event_name = key.slice(2);
var delegated = DelegatedEvents.includes(event_name);

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -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">');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang="ts">
const props = {};
let changed = $state(false);
</script>

{changed}
<input {...props} oninput={() => (changed = true)} class="hello" />