Skip to content

Commit f83fcf0

Browse files
authored
Fixes toJSON() for Struct to currectly return a dom.Value instance (#752)
1 parent 03384c3 commit f83fcf0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/dom/Struct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class Struct extends Value(
182182
}
183183

184184
toJSON() {
185-
let normalizedFields = Object.create(null);
185+
let normalizedFields = Object.create(Struct.prototype);
186186
for (const [key, value] of this.fields()) {
187187
normalizedFields[key] = value;
188188
}

test/dom/json.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,17 @@ describe('JSON', () => {
145145
JSON.stringify(load('foo'))
146146
);
147147
});
148+
it('Struct is instanceof dom.Value inside JSON.stringify', () => {
149+
let struct: Value = load(`$ion_1_0
150+
{
151+
foo:"bar"
152+
}`)!;
153+
154+
const replacer = (key, value) => {
155+
assert.isTrue(value instanceof Value)
156+
}
157+
158+
JSON.stringify(struct, replacer, 2);
159+
})
148160
});
149161
});

0 commit comments

Comments
 (0)