Skip to content

Commit 24bf1af

Browse files
committed
fix: ensure inline object literals are correctly serialised
1 parent 95ab85f commit 24bf1af

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

.changeset/wicked-readers-knock.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 inline object literals are correctly serialised

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export function is_pure(node, context) {
184184
if (node.type !== 'Identifier' && node.type !== 'MemberExpression') {
185185
return false;
186186
}
187+
if (node.type === 'MemberExpression' && node.object.type === 'Literal') {
188+
return true;
189+
}
187190

188191
const left = object(node);
189192
if (!left) return false;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
<p>4</p>`
10+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>Without text expression: 7.36</p>
2+
<p>With text expression: {7.36}</p>
3+
<p>With text expression and function call: {(7.36).toLocaleString()}</p>
4+
<p>With text expression and property access: {"test".length}</p>
5+
<p>{"test".length}</p>

0 commit comments

Comments
 (0)