diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 037880eff5..66552900c9 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -792,7 +792,7 @@ export default class Component { current_group = { kind: node.kind, declarators: [declarator], insert }; coalesced_declarations.push(current_group); } else if (insert) { - current_group.insert = insert + current_group.insert = insert; current_group.declarators.push(declarator); } else { current_group.declarators.push(declarator); @@ -841,8 +841,9 @@ export default class Component { }); coalesced_declarations.forEach(group => { - let c = 0; + const writable = group.kind === 'var' || group.kind === 'let'; + let c = 0; let combining = false; group.declarators.forEach(declarator => { @@ -851,7 +852,7 @@ export default class Component { if (combining) { code.overwrite(c, id.start, ', '); } else { - code.appendLeft(id.start, '{ '); + if (writable) code.appendLeft(id.start, '{ '); combining = true; } @@ -863,7 +864,7 @@ export default class Component { ? `; ${group.insert}` : ''; - const suffix = code.original[c] === ';' ? ` } = $$props${insert}` : ` } = $$props${insert};`; + const suffix = `${writable ? ` } = $$props` : ``}${insert}` + (code.original[c] === ';' ? `` : `;`); code.appendLeft(c, suffix); } }); diff --git a/test/runtime/samples/prop-const/Nested.svelte b/test/runtime/samples/prop-const/Nested.svelte new file mode 100644 index 0000000000..0e4dca42f5 --- /dev/null +++ b/test/runtime/samples/prop-const/Nested.svelte @@ -0,0 +1,7 @@ + + +

a: {a}

+

b: {b}

\ No newline at end of file diff --git a/test/runtime/samples/prop-const/_config.js b/test/runtime/samples/prop-const/_config.js new file mode 100644 index 0000000000..489a48476f --- /dev/null +++ b/test/runtime/samples/prop-const/_config.js @@ -0,0 +1,23 @@ +export default { + props: { + a: 3, + b: 4 + }, + + html: ` +

a: 3

+

b: 2

+ `, + + async test({ assert, component, target }) { + await component.$set({ + a: 5, + b: 6 + }); + + assert.htmlEqual(target.innerHTML, ` +

a: 5

+

b: 2

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/prop-const/main.svelte b/test/runtime/samples/prop-const/main.svelte new file mode 100644 index 0000000000..41d9075526 --- /dev/null +++ b/test/runtime/samples/prop-const/main.svelte @@ -0,0 +1,8 @@ + + + \ No newline at end of file