Skip to content

Commit 747d408

Browse files
authored
fix: ensure is_pure takes into account runes (#14333)
* fix: ensure is_pure takes into account runes * feedback
1 parent 7411068 commit 747d408

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

.changeset/slimy-islands-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure is_pure takes into account $effect.tracking()

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
/** @import { Scope } from '../../../scope' */
55
/** @import { NodeLike } from '../../../../errors.js' */
66
import * as e from '../../../../errors.js';
7-
import { extract_identifiers, object } from '../../../../utils/ast.js';
7+
import { extract_identifiers } from '../../../../utils/ast.js';
88
import * as w from '../../../../warnings.js';
9+
import * as b from '../../../../utils/builders.js';
10+
import { get_rune } from '../../../scope.js';
911

1012
/**
1113
* @param {AssignmentExpression | UpdateExpression} node
@@ -184,6 +186,7 @@ export function is_pure(node, context) {
184186
if (node.type === 'Literal') {
185187
return true;
186188
}
189+
187190
if (node.type === 'CallExpression') {
188191
if (!is_pure(node.callee, context)) {
189192
return false;
@@ -195,10 +198,15 @@ export function is_pure(node, context) {
195198
}
196199
return true;
197200
}
201+
198202
if (node.type !== 'Identifier' && node.type !== 'MemberExpression') {
199203
return false;
200204
}
201205

206+
if (get_rune(b.call(node), context.state.scope) === '$effect.tracking') {
207+
return false;
208+
}
209+
202210
/** @type {Expression | Super | null} */
203211
let left = node;
204212
while (left.type === 'MemberExpression') {

packages/svelte/tests/runtime-legacy/samples/inline-expressions-2/_config.js

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `
5+
<p>Without text expression: 7.36</p>
6+
<p>With text expression: 7.36</p>
7+
<p>With text expression and function call: 7.36</p>
8+
<p>With text expression and property access: 4</p>
9+
<h1>Hello name!</h1>
10+
<p>4</p>
11+
<h1>Tracking: true</h1>`,
12+
13+
ssrHtml: `
14+
<p>Without text expression: 7.36</p>
15+
<p>With text expression: 7.36</p>
16+
<p>With text expression and function call: 7.36</p>
17+
<p>With text expression and property access: 4</p>
18+
<h1>Hello name!</h1>
19+
<p>4</p>
20+
<h1>Tracking: false</h1>`
21+
});

packages/svelte/tests/runtime-legacy/samples/inline-expressions-2/main.svelte renamed to packages/svelte/tests/runtime-runes/samples/inline-expressions/main.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
<p>With text expression and property access: {"test".length}</p>
55
<h1>Hello {('name').toUpperCase().toLowerCase()}!</h1>
66
<p>{"test".length}</p>
7+
<h1>Tracking: {$effect.tracking()}</h1>

0 commit comments

Comments
 (0)