Skip to content

Commit 8feb865

Browse files
authored
fix: use init properties when exporting non-state values (#10521)
1 parent a279e80 commit 8feb865

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

.changeset/empty-bags-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: use init properties when exporting non-state values in prod

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ export function client_component(source, analysis, options) {
242242
const binding = analysis.instance.scope.get(name);
243243
const is_source = binding !== null && is_state_source(binding, state);
244244

245-
// TODO This is always a getter because the `renamed-instance-exports` test wants it that way.
246-
// Should we for code size reasons make it an init in runes mode and/or non-dev mode?
247-
return b.get(alias ?? name, [b.return(is_source ? b.call('$.get', b.id(name)) : b.id(name))]);
245+
if (is_source || options.dev) {
246+
return b.get(alias ?? name, [b.return(is_source ? b.call('$.get', b.id(name)) : b.id(name))]);
247+
}
248+
249+
return b.init(alias ?? name, b.id(name));
248250
});
249251

250252
if (analysis.accessors) {

packages/svelte/tests/runtime-legacy/samples/prop-accessors/_config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { test } from '../../test';
22

33
export default test({
4+
compileOptions: {
5+
dev: true
6+
},
7+
48
accessors: false,
9+
510
test({ assert, component }) {
611
assert.equal(component.foo1, 42);
712
assert.equal(component.foo2(), 42);

packages/svelte/tests/runtime-legacy/samples/renamed-instance-exports/_config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { test } from '../../test';
22

33
export default test({
4+
compileOptions: {
5+
dev: true
6+
},
7+
48
test({ assert, component }) {
59
assert.equal(component.bar1, 42);
610
assert.equal(component.bar2, 42);

0 commit comments

Comments
 (0)