diff --git a/src/compile/Component.ts b/src/compile/Component.ts index f7c1c7dc5d..51746fb067 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -834,8 +834,8 @@ export default class Component { current_group.declarators.push(declarator); } - if (variable.name !== variable.export_name) { - code.prependRight(declarator.id.start, `${variable.export_name}:`) + if (variable.writable && variable.name !== variable.export_name) { + code.prependRight(declarator.id.start, `${variable.export_name}: `) } if (next) { diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 5b37ac031c..6678b21872 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -114,7 +114,7 @@ export default function dom( if (component.component_options.accessors) { body.push(deindent` set ${x.export_name}(${x.name}) { - this.$set({ ${x.name} }); + this.$set({ ${x.name === x.export_name ? x.name : `${x.export_name}: ${x.name}`} }); @flush(); } `); diff --git a/test/runtime/samples/renamed-instance-exports/_config.js b/test/runtime/samples/renamed-instance-exports/_config.js new file mode 100644 index 0000000000..965df3b4f3 --- /dev/null +++ b/test/runtime/samples/renamed-instance-exports/_config.js @@ -0,0 +1,10 @@ +export default { + test({ assert, component }) { + assert.equal(component.bar1, 42); + assert.equal(component.bar2, 42); + component.bar1 = 100; + component.bar2 = 100; + assert.equal(component.bar1, 42); + assert.equal(component.bar2, 100); + } +}; diff --git a/test/runtime/samples/renamed-instance-exports/main.svelte b/test/runtime/samples/renamed-instance-exports/main.svelte new file mode 100644 index 0000000000..7c991f56c4 --- /dev/null +++ b/test/runtime/samples/renamed-instance-exports/main.svelte @@ -0,0 +1,5 @@ +