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
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TypeNative
2
2
 
3
- TypeNative is a TypeScript-to-Go transpiler, it turns TypeScript into Go code and compiles it to a single-file native executable — no Node.js runtime, no bundler, just a binary. Write TypeScript, ship native binaries.
3
+ TypeNative is a TypeScript-to-Go transpiler, it turns TypeScript into Go code and compiles it to a single-file native executable, no Node.js runtime, no bundler, just a binary. Write TypeScript, ship native binaries.
4
4
 
5
5
  ```ts
6
6
  // hello.ts
@@ -18,6 +18,7 @@ npx typenative --source hello.ts --script
18
18
 
19
19
  ## Contents
20
20
 
21
+ - [Why use TypeNative](#why-use-typenative)
21
22
  - [Requirements](#requirements)
22
23
  - [Install](#install)
23
24
  - [Quick start](#quick-start)
@@ -29,9 +30,20 @@ npx typenative --source hello.ts --script
29
30
  - [Self-hosted native compiler](#self-hosted-native-compiler)
30
31
  - [License](#license)
31
32
 
33
+ ## Why use TypeNative
34
+
35
+ - **Ship one file.** The output is a single self-contained executable: no Node.js install, no `node_modules`, no bundler. Copy it to a server and run it, or cross-compile for Linux, macOS and Windows from any OS with `--target`.
36
+ - **Start instantly.** There is no runtime to boot and no JIT to warm up: a hello world starts in ~7 ms vs ~60 ms under Node, which matters for CLI tools that run often.
37
+ - **Run faster.** Code is compiled ahead of time to machine code through Go. CPU-bound work like recursive `fib(35)` runs ~2x faster than Node, and hashing a directory tree of files runs ~3x faster.
38
+ - **Keep your TypeScript.** Same syntax, same types, and Node's own APIs (`node:fs`, `node:http`, `node:crypto`, …) with Node's signatures. The [examples](examples/) run unchanged under both `node` and TypeNative.
39
+ - **Reach into Go.** Import any Go package directly (`import { Println } from 'go:fmt'`) when you need something Node doesn't have.
40
+ - **Know what works.** Type errors and unsupported syntax are reported against your `.ts` lines before anything builds, and every supported feature is backed by a runnable probe in [conformance.md](conformance.md).
41
+
42
+ Numbers are medians from the [examples/](examples/) benchmarks (Windows 11, Ryzen 5 7600, Node 26, Go 1.27); each example's README has the full methodology. TypeNative compiles a subset of TypeScript, so it fits best for CLIs, servers and tools where you control the code, rather than for running arbitrary existing npm projects.
43
+
32
44
  ## Requirements
33
45
 
34
- - [Node.js v24](https://nodejs.org/en) or newer.
46
+ - [Node.js v26](https://nodejs.org/en) or newer.
35
47
  - [Go 1.26](https://go.dev/doc/install) or newer
36
48
 
37
49
  ## Install
@@ -104,7 +116,8 @@ Scaffolded `tsconfig.json` targets the TypeNative type surface:
104
116
  ```json
