Skip to content

Commit

Permalink
fix: ensure is_pure takes into account runes (#14333)
Browse files Browse the repository at this point in the history
* fix: ensure is_pure takes into account runes

* feedback
  • Loading branch information
trueadm authored Nov 19, 2024
1 parent 7411068 commit 747d408
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-islands-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure is_pure takes into account $effect.tracking()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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') {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from '../../test';

export default test({
html: `
<p>Without text expression: 7.36</p>
<p>With text expression: 7.36</p>
<p>With text expression and function call: 7.36</p>
<p>With text expression and property access: 4</p>
<h1>Hello name!</h1>
<p>4</p>
<h1>Tracking: true</h1>`,

ssrHtml: `
<p>Without text expression: 7.36</p>
<p>With text expression: 7.36</p>
<p>With text expression and function call: 7.36</p>
<p>With text expression and property access: 4</p>
<h1>Hello name!</h1>
<p>4</p>
<h1>Tracking: false</h1>`
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
<p>With text expression and property access: {"test".length}</p>
<h1>Hello {('name').toUpperCase().toLowerCase()}!</h1>
<p>{"test".length}</p>
<h1>Tracking: {$effect.tracking()}</h1>

0 comments on commit 747d408

Please sign in to comment.