mirror of https://github.com/sveltejs/svelte
feat: function called as tagged template literal is reactively called (#12692)
* feat: function called as tagged template literal is reactively called Co-authored-by: Oscar Dominguez <dominguez.celada@gmail.com> * chore: re-organize import of visitors * simplify --------- Co-authored-by: Oscar Dominguez <dominguez.celada@gmail.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/12707/head
parent
e4e66e237f
commit
3286617e3c
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
feat: function called as tagged template literal is reactively called
|
@ -0,0 +1,23 @@
|
||||
/** @import { TaggedTemplateExpression, VariableDeclarator } from 'estree' */
|
||||
/** @import { Context } from '../types' */
|
||||
import { is_known_safe_call } from './shared/utils.js';
|
||||
|
||||
/**
|
||||
* @param {TaggedTemplateExpression} node
|
||||
* @param {Context} context
|
||||
*/
|
||||
export function TaggedTemplateExpression(node, context) {
|
||||
if (context.state.expression && !is_known_safe_call(node.tag, context)) {
|
||||
context.state.expression.has_call = true;
|
||||
context.state.expression.has_state = true;
|
||||
}
|
||||
|
||||
if (node.tag.type === 'Identifier') {
|
||||
const binding = context.state.scope.get(node.tag.name);
|
||||
|
||||
if (binding !== null) {
|
||||
binding.is_called = true;
|
||||
}
|
||||
}
|
||||
context.next();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client'],
|
||||
async test({ assert, target, ok }) {
|
||||
const button = target.querySelector('button');
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `0 <button></button>`);
|
||||
|
||||
flushSync(() => {
|
||||
button?.click();
|
||||
});
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `1 <button></button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
let count = $state(0);
|
||||
function showCount() {
|
||||
return count;
|
||||
}
|
||||
</script>
|
||||
|
||||
{showCount``} <button onclick={() => count++}></button>
|
Loading…
Reference in new issue