typenative 0.4.1 → 0.6.0

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.
Files changed (270) hide show
  1. package/.github/workflows/ci.yml +2 -2
  2. package/.github/workflows/npm-publish-github-packages.yml +2 -2
  3. package/CHANGELOG.md +442 -1
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +73 -25
  6. package/bin/cli.js +2 -0
  7. package/bin/index.js +75 -5
  8. package/bin/main.js +2 -0
  9. package/bin/node/assert.js +2 -2
  10. package/bin/node/async_hooks.js +1 -1
  11. package/bin/node/buffer.js +16 -5
  12. package/bin/node/child_process.js +7 -7
  13. package/bin/node/cluster.js +3 -3
  14. package/bin/node/core.js +41 -0
  15. package/bin/node/crypto_keys.js +21 -21
  16. package/bin/node/dgram.js +1 -1
  17. package/bin/node/diagnostics_channel.js +3 -3
  18. package/bin/node/dns.js +2 -2
  19. package/bin/node/events.js +18 -13
  20. package/bin/node/fetch.js +2 -2
  21. package/bin/node/fs.js +3 -3
  22. package/bin/node/fs_watch.js +5 -5
  23. package/bin/node/http.js +3 -3
  24. package/bin/node/http2.js +3 -3
  25. package/bin/node/net.js +8 -8
  26. package/bin/node/path.js +17 -3
  27. package/bin/node/process.js +47 -11
  28. package/bin/node/punycode.js +2 -2
  29. package/bin/node/readline.js +1 -1
  30. package/bin/node/registry.js +4 -1
  31. package/bin/node/sqlite.js +6 -6
  32. package/bin/node/stream.js +81 -15
  33. package/bin/node/stream_web.js +10 -10
  34. package/bin/node/system_extra.js +3 -3
  35. package/bin/node/test.js +674 -366
  36. package/bin/node/test_coverage.js +187 -0
  37. package/bin/node/test_report.js +1392 -0
  38. package/bin/node/test_run.js +575 -0
  39. package/bin/node/timers.js +8 -6
  40. package/bin/node/tls.js +5 -5
  41. package/bin/node/url.js +1 -1
  42. package/bin/node/util.js +31 -7
  43. package/bin/node/util_extra.js +7 -7
  44. package/bin/node/webview.js +654 -0
  45. package/bin/node/worker_threads.js +1 -1
  46. package/bin/node/zlib.js +3 -3
  47. package/bin/parse-node.js +6 -2
  48. package/bin/regex_vm.js +2057 -0
  49. package/bin/transpiler.js +32872 -11265
  50. package/bin/typecheck-node.js +2 -1
  51. package/bin/version.js +1 -1
  52. package/conformance.md +515 -345
  53. package/examples/README.md +71 -11
  54. package/examples/angular-templates/README.md +139 -0
  55. package/examples/angular-templates/bench.mjs +173 -0
  56. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  57. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  58. package/examples/angular-templates/main.ts +135 -0
  59. package/examples/angular-templates/parity.mjs +157 -0
  60. package/examples/angular-templates/run-node.mjs +69 -0
  61. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  62. package/examples/desktop-notes/README.md +106 -0
  63. package/examples/desktop-notes/bench.mjs +125 -0
  64. package/examples/desktop-notes/main.ts +131 -0
  65. package/examples/desktop-notes/package-lock.json +726 -0
  66. package/examples/desktop-notes/package.json +9 -0
  67. package/examples/desktop-notes/ui.ts +176 -0
  68. package/examples/dupe-finder/README.md +78 -0
  69. package/examples/dupe-finder/bench.mjs +120 -0
  70. package/examples/dupe-finder/main.ts +87 -0
  71. package/examples/fibonacci/README.md +7 -7
  72. package/examples/hello-world/README.md +6 -6
  73. package/examples/json-server/README.md +19 -18
  74. package/examples/mandelbrot-png/README.md +63 -0
  75. package/examples/mandelbrot-png/bench.mjs +95 -0
  76. package/examples/mandelbrot-png/main.ts +98 -0
  77. package/examples/mandelbrot-png/preview.png +0 -0
  78. package/examples/marked-cli/README.md +160 -0
  79. package/examples/marked-cli/bench.mjs +178 -0
  80. package/examples/marked-cli/main.ts +292 -0
  81. package/examples/marked-cli/parity.mjs +185 -0
  82. package/examples/marked-cli/vendor/marked/LICENSE +44 -0
  83. package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
  84. package/examples/openai-chat/README.md +148 -0
  85. package/examples/openai-chat/bench.mjs +175 -0
  86. package/examples/openai-chat/main.ts +488 -0
  87. package/examples/react-compiler/README.md +170 -0
  88. package/examples/react-compiler/bench.mjs +181 -0
  89. package/examples/react-compiler/main.ts +158 -0
  90. package/examples/react-compiler/parity.mjs +362 -0
  91. package/examples/react-compiler/run-node.mjs +88 -0
  92. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  93. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  94. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  95. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  96. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  97. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  98. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  99. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  100. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  101. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  102. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  103. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  104. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  105. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  106. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  107. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  108. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  109. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  110. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  111. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  112. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  113. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  114. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  115. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  116. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  117. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  118. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  119. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  120. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  121. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  145. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  146. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  147. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  148. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  149. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  150. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  151. package/examples/react-compiler/vendor.mjs +688 -0
  152. package/examples/todo-cli/README.md +69 -0
  153. package/examples/todo-cli/bench.mjs +89 -0
  154. package/examples/todo-cli/main.ts +92 -0
  155. package/examples/yaml-cli/README.md +146 -0
  156. package/examples/yaml-cli/bench.mjs +265 -0
  157. package/examples/yaml-cli/main.ts +29 -0
  158. package/examples/yaml-cli/parity.mjs +156 -0
  159. package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
  160. package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
  161. package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
  162. package/govendor/github.com/jchv/go-webview2/README.md +21 -0
  163. package/govendor/github.com/jchv/go-webview2/common.go +84 -0
  164. package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
  165. package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
  166. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
  167. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
  168. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
  169. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
  170. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
  171. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
  172. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
  173. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
  174. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
  175. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
  176. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
  177. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
  178. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
  179. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
  180. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
  181. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
  182. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
  183. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
  184. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
  185. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
  186. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
  187. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
  188. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
  189. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
  190. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
  191. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
  192. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
  193. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
  194. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
  195. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
  196. package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
  197. package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
  198. package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
  199. package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
  200. package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
  201. package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
  202. package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
  203. package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
  204. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
  205. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
  206. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
  207. package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
  208. package/govendor/github.com/jchv/go-winloader/README.md +124 -0
  209. package/govendor/github.com/jchv/go-winloader/common.go +11 -0
  210. package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
  211. package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
  212. package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
  213. package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
  214. package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
  215. package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
  216. package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
  217. package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
  218. package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
  219. package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
  220. package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
  221. package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
  222. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
  223. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
  224. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
  225. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
  226. package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
  227. package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
  228. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
  229. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
  230. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
  231. package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
  232. package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
  233. package/govendor/manifest.txt +3 -1
  234. package/package.json +8 -5
  235. package/performance/README.md +195 -0
  236. package/performance/any-dynamic.ts +21 -0
  237. package/performance/any-record-view.ts +20 -0
  238. package/performance/arr-hof.ts +21 -0
  239. package/performance/arr-push-index.ts +15 -0
  240. package/performance/arr-sort.ts +21 -0
  241. package/performance/async-await.ts +24 -0
  242. package/performance/class-dispatch.ts +52 -0
  243. package/performance/events-emit.ts +27 -0
  244. package/performance/exc-throw-rare.ts +25 -0
  245. package/performance/exc-try-catch.ts +26 -0
  246. package/performance/fn-closures.ts +29 -0
  247. package/performance/fn-recursion-tree.ts +31 -0
  248. package/performance/gen-for-of.ts +46 -0
  249. package/performance/json-roundtrip.ts +27 -0
  250. package/performance/map-delete.ts +24 -0
  251. package/performance/map-string-keys.ts +22 -0
  252. package/performance/num-arith-loop.ts +14 -0
  253. package/performance/num-bitwise.ts +21 -0
  254. package/performance/num-mod-int.ts +16 -0
  255. package/performance/num-to-string.ts +16 -0
  256. package/performance/obj-alloc.ts +32 -0
  257. package/performance/regex-exec.ts +29 -0
  258. package/performance/regex-site.ts +28 -0
  259. package/performance/set-ops.ts +20 -0
  260. package/performance/str-char-scan.ts +35 -0
  261. package/performance/str-concat-plus.ts +18 -0
  262. package/performance/str-concat.ts +24 -0
  263. package/performance/str-short-scan.ts +26 -0
  264. package/performance/str-split-join.ts +23 -0
  265. package/performance/str-template.ts +16 -0
  266. package/performance/union-switch.ts +57 -0
  267. package/tsparser/check.go +2 -1
  268. package/tsparser/main.go +5 -0
  269. package/types/typenative-npm.d.ts +193 -4
  270. package/types/typenative.d.ts +138 -41
