forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix mutation to imported variable (sveltejs#4713)
- Loading branch information
1 parent
b7b801e
commit 49a0152
Showing
8 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
html: `<p>prop value</p>` | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const obj = { | ||
prop: 'prop value' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
import { obj } from './data.js'; | ||
$: prop = obj.prop; | ||
obj.foo = 'a different prop'; | ||
</script> | ||
|
||
<p>{prop}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const numbers = [1, 2, 3, 4]; |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/reactive-import-statement/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |