mirror of https://github.com/sveltejs/svelte
fix mutation to imported variable (#4713)
parent
676d57b5f7
commit
aabb23cc34
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: `<p>prop value</p>`
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
export const obj = {
|
||||
prop: 'prop value'
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import { obj } from './data.js';
|
||||
|
||||
$: prop = obj.prop;
|
||||
obj.foo = 'a different prop';
|
||||
</script>
|
||||
|
||||
<p>{prop}</p>
|
@ -0,0 +1,38 @@
|
||||
import * as path from 'path';
|
||||
|
||||
export default {
|
||||
html: `
|
||||
import
|
||||
<p>1 + 2 + 3 + 4 = 10</p>
|
||||
local
|
||||
<p>1 + 2 + 3 + 4 = 10</p>
|
||||
<button>Add a number</button>
|
||||
`,
|
||||
before_test() {
|
||||
delete require.cache[path.resolve(__dirname, 'data.js')];
|
||||
},
|
||||
async test({ assert, target, window, }) {
|
||||
const btn = target.querySelector('button');
|
||||
const clickEvent = new window.MouseEvent('click');
|
||||
|
||||
await btn.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
import
|
||||
<p>1 + 2 + 3 + 4 + 5 = 15</p>
|
||||
local
|
||||
<p>1 + 2 + 3 + 4 + 5 = 15</p>
|
||||
<button>Add a number</button>
|
||||
`);
|
||||
|
||||
await btn.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
import
|
||||
<p>1 + 2 + 3 + 4 + 5 + 6 = 21</p>
|
||||
local
|
||||
<p>1 + 2 + 3 + 4 + 5 + 6 = 21</p>
|
||||
<button>Add a number</button>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1 @@
|
||||
export const numbers = [1, 2, 3, 4];
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { numbers } from './data.js';
|
||||
const local_numbers = [1, 2, 3, 4];
|
||||
|
||||
function addNumber() {
|
||||
numbers[numbers.length] = numbers.length + 1;
|
||||
local_numbers[local_numbers.length] = local_numbers.length + 1;
|
||||
}
|
||||
|
||||
$: sum = numbers.reduce((t, n) => t + n, 0);
|
||||
$: local_sum = local_numbers.reduce((t, n) => t + n, 0);
|
||||
</script>
|
||||
|
||||
import <p>{numbers.join(' + ')} = {sum}</p>
|
||||
local <p>{local_numbers.join(' + ')} = {local_sum}</p>
|
||||
|
||||
<button on:click={addNumber}>
|
||||
Add a number
|
||||
</button>
|
Loading…
Reference in new issue