@@ -0,0 +1,25 @@
1
+ // perf: `try`/`catch`/`finally` in a hot loop where nothing throws
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ function step(i: number): number {
5
+ if (i < 0) throw new Error('negative');
6
+ return i & 255;
7
+ }
8
+
9
+ const n = 50_000_000;
10
+ const start = performance.now();
11
+ let total = 0;
12
+ let cleanups = 0;
13
+ for (let i = 0; i < n; i++) {
14
+ try {
15
+ total += step(i);
16
+ } catch (e) {
17
+ total -= 1;
18
+ } finally {
19
+ cleanups++;
20
+ }
21
+ }
22
+ const elapsed = performance.now() - start;
23
+
24
+ console.log(`checksum: ${total + cleanups}`);
25
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,26 @@
1
+ // perf: `try`/`catch`/`finally` in a hot loop where one call in 1,024 throws
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ function risky(i: number): number {
5
+ if ((i & 1023) === 0) throw new Error('bad ' + i);
6
+ return i & 7;
7
+ }
8
+
9
+ const n = 10_000_000;
10
+
11
+ const start = performance.now();
12
+ let total = 0;
13
+ let caught = 0;
14
+ for (let i = 0; i < n; i++) {
15
+ try {
16
+ total += risky(i);
17
+ } catch (e) {
18
+ caught++;
19
+ } finally {
20
+ total++;
21
+ }
22
+ }
23
+ const elapsed = performance.now() - start;
24
+
25
+ console.log(`checksum: ${total + caught}`);
26
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,29 @@
1
+ // perf: creating closures over mutable state and calling them indirectly
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ function makeCounter(step: number): () => number {
5
+ let count = 0;
6
+ return () => {
7
+ count += step;
8
+ return count;
9
+ };
10
+ }
11
+
12
+ function apply(f: (x: number) => number, x: number): number {
13
+ return f(x);
14
+ }
15
+
16
+ const n = 12_000_000;
17
+
18
+ const start = performance.now();
19
+ let total = 0;
20
+ for (let i = 0; i < n; i++) {
21
+ const next = makeCounter(i & 3);
22
+ next();
23
+ total += next();
24
+ total += apply((x) => x + (i & 1), 1);
25
+ }
26
+ const elapsed = performance.now() - start;
27
+
28
+ console.log(`checksum: ${total}`);
29
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,31 @@
1
+ // perf: building and walking binary trees (recursion plus allocation)
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ class TreeNode {
5
+ left: TreeNode | null;
6
+ right: TreeNode | null;
7
+ constructor(left: TreeNode | null, right: TreeNode | null) {
8
+ this.left = left;
9
+ this.right = right;
10
+ }
11
+ }
12
+
13
+ function make(depth: number): TreeNode {
14
+ return depth === 0 ? new TreeNode(null, null) : new TreeNode(make(depth - 1), make(depth - 1));
15
+ }
16
+
17
+ function check(node: TreeNode): number {
18
+ if (node.left === null || node.right === null) return 1;
19
+ return 1 + check(node.left) + check(node.right);
20
+ }
21
+
22
+ const start = performance.now();
23
+ let total = 0;
24
+ for (let depth = 4; depth <= 16; depth += 2) {
25
+ const iterations = 1 << (16 - depth + 4);
26
+ for (let i = 0; i < iterations; i++) total += check(make(depth));
27
+ }
28
+ const elapsed = performance.now() - start;
29
+
30
+ console.log(`checksum: ${total}`);
31
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,46 @@
1
+ // perf: sync generators (a method, `*[Symbol.iterator]()`, `yield*`) consumed by `for…of`
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ class Op {
5
+ value: number;
6
+ constructor(value: number) {
7
+ this.value = value;
8
+ }
9
+ }
10
+
11
+ class OpList {
12
+ private items: Op[] = [];
13
+ push(op: Op): void {
14
+ this.items.push(op);
15
+ }
16
+ *[Symbol.iterator](): Generator<Op> {
17
+ for (let i = 0; i < this.items.length; i++) yield this.items[i];
18
+ }
19
+ *reversed(): Generator<Op> {
20
+ for (let i = this.items.length - 1; i >= 0; i--) yield this.items[i];
21
+ }
22
+ }
23
+
24
+ function* range(n: number): Generator<number> {
25
+ for (let i = 0; i < n; i++) yield i;
26
+ }
27
+
28
+ function* both(list: OpList): Generator<Op> {
29
+ yield* list.reversed();
30
+ }
31
+
32
+ const list = new OpList();
33
+ for (let i = 0; i < 2000; i++) list.push(new Op(i));
34
+
35
+ const start = performance.now();
36
+ let total = 0;
37
+ for (let pass = 0; pass < 500; pass++) {
38
+ for (const op of list) total += op.value;
39
+ for (const op of list.reversed()) total -= op.value >> 1;
40
+ for (const i of range(2000)) total += i & 7;
41
+ for (const op of both(list)) total += op.value & 3;
42
+ }
43
+ const elapsed = performance.now() - start;
44
+
45
+ console.log(`checksum: ${total}`);
46
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,27 @@
1
+ // perf: `JSON.stringify` and `JSON.parse` of an array of nested objects
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ interface Item {
5
+ id: number;
6
+ name: string;
7
+ price: number;
8
+ tags: string[];
9
+ dims: { w: number; h: number };
10
+ }
11
+
12
+ const items: Item[] = [];
13
+ for (let i = 0; i < 5000; i++) {
14
+ items.push({ id: i, name: `item "${i}"`, price: i * 1.25, tags: ['x', 'y' + (i % 9)], dims: { w: i % 50, h: 3 } });
15
+ }
16
+
17
+ const start = performance.now();
18
+ let total = 0;
19
+ for (let pass = 0; pass < 20; pass++) {
20
+ const text = JSON.stringify(items);
21
+ const back = JSON.parse(text) as Item[];
22
+ total += text.length + back.length + back[pass].dims.w;
23
+ }
24
+ const elapsed = performance.now() - start;
25
+
26
+ console.log(`checksum: ${total}`);
27
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,24 @@
1
+ // perf: `Map<string, number>` insert/delete churn (an LRU-style sliding window)
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const keys: string[] = [];
5
+ for (let i = 0; i < 4096; i++) keys.push(`key-${i}`);
6
+ const window = 2048;
7
+ const n = 1_000_000;
8
+
9
+ const start = performance.now();
10
+ const m = new Map<string, number>();
11
+ let total = 0;
12
+ for (let i = 0; i < n; i++) {
13
+ m.set(keys[i & 4095], i);
14
+ if (i >= window) {
15
+ const old = keys[(i - window) & 4095];
16
+ if (m.delete(old)) total++;
17
+ }
18
+ if (m.has(keys[(i * 7) & 4095])) total += 2;
19
+ }
20
+ for (const [, v] of m) total += v & 15;
21
+ const elapsed = performance.now() - start;
22
+
23
+ console.log(`checksum: ${total * 10 + m.size}`);
24
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,22 @@
1
+ // perf: `Map<string, number>` `set` / `get` / `has` word counting
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const keys: string[] = [];
5
+ for (let i = 0; i < 50_000; i++) keys.push('word' + ((i * 7) % 20_000));
6
+
7
+ const start = performance.now();
8
+ let hits = 0;
9
+ for (let pass = 0; pass < 30; pass++) {
10
+ const counts = new Map<string, number>();
11
+ for (const k of keys) {
12
+ counts.set(k, (counts.get(k) ?? 0) + 1);
13
+ }
14
+ for (let i = 0; i < 25_000; i++) {
15
+ if (counts.has('word' + i)) hits++;
16
+ }
17
+ hits += counts.size;
18
+ }
19
+ const elapsed = performance.now() - start;
20
+
21
+ console.log(`checksum: ${hits}`);
22
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,14 @@
1
+ // perf: tight float64 loop with `%`, `*` and `Math.floor`
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const n = 50_000_000;
5
+
6
+ const start = performance.now();
7
+ let sum = 0;
8
+ for (let i = 0; i < n; i++) {
9
+ sum += Math.floor((i * 31) / 7) % 13;
10
+ }
11
+ const elapsed = performance.now() - start;
12
+
13
+ console.log(`checksum: ${sum}`);
14
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,21 @@
1
+ // perf: bitwise and, or, xor and shifts (`<<`, `>>`, `>>>`) on integers, and flag tests
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const F_A = 1 << 0;
5
+ const F_B = 1 << 3;
6
+ const F_C = 1 << 7;
7
+ const n = 20_000_000;
8
+
9
+ const start = performance.now();
10
+ let acc = 0;
11
+ let hits = 0;
12
+ for (let i = 0; i < n; i++) {
13
+ const flags = (i ^ (i >> 3)) & 0xff;
14
+ if ((flags & F_A) !== 0) hits++;
15
+ if ((flags & (F_B | F_C)) === F_B) hits += 2;
16
+ acc = (acc + ((i << 2) | (flags >>> 1))) & 0xffffff;
17
+ }
18
+ const elapsed = performance.now() - start;
19
+
20
+ console.log(`checksum: ${acc * 1000 + hits}`);
21
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,16 @@
1
+ // perf: `%` on integer operands (hash buckets, cycling indexes)
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const n = 20_000_000;
5
+
6
+ const start = performance.now();
7
+ let sum = 0;
8
+ let k = 7;
9
+ for (let i = 0; i < n; i++) {
10
+ sum += (i * 31 + k) % 1009;
11
+ k = (k + i) % 97;
12
+ }
13
+ const elapsed = performance.now() - start;
14
+
15
+ console.log(`checksum: ${sum}`);
16
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,16 @@
1
+ // perf: number/string conversion: `String(n)`, `toFixed`, `Number(str)`, `parseInt`
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const n = 1_000_000;
5
+
6
+ const start = performance.now();
7
+ let sum = 0;
8
+ for (let i = 0; i < n; i++) {
9
+ const s = String(i * 3);
10
+ const f = (i / 8).toFixed(2);
11
+ sum += s.length + f.length + Number(s) + parseInt(f, 10);
12
+ }
13
+ const elapsed = performance.now() - start;
14
+
15
+ console.log(`checksum: ${sum}`);
16
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,32 @@
1
+ // perf: allocating many short-lived object literals and class instances
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ interface Point {
5
+ x: number;
6
+ y: number;
7
+ }
8
+
9
+ class Vec {
10
+ x: number;
11
+ y: number;
12
+ constructor(x: number, y: number) {
13
+ this.x = x;
14
+ this.y = y;
15
+ }
16
+ }
17
+
18
+ const n = 15_000_000;
19
+
20
+ const start = performance.now();
21
+ let sum = 0;
22
+ const keep: Point[] = [];
23
+ for (let i = 0; i < n; i++) {
24
+ const p: Point = { x: i, y: i * 2 };
25
+ const v = new Vec(p.y, p.x);
26
+ sum += v.x - v.y;
27
+ if ((i & 127) === 0) keep.push(p);
28
+ }
29
+ const elapsed = performance.now() - start;
30
+
31
+ console.log(`checksum: ${sum + keep.length}`);
32
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,29 @@
1
+ // perf: regex `test`, `exec` with groups and global `replace` over log lines
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const lines: string[] = [];
5
+ for (let i = 0; i < 5000; i++) {
6
+ const day = String((i % 28) + 1).padStart(2, '0');
7
+ const minute = String(i % 60).padStart(2, '0');
8
+ const level = i % 3 === 0 ? 'ERROR' : 'INFO';
9
+ lines.push(`2026-11-${day} 12:${minute} [${level}] user=${i} took ${i % 997}ms path=/api/v1/items/${i}`);
10
+ }
11
+
12
+ const lineRe = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}) \[(\w+)\] user=(\d+) took (\d+)ms/;
13
+ const errorRe = /\[ERROR\]/;
14
+ const idRe = /\/(\d+)/g;
15
+
16
+ const start = performance.now();
17
+ let total = 0;
18
+ for (let pass = 0; pass < 60; pass++) {
19
+ for (const line of lines) {
20
+ const m = lineRe.exec(line);
21
+ if (m !== null) total += Number(m[8]) + m[6].length;
22
+ if (errorRe.test(line)) total++;
23
+ total += line.replace(idRe, '/:id').length;
24
+ }
25
+ }
26
+ const elapsed = performance.now() - start;
27
+
28
+ console.log(`checksum: ${total}`);
29
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,28 @@
1
+ // perf: `/g` regex literals evaluated inside a hot function, and `.index` on long input
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ function tokenize(line: string): number {
5
+ let count = 0;
6
+ const word = /[A-Za-z_]\w*/g;
7
+ let m: RegExpExecArray | null;
8
+ while ((m = word.exec(line)) !== null) count += m[0].length;
9
+ if (/^\s*#/.test(line)) count += 100;
10
+ return count;
11
+ }
12
+
13
+ const lines: string[] = [];
14
+ for (let i = 0; i < 2000; i++) lines.push(` item_${i} = compute(alpha, beta_${i & 7}) # note ${i}`);
15
+ const doc = lines.join('\n');
16
+
17
+ const start = performance.now();
18
+ let total = 0;
19
+ for (let pass = 0; pass < 200; pass++) {
20
+ for (const line of lines) total += tokenize(line);
21
+ }
22
+ const marker = /compute\(alpha, beta_3\)/g;
23
+ let m: RegExpExecArray | null;
24
+ while ((m = marker.exec(doc)) !== null) total += m.index & 1023;
25
+ const elapsed = performance.now() - start;
26
+
27
+ console.log(`checksum: ${total}`);
28
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,20 @@
1
+ // perf: `Set<number>` `add` / `has` / `delete` on a 16,384-entry set
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const passes = 10;
5
+ const n = 100_000;
6
+
7
+ const start = performance.now();
8
+ let total = 0;
9
+ for (let pass = 0; pass < passes; pass++) {
10
+ const s = new Set<number>();
11
+ for (let i = 0; i < n; i++) s.add((i * 13 + pass) & 16383);
12
+ let hits = 0;
13
+ for (let i = 0; i < n; i++) if (s.has(i)) hits++;
14
+ for (let i = 0; i < n; i += 2) s.delete(i);
15
+ total += hits * 10 + s.size;
16
+ }
17
+ const elapsed = performance.now() - start;
18
+
19
+ console.log(`checksum: ${total}`);
20
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,35 @@
1
+ // perf: lexer-style scan of a large string with `charCodeAt` and `str[i]`
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const chunk = 'let value_1 = foo(bar, 42) + "text" * 3.5; // comment\n';
5
+ let text = '';
6
+ for (let i = 0; i < 40_000; i++) text += chunk;
7
+
8
+ const start = performance.now();
9
+ let idents = 0;
10
+ let digits = 0;
11
+ let quotes = 0;
12
+ for (let pass = 0; pass < 15; pass++) {
13
+ let i = 0;
14
+ while (i < text.length) {
15
+ const c = text.charCodeAt(i);
16
+ if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90) || c === 95) {
17
+ while (i < text.length) {
18
+ const d = text.charCodeAt(i);
19
+ if (!((d >= 97 && d <= 122) || (d >= 65 && d <= 90) || d === 95 || (d >= 48 && d <= 57))) break;
20
+ i++;
21
+ }
22
+ idents++;
23
+ } else if (c >= 48 && c <= 57) {
24
+ digits++;
25
+ i++;
26
+ } else {
27
+ if (text[i] === '"') quotes++;
28
+ i++;
29
+ }
30
+ }
31
+ }
32
+ const elapsed = performance.now() - start;
33
+
34
+ console.log(`checksum: ${idents * 1000000 + digits * 1000 + quotes}`);
35
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,18 @@
1
+ // perf: growing strings with `s = s + x` (not `+=`), each pass starting empty
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const passes = 1000;
5
+
6
+ const start = performance.now();
7
+ let total = 0;
8
+ for (let pass = 0; pass < passes; pass++) {
9
+ let lines = '';
10
+ for (let i = 0; i < 3000; i++) {
11
+ lines = lines + 'line ' + i + '\n';
12
+ }
13
+ total += lines.length;
14
+ }
15
+ const elapsed = performance.now() - start;
16
+
17
+ console.log(`checksum: ${total}`);
18
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,24 @@
1
+ // perf: growing ~20 KB strings with `s += x` and `s = s + …` (each pass starts empty)
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const passes = 400;
5
+ const words = ['alpha', 'beta', 'gamma', 'delta'];
6
+
7
+ const start = performance.now();
8
+ let total = 0;
9
+ for (let pass = 0; pass < passes; pass++) {
10
+ let out = '';
11
+ for (let i = 0; i < 3000; i++) {
12
+ out += words[i & 3];
13
+ out += ' ';
14
+ }
15
+ let lines = '';
16
+ for (let i = 0; i < 300; i++) {
17
+ lines = lines + 'line ' + i + '\n';
18
+ }
19
+ total += out.length + lines.length;
20
+ }
21
+ const elapsed = performance.now() - start;
22
+
23
+ console.log(`checksum: ${total}`);
24
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,26 @@
1
+ // perf: `charCodeAt(i)` / `s[i]` scans of many short (< 512 byte) lines
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const lines: string[] = [];
5
+ for (let i = 0; i < 2000; i++) {
6
+ lines.push(` key_${i}: value ${i * 3} "quoted text" # a comment that pads the line out a bit more ${i}`);
7
+ }
8
+
9
+ const start = performance.now();
10
+ let idents = 0;
11
+ let digits = 0;
12
+ let quotes = 0;
13
+ for (let pass = 0; pass < 100; pass++) {
14
+ for (const line of lines) {
15
+ for (let i = 0; i < line.length; i++) {
16
+ const c = line.charCodeAt(i);
17
+ if ((c >= 97 && c <= 122) || c === 95) idents++;
18
+ else if (c >= 48 && c <= 57) digits++;
19
+ else if (line[i] === '"') quotes++;
20
+ }
21
+ }
22
+ }
23
+ const elapsed = performance.now() - start;
24
+
25
+ console.log(`checksum: ${idents * 1000000 + digits * 1000 + quotes}`);
26
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,23 @@
1
+ // perf: `split`, `join`, `indexOf`, `slice` and `trim` on CSV-like lines
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const lines: string[] = [];
5
+ for (let i = 0; i < 1000; i++) lines.push(` id${i}, name ${i}, ${i * 7}, tag-${i % 17}, done `);
6
+ const csv = lines.join('\n');
7
+
8
+ const start = performance.now();
9
+ let sum = 0;
10
+ for (let pass = 0; pass < 200; pass++) {
11
+ const rows = csv.split('\n');
12
+ for (const row of rows) {
13
+ const cells = row.split(',');
14
+ sum += cells.length;
15
+ const tag = cells[3].trim();
16
+ sum += tag.slice(tag.indexOf('-') + 1).length;
17
+ sum += cells.map((c) => c.trim()).join('|').length;
18
+ }
19
+ }
20
+ const elapsed = performance.now() - start;
21
+
22
+ console.log(`checksum: ${sum}`);
23
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,16 @@
1
+ // perf: template literals mixing strings, integers, floats and booleans
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ const n = 1_000_000;
5
+ const names = ['ada', 'grace', 'linus', 'ken'];
6
+
7
+ const start = performance.now();
8
+ let total = 0;
9
+ for (let i = 0; i < n; i++) {
10
+ const s = `${names[i & 3]}#${i}: ${i / 4} items, ok=${(i & 1) === 0}`;
11
+ total += s.length;
12
+ }
13
+ const elapsed = performance.now() - start;
14
+
15
+ console.log(`checksum: ${total}`);
16
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
@@ -0,0 +1,57 @@
1
+ // perf: evaluating an expression tree of a discriminated union with `switch (e.kind)`
2
+ import { performance } from 'node:perf_hooks';
3
+
4
+ interface Num {
5
+ kind: 'num';
6
+ value: number;
7
+ }
8
+ interface Add {
9
+ kind: 'add';
10
+ left: Expr;
11
+ right: Expr;
12
+ }
13
+ interface Mul {
14
+ kind: 'mul';
15
+ left: Expr;
16
+ right: Expr;
17
+ }
18
+ interface Neg {
19
+ kind: 'neg';
20
+ operand: Expr;
21
+ }
22
+ type Expr = Num | Add | Mul | Neg;
23
+
24
+ function build(depth: number, seed: number): Expr {
25
+ if (depth === 0) return { kind: 'num', value: (seed % 10) + 1 };
26
+ switch (seed % 3) {
27
+ case 0:
28
+ return { kind: 'add', left: build(depth - 1, seed * 3 + 1), right: build(depth - 1, seed + 7) };
29
+ case 1:
30
+ return { kind: 'mul', left: build(depth - 1, seed + 2), right: build(depth - 1, seed * 7 + 3) };
31
+ default:
32
+ return { kind: 'neg', operand: build(depth - 1, seed + 5) };
33
+ }
34
+ }
35
+
36
+ function evaluate(e: Expr): number {
37
+ switch (e.kind) {
38
+ case 'num':
39
+ return e.value;
40
+ case 'add':
41
+ return (evaluate(e.left) + evaluate(e.right)) % 1009;
42
+ case 'mul':
43
+ return ((evaluate(e.left) * evaluate(e.right)) % 1009) + 1;
44
+ case 'neg':
45
+ return 1010 - evaluate(e.operand);
46
+ }
47
+ }
48
+
49
+ const tree = build(18, 1);
50
+
51
+ const start = performance.now();
52
+ let total = 0;
53
+ for (let i = 0; i < 20; i++) total += evaluate(tree);
54
+ const elapsed = performance.now() - start;
55
+
56
+ console.log(`checksum: ${total}`);
57
+ console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
package/tsparser/check.go CHANGED
@@ -86,7 +86,8 @@ func runCheck(entry string, typesDir string) {
86
86
  }
87
87
  } else {
88
88
  options = &core.CompilerOptions{
89
- Target: core.ScriptTargetES2020,
89
+ Target: core.ScriptTargetES2025,
90
+ UseDefineForClassFields: core.TSFalse,
90
91
  Module: core.ModuleKindESNext,
91
92
  ModuleResolution: core.ModuleResolutionKindBundler,
92
93
  Lib: []string{},
package/tsparser/main.go CHANGED
@@ -221,6 +221,10 @@ func setPosition(n *ast.Node, obj map[string]any) {
221
221
  line, character := scanner.GetECMALineAndUTF16CharacterOfPosition(parsedFile, scanner.GetTokenPosOfNode(n, parsedFile, false))
222
222
  obj["line"] = line + 1
223
223
  obj["column"] = int(character) + 1
224
+ // where it ends (exclusive): node:test coverage ranges
225
+ endLine, endCharacter := scanner.GetECMALineAndUTF16CharacterOfPosition(parsedFile, n.End())
226
+ obj["endLine"] = endLine + 1
227
+ obj["endColumn"] = int(endCharacter) + 1
224
228
  }
225
229
 
226
230
  // collectFields serializes a typed data struct's fields into obj, recursing
@@ -355,4 +359,5 @@ func lowerFirst(s string) string {
355
359
  // Field renames to match the TypeScript API's names.
356
360
  var fieldRenames = map[string]string{
357
361
  "PostfixToken": "questionToken", // optional property `a?: string`
362
+ "DefaultType": "default", // type parameter default `<S = any>`
358
363
  }