105
117
  {
106
118
  "compilerOptions": {
107
- "target": "es2020",
119
+ "target": "es2025",
120
+ "useDefineForClassFields": false,
108
121
  "lib": [],
109
122
  "types": ["typenative", "typenative/go", "typenative/npm"],
110
123
  "strict": true
@@ -112,22 +125,25 @@ Scaffolded `tsconfig.json` targets the TypeNative type surface:
112
125
  }
113
126
  ```
114
127
 
115
- `lib: []` disables the standard TypeScript libraries, so `typenative`'s own declarations are the entire type surface — the compiler only accepts what actually transpiles.
128
+ `lib: []` disables the standard TypeScript libraries, so `typenative`'s own declarations are the entire type surface, the compiler only accepts what actually transpiles.
129
+
130
+ `useDefineForClassFields: false` keeps TypeScript's classic class-field order, which is the order TypeNative compiles: `super()`, then parameter properties, then field initializers, then the constructor body. Without it, any target from ES2022 on switches to native class-field semantics, and a field initializer that reads a parameter property (`doubled = this.k * 2` with `constructor(public k: number)`) becomes a type error.
116
131
 
117
132
  ## CLI reference
118
133
 
119
- | Flag | Mode | Description |
120
- | ----------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
121
- | `--source <file>` | build / script | TypeScript entry file. Relative imports (`./util`) and npm packages are resolved from its directory. |
122
- | `--output <path>` | build | Where to copy the compiled binary. If omitted with `--script`, the temp binary in `dist/` is executed and kept there. |
123
- | `--script` | run | Build to `dist/native(.exe)` and execute immediately with inherited stdio. Combine with `--source`, or omit `--source` to type code into the prompt. |
124
- | `--new` | scaffold | Create a new project directory (`main.ts`, `package.json`, `tsconfig.json`, `README.md`, `.gitignore`). |
125
- | `--no-typecheck` | build / script | Skip the type-check that runs before transpiling. |
126
- | `--target <os/arch>` | build | Cross-compile for another platform (`linux/amd64`, `linux/arm64`, `darwin/arm64`, `windows/amd64`, … — `go tool dist list` shows every pair). `--script` only runs host builds. |
127
- | `--release` | build / script | Smaller binary: strips symbols and file paths (`-trimpath -ldflags="-s -w"`). |
128
- | `--emit-go <dir>` | build | Write the generated Go (`code.go`, `go.mod`, vendored modules) to `<dir>` instead of building; `go build -C <dir>` builds it. |
129
- | `-h`, `--help` | | Print the options. |
130
- | `-v`, `--version` | | Print the TypeNative version. |
134
+ | Flag | Mode | Description |
135
+ | -------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
136
+ | `--source <file>` | build / script | TypeScript entry file. Relative imports (`./util`) and npm packages are resolved from its directory. |
137
+ | `--output <path>` | build | Where to copy the compiled binary. If omitted with `--script`, the temp binary in `dist/` is executed and kept there. |
138
+ | `--script` | run | Build to `dist/native(.exe)` and execute immediately with inherited stdio. Combine with `--source`, or omit `--source` to type code into the prompt. |
139
+ | `--new` | scaffold | Create a new project directory (`main.ts`, `package.json`, `tsconfig.json`, `README.md`, `.gitignore`). |
140
+ | `--no-typecheck` | build / script | Skip the type-check that runs before transpiling. |
141
+ | `--target <os/arch>` | build | Cross-compile for another platform (`linux/amd64`, `linux/arm64`, `darwin/arm64`, `windows/amd64`, … `go tool dist list` shows every pair). `--script` only runs host builds. |
142
+ | `--release` | build / script | Smaller binary: strips symbols and file paths (`-trimpath -ldflags="-s -w"`). |
143
+ | `--gui` | build / script | A windowed app: no console window on Windows (`-ldflags=-H=windowsgui`). Ignored for other targets. |
144
+ | `--emit-go <dir>` | build | Write the generated Go (`code.go`, `go.mod`, vendored modules) to `<dir>` instead of building; `go build -C <dir>` builds it. |
145
+ | `-h`, `--help` | | Print the options. |
146
+ | `-v`, `--version` | | Print the TypeNative version. |
131
147
 
132
148
  The entry file can also be the last argument (`typenative main.ts --script`), and every option accepts `--flag=value`. Unknown options are an error (exit code `2`). Before building, the CLI checks that Go 1.26 or newer is on the `PATH`.
133
149
 
@@ -142,7 +158,7 @@ Errors point at your TypeScript, not the generated Go: `dist/code.go` carries Go
142
158
 
143
159
  ## Writing TypeNative-compatible TypeScript
144
160
 
145
- TypeNative supports a growing subset of TypeScript, not the whole language. The source of truth is [conformance.md](conformance.md) — every supported feature links to a runnable probe in [conformance/](conformance/).
161
+ TypeNative supports a growing subset of TypeScript, not the whole language. The source of truth is [conformance.md](conformance.md). Every supported feature links to a runnable probe in [conformance/](conformance/).
146
162
 
147
163
  **Language highlights that work today:**
148
164
 
@@ -169,7 +185,7 @@ TypeNative supports a growing subset of TypeScript, not the whole language. The
169
185
  | `JSON` | `parse` / `stringify` |
170
186
  | `RegExp` | Literals + `new RegExp()`, `test()`, `exec()` with named groups (`.groups`), flags `i`/`m`/`s`/`g`/`y`/`u`, stateful `lastIndex` for `/g` loops, `source`/`flags`/`global`/... properties. Backreferences, lookahead and lookbehind run on a small backtracking engine (RE2 does not support them) |
171
187
  | Globals | `setTimeout`/`clearTimeout`, `setInterval`/`clearInterval`, `queueMicrotask`, `structuredClone`, `globalThis`, `encodeURIComponent`/`decodeURIComponent`, `isNaN`/`isFinite`, `NaN`/`Infinity` |
172
- | `process` | `argv`, `platform` (→ Node-style names), `env`, `cwd`, `exit`, `exitCode`, `hrtime`, `stdout`/`stderr`/`stdin`, `on('exit')`, … (see [node:process](conformance.md#nodeprocess)) |
188
+ | `process` | `argv`, `platform` (→ Node-style names), `env`, `cwd`, `exit`, `exitCode`, `hrtime`, `stdout`/`stderr`/`stdin`, `on('exit')`, … (see [node:process](conformance.md#nodeprocess)) |
173
189
 
174
190
  **Node built-ins (import with the `node:` prefix, mapped to Go helpers):**
175
191
 
@@ -195,7 +211,7 @@ import { ToUpper } from 'go:strings';
195
211
  Println(Sprintf('hi %s', ToUpper('bob')));
196
212
  ```
197
213
 
198
- Any Go package can be imported this way (`import { X } from 'go:pkg'` → `pkg.X` with numeric conversion and throw-on-error results). The full standard library is declared for typechecking (`npm run gen:go`), with 154 packages probed — see [conformance.md](conformance.md#go-bridges-gostar).
214
+ Any Go package can be imported this way (`import { X } from 'go:pkg'` → `pkg.X` with numeric conversion and throw-on-error results). The full standard library is declared for typechecking (`npm run gen:go`), with 154 packages probed, see [conformance.md](conformance.md#go-bridges-gostar).
199
215
 
200
216
  **npm packages:**
201
217
 
@@ -247,9 +263,39 @@ c.inc();
247
263
  console.log(`count=${c.count} seen=${seen.get('a')}`);
248
264
  ```
249
265
 
250
- Complete, runnable projects — including Node-vs-TypeNative benchmarks for
251
- each — live in [examples/](examples/): a hello world (startup), a recursive
252
- fibonacci (CPU), and a JSON web server (`node:http` GET/POST).
266
+ A desktop app with a webview window:
267
+
268
+ ```ts
269
+ import { Application } from '@webviewjs/webview';
270
+
271
+ const app = new Application();
272
+ const win = app.createBrowserWindow({ title: 'Hello', width: 800, height: 600, logical: true });
273
+ win.createWebview({ html: '<h1>Hello from a native window</h1>' });
274
+ app.run();
275
+ ```
276
+
277
+ ```sh
278
+ npx typenative --source app.ts --output hello.exe --gui --release
279
+ ```
280
+
281
+ The same source runs under Node.js with the
282
+ [`@webviewjs/webview`](https://www.npmjs.com/package/@webviewjs/webview) npm
283
+ package; compiled programs need neither the package nor a C toolchain. On
284
+ Windows the window embeds the system WebView2. On macOS and Linux, and on
285
+ Windows without the WebView2 runtime, it's Chrome, Edge or Chromium in app mode.
286
+ [conformance.md](conformance.md#native-app-windows-webviewjswebview) lists the
287
+ supported API, and [desktop-notes](examples/desktop-notes/) is a complete app.
288
+
289
+ Complete, runnable projects, including Node-vs-TypeNative benchmarks for
290
+ each, live in [examples/](examples/). The flagships are
291
+ [yaml-cli](examples/yaml-cli/): the `yaml` package's own CLI compiled from its
292
+ unmodified source, matching Node's output on all 1,608 yaml-test-suite cases,
293
+ and [marked-cli](examples/marked-cli/): the `marked` markdown parser's CLI,
294
+ also from unmodified source, matching Node on all 2,859 cases of marked's spec
295
+ suites (CommonMark, GFM, its own tests and ReDoS inputs). The newest,
296
+ [react-compiler](examples/react-compiler/), compiles the React Compiler
297
+ itself (`babel-plugin-react-compiler` on Babel 7.29 and zod 4 — the largest
298
+ codebase yet) and is one runtime gap away from its benchmarks.
253
299
 
254
300
  ## How it works
255
301
 
@@ -266,9 +312,11 @@ main.ts --(type-check)--(parse)--> normalized JSON AST --(transpileToNative)-->
266
312
 
267
313
  `npm test` is `npm run conformance`: every `conformance/*.ts` probe is type-checked, transpiled, built with `go`, executed, and must exit `0` (`npm run conformance:parallel` runs them concurrently). Results print per category (`syntax` / `semantics` / `lib`) plus a total pass rate; any failure exits non-zero and lists the first diagnostic line (`*.go:line`, `panic:`, `Unsupported syntax`, `Error`).
268
314
 
269
- CI (`.github/workflows/ci.yml`) runs `npm run build`, `npm run check:go-types` and the conformance suite on Ubuntu, Windows and macOS with Node 24 and Go 1.26, and a Linux job that builds the self-hosted compiler, checks the bootstrap fixpoint (`npm run bootstrap:check`) and runs the suite through it. Releases are cut from `TypeNative_*` tags via trusted publishing, from a fresh `npm run build`.
315
+ CI (`.github/workflows/ci.yml`) runs `npm run build`, `npm run check:go-types` and the conformance suite on Ubuntu, Windows and macOS with Node 26 and Go 1.26, and a Linux job that builds the self-hosted compiler, checks the bootstrap fixpoint (`npm run bootstrap:check`) and runs the suite through it. Releases are cut from `TypeNative_*` tags via trusted publishing, from a fresh `npm run build`.
316
+
317
+ When adding a feature: add a probe, link it from [conformance.md](conformance.md), and keep the ✅/❌ matrix honest gaps are documented, not hidden.
270
318
 
271
- When adding a feature: add a probe, link it from [conformance.md](conformance.md), and keep the ✅/❌ matrix honest — gaps are documented, not hidden.
319
+ `npm run perf` runs the [performance/](performance/) probes. Each is a micro-benchmark of one hot path (string `+=`, `Map` lookups, `switch` over a discriminated union, `any` property access, regex, …), timed under Node.js and as a TypeNative binary, with checksums that must match. Results and notes on the slow paths are in [performance/README.md](performance/README.md).
272
320
 
273
321
  ## Self-hosted native compiler
274
322
 
@@ -284,4 +332,4 @@ native/typenative --source app.ts --script
284
332
 
285
333
  ## License
286
334
 
287
- MIT — see [LICENSE](LICENSE).
335
+ MIT [LICENSE](LICENSE).
package/bin/cli.js CHANGED
@@ -77,7 +77,9 @@ import { VERSION } from './version.js';
77
77
  vendorDir: fileURLToPath(new URL('../govendor', import.meta.url)),
78
78
  target: args.target,
79
79
  release: args.release,
80
+ gui: args.gui,
80
81
  cover: args.cover,
82
+ profile: args.profile,
81
83
  emitGo: args.emitGo
82
84
  });
83
85
  })();
package/bin/index.js CHANGED
@@ -11,6 +11,48 @@ import { platform } from 'node:os';
11
11
  import * as childProcess from 'node:child_process';
12
12
  import { transpileToNative, GENERATED_HEADER } from './transpiler.js';
13
13
  import { VERSION } from './version.js';
14
+ // --profile: starts a CPU profile before any module initializes and stops
15
+ // it on every exit path (see profiled() in the build)
16
+ const PROFILE_GO = `${GENERATED_HEADER}
17
+
18
+ package main
19
+
20
+ import (
21
+ "os"
22
+ "runtime/pprof"
23
+ )
24
+
25
+ var tnProfileOut *os.File
26
+
27
+ func init() {
28
+ path := os.Getenv("TYPENATIVE_CPUPROFILE")
29
+ if path == "" {
30
+ path = "cpu.pprof"
31
+ }
32
+ f, err := os.Create(path)
33
+ if err != nil {
34
+ return
35
+ }
36
+ if pprof.StartCPUProfile(f) != nil {
37
+ f.Close()
38
+ return
39
+ }
40
+ tnProfileOut = f
41
+ }
42
+
43
+ func tnProfileStop() {
44
+ if tnProfileOut != nil {
45
+ pprof.StopCPUProfile()
46
+ tnProfileOut.Close()
47
+ tnProfileOut = nil
48
+ }
49
+ }
50
+
51
+ func tnProfileExit(code int) {
52
+ tnProfileStop()
53
+ os.Exit(code)
54
+ }
55
+ `;
14
56
  // The minimum Go toolchain generated code needs
15
57
  const MIN_GO_MAJOR = 1;
16
58
  const MIN_GO_MINOR = 26;
@@ -27,8 +69,11 @@ Options:
27
69
  --target <os/arch> Cross-compile, e.g. linux/amd64, linux/arm64, darwin/arm64,
28
70
  windows/amd64 ('go tool dist list' shows every pair)
29
71
  --release Smaller binary: drop symbols and file paths
72
+ --gui Windowed app: no console window on Windows (ignored elsewhere)
30
73
  --cover Build with coverage counters, for go:runtime/coverage
31
74
  (set GOCOVERDIR to also write a profile at exit)
75
+ --profile Write a CPU profile at exit, to $TYPENATIVE_CPUPROFILE
76
+ (default cpu.pprof); read it with go tool pprof
32
77
  --emit-go <dir> Write the generated Go (and go.mod) to <dir> instead of building
33
78
  --no-typecheck Skip type-checking
34
79
  -h, --help Show this help
@@ -49,7 +94,9 @@ export function parseCliArgs(argv) {
49
94
  script: false,
50
95
  noTypeCheck: false,
51
96
  release: false,
97
+ gui: false,
52
98
  cover: false,
99
+ profile: false,
53
100
  source: null,
54
101
  output: null,
55
102
  target: null,
@@ -76,8 +123,12 @@ export function parseCliArgs(argv) {
76
123
  args.noTypeCheck = true;
77
124
  else if (arg === '--release')
78
125
  args.release = true;
126
+ else if (arg === '--gui')
127
+ args.gui = true;
79
128
  else if (arg === '--cover')
80
129
  args.cover = true;
130
+ else if (arg === '--profile')
131
+ args.profile = true;
81
132
  else if (arg === '--source' || arg === '--output' || arg === '--target' || arg === '--emit-go') {
82
133
  if (value === null) {
83
134
  if (i + 1 >= argv.length || argv[i + 1].startsWith('--')) {
@@ -404,7 +455,8 @@ export function run(opts) {
404
455
  tsx: !!sourcePath && sourcePath.endsWith('.tsx'),
405
456
  fileName: displayPath(entryPath),
406
457
  goFile: goFile,
407
- goos: targetOs
458
+ goos: targetOs,
459
+ cwd: process.cwd().split('\\').join('/')
408
460
  };
409
461
  if (sourceDir) {
410
462
  transpileOptions.readFile = (specifier, fromDir) => {
@@ -479,12 +531,23 @@ export function run(opts) {
479
531
  else if (existing.endsWith('.go') && (!opts.emitGo || fs.readFileSync(file, 'utf-8').startsWith(GENERATED_HEADER)))
480
532
  fs.rmSync(file);
481
533
  }
482
- fs.writeFileSync(path.join(outDir, 'code.go'), transpileResult.main);
534
+ // --profile: every exit path (process.exit, the end of the event loop)
535
+ // stops the profile first, so os.Exit goes through tnProfileExit
536
+ // (and a main that returns stops it too)
537
+ const profiled = (content) => (opts.profile ? content.replace(/\bos\.Exit\(/g, 'tnProfileExit(') : content);
538
+ const mainGo = opts.profile
539
+ ? transpileResult.main.replace(/^func main\(\) \{$/m, 'func main() {\n\tdefer tnProfileStop()')
540
+ : transpileResult.main;
541
+ fs.writeFileSync(path.join(outDir, 'code.go'), profiled(mainGo));
483
542
  const goFiles = ['code.go'];
484
543
  for (const [filename, content] of transpileResult.files) {
485
- fs.writeFileSync(path.join(outDir, filename), content);
544
+ fs.writeFileSync(path.join(outDir, filename), profiled(content));
486
545
  goFiles.push(filename);
487
546
  }
547
+ if (opts.profile) {
548
+ fs.writeFileSync(path.join(outDir, 'tn_profile.go'), PROFILE_GO);
549
+ goFiles.push('tn_profile.go');
550
+ }
488
551
  if (sourceDir)
489
552
  copyEmbeds(sourceDir, transpileResult.embeds, outDir);
490
553
  // Third-party Go modules the program imports (see vendorXText / vendorGoModules)
@@ -524,8 +587,14 @@ export function run(opts) {
524
587
  // is ~5 MB of Go) compile once, not again for every project directory
525
588
  if (opts.release || modules.length > 0)
526
589
  buildArgs.push('-trimpath');
590
+ // One value: go build keeps only the last -ldflags
591
+ const ldflags = [];
527
592
  if (opts.release)
528
- buildArgs.push('-ldflags=-s -w');
593
+ ldflags.push('-s', '-w');
594
+ if (opts.gui && targetOs === 'windows')
595
+ ldflags.push('-H=windowsgui');
596
+ if (ldflags.length > 0)
597
+ buildArgs.push(`-ldflags=${ldflags.join(' ')}`);
529
598
  // atomic counters: coverage.ClearCounters refuses the default 'set' mode
530
599
  if (opts.cover)
531
600
  buildArgs.push('-cover', '-covermode=atomic');
@@ -655,7 +724,8 @@ function getTsConfig() {
655
724
  const tsConfig = {
656
725
  include: ['**/*.ts'],
657
726
  compilerOptions: {
658
- target: 'es2020',
727
+ target: 'es2025',
728
+ useDefineForClassFields: false,
659
729
  lib: [],
660
730
  types: ['typenative', 'typenative/go', 'typenative/npm'],
661
731
  rootDir: '.',
package/bin/main.js CHANGED
@@ -54,7 +54,9 @@ import { VERSION } from './version.js';
54
54
  vendorDir,
55
55
  target: args.target,
56
56
  release: args.release,
57
+ gui: args.gui,
57
58
  cover: args.cover,
59
+ profile: args.profile,
58
60
  emitGo: args.emitGo
59
61
  });
60
62
  })();
