I don't understand your point. it's working as it should, I mean, you're reassigning get_answer to another function... even with hoisting you're overriding it
Yeah, we're still overriding something — but it's the global function, not the per-instance one which is what should happen.
Granted, I believe this is a very low priority bug, but we should eventually get to it.
Plain javascript version to clarify what I mean:
// this is what we write
function component_init(props) {
function secret() {
return secret.value;
}
secret.value = props.value;
return secret;
}
// this is how svelte currently hoists functions
function secret() {
return secret.value;
}
function component_init_transformed(props) {
secret.value = props.value;
return secret;
}
const a = component_init(10);
const b = component_init(20);
const c = component_init_transformed(30);
const d = component_init_transformed(40);
console.log(a(), b(), c(), d()); // 10 20 40 40 instead of 10 20 30 40
It looks like this was fixed unless I'm misunderstanding.
It's now indeed not as aggressive, but when the value escapes our code through function calls it should still be deemed mutable: repl.
And in order to be compliant, getters also need to be considered unsafe, even though that's more of a fringe aspect.
Most helpful comment
I don't understand your point. it's working as it should, I mean, you're reassigning get_answer to another function... even with hoisting you're overriding it