json-as 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/README.md +1 -1
- package/assembly/__benches__/large.bench.ts +19 -22
- package/assembly/__tests__/lib/index.ts +7 -3
- package/bench/large.bench.ts +215 -104
- package/bench/lib/test.ts +37 -0
- package/package.json +1 -1
- package/run-bench.js.sh +1 -1
- package/transform/lib/index.js +66 -30
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linker.js +3 -3
- package/transform/lib/linker.js.map +1 -1
- package/transform/src/index.ts +144 -114
- package/transform/src/linker.ts +11 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## 2025-05-
|
|
3
|
+
## 2025-05-28 - 1.1.11
|
|
4
|
+
|
|
5
|
+
- fix: class resolving should only search top level statements for class declarations
|
|
6
|
+
- fix: add helpful error if class is missing an @json decorator
|
|
7
|
+
- fix: properly calculate relative path when json-as is a library
|
|
8
|
+
- fix: add proper null check when resolving imported classes
|
|
9
|
+
|
|
10
|
+
## 2025-05-28 - 1.1.10
|
|
4
11
|
|
|
5
12
|
- feat: add more debug levels (1 = print transform code, 2 = print keys/values at runtime)
|
|
6
13
|
- feat: add write out feature (`JSON_WRITE=path-to-file.ts`) which writes out generated code
|
package/README.md
CHANGED
|
@@ -2,11 +2,10 @@ import { JSON } from "..";
|
|
|
2
2
|
import { expect } from "../__tests__/lib";
|
|
3
3
|
import { bench } from "./lib/bench";
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
@json
|
|
7
6
|
class RepoOwner {
|
|
8
7
|
public login!: string;
|
|
9
|
-
public id!:
|
|
8
|
+
public id!: number;
|
|
10
9
|
public node_id!: string;
|
|
11
10
|
public avatar_url!: string;
|
|
12
11
|
public gravatar_id!: string;
|
|
@@ -26,7 +25,6 @@ class RepoOwner {
|
|
|
26
25
|
public site_admin!: boolean;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
28
|
@json
|
|
31
29
|
class RepoLicense {
|
|
32
30
|
public key!: string;
|
|
@@ -36,10 +34,9 @@ class RepoLicense {
|
|
|
36
34
|
public node_id!: string;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
37
|
@json
|
|
41
38
|
class Repo {
|
|
42
|
-
public id!:
|
|
39
|
+
public id!: number;
|
|
43
40
|
public node_id!: string;
|
|
44
41
|
public name!: string;
|
|
45
42
|
public full_name!: string;
|
|
@@ -93,9 +90,9 @@ class Repo {
|
|
|
93
90
|
public clone_url!: string;
|
|
94
91
|
public svn_url!: string;
|
|
95
92
|
public homepage!: string | null;
|
|
96
|
-
public size!:
|
|
97
|
-
public stargazers_count!:
|
|
98
|
-
public watchers_count!:
|
|
93
|
+
public size!: number;
|
|
94
|
+
public stargazers_count!: number;
|
|
95
|
+
public watchers_count!: number;
|
|
99
96
|
public language!: string | null;
|
|
100
97
|
public has_issues!: boolean;
|
|
101
98
|
public has_projects!: boolean;
|
|
@@ -103,24 +100,24 @@ class Repo {
|
|
|
103
100
|
public has_wiki!: boolean;
|
|
104
101
|
public has_pages!: boolean;
|
|
105
102
|
public has_discussions!: boolean;
|
|
106
|
-
public forks_count!:
|
|
103
|
+
public forks_count!: number;
|
|
107
104
|
public mirror_url!: string | null;
|
|
108
105
|
public archived!: boolean;
|
|
109
106
|
public disabled!: boolean;
|
|
110
|
-
public open_issues_count!:
|
|
107
|
+
public open_issues_count!: number;
|
|
111
108
|
public license!: RepoLicense | null;
|
|
112
109
|
public allow_forking!: boolean;
|
|
113
110
|
public is_template!: boolean;
|
|
114
111
|
public web_commit_signoff_required!: boolean;
|
|
115
112
|
public topics!: string[];
|
|
116
113
|
public visibility!: string;
|
|
117
|
-
public forks!:
|
|
118
|
-
public open_issues!:
|
|
119
|
-
public watchers!:
|
|
114
|
+
public forks!: number;
|
|
115
|
+
public open_issues!: number;
|
|
116
|
+
public watchers!: number;
|
|
120
117
|
public default_branch!: string;
|
|
121
118
|
}
|
|
122
119
|
|
|
123
|
-
|
|
120
|
+
let v1: Repo = {
|
|
124
121
|
id: 132935648,
|
|
125
122
|
node_id: "MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=",
|
|
126
123
|
name: "boysenberry-repo-1",
|
|
@@ -145,7 +142,7 @@ const v1: Repo = {
|
|
|
145
142
|
received_events_url: "https://api.github.com/users/octocat/received_events",
|
|
146
143
|
type: "User",
|
|
147
144
|
user_view_type: "public",
|
|
148
|
-
site_admin: false
|
|
145
|
+
site_admin: false
|
|
149
146
|
},
|
|
150
147
|
html_url: "https://github.com/octocat/boysenberry-repo-1",
|
|
151
148
|
description: "Testing",
|
|
@@ -219,26 +216,26 @@ const v1: Repo = {
|
|
|
219
216
|
forks: 20,
|
|
220
217
|
open_issues: 1,
|
|
221
218
|
watchers: 332,
|
|
222
|
-
default_branch: "master"
|
|
223
|
-
}
|
|
219
|
+
default_branch: "master"
|
|
220
|
+
}
|
|
224
221
|
|
|
225
222
|
const v2 = `{"id":132935648,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=","name":"boysenberry-repo-1","full_name":"octocat/boysenberry-repo-1","private":true,"owner":{"login":"octocat","id":583231,"node_id":"MDQ6VXNlcjU4MzIzMQ==","avatar_url":"https://avatars.githubusercontent.com/u/583231?v=4","gravatar_id":"","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","user_view_type":"public","site_admin":false},"html_url":"https://github.com/octocat/boysenberry-repo-1","description":"Testing","fork":true,"url":"https://api.github.com/repos/octocat/boysenberry-repo-1","forks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/forks","keys_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/teams","hooks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/hooks","issue_events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/events","assignees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/tags","blobs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/languages","stargazers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers","contributors_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contributors","subscribers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers","subscription_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscription","commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/merges","archive_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/downloads","issues_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}","releases_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}","deployments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/deployments","created_at":"2018-05-10T17:51:29Z","updated_at":"2025-05-24T02:01:19Z","pushed_at":"2024-05-26T07:02:05Z","git_url":"git://github.com/octocat/boysenberry-repo-1.git","ssh_url":"git@github.com:octocat/boysenberry-repo-1.git","clone_url":"https://github.com/octocat/boysenberry-repo-1.git","svn_url":"https://github.com/octocat/boysenberry-repo-1","homepage":"","size":4,"stargazers_count":332,"watchers_count":332,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"has_discussions":false,"forks_count":20,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"allow_forking":true,"is_template":false,"web_commit_signoff_required":false,"topics":[],"visibility":"public","forks":20,"open_issues":1,"watchers":332,"default_branch":"master"}`;
|
|
226
223
|
|
|
227
224
|
expect(JSON.stringify(v1)).toBe(v2);
|
|
228
|
-
expect(JSON.stringify(JSON.parse
|
|
225
|
+
expect(JSON.stringify(JSON.parse(v2))).toBe(v2);
|
|
229
226
|
|
|
230
227
|
bench(
|
|
231
228
|
"Serialize Large Object",
|
|
232
229
|
() => {
|
|
233
230
|
JSON.stringify(v1);
|
|
234
231
|
},
|
|
235
|
-
|
|
232
|
+
1_000_000,
|
|
236
233
|
);
|
|
237
234
|
|
|
238
235
|
bench(
|
|
239
236
|
"Deserialize Large Object",
|
|
240
237
|
() => {
|
|
241
|
-
JSON.parse
|
|
238
|
+
JSON.parse(v2);
|
|
242
239
|
},
|
|
243
|
-
|
|
244
|
-
);
|
|
240
|
+
1_000_000,
|
|
241
|
+
);
|
|
@@ -13,7 +13,7 @@ export function expect<T>(left: T): Expectation {
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
if (!isDefined(left.toString)) throw new Error("Expected left to have a toString method, but it does not.");
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
return new Expectation(left
|
|
16
|
+
return new Expectation(isNull(left) ? "null" : left.toString());
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
class Expectation {
|
|
@@ -26,12 +26,16 @@ class Expectation {
|
|
|
26
26
|
// @ts-ignore
|
|
27
27
|
if (!isDefined(right.toString)) throw new Error("Expected right to have a toString method, but it does not.");
|
|
28
28
|
// @ts-ignore
|
|
29
|
-
if (this.left != (right
|
|
29
|
+
if (this.left != (isNull(right) ? "null" : right.toString())) {
|
|
30
30
|
console.log(" " + currentDescription + "\n");
|
|
31
31
|
// @ts-ignore
|
|
32
|
-
console.log(" (expected) -> " + (right
|
|
32
|
+
console.log(" (expected) -> " + (isNull(right) ? "null" : right.toString()));
|
|
33
33
|
console.log(" (received) -> " + this.left);
|
|
34
34
|
unreachable();
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
function isNull<T>(value: T): boolean {
|
|
40
|
+
return isInteger<T>() && !isSigned<T>() && nameof<T>() == "usize" && value == 0;
|
|
41
|
+
}
|
package/bench/large.bench.ts
CHANGED
|
@@ -1,120 +1,231 @@
|
|
|
1
1
|
import { bench } from "./lib/bench.js";
|
|
2
|
+
import { expect } from "./lib/test.js";
|
|
2
3
|
|
|
3
|
-
class
|
|
4
|
-
public
|
|
5
|
-
public
|
|
6
|
-
public
|
|
4
|
+
class RepoOwner {
|
|
5
|
+
public login!: string;
|
|
6
|
+
public id!: number;
|
|
7
|
+
public node_id!: string;
|
|
8
|
+
public avatar_url!: string;
|
|
9
|
+
public gravatar_id!: string;
|
|
10
|
+
public url!: string;
|
|
11
|
+
public html_url!: string;
|
|
12
|
+
public followers_url!: string;
|
|
13
|
+
public following_url!: string;
|
|
14
|
+
public gists_url!: string;
|
|
15
|
+
public starred_url!: string;
|
|
16
|
+
public subscriptions_url!: string;
|
|
17
|
+
public organizations_url!: string;
|
|
18
|
+
public repos_url!: string;
|
|
19
|
+
public events_url!: string;
|
|
20
|
+
public received_events_url!: string;
|
|
21
|
+
public type!: string;
|
|
22
|
+
public user_view_type!: string;
|
|
23
|
+
public site_admin!: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class RepoLicense {
|
|
27
|
+
public key!: string;
|
|
28
|
+
public name!: string;
|
|
29
|
+
public spdx_id!: string;
|
|
30
|
+
public url!: string | null;
|
|
31
|
+
public node_id!: string;
|
|
7
32
|
}
|
|
8
33
|
|
|
9
|
-
class
|
|
34
|
+
class Repo {
|
|
10
35
|
public id!: number;
|
|
36
|
+
public node_id!: string;
|
|
11
37
|
public name!: string;
|
|
12
|
-
public
|
|
13
|
-
public
|
|
14
|
-
public
|
|
15
|
-
public
|
|
16
|
-
public
|
|
17
|
-
public
|
|
18
|
-
public
|
|
19
|
-
public
|
|
20
|
-
public
|
|
21
|
-
public
|
|
22
|
-
public
|
|
38
|
+
public full_name!: string;
|
|
39
|
+
public private!: boolean;
|
|
40
|
+
public owner: RepoOwner = new RepoOwner();
|
|
41
|
+
public html_url!: string;
|
|
42
|
+
public description!: string | null;
|
|
43
|
+
public fork!: boolean;
|
|
44
|
+
public url!: string;
|
|
45
|
+
public forks_url!: string;
|
|
46
|
+
public keys_url!: string;
|
|
47
|
+
public collaborators_url!: string;
|
|
48
|
+
public teams_url!: string;
|
|
49
|
+
public hooks_url!: string;
|
|
50
|
+
public issue_events_url!: string;
|
|
51
|
+
public events_url!: string;
|
|
52
|
+
public assignees_url!: string;
|
|
53
|
+
public branches_url!: string;
|
|
54
|
+
public tags_url!: string;
|
|
55
|
+
public blobs_url!: string;
|
|
56
|
+
public git_tags_url!: string;
|
|
57
|
+
public git_refs_url!: string;
|
|
58
|
+
public trees_url!: string;
|
|
59
|
+
public statuses_url!: string;
|
|
60
|
+
public languages_url!: string;
|
|
61
|
+
public stargazers_url!: string;
|
|
62
|
+
public contributors_url!: string;
|
|
63
|
+
public subscribers_url!: string;
|
|
64
|
+
public subscription_url!: string;
|
|
65
|
+
public commits_url!: string;
|
|
66
|
+
public git_commits_url!: string;
|
|
67
|
+
public comments_url!: string;
|
|
68
|
+
public issue_comment_url!: string;
|
|
69
|
+
public contents_url!: string;
|
|
70
|
+
public compare_url!: string;
|
|
71
|
+
public merges_url!: string;
|
|
72
|
+
public archive_url!: string;
|
|
73
|
+
public downloads_url!: string;
|
|
74
|
+
public issues_url!: string;
|
|
75
|
+
public pulls_url!: string;
|
|
76
|
+
public milestones_url!: string;
|
|
77
|
+
public notifications_url!: string;
|
|
78
|
+
public labels_url!: string;
|
|
79
|
+
public releases_url!: string;
|
|
80
|
+
public deployments_url!: string;
|
|
81
|
+
public created_at!: string;
|
|
82
|
+
public updated_at!: string;
|
|
83
|
+
public pushed_at!: string;
|
|
84
|
+
public git_url!: string;
|
|
85
|
+
public ssh_url!: string;
|
|
86
|
+
public clone_url!: string;
|
|
87
|
+
public svn_url!: string;
|
|
88
|
+
public homepage!: string | null;
|
|
89
|
+
public size!: number;
|
|
90
|
+
public stargazers_count!: number;
|
|
91
|
+
public watchers_count!: number;
|
|
92
|
+
public language!: string | null;
|
|
93
|
+
public has_issues!: boolean;
|
|
94
|
+
public has_projects!: boolean;
|
|
95
|
+
public has_downloads!: boolean;
|
|
96
|
+
public has_wiki!: boolean;
|
|
97
|
+
public has_pages!: boolean;
|
|
98
|
+
public has_discussions!: boolean;
|
|
99
|
+
public forks_count!: number;
|
|
100
|
+
public mirror_url!: string | null;
|
|
101
|
+
public archived!: boolean;
|
|
102
|
+
public disabled!: boolean;
|
|
103
|
+
public open_issues_count!: number;
|
|
104
|
+
public license!: RepoLicense | null;
|
|
105
|
+
public allow_forking!: boolean;
|
|
106
|
+
public is_template!: boolean;
|
|
107
|
+
public web_commit_signoff_required!: boolean;
|
|
108
|
+
public topics!: string[];
|
|
109
|
+
public visibility!: string;
|
|
110
|
+
public forks!: number;
|
|
111
|
+
public open_issues!: number;
|
|
112
|
+
public watchers!: number;
|
|
113
|
+
public default_branch!: string;
|
|
23
114
|
}
|
|
24
115
|
|
|
25
|
-
|
|
26
|
-
id:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
let v1: Repo = {
|
|
117
|
+
id: 132935648,
|
|
118
|
+
node_id: "MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=",
|
|
119
|
+
name: "boysenberry-repo-1",
|
|
120
|
+
full_name: "octocat/boysenberry-repo-1",
|
|
121
|
+
private: true,
|
|
122
|
+
owner: {
|
|
123
|
+
login: "octocat",
|
|
124
|
+
id: 583231,
|
|
125
|
+
node_id: "MDQ6VXNlcjU4MzIzMQ==",
|
|
126
|
+
avatar_url: "https://avatars.githubusercontent.com/u/583231?v=4",
|
|
127
|
+
gravatar_id: "",
|
|
128
|
+
url: "https://api.github.com/users/octocat",
|
|
129
|
+
html_url: "https://github.com/octocat",
|
|
130
|
+
followers_url: "https://api.github.com/users/octocat/followers",
|
|
131
|
+
following_url: "https://api.github.com/users/octocat/following{/other_user}",
|
|
132
|
+
gists_url: "https://api.github.com/users/octocat/gists{/gist_id}",
|
|
133
|
+
starred_url: "https://api.github.com/users/octocat/starred{/owner}{/repo}",
|
|
134
|
+
subscriptions_url: "https://api.github.com/users/octocat/subscriptions",
|
|
135
|
+
organizations_url: "https://api.github.com/users/octocat/orgs",
|
|
136
|
+
repos_url: "https://api.github.com/users/octocat/repos",
|
|
137
|
+
events_url: "https://api.github.com/users/octocat/events{/privacy}",
|
|
138
|
+
received_events_url: "https://api.github.com/users/octocat/received_events",
|
|
139
|
+
type: "User",
|
|
140
|
+
user_view_type: "public",
|
|
141
|
+
site_admin: false
|
|
142
|
+
},
|
|
143
|
+
html_url: "https://github.com/octocat/boysenberry-repo-1",
|
|
144
|
+
description: "Testing",
|
|
145
|
+
fork: true,
|
|
146
|
+
url: "https://api.github.com/repos/octocat/boysenberry-repo-1",
|
|
147
|
+
forks_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/forks",
|
|
148
|
+
keys_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}",
|
|
149
|
+
collaborators_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}",
|
|
150
|
+
teams_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/teams",
|
|
151
|
+
hooks_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/hooks",
|
|
152
|
+
issue_events_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}",
|
|
153
|
+
events_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/events",
|
|
154
|
+
assignees_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}",
|
|
155
|
+
branches_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}",
|
|
156
|
+
tags_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/tags",
|
|
157
|
+
blobs_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}",
|
|
158
|
+
git_tags_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}",
|
|
159
|
+
git_refs_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}",
|
|
160
|
+
trees_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}",
|
|
161
|
+
statuses_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}",
|
|
162
|
+
languages_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/languages",
|
|
163
|
+
stargazers_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers",
|
|
164
|
+
contributors_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/contributors",
|
|
165
|
+
subscribers_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers",
|
|
166
|
+
subscription_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/subscription",
|
|
167
|
+
commits_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}",
|
|
168
|
+
git_commits_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}",
|
|
169
|
+
comments_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}",
|
|
170
|
+
issue_comment_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}",
|
|
171
|
+
contents_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}",
|
|
172
|
+
compare_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}",
|
|
173
|
+
merges_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/merges",
|
|
174
|
+
archive_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}",
|
|
175
|
+
downloads_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/downloads",
|
|
176
|
+
issues_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}",
|
|
177
|
+
pulls_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}",
|
|
178
|
+
milestones_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}",
|
|
179
|
+
notifications_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}",
|
|
180
|
+
labels_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}",
|
|
181
|
+
releases_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}",
|
|
182
|
+
deployments_url: "https://api.github.com/repos/octocat/boysenberry-repo-1/deployments",
|
|
183
|
+
created_at: "2018-05-10T17:51:29Z",
|
|
184
|
+
updated_at: "2025-05-24T02:01:19Z",
|
|
185
|
+
pushed_at: "2024-05-26T07:02:05Z",
|
|
186
|
+
git_url: "git://github.com/octocat/boysenberry-repo-1.git",
|
|
187
|
+
ssh_url: "git@github.com:octocat/boysenberry-repo-1.git",
|
|
188
|
+
clone_url: "https://github.com/octocat/boysenberry-repo-1.git",
|
|
189
|
+
svn_url: "https://github.com/octocat/boysenberry-repo-1",
|
|
190
|
+
homepage: "",
|
|
191
|
+
size: 4,
|
|
192
|
+
stargazers_count: 332,
|
|
193
|
+
watchers_count: 332,
|
|
194
|
+
language: null,
|
|
195
|
+
has_issues: false,
|
|
196
|
+
has_projects: true,
|
|
197
|
+
has_downloads: true,
|
|
198
|
+
has_wiki: true,
|
|
199
|
+
has_pages: false,
|
|
200
|
+
has_discussions: false,
|
|
201
|
+
forks_count: 20,
|
|
202
|
+
mirror_url: null,
|
|
203
|
+
archived: false,
|
|
204
|
+
disabled: false,
|
|
205
|
+
open_issues_count: 1,
|
|
206
|
+
license: null,
|
|
207
|
+
allow_forking: true,
|
|
208
|
+
is_template: false,
|
|
209
|
+
web_commit_signoff_required: false,
|
|
210
|
+
topics: [],
|
|
211
|
+
visibility: "public",
|
|
212
|
+
forks: 20,
|
|
213
|
+
open_issues: 1,
|
|
214
|
+
watchers: 332,
|
|
215
|
+
default_branch: "master"
|
|
216
|
+
}
|
|
109
217
|
|
|
110
|
-
const v2 = `{"id":
|
|
218
|
+
const v2 = `{"id":132935648,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=","name":"boysenberry-repo-1","full_name":"octocat/boysenberry-repo-1","private":true,"owner":{"login":"octocat","id":583231,"node_id":"MDQ6VXNlcjU4MzIzMQ==","avatar_url":"https://avatars.githubusercontent.com/u/583231?v=4","gravatar_id":"","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","user_view_type":"public","site_admin":false},"html_url":"https://github.com/octocat/boysenberry-repo-1","description":"Testing","fork":true,"url":"https://api.github.com/repos/octocat/boysenberry-repo-1","forks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/forks","keys_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/teams","hooks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/hooks","issue_events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/events","assignees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/tags","blobs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/languages","stargazers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers","contributors_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contributors","subscribers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers","subscription_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscription","commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/merges","archive_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/downloads","issues_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}","releases_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}","deployments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/deployments","created_at":"2018-05-10T17:51:29Z","updated_at":"2025-05-24T02:01:19Z","pushed_at":"2024-05-26T07:02:05Z","git_url":"git://github.com/octocat/boysenberry-repo-1.git","ssh_url":"git@github.com:octocat/boysenberry-repo-1.git","clone_url":"https://github.com/octocat/boysenberry-repo-1.git","svn_url":"https://github.com/octocat/boysenberry-repo-1","homepage":"","size":4,"stargazers_count":332,"watchers_count":332,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"has_discussions":false,"forks_count":20,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"allow_forking":true,"is_template":false,"web_commit_signoff_required":false,"topics":[],"visibility":"public","forks":20,"open_issues":1,"watchers":332,"default_branch":"master"}`;
|
|
219
|
+
|
|
220
|
+
expect(JSON.stringify(v1)).toBe(v2);
|
|
221
|
+
expect(JSON.stringify(JSON.parse(v2))).toBe(v2);
|
|
111
222
|
|
|
112
223
|
bench(
|
|
113
224
|
"Serialize Large Object",
|
|
114
225
|
() => {
|
|
115
226
|
JSON.stringify(v1);
|
|
116
227
|
},
|
|
117
|
-
|
|
228
|
+
1_000_000,
|
|
118
229
|
);
|
|
119
230
|
|
|
120
231
|
bench(
|
|
@@ -122,5 +233,5 @@ bench(
|
|
|
122
233
|
() => {
|
|
123
234
|
JSON.parse(v2);
|
|
124
235
|
},
|
|
125
|
-
|
|
126
|
-
);
|
|
236
|
+
1_000_000,
|
|
237
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
let currentDescription: string = "";
|
|
2
|
+
export function describe(description: string, routine: () => void): void {
|
|
3
|
+
currentDescription = description;
|
|
4
|
+
routine();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function it(description: string, routine: () => void): void {
|
|
8
|
+
currentDescription = description;
|
|
9
|
+
routine();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function expect<T>(left: T): Expectation {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (!left.toString) throw new Error("Expected left to have a toString method, but it does not.");
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
return new Expectation(left == null ? "null" : left.toString());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class Expectation {
|
|
20
|
+
public left: string;
|
|
21
|
+
|
|
22
|
+
constructor(left: string) {
|
|
23
|
+
this.left = left;
|
|
24
|
+
}
|
|
25
|
+
toBe<T>(right: T): void {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
if (!right.toString) throw new Error("Expected right to have a toString method, but it does not.");
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
if (this.left != (right == null ? "null" : right.toString())) {
|
|
30
|
+
console.log(" " + currentDescription + "\n");
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
console.log(" (expected) -> " + (right == null ? "null" : right.toString()));
|
|
33
|
+
console.log(" (received) -> " + this.left);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/package.json
CHANGED
package/run-bench.js.sh
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
RUNTIMES=${RUNTIMES:-"v8-liftoff v8-ignition v8-sparkplug v8-turbofan jsc-default"}
|
|
3
3
|
npx tsc -p ./bench > /dev/null 2>&1
|
|
4
|
-
for file in ./bench
|
|
4
|
+
for file in ./bench/large.bench.ts; do
|
|
5
5
|
filename=$(basename -- "$file")
|
|
6
6
|
file_js="${filename%.ts}.js"
|
|
7
7
|
|