@@ -121,7 +121,7 @@ func TnErrorText(e interface{}) string {
121
121
  if s, ok := e.(string); ok {
122
122
  return s
123
123
  }
124
- if msg, ok := TnGet(e, "message").(string); ok {
124
+ if msg, ok := TnGetValue(e, "message").(string); ok {
125
125
  return "Error: " + msg
126
126
  }
127
127
  return fmt.Sprint(e)
@@ -133,7 +133,7 @@ func TnErrorMatches(e interface{}, expected map[string]interface{}) bool {
133
133
  got := TnGet(e, key)
134
134
  if key == "message" {
135
135
  if _, ok := e.(*TnError); !ok {
136
- if m, ok := TnGet(e, "message").(string); ok {
136
+ if m, ok := TnGetValue(e, "message").(string); ok {
137
137
  got = m
138
138
  }
139
139
  }
@@ -14,7 +14,7 @@ type TnAsyncLocalStorage struct {
14
14
  func TnNewAsyncLocalStorage(options ...interface{}) *TnAsyncLocalStorage {
15
15
  als := &TnAsyncLocalStorage{}
16
16
  if len(options) > 0 && options[0] != nil {
17
- if n, ok := TnGet(options[0], "name").(string); ok {
17
+ if n, ok := TnGetValue(options[0], "name").(string); ok {
18
18
  als.name = n
19
19
  }
20
20
  }
@@ -425,12 +425,16 @@ func TnBufferWriteFloat(b []byte, value float64, offset float64, size int, littl
425
425
  return float64(o + size)
426
426
  }
427
427
 
428
- func TnBufferToJSON(b []byte) map[string]interface{} {
428
+ // { type: 'Buffer', data: [...] }, in that key order
429
+ func TnBufferToJSON(b []byte) *TnMap[string, interface{}] {
429
430
  data := make([]interface{}, len(b))
430
431
  for i, c := range b {
431
432
  data[i] = float64(c)
432
433
  }
433
- return map[string]interface{}{"type": "Buffer", "data": data}
434
+ m := TnNewMap[string, interface{}]()
435
+ m.Set("type", "Buffer")
436
+ m.Set("data", data)
437
+ return m
434
438
  }
435
439
 
436
440
  // <Buffer 68 69>, as console.log / util.inspect show a Buffer
@@ -513,7 +517,7 @@ func (d *TnTextDecoder) decode(args ...interface{}) string {
513
517
  }
514
518
  stream := false
515
519
  if len(args) > 1 && args[1] != nil {
516
- stream, _ = TnGet(args[1], "stream").(bool)
520
+ stream, _ = TnGetValue(args[1], "stream").(bool)
517
521
  }
518
522
  data := b
519
523
  if len(d.pending) > 0 {
@@ -588,7 +592,7 @@ function boundsArgs(call, from) {
588
592
  }
589
593
  export function registerBuffer(r) {
590
594
  defineModule(r, 'buffer');
591
- defineHelper(r, 'buffer', ['bytes', 'encoding/base64', 'encoding/binary', 'encoding/hex', 'fmt', 'math', 'math/big', 'strconv', 'strings', 'unicode/utf16', 'unicode/utf8'], ['error', 'dynamic'], bufferHelper);
595
+ defineHelper(r, 'buffer', ['bytes', 'encoding/base64', 'encoding/binary', 'encoding/hex', 'fmt', 'math', 'math/big', 'strconv', 'strings', 'unicode/utf16', 'unicode/utf8'], ['error', 'dynamic', 'orderedMap'], bufferHelper);
592
596
  // Uint8Array first: Buffer owns the []byte instance methods
593
597
  defineClass(r, 'globals.Uint8Array', '[]byte', 'Buffer', '', '', '', '');
594
598
  defineClass(r, 'buffer.Buffer', '[]byte', 'Buffer', '', '', '', '');
@@ -646,6 +650,12 @@ export function registerBuffer(r) {
646
650
  };
647
651
  setResults(r, 'buffer.Buffer', 'from=[]byte; alloc=[]byte; allocUnsafe=[]byte; allocUnsafeSlow=[]byte; concat=[]byte; byteLength=float64; isBuffer=bool; isEncoding=bool; compare=float64');
648
652
  r.results['globals.Uint8Array.from'] = '[]byte';
653
+ // Uint8Array.fromBase64(s) / u8.toBase64() (ES2026)
654
+ r.functions['globals.Uint8Array.fromBase64'] = (call) => {
655
+ use();
656
+ return `TnBufferFromString(${call.args[0]}, "base64")`;
657
+ };
658
+ r.results['globals.Uint8Array.fromBase64'] = '[]byte';
649
659
  r.functions['buffer.atob'] = (call) => {
650
660
  use();
651
661
  return `TnAtob(${call.args[0]})`;
@@ -726,7 +736,8 @@ export function registerBuffer(r) {
726
736
  r.results[`buffer.Buffer#${name}`] = result;
727
737
  };
728
738
  method('toString', 'string', (c) => `TnBufferToString(${c.recv}, ${encArg(c, 0)}${boundsArgs(c, 1)})`);
729
- method('toJSON', 'map[string]interface{}', (c) => `TnBufferToJSON(${c.recv})`);
739
+ method('toBase64', 'string', (c) => `TnBufferToString(${c.recv}, "base64")`);
740
+ method('toJSON', '*TnMap[string, interface{}]', (c) => `TnBufferToJSON(${c.recv})`);
730
741
  method('equals', 'bool', (c) => `bytes.Equal(${c.recv}, ${c.args[0]})`);
731
742
  method('compare', 'float64', (c) => `float64(bytes.Compare(${c.recv}, ${c.args[0]}))`);
732
743
  method('subarray', '[]byte', (c) => `TnBufferSlice(${c.recv}${boundsArgs(c, 0)})`);
@@ -49,25 +49,25 @@ func tnSpawnOpts(options []interface{}) tnSpawnOptions {
49
49
  return o
50
50
  }
51
51
  opts := options[0]
52
- if s, ok := TnGet(opts, "cwd").(string); ok {
52
+ if s, ok := TnGetValue(opts, "cwd").(string); ok {
53
53
  o.cwd = s
54
54
  }
55
55
  if env := TnGet(opts, "env"); env != nil {
56
56
  o.env = tnEnvList(env)
57
57
  }
58
- switch sh := TnGet(opts, "shell").(type) {
58
+ switch sh := TnGetValue(opts, "shell").(type) {
59
59
  case bool:
60
60
  o.shell = sh
61
61
  case string:
62
62
  o.shell = sh != ""
63
63
  }
64
- switch in := TnGet(opts, "input").(type) {
64
+ switch in := TnGetValue(opts, "input").(type) {
65
65
  case string:
66
66
  o.input = []byte(in)
67
67
  case []byte:
68
68
  o.input = in
69
69
  }
70
- switch st := TnGet(opts, "stdio").(type) {
70
+ switch st := TnGetValue(opts, "stdio").(type) {
71
71
  case string:
72
72
  o.stdio = st
73
73
  case []interface{}:
@@ -81,10 +81,10 @@ func tnSpawnOpts(options []interface{}) tnSpawnOptions {
81
81
  o.stdio = st[1]
82
82
  }
83
83
  }
84
- if e, ok := TnGet(opts, "encoding").(string); ok {
84
+ if e, ok := TnGetValue(opts, "encoding").(string); ok {
85
85
  o.encoding = e
86
86
  }
87
- if d, ok := TnGet(opts, "detached").(bool); ok {
87
+ if d, ok := TnGetValue(opts, "detached").(bool); ok {
88
88
  o.detached = d
89
89
  }
90
90
  return o
@@ -440,7 +440,7 @@ func tnExecCollect(cp *TnChildProcess, display string, encoding string, cb inter
440
440
 
441
441
  func tnExecEncoding(options []interface{}) string {
442
442
  if len(options) > 0 && options[0] != nil {
443
- if e, ok := TnGet(options[0], "encoding").(string); ok {
443
+ if e, ok := TnGetValue(options[0], "encoding").(string); ok {
444
444
  return e
445
445
  }
446
446
  }
@@ -232,11 +232,11 @@ func tnForkWith(argv []string, opts interface{}, extraEnv []string) *TnChildProc
232
232
  }
233
233
  }
234
234
  stdio := "inherit"
235
- if silent, _ := TnGet(opts, "silent").(bool); silent {
235
+ if silent, _ := TnGetValue(opts, "silent").(bool); silent {
236
236
  stdio = "pipe"
237
237
  }
238
238
  spawnOpts := map[string]interface{}{"env": envMap, "stdio": stdio}
239
- if cwd, ok := TnGet(opts, "cwd").(string); ok && cwd != "" {
239
+ if cwd, ok := TnGetValue(opts, "cwd").(string); ok && cwd != "" {
240
240
  spawnOpts["cwd"] = cwd
241
241
  }
242
242
  cp := TnSpawn(exe, argv, spawnOpts)
@@ -529,7 +529,7 @@ func (c *TnCluster) setupPrimary(settings ...interface{}) {
529
529
  }
530
530
  }
531
531
  }
532
- if b, ok := TnGet(s, "silent").(bool); ok {
532
+ if b, ok := TnGetValue(s, "silent").(bool); ok {
533
533
  c.silent = b
534
534
  }
535
535
  for _, key := range []string{"args", "silent", "exec", "execArgv", "cwd"} {
package/bin/node/core.js CHANGED
@@ -7,6 +7,39 @@ type TnCallback = func(...interface{})
7
7
  // Calls a JS callback of any Go func type with JS arguments: extra arguments
8
8
  // are dropped, missing ones are zero values, numbers convert between kinds
9
9
  func TnInvoke(fn interface{}, args ...interface{}) interface{} {
10
+ // (the common listener and callback shapes, called without reflect)
11
+ switch f := fn.(type) {
12
+ case func():
13
+ if f != nil {
14
+ f()
15
+ }
16
+ return nil
17
+ case func(...interface{}):
18
+ if f != nil {
19
+ f(args...)
20
+ }
21
+ return nil
22
+ case func(interface{}):
23
+ if f != nil {
24
+ f(tnInvokeAt(args, 0))
25
+ }
26
+ return nil
27
+ case func(interface{}, interface{}):
28
+ if f != nil {
29
+ f(tnInvokeAt(args, 0), tnInvokeAt(args, 1))
30
+ }
31
+ return nil
32
+ case func(float64):
33
+ if a, ok := tnInvokeAt(args, 0).(float64); ok && f != nil {
34
+ f(a)
35
+ return nil
36
+ }
37
+ case func(string):
38
+ if a, ok := tnInvokeAt(args, 0).(string); ok && f != nil {
39
+ f(a)
40
+ return nil
41
+ }
42
+ }
10
43
  fv := reflect.ValueOf(fn)
11
44
  if !fv.IsValid() || fv.Kind() != reflect.Func || fv.IsNil() {
12
45
  return nil
@@ -35,6 +68,14 @@ func TnInvoke(fn interface{}, args ...interface{}) interface{} {
35
68
  return nil
36
69
  }
37
70
 
71
+ // args[i], or nil past the end (a missing argument is undefined)
72
+ func tnInvokeAt(args []interface{}, i int) interface{} {
73
+ if i < len(args) {
74
+ return args[i]
75
+ }
76
+ return nil
77
+ }
78
+
38
79
  func tnInvokeArg(a interface{}, t reflect.Type) reflect.Value {
39
80
  if a == nil {
40
81
  return reflect.Zero(t)