fix: support dynamic attributes containing call expressions (#9443)

Fixes #9403. We weren't taking into account the containment of call expressions logic before.
pull/9446/head
Dominic Gannaway 1 year ago committed by GitHub
parent a6fdc47a0b
commit da37c928ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure dynamic attributes containing call expressions update

@ -762,7 +762,7 @@ const common_visitors = {
return false;
}
return chunk.metadata.dynamic;
return chunk.metadata.dynamic || chunk.metadata.contains_call_expression;
});
if (is_event_attribute(node)) {

@ -0,0 +1,17 @@
import { test } from '../../test';
import { flushSync } from 'svelte';
export default test({
html: `<div style="background-color: red">Hello world</div><button>Make blue</button`,
async test({ assert, target, component }) {
const [b1] = target.querySelectorAll('button');
flushSync(() => {
b1.click();
});
assert.htmlEqual(
target.innerHTML,
`<div style="background-color: blue">Hello world</div><button>Make blue</button`
);
}
});

@ -0,0 +1,9 @@
<script>
let color = $state('red');
const getColor = () => color;
</script>
<div style="background-color: {getColor()}">Hello world</div>
<button onclick={() => color = 'blue'}>Make blue</button>
Loading…
Cancel
Save