Skip to content

Commit c3124f7

Browse files
committed
Second try
1 parent 61ad69f commit c3124f7

File tree

5 files changed

+150
-103
lines changed

5 files changed

+150
-103
lines changed

src/lib/es5.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,13 @@ interface JSON {
11171117
* If a member contains nested objects, the nested objects are transformed before the parent object is.
11181118
*/
11191119
parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
1120+
/**
1121+
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
1122+
* @param value A JavaScript value, usually an object or array, to be converted.
1123+
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.
1124+
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
1125+
*/
1126+
stringify(value: Function | Symbol | undefined, replacer?: (number | string)[] | null, space?: string | number): undefined;
11201127
/**
11211128
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
11221129
* @param value A JavaScript value, usually an object or array, to be converted.
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
//// [json.stringify.ts]
1+
//// [json.stringify.ts]
22
var value = null;
33
JSON.stringify(value, undefined, 2);
44
JSON.stringify(value, null, 2);
55
JSON.stringify(value, ["a", 1], 2);
66
JSON.stringify(value, (k) => undefined, 2);
7-
JSON.stringify(value, undefined, 2);
8-
9-
//// [json.stringify.js]
10-
var value = null;
11-
JSON.stringify(value, undefined, 2);
12-
JSON.stringify(value, null, 2);
13-
JSON.stringify(value, ["a", 1], 2);
14-
JSON.stringify(value, function (k) { return undefined; }, 2);
15-
JSON.stringify(value, undefined, 2);
7+
JSON.stringify(() => {}, undefined, 2);
8+
JSON.stringify(Symbol('s'), undefined, 2);
9+
JSON.stringify(undefined, undefined, 2);
10+
11+
//// [json.stringify.js]
12+
var value = null;
13+
JSON.stringify(value, undefined, 2);
14+
JSON.stringify(value, null, 2);
15+
JSON.stringify(value, ["a", 1], 2);
16+
JSON.stringify(value, function (k) { return undefined; }, 2);
17+
JSON.stringify(function () { }, undefined, 2);
18+
JSON.stringify(Symbol('s'), undefined, 2);
19+
JSON.stringify(undefined, undefined, 2);
Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
1-
=== tests/cases/compiler/json.stringify.ts ===
2-
var value = null;
3-
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
4-
5-
JSON.stringify(value, undefined, 2);
6-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
7-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
8-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
9-
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
10-
>undefined : Symbol(undefined)
11-
12-
JSON.stringify(value, null, 2);
13-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
14-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
15-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
16-
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
17-
18-
JSON.stringify(value, ["a", 1], 2);
19-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
20-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
21-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
22-
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
23-
24-
JSON.stringify(value, (k) => undefined, 2);
25-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
26-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
27-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
28-
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
29-
>k : Symbol(k, Decl(json.stringify.ts, 4, 23))
30-
>undefined : Symbol(undefined)
31-
32-
JSON.stringify(value, undefined, 2);
33-
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34-
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
35-
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36-
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
37-
>undefined : Symbol(undefined)
38-
1+
=== tests/cases/compiler/json.stringify.ts ===
2+
var value = null;
3+
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
4+
5+
JSON.stringify(value, undefined, 2);
6+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
7+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
8+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
9+
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
10+
>undefined : Symbol(undefined)
11+
12+
JSON.stringify(value, null, 2);
13+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
14+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
15+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
16+
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
17+
18+
JSON.stringify(value, ["a", 1], 2);
19+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
20+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
21+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
22+
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
23+
24+
JSON.stringify(value, (k) => undefined, 2);
25+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
26+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
27+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
28+
>value : Symbol(value, Decl(json.stringify.ts, 0, 3))
29+
>k : Symbol(k, Decl(json.stringify.ts, 4, 23))
30+
>undefined : Symbol(undefined)
31+
32+
JSON.stringify(() => {}, undefined, 2);
33+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
34+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
35+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
36+
>undefined : Symbol(undefined)
37+
38+
JSON.stringify(Symbol('s'), undefined, 2);
39+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
40+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
41+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
42+
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
43+
>undefined : Symbol(undefined)
44+
45+
JSON.stringify(undefined, undefined, 2);
46+
>JSON.stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
47+
>JSON : Symbol(JSON, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
48+
>stringify : Symbol(JSON.stringify, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
49+
>undefined : Symbol(undefined)
50+
>undefined : Symbol(undefined)
51+
Lines changed: 74 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,74 @@
1-
=== tests/cases/compiler/json.stringify.ts ===
2-
var value = null;
3-
>value : null
4-
>null : null
5-
6-
JSON.stringify(value, undefined, 2);
7-
>JSON.stringify(value, undefined, 2) : string
8-
>JSON.stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
9-
>JSON : JSON
10-
>stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
11-
>value : null
12-
>undefined : undefined
13-
>2 : 2
14-
15-
JSON.stringify(value, null, 2);
16-
>JSON.stringify(value, null, 2) : string
17-
>JSON.stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
18-
>JSON : JSON
19-
>stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
20-
>value : null
21-
>null : null
22-
>2 : 2
23-
24-
JSON.stringify(value, ["a", 1], 2);
25-
>JSON.stringify(value, ["a", 1], 2) : string
26-
>JSON.stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
27-
>JSON : JSON
28-
>stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
29-
>value : null
30-
>["a", 1] : (string | number)[]
31-
>"a" : "a"
32-
>1 : 1
33-
>2 : 2
34-
35-
JSON.stringify(value, (k) => undefined, 2);
36-
>JSON.stringify(value, (k) => undefined, 2) : string
37-
>JSON.stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
38-
>JSON : JSON
39-
>stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
40-
>value : null
41-
>(k) => undefined : (this: any, k: string) => undefined
42-
>k : string
43-
>undefined : undefined
44-
>2 : 2
45-
46-
JSON.stringify(value, undefined, 2);
47-
>JSON.stringify(value, undefined, 2) : string
48-
>JSON.stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
49-
>JSON : JSON
50-
>stringify : { (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
51-
>value : null
52-
>undefined : undefined
53-
>2 : 2
54-
1+
=== tests/cases/compiler/json.stringify.ts ===
2+
var value = null;
3+
>value : null
4+
>null : null
5+
6+
JSON.stringify(value, undefined, 2);
7+
>JSON.stringify(value, undefined, 2) : string
8+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
9+
>JSON : JSON
10+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
11+
>value : null
12+
>undefined : undefined
13+
>2 : 2
14+
15+
JSON.stringify(value, null, 2);
16+
>JSON.stringify(value, null, 2) : string
17+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
18+
>JSON : JSON
19+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
20+
>value : null
21+
>null : null
22+
>2 : 2
23+
24+
JSON.stringify(value, ["a", 1], 2);
25+
>JSON.stringify(value, ["a", 1], 2) : string
26+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
27+
>JSON : JSON
28+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
29+
>value : null
30+
>["a", 1] : (string | number)[]
31+
>"a" : "a"
32+
>1 : 1
33+
>2 : 2
34+
35+
JSON.stringify(value, (k) => undefined, 2);
36+
>JSON.stringify(value, (k) => undefined, 2) : string
37+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
38+
>JSON : JSON
39+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
40+
>value : null
41+
>(k) => undefined : (this: any, k: string) => undefined
42+
>k : string
43+
>undefined : undefined
44+
>2 : 2
45+
46+
JSON.stringify(() => {}, undefined, 2);
47+
>JSON.stringify(() => {}, undefined, 2) : undefined
48+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
49+
>JSON : JSON
50+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
51+
>() => {} : () => void
52+
>undefined : undefined
53+
>2 : 2
54+
55+
JSON.stringify(Symbol('s'), undefined, 2);
56+
>JSON.stringify(Symbol('s'), undefined, 2) : undefined
57+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
58+
>JSON : JSON
59+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
60+
>Symbol('s') : symbol
61+
>Symbol : SymbolConstructor
62+
>'s' : "s"
63+
>undefined : undefined
64+
>2 : 2
65+
66+
JSON.stringify(undefined, undefined, 2);
67+
>JSON.stringify(undefined, undefined, 2) : undefined
68+
>JSON.stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
69+
>JSON : JSON
70+
>stringify : { (value: Function | Symbol | undefined, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): undefined; (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; }
71+
>undefined : undefined
72+
>undefined : undefined
73+
>2 : 2
74+
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// @strictNullChecks: true
2+
// @lib: es2015
23

34
var value = null;
45
JSON.stringify(value, undefined, 2);
56
JSON.stringify(value, null, 2);
67
JSON.stringify(value, ["a", 1], 2);
78
JSON.stringify(value, (k) => undefined, 2);
8-
JSON.stringify(value, undefined, 2);
9+
JSON.stringify(() => {}, undefined, 2);
10+
JSON.stringify(Symbol('s'), undefined, 2);
11+
JSON.stringify(undefined, undefined, 2);

0 commit comments

Comments
 (0)