mark reassigned/mutated values as non-hoistable - fixes #2731

pull/3451/head
Rich Harris 5 years ago
parent 64c56eddcd
commit d8445e6350

@ -1069,9 +1069,12 @@ export default class Component {
} else if (name[0] === '$' && !owner) {
hoistable = false;
} else if (owner === instance_scope) {
const variable = var_lookup.get(name);
if (variable.reassigned || variable.mutated) hoistable = false;
if (name === fn_declaration.id.name) return;
const variable = var_lookup.get(name);
if (variable.hoistable) return;
if (top_level_function_declarations.has(name)) {

@ -0,0 +1,9 @@
export default {
html: `1-2`,
async test({ assert, component, target }) {
await component.update();
assert.htmlEqual(target.innerHTML, `3-4`);
}
};

@ -0,0 +1,14 @@
<script>
let foo = () => 1;
function bar() {
return 2;
}
export function update() {
foo = () => 3;
bar = () => 4;
}
</script>
{foo()}-{bar()}
Loading…
Cancel
Save