Merge pull request #2245 from sveltejs/gh-2236

prevent overwriting export consts
pull/2248/head
Rich Harris 6 years ago committed by GitHub
commit 81d33a2fb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -794,7 +794,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);
@ -843,8 +843,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 => {
@ -853,7 +854,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;
}
@ -865,7 +866,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);
}
});

@ -0,0 +1,7 @@
<script>
export let a;
export const b = 2;
</script>
<p>a: {a}</p>
<p>b: {b}</p>

@ -0,0 +1,23 @@
export default {
props: {
a: 3,
b: 4
},
html: `
<p>a: 3</p>
<p>b: 2</p>
`,
async test({ assert, component, target }) {
await component.$set({
a: 5,
b: 6
});
assert.htmlEqual(target.innerHTML, `
<p>a: 5</p>
<p>b: 2</p>
`);
}
};

@ -0,0 +1,8 @@
<script>
import Nested from './Nested.svelte';
export let a;
export let b;
</script>
<Nested a={a} b={b}/>
Loading…
Cancel
Save