fix: use init properties when exporting non-state values (#10521)

pull/10535/head
Rich Harris 2 years ago committed by GitHub
parent a279e802d5
commit 8feb86583a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: use init properties when exporting non-state values in prod

@ -242,9 +242,11 @@ export function client_component(source, analysis, options) {
const binding = analysis.instance.scope.get(name);
const is_source = binding !== null && is_state_source(binding, state);
// TODO This is always a getter because the `renamed-instance-exports` test wants it that way.
// Should we for code size reasons make it an init in runes mode and/or non-dev mode?
return b.get(alias ?? name, [b.return(is_source ? b.call('$.get', b.id(name)) : b.id(name))]);
if (is_source || options.dev) {
return b.get(alias ?? name, [b.return(is_source ? b.call('$.get', b.id(name)) : b.id(name))]);
}
return b.init(alias ?? name, b.id(name));
});
if (analysis.accessors) {

@ -1,7 +1,12 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
accessors: false,
test({ assert, component }) {
assert.equal(component.foo1, 42);
assert.equal(component.foo2(), 42);

@ -1,6 +1,10 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
test({ assert, component }) {
assert.equal(component.bar1, 42);
assert.equal(component.bar2, 42);

Loading…
Cancel
Save