diff --git a/.changeset/slimy-islands-cry.md b/.changeset/slimy-islands-cry.md new file mode 100644 index 0000000000..f7f34b60e1 --- /dev/null +++ b/.changeset/slimy-islands-cry.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure is_pure takes into account $effect.tracking() diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js index 2dec4361c8..8698174c6b 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/shared/utils.js @@ -4,8 +4,10 @@ /** @import { Scope } from '../../../scope' */ /** @import { NodeLike } from '../../../../errors.js' */ import * as e from '../../../../errors.js'; -import { extract_identifiers, object } from '../../../../utils/ast.js'; +import { extract_identifiers } from '../../../../utils/ast.js'; import * as w from '../../../../warnings.js'; +import * as b from '../../../../utils/builders.js'; +import { get_rune } from '../../../scope.js'; /** * @param {AssignmentExpression | UpdateExpression} node @@ -184,6 +186,7 @@ export function is_pure(node, context) { if (node.type === 'Literal') { return true; } + if (node.type === 'CallExpression') { if (!is_pure(node.callee, context)) { return false; @@ -195,10 +198,15 @@ export function is_pure(node, context) { } return true; } + if (node.type !== 'Identifier' && node.type !== 'MemberExpression') { return false; } + if (get_rune(b.call(node), context.state.scope) === '$effect.tracking') { + return false; + } + /** @type {Expression | Super | null} */ let left = node; while (left.type === 'MemberExpression') { diff --git a/packages/svelte/tests/runtime-legacy/samples/inline-expressions-2/_config.js b/packages/svelte/tests/runtime-legacy/samples/inline-expressions-2/_config.js deleted file mode 100644 index 1869540b2c..0000000000 --- a/packages/svelte/tests/runtime-legacy/samples/inline-expressions-2/_config.js +++ /dev/null @@ -1,11 +0,0 @@ -import { test } from '../../test'; - -export default test({ - html: ` -
Without text expression: 7.36
-With text expression: 7.36
-With text expression and function call: 7.36
-With text expression and property access: 4
-4
` -}); diff --git a/packages/svelte/tests/runtime-runes/samples/inline-expressions/_config.js b/packages/svelte/tests/runtime-runes/samples/inline-expressions/_config.js new file mode 100644 index 0000000000..c5d4a75379 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/inline-expressions/_config.js @@ -0,0 +1,21 @@ +import { test } from '../../test'; + +export default test({ + html: ` +Without text expression: 7.36
+With text expression: 7.36
+With text expression and function call: 7.36
+With text expression and property access: 4
+4
+Without text expression: 7.36
+With text expression: 7.36
+With text expression and function call: 7.36
+With text expression and property access: 4
+4
+With text expression and property access: {"test".length}
{"test".length}
+