Skip to content

Svelte 5: Static class fields are transformed incorrectly #9547

@brunnerh

Description

@brunnerh

Describe the bug

Static fields get converted into instance field/accessors.

Reproduction

<script>
	class Test {
		static value = $state(0)
	}
</script>
<input bind:value={Test.value} /> {Test.value}

REPL

Output:

class Test {
	#value = $.source(0);

	get value() {
		return $.get(this.#value);
	}

	set value(value) {
		$.set(this.#value, value);
	}
}

Correct output would probably be:

class Test {
    static #value = $.source(0);
    static get value() { return $.get(Test.#value); }
    static set value(value) { $.set(Test.#value, value); }
}

Logs

No response

System Info

REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions