Skip to content

Commit

Permalink
Fixes toJSON() for Struct to currectly return a dom.Value insta…
Browse files Browse the repository at this point in the history
…nce (#752)
  • Loading branch information
desaikd committed Mar 30, 2023
1 parent 03384c3 commit f83fcf0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dom/Struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class Struct extends Value(
}

toJSON() {
let normalizedFields = Object.create(null);
let normalizedFields = Object.create(Struct.prototype);
for (const [key, value] of this.fields()) {
normalizedFields[key] = value;
}
Expand Down
12 changes: 12 additions & 0 deletions test/dom/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,17 @@ describe('JSON', () => {
JSON.stringify(load('foo'))
);
});
it('Struct is instanceof dom.Value inside JSON.stringify', () => {
let struct: Value = load(`$ion_1_0
{
foo:"bar"
}`)!;

const replacer = (key, value) => {
assert.isTrue(value instanceof Value)
}

JSON.stringify(struct, replacer, 2);
})
});
});

0 comments on commit f83fcf0

Please sign in to comment.