Skip to content

Commit 7047196

Browse files
authored
fix(runtime): fixed parsing of complex attributes that contains JSON strings (#6359)
* fix(runtime): fixed parsing of complex attributes that contains JSON strings * Added test * Prettier styling fix
1 parent 0831d2c commit 7047196

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/runtime/test/prop.spec.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,35 @@ describe('prop', () => {
208208
<cmp-a>4</cmp-a>
209209
`);
210210
});
211+
212+
it('should demonstrate JSON parsing for complex object props', async () => {
213+
@Component({ tag: 'simple-demo' })
214+
class SimpleDemo {
215+
@Prop() message: { text: string } = { text: 'default' };
216+
@Prop() messageAny: any = { text: 'default' };
217+
218+
render() {
219+
return (
220+
<div>
221+
<div>{this.message.text}</div>
222+
<div>{this.messageAny.text}</div>
223+
</div>
224+
);
225+
}
226+
}
227+
228+
const { root } = await newSpecPage({
229+
components: [SimpleDemo],
230+
html: `<simple-demo message='{"text": "Hello World"}' message-any='{"text": "Hello World"}'></simple-demo>`,
231+
});
232+
233+
expect(root).toEqualHtml(`
234+
<simple-demo message='{"text": "Hello World"}' message-any='{"text": "Hello World"}'>
235+
<div>
236+
<div>Hello World</div>
237+
<div>Hello World</div>
238+
</div>
239+
</simple-demo>
240+
`);
241+
});
211242
});

src/utils/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const enum MEMBER_FLAGS {
1717
Setter = 1 << 12,
1818

1919
Prop = String | Number | Boolean | Any | Unknown,
20-
HasAttribute = String | Number | Boolean | Any,
20+
HasAttribute = String | Number | Boolean | Any | Unknown,
2121
PropLike = Prop | State,
2222
}
2323

0 commit comments

Comments
 (0)