Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure inline object literals are correctly serialised #14325

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-readers-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: treat property accesses of literals as pure
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export function is_pure(node, context) {
return false;
}

if (node.type === 'MemberExpression' && node.object.type === 'Literal') {
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

const left = object(node);
if (!left) return false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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>
<p>4</p>`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Without text expression: 7.36</p>
<p>With text expression: {7.36}</p>
<p>With text expression and function call: {(7.36).toLocaleString()}</p>
<p>With text expression and property access: {"test".length}</p>
<p>{"test".length}</p>
Loading