Skip to content

Commit b24a72a

Browse files
committed
test(compiler): add reviver context tests for arrays and nested objects
- Add test cases for array elements and nested structures. - Ensure JSDoc aligns with existing patterns. Signed-off-by: Vedant Madane <[email protected]>
1 parent 39b6245 commit b24a72a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/lib/es2025.json.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ interface JSON {
1919
* If a member contains nested objects, the nested objects are transformed before the parent object is.
2020
* For primitive values the reviver also receives a `context` object whose `source` property is the original JSON
2121
* text of that value.
22-
* @throws {SyntaxError} If `text` is not valid JSON.
2322
*/
2423
parse(text: string, reviver: (this: any, key: string, value: any, context: { source: string }) => any): any;
2524

tests/cases/compiler/jsonParseWithSource.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ JSON.parse('{"key":123}', (key, value, context) => {
1919
return value;
2020
});
2121

22+
// Test coverage for reviver context on array elements
23+
JSON.parse('[1, 2, 3]', (key, value, context) => {
24+
const src: string = context.source;
25+
return value;
26+
});
27+
28+
// Test coverage for reviver context on nested objects
29+
JSON.parse('{"a": {"b": 1}}', (key, value, context) => {
30+
const src: string = context.source;
31+
return value;
32+
});
33+
2234
// Existing JSON.parse overloads still work
2335
JSON.parse("{}");
2436
JSON.parse('{"a":1}', (key, value) => value);

0 commit comments

Comments
 (0)