typenative 0.5.0 → 0.6.1

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 (149) 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 +339 -0
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +16 -7
  6. package/bin/cli.js +1 -0
  7. package/bin/index.js +62 -3
  8. package/bin/main.js +1 -0
  9. package/bin/node/core.js +46 -0
  10. package/bin/node/events.js +154 -15
  11. package/bin/node/http.js +1265 -127
  12. package/bin/node/process.js +13 -0
  13. package/bin/node/punycode.js +2 -2
  14. package/bin/node/stream.js +56 -7
  15. package/bin/node/stream_web.js +2 -2
  16. package/bin/node/timers.js +4 -2
  17. package/bin/node/url.js +28 -3
  18. package/bin/parse-node.js +2 -2
  19. package/bin/regex_vm.js +2105 -0
  20. package/bin/transpiler.js +17970 -4419
  21. package/bin/typecheck-node.js +2 -1
  22. package/bin/version.js +1 -1
  23. package/conformance.md +57 -15
  24. package/examples/README.md +50 -28
  25. package/examples/angular-templates/README.md +141 -0
  26. package/examples/angular-templates/bench.mjs +173 -0
  27. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  28. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  29. package/examples/angular-templates/main.ts +135 -0
  30. package/examples/angular-templates/parity.mjs +157 -0
  31. package/examples/angular-templates/run-node.mjs +69 -0
  32. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  33. package/examples/desktop-notes/README.md +11 -13
  34. package/examples/dupe-finder/README.md +7 -5
  35. package/examples/fibonacci/README.md +7 -7
  36. package/examples/hello-world/README.md +6 -6
  37. package/examples/json-server/README.md +22 -18
  38. package/examples/mandelbrot-png/README.md +11 -13
  39. package/examples/marked-cli/README.md +60 -44
  40. package/examples/marked-cli/main.ts +122 -4
  41. package/examples/openai-chat/README.md +148 -0
  42. package/examples/openai-chat/bench.mjs +175 -0
  43. package/examples/openai-chat/main.ts +488 -0
  44. package/examples/react-compiler/README.md +185 -0
  45. package/examples/react-compiler/bench.mjs +181 -0
  46. package/examples/react-compiler/main.ts +324 -0
  47. package/examples/react-compiler/parity.mjs +362 -0
  48. package/examples/react-compiler/run-node.mjs +90 -0
  49. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  50. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  51. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  52. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  53. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  54. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  55. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  56. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  57. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  58. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  59. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  60. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  61. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  62. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  63. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  64. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  65. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  66. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  67. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  68. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  69. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  70. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  71. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  72. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  73. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  74. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  75. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  76. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  77. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  78. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  79. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  80. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  81. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  82. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  83. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  84. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  85. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  86. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  87. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  88. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  89. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  90. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  91. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  92. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  93. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  94. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  95. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  96. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  97. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  98. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  99. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  100. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  101. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  102. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  103. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  104. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  105. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  106. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  107. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  108. package/examples/react-compiler/vendor.mjs +688 -0
  109. package/examples/todo-cli/README.md +9 -9
  110. package/examples/yaml-cli/README.md +50 -34
  111. package/examples/yaml-cli/main.ts +236 -14
  112. package/package.json +8 -5
  113. package/performance/README.md +196 -0
  114. package/performance/any-dynamic.ts +21 -0
  115. package/performance/any-record-view.ts +20 -0
  116. package/performance/arr-hof.ts +21 -0
  117. package/performance/arr-push-index.ts +15 -0
  118. package/performance/arr-sort.ts +21 -0
  119. package/performance/async-await.ts +24 -0
  120. package/performance/class-dispatch.ts +52 -0
  121. package/performance/events-emit.ts +27 -0
  122. package/performance/exc-throw-rare.ts +25 -0
  123. package/performance/exc-try-catch.ts +26 -0
  124. package/performance/fn-closures.ts +29 -0
  125. package/performance/fn-recursion-tree.ts +31 -0
  126. package/performance/gen-for-of.ts +46 -0
  127. package/performance/json-roundtrip.ts +27 -0
  128. package/performance/map-delete.ts +24 -0
  129. package/performance/map-string-keys.ts +22 -0
  130. package/performance/num-arith-loop.ts +14 -0
  131. package/performance/num-bitwise.ts +21 -0
  132. package/performance/num-mod-int.ts +16 -0
  133. package/performance/num-to-string.ts +16 -0
  134. package/performance/obj-alloc.ts +32 -0
  135. package/performance/regex-exec.ts +29 -0
  136. package/performance/regex-site.ts +28 -0
  137. package/performance/set-ops.ts +20 -0
  138. package/performance/str-char-scan.ts +35 -0
  139. package/performance/str-concat-plus.ts +18 -0
  140. package/performance/str-concat.ts +24 -0
  141. package/performance/str-short-scan.ts +26 -0
  142. package/performance/str-split-join.ts +23 -0
  143. package/performance/str-template.ts +16 -0
  144. package/performance/union-switch.ts +57 -0
  145. package/tsparser/check.go +2 -1
  146. package/tsparser/main.go +1 -0
  147. package/types/typenative-npm.d.ts +3 -2
  148. package/types/typenative.d.ts +42 -12
  149. package/ROUND2-HANDOFF.md +0 -200
@@ -17,7 +17,7 @@ jobs:
17
17
 
18
18
  - uses: actions/setup-node@v4
19
19
  with:
20
- node-version: 24
20
+ node-version: 26
21
21
  cache: npm
22
22
 
23
23
  - uses: actions/setup-go@v5
@@ -46,7 +46,7 @@ jobs:
46
46
 
47
47
  - uses: actions/setup-node@v4
48
48
  with:
49
- node-version: 24
49
+ node-version: 26
50
50
  cache: npm
51
51
 
52
52
  - uses: actions/setup-go@v5
@@ -24,7 +24,7 @@ jobs:
24
24
  - uses: actions/checkout@v4
25
25
  - uses: actions/setup-node@v4
26
26
  with:
27
- node-version: 24
27
+ node-version: 26
28
28
  - uses: actions/setup-go@v5
29
29
  with:
30
30
  go-version: '1.26'
@@ -65,7 +65,7 @@ jobs:
65
65
 
66
66
  - uses: actions/setup-node@v4
67
67
  with:
68
- node-version: 24
68
+ node-version: 26
69
69
  registry-url: https://registry.npmjs.org/
70
70
 
71
71
  # Trusted Publishing (OIDC) requires npm >= 11.5.1 — ensure we have it
package/CHANGELOG.md CHANGED
@@ -7,6 +7,345 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.1] - 2026-11-15
11
+
12
+ ### Changed
13
+
14
+ - **examples/react-compiler: faster than Node at 64 KB.** The React Compiler
15
+ now runs a 64 KB component file in 615 ms vs Node's 1,030 ms (1.7x faster;
16
+ it was 3.5x slower), and per call is 3.5x faster (100 vs 349 ms). Plain
17
+ functions assigned to `NodePath.prototype` declare `this: NodePath`; that
18
+ now types `__this` as the class, so Babel's per-node path maintenance
19
+ (`visit`, `setScope`, `setContext`, `parentPath` walks) is direct field
20
+ access instead of dynamic plan lookups. Dynamic calls of the program's own
21
+ function types go through a generated `tnCallValueTyped` case per Go func
22
+ type (no `reflect.Value.Call`), and optional calls to prototype methods
23
+ added at run time are guarded dynamic calls. For large files the example
24
+ compiles independent top-level functions in parallel worker processes and
25
+ joins their output; under Node each worker re-imports the compiler, while a
26
+ TypeNative worker starts from the compiled binary.
27
+ - **Iterating class iterators through dynamic values:** `TnToArray` (used by
28
+ spread, `Array.from`, destructuring and `for…of` on a dynamically typed
29
+ value) recognizes a class's generator push form directly
30
+ (`Symbol_iterator__seq`) and iterates it in place instead of finding
31
+ `*[Symbol.iterator]()` through reflection, calling it and draining its
32
+ channel on a goroutine. An interface-yield channel method also gets a direct
33
+ type assertion. This is what Angular's `OpList` hit through an op's dynamic
34
+ `handlerOps` / `trackByOps` fields; angular-templates' 64 KB run fell from
35
+ about 600 ms to 305 ms (now 1.2x faster than Node), and per-call latency is
36
+ 4.4x Node's (50 vs 219 ms).
37
+ - **yaml-cli throughput:** `yaml --json` on a large, plain stream is split
38
+ before the `---` lines that start its documents, and up to six worker
39
+ processes compose runs of them and print their JSON arrays, which the main
40
+ process joins. Directives, errors, warnings, CR line endings and
41
+ collection-valued keys fall back to the normal `cli()` path (the example
42
+ runs under Node too). On the 10 MB benchmark the complete process run is
43
+ now 754 ms vs Node's 851 ms (median, 1.1x); the single-process path also
44
+ got faster.
45
+ - **Object conversions and dynamic writes:** conversion identity holds one
46
+ weak pointer per conversion, sweeps dead entries in batches and keeps a
47
+ recent cache; a fresh local object converted once is copied without an
48
+ identity entry (`TnAsCopy`), and a conversion between two statically known
49
+ struct types is emitted as a struct literal. `Object.assign({ defaults },
50
+ typedSource)` sets the target's fields directly instead of through
51
+ reflection, `obj[key] = v` on a plain object skips reflection
52
+ (`TnSetProp`), and `s += chunk` for an untyped chunk appends in place
53
+ instead of copying the whole string.
54
+ - **List building:** a single-value `push` grows the backing slice by 2x
55
+ (`TnPush`) rather than Go's 1.25x, whose repeated copies add up to about
56
+ five times a long list's final memory.
57
+ - **marked-cli throughput:** large markdown documents are parsed in up to six
58
+ worker processes, one contiguous run of top-level sections each, with a
59
+ sequential fallback (small inputs, reference link definitions, raw HTML
60
+ blocks, CRLF, `--tokens`). On the example's 10 MB benchmark the complete
61
+ process run is now 1.2x faster than Node (512 ms vs 596 ms); parity stays
62
+ 2,859/2,859. The single-process parse also got faster: `[...s].length` /
63
+ `[...s][i]` / `[...s].at(i)` no longer build rune arrays, truthiness-only
64
+ `re.exec` runs `re.test`, nullable regex results box only on a match, greedy
65
+ `[^x]+` runs use `IndexByte`, and the long-string ASCII cache and regex
66
+ replacement builders no longer allocate per token.
67
+
68
+ ### Fixed
69
+
70
+ - **process.stdin:** `TnStdin` sets its `_stdinRef` hook through `setHook`
71
+ again after the lazy emitter/hook state change; reading stdin no longer
72
+ panics with `assignment to entry in nil map`.
73
+ - **events.errorMonitor:** with only the two inline listeners, an `'error'`
74
+ event calls an `errorMonitor` listener before the error listeners again (the
75
+ lazy listener path skipped it, so the conformance probe saw `handler` first).
76
+
77
+ ## [0.6.0] - 2026-11-13
78
+
79
+ The React Compiler itself (`babel-plugin-react-compiler` + Babel + zod, ~470 vendored files)
80
+ compiles React components and hooks to their auto-memoized form, natively, and an
81
+ OpenAI-compatible chat client streams answers token by token. Getting there drove the round's
82
+ transpiler fixes: JS object identity and callee write-back across Go conversions, one
83
+ backtracking regex VM with JS semantics for every pattern, and module initialization in the
84
+ import graph's evaluation order. TypeNative now requires Node.js 26. A `--profile` flag
85
+ and two rounds of hot-path fixes (bitwise and `%` arithmetic, generators, Map / Set deletes,
86
+ class dispatch, async functions and `JSON.parse`) narrow the gap with Node on the large
87
+ examples: react-compiler runs 26% faster at 64 KB and angular-templates 17% faster.
88
+
89
+ ### Added
90
+
91
+ - **`--profile`:** the built program writes a CPU profile (`runtime/pprof`) to
92
+ `$TYPENATIVE_CPUPROFILE` (default `cpu.pprof`) when it exits, on every exit
93
+ path, for `go tool pprof`
94
+ - **Performance probes:** `num-bitwise`, `num-mod-int`, `map-delete`,
95
+ `gen-for-of`, `str-short-scan`, `str-concat-plus`, `regex-site`,
96
+ `events-emit`, `async-await` and `exc-throw-rare`, covering what the large
97
+ examples stress; `performance/README.md` lists each fixed and open cause
98
+ - **examples/react-compiler:** the React Compiler (`babel-plugin-react-compiler` + Babel 7.29 parser/traverse/generator + zod 4, ~470 vendored files) compiling
99
+ React components and hooks to their auto-memoized form, natively. The build
100
+ drove a series of transpiler and runtime fixes (below); every fixture in
101
+ `parity.mjs` — components, hooks, the compiler's pragmas, JSX outlining,
102
+ TypeScript syntax and the error paths — now matches Node byte for byte,
103
+ output, `// CompileSuccess` counts and error code frames included, and
104
+ `bench.mjs` reports per-call latency and scaling
105
+ - **JS object and array identity across Go conversions:** converting one
106
+ object to another struct type gives the same converted object every time
107
+ (Set / Map keys and `===` find it), and union and intersection members are
108
+ views of the same memory; arrays stay shared through any-typed fields,
109
+ getters, dynamic calls and `splice`; a callee's changes to a converted
110
+ argument — an array, a Map or Set, an object's fields, through an
111
+ override too — are written back to the caller's; `slice` copies
112
+ - **JS semantics at the edges:** object-literal getters stay live (also when
113
+ a function returns the literal as `{ value: T }`); `Object.prototype`
114
+ methods read as values (`const toString = {}.toString`) run through
115
+ `call` / `apply`; default parameters apply to an explicit or forwarded
116
+ `undefined`; `null` stays apart from `undefined` where a function tests
117
+ both; Map misses and unset optional enum fields fall back with `??`; keys
118
+ written as `undefined` are own keys for `Object.keys`; `x.at(i)` and
119
+ `?.push` work on arrays held as any
120
+ - **Regex `v` flag (`unicodeSets`):** the backtracking VM now reads v-flag
121
+ class set expressions: subtraction (`[\p{L}--[aeiou]]`), intersection
122
+ (`[\p{Lu}&&[A-F]]`), nested and negated classes, and `\q{…}` strings, which
123
+ are tried longest first. With `i`, each operand is case-folded before the set
124
+ operation, as in JS. `v` implies unicode mode, and `re.unicodeSets` reports
125
+ the flag. Until now these patterns went to RE2, which misread the class and
126
+ matched the wrong text. Properties of strings (`\p{RGI_Emoji}`) aren't
127
+ supported.
128
+ - **examples/openai-chat:** a chat client for any OpenAI-compatible
129
+ `/v1/chat/completions` API. Answers stream into the terminal token by token:
130
+ `fetch` with a streaming response body (`response.body.getReader()`),
131
+ hand-parsed server-sent events (`data:` lines, `[DONE]`, ignored keep-alive
132
+ comments), an `AbortController` timeout, Ctrl+C aborting the answer in flight,
133
+ and a `for await` readline REPL with `/clear` and `/system`. Targets the free
134
+ OpenRouter API by default (`google/gemma-4-31b-it:free`), and OpenAI, Ollama
135
+ or any other compatible server through `--base-url`. `bench.mjs` stands up a
136
+ local mock SSE API, checks Node and TypeNative stdout byte for byte, then
137
+ times full one-shot runs (1.2x faster per answer, 716 vs 875 ms median — both
138
+ runtimes mostly wait on the mock's paced chunks). The example works around
139
+ two catch-block sharp edges (`return`/`continue` inside `catch` compiles
140
+ wrong or not at all), documented in its README
141
+ - **conformance:** `lib-regex-engine`, `lib-string-long-slices` and
142
+ `semantics-dynamic-field-access`, with expected values checked against Node
143
+
144
+ ### Changed
145
+
146
+ - **Node 26 and ES2025:** TypeNative now requires Node.js 26 or newer
147
+ (`engines`), and CI runs on Node 26. Scaffolded projects (`--new`) and the
148
+ default type-check (no `tsconfig.json`) target `es2025` instead of `es2020`,
149
+ so target-gated syntax such as the regex `v` flag, regex modifiers and
150
+ duplicate named groups type-checks. `useDefineForClassFields: false` is set
151
+ alongside it to keep TypeScript's classic field order (parameter properties
152
+ before field initializers), which is what TypeNative compiles. Existing
153
+ projects that keep `target: es2020` are unaffected.
154
+ - **Regex engine:** every `TnRegex` now runs on one backtracking VM with JS
155
+ semantics (`src/regex_vm.ts`), replacing the closure-based backtracker and RE2
156
+ as the first choice. Programs compile lazily and once per pattern and flags. A
157
+ match allocates only its result, and first-byte sets, literal prefixes and
158
+ anchors reject most calls without running anything. RE2 stays as a fallback
159
+ for patterns it can run that exhaust the VM's step budget, so those keep their
160
+ linear-time guarantee. Regex literals used inline get the same engine; only
161
+ Node built-ins' arguments and `/(?<name>…)/.exec(s)` stay on plain RE2
162
+ - **Dynamic values:** property reads and writes on objects held as any go through
163
+ plans cached per type and key instead of reflection; a read consumed on the
164
+ spot doesn't box its value; `obj.list.push(x)` appends in place instead of
165
+ converting the array on every push; object-type conversions are compiled per
166
+ pair of types; `Object.assign` between objects uses the same plans; `switch`
167
+ on a dynamic value over string literals is a Go string switch
168
+ - **Strings:** long strings grown with `+=` on a dynamic value are amortized;
169
+ short ASCII strings need no code-point index
170
+ - **Performance:** on 10 MB of input, examples/marked-cli went from 5.5x to 1.6x
171
+ slower than Node and examples/yaml-cli from 3.8x to 1.9x (the native binary
172
+ now finishes first up to about 1–2 MB per run), and marked's ReDoS inputs from
173
+ over 72 s to 4.7 s in total
174
+ - **Hot paths:** bitwise operators no longer call `math.Mod` (`TnInt32`
175
+ converts in-range values directly, literal operands fold, nested bitwise
176
+ expressions stay int32); `%` on integers is an `int64` remainder; a sync
177
+ generator iterated by `for…of` runs as a Go range function instead of a
178
+ goroutine in lockstep (break and throw keep JS's `finally` / `catch`
179
+ semantics); `Map` / `Set` deletes are O(1) and key handling takes no
180
+ reflection; `s = s + …` appends in place like `s += …`; `charCodeAt` over
181
+ short strings no longer rescans the string; `toFixed` skips exact
182
+ 1100-digit formatting except on ties; any-typed objects read their map
183
+ first; `Record<string, any>` views of an any object share its map;
184
+ common listener shapes are called without reflection; regex literals
185
+ share their compiled program per site. Probe medians: bitwise 2160 →
186
+ 129 ms, `%` loops 4527 → 162 ms, generators 1843 → 12 ms (now 4.4x faster
187
+ than Node), `Set` churn 1556 → 97 ms. examples/react-compiler at 64 KB
188
+ runs 26% faster (7.5 s → 5.6 s, interleaved against the previous build)
189
+ - **Dispatch, async and JSON hot paths:** a generator method called on a
190
+ value typed as a base class or interface (`unit.ops()`) runs its push form
191
+ through `TnCallSeq_<m>`, lazily as JS does (it used to collect every value
192
+ before the loop ran), and spread / `Array.from` of a generator collect its
193
+ push form into a typed slice; a method call through a class or interface
194
+ hierarchy whose implementations share a signature goes through a typed
195
+ dispatcher, without boxing; async functions that never wait on anything
196
+ pending run on the caller's goroutine, and settling a promise no longer
197
+ allocates when nobody waits; `JSON.parse(text) as T[]` decodes straight
198
+ into `T` when the text matches it; `for` loop counters and bitwise-result
199
+ consts are Go integers. Probe medians: `async-await` 1985 → 201 ms,
200
+ `class-dispatch` 709 → 124 ms, `json-roundtrip` 347 → 97 ms, `num-bitwise`
201
+ 128 → 114 ms; examples/angular-templates at 64 KB runs 17% faster (721 →
202
+ 601 ms, interleaved against the previous build)
203
+
204
+ ### Fixed
205
+
206
+ - **`null` is not `undefined`:** `typeof null` is `"object"` (it gave
207
+ `"undefined"`), `String(null)` and `null` in `+` / template strings give
208
+ `"null"` (`String(null)` printed `<nil>`), and `null` declared or assigned
209
+ into an `any` / `unknown` variable stays JS null
210
+ - **Classes with `*[Symbol.iterator]()`:** instances destructure
211
+ (`const [a, b] = bag`, reading only as many values as are bound, so an
212
+ endless iterator ends and its `finally` runs), spread into call and `new`
213
+ arguments (`Math.max(...bag)`, `f(...bag)`), and `bag[Symbol.iterator]()`
214
+ is a generator of its own; subclasses inherit all of it. Spreads that are
215
+ not the only argument of a rest parameter (`f(1, ...xs, 2)`,
216
+ `f(...xs, ...ys)`) now compile, for arrays too
217
+ - **Spread of a generator into arguments:** `f(...gen())` into a rest
218
+ parameter failed to compile, and `xs.push(...unit.ops())` through a
219
+ dynamic receiver asserted the generator's channel to an array
220
+ - **`(-Infinity).toFixed(n)`** returns `"-Infinity"` (it printed `-Inf`)
221
+
222
+ - **Namespaces of types only:** `namespace Tokens { export interface Def … }`
223
+ is flattened like any namespace (`Tokens_Def`) instead of being dropped, so
224
+ `Tokens.Def` resolves to its declaration (an unmatched regex group stored in
225
+ one of its `string` fields stays `undefined` and `JSON.stringify` leaves it
226
+ out: marked's `--tokens` printed `"title": ""` for a link definition without
227
+ a title). Only type references `Ns.T` are rewritten for such a namespace, so
228
+ a class merged with it keeps its value reads (`Scope.x`, `typeof Scope.x`)
229
+
230
+ - **Converting an object to a wider struct no longer reads or writes past
231
+ it:** a conversion whose source struct's fields are a prefix of the
232
+ target's (a member held in a merged union's slot) used to view the source's
233
+ memory as the target, so the target's extra fields lay past the object — in
234
+ the next object, or in size-class slack the garbage collector doesn't scan
235
+ for pointers. Such a view is now made only where the object's memory is
236
+ known to cover the target: a union narrowed to a member and widened back,
237
+ or an object literal allocated union-sized (an object literal whose struct
238
+ is a strict prefix of merged unions now gets room for their fields, with
239
+ the pointer layout they share, so a member held in a union's slot stays the
240
+ one object). Every other such conversion copies, through the identity
241
+ cache. (A literal's struct read as the interface it matches plus the
242
+ interface's key list `__keys` read the key list from whatever followed
243
+ the literal: `JSON.stringify` crashed on marked's table cells)
244
+ - **Module initialization order:** a program's module-level code now runs in
245
+ the import graph's evaluation order, as JS evaluates it — each module after
246
+ the modules it imports, with an import cycle's back edge not waiting (the
247
+ way Node starts evaluating a cycle mid-way through a module). It used to be
248
+ the emission order, which a cycle (the React Compiler's entrypoint barrels,
249
+ zod's) evaluates differently, leaving re-exported values uninitialized.
250
+ Imports whose bindings the code never uses as values — which tsc's emit
251
+ elides — no longer order inits either
252
+ - **`new F(…)` on a constructor-function value** now has JS `new` semantics:
253
+ the function runs with `this` a fresh object, which it may return or fill
254
+ (zod's `$constructor` factories read `this`); it used to be a plain call,
255
+ so a function reading `this` saw nothing
256
+ - **`fn.bind(…)` on a function value held as any** returns a bound function
257
+ (with the bound `this` and prepended arguments) instead of failing with
258
+ "bind is not a function"
259
+ - **`Object.assign(fn, props)`** copies the properties onto the function
260
+ value, where `fn.prop` reads them, instead of dropping them
261
+ - **`C.prototype[k] = fn` with a computed key** adds the method to the
262
+ class's prototype (its instances call it with `this` the instance) instead
263
+ of failing
264
+ - **A dynamic array method whose name a class or object literal declares
265
+ too** (`values.map(…)` beside a `Result.map`) runs the array method on
266
+ arrays and dispatches to the class on class instances, decided at run time
267
+ - **`x ??= v` on a nullable array variable** tests the reference itself
268
+ instead of dereferencing it, which panicked when it was unset
269
+ - **An empty object literal (`{}`) is no longer a zero-size Go value** — Go
270
+ gives every zero-size value the same address, which made every `{}` in a
271
+ program one shared object (each zod schema's internals landed in one place,
272
+ every schema reading the last-written definition)
273
+ - **Properties set on dynamic objects** are keyed by the object itself, so a
274
+ garbage-collected object's address being reused cannot hand its properties
275
+ to the new object
276
+ - **`Object.assign`/spread into a fresh object** skips a struct's internal
277
+ `__`-prefixed fields
278
+ - **A property assigned a value its field's Go type can't hold** now replaces
279
+ the property, as in JS: the field reads as undefined and the value is kept
280
+ beside the object (`Object.defineProperty`-style visitors — Babel's traverse
281
+ `explode` replaces a visitor function with `{ enter: fn }`) instead of
282
+ leaving the stale value readable and dropping the assignment. Reads fall
283
+ through a nil reference field to what was set beside the object, and
284
+ `Object.defineProperty` with a getter/setter now defines a real accessor on
285
+ class instances too (Babel's ParseError computes its `message` in a getter
286
+ that self-assigns); it used to silently support them only on dynamic objects
287
+ - **A call's argument converted to a copy the callee changes** is written back
288
+ at every statement position (plain calls, `x = f(op)`, `const x = f(op)`,
289
+ `return f(op)`), including arguments written `node as SomeType` and calls
290
+ through a mixin's virtual table, when the callee mutates the parameter's
291
+ fields — directly or by passing it on to a function that does. The fields it
292
+ changes are copied back to the original object, and ones the original's type
293
+ has no slot for are kept beside it (Babel's parser passes its nodes between
294
+ `parseExport`/`maybeParseExportDeclaration` and reads the fields back on the
295
+ original); the copy's changes used to be lost, emptying the parse result
296
+ - **`arr.push(x)` on an array read out of a container** (`aliases[k].push(x)`,
297
+ a Map's array value) stores the appended array back into the container, as
298
+ push mutates it in JS; it used to append to a copy and drop it, which left
299
+ @babel/types' alias tables empty and its node validators rejecting every node
300
+ - **A class instance passed where an interface type is expected** converts
301
+ with the properties it carries beyond its class filling the interface's
302
+ fields (Babel's parser keeps `imported`/`local` of an import specifier on a
303
+ bare Node); the conversion used to build a zero-filled struct
304
+ - **`f?.call(thisArg, …)` on a function value** calls nothing when f is unset
305
+ (an optional callback parameter's Go func type is nil); it used to deref nil.
306
+ A `do { … = this.parseSubscript(…, state) } while (!state.stop)` also no
307
+ longer loops forever: the state object the callee writes through the
308
+ converted parameter is written back
309
+ - **An intersection type alias** (`ParseResult<File> = File & { … }`) compiles
310
+ to a struct with every member's fields, and an interface renamed for a
311
+ cross-module name collision still resolves its fields (and shadows a Node
312
+ global's type) through the original name — the parser's `File` used to
313
+ convert to a 3-field struct and Node's `File` global type leaked into Babel's
314
+ - **A nullable array parameter with a default** (`tokens: Token[] | null =
315
+ null`) reads as nil when absent instead of dereferencing nil
316
+ - Optional chain calls guard the receiver, and a function's result type drives
317
+ `return f(…)` conversions again after the write-back change
318
+ - **A destructured binding of an object's array field** binds the array
319
+ itself, as in JS: push/pop/splice through it mutate the field's array
320
+ (`const { context } = this.state` then `context.push(…)` in Babel's JSX
321
+ tokenizer); it used to bind a copy and drop every mutation, flattening the
322
+ tokenizer's element context stack
323
+ - **An array stored into a dynamic object is kept as a reference**, as JS
324
+ arrays are shared: a push through any binding of the value reaches the
325
+ object's entry (`(ids[name] = ids[name] || []).push(…)` building Babel
326
+ traverse's Scope binding tables); the push used to append to a copy and
327
+ never register a binding, which rejected every node in Scope's validators.
328
+ `push`/`pop`/`shift`/`unshift` work on such references held as any
329
+ - **`x.push(…)` on an expando-stored array** (a bare parser Node's `body`)
330
+ appends to the array the object holds; it used to append to a copy and drop
331
+ it, which emptied every statement list the compiler's lowering walked
332
+ - **A mixin virtual method call returns its implementations' result** even
333
+ when an abstract declaration types it `: void` (Babel:
334
+ `return this.parseObjPropValue(prop, …)` over an
335
+ `abstract parseObjPropValue(…): void`); the returned node used to be
336
+ dropped, which made the compiler lower every function body to nothing
337
+ - **conformance:parallel:** example builds get the 10-minute budget the
338
+ sequential runner already gave them (the vendored-package examples
339
+ transpile tens of thousands of lines and go build the result — the React
340
+ Compiler example used to be killed at 90 s and reported as a bare `exit 1`),
341
+ and the largest example runs alone before the pack
342
+ - `.`, `^` and `$` follow JS's line terminators in every regex, `[]` and `[^]`
343
+ mean what they do in JS, captures reset on each loop iteration, and `\p` is a
344
+ property only with the `u` flag
345
+ - `\k<name>` in a regex literal panicked in RE2
346
+ - Slices of a long non-ASCII string rebuilt its whole index each time, making a
347
+ lexer over non-ASCII input quadratic
348
+
10
349
  ## [0.5.0] - 2026-11-01
11
350
 
12
351
  The `yaml` package's own CLI, compiled from its unmodified TypeScript source, as the first
package/CONTRIBUTION.md CHANGED
@@ -8,6 +8,7 @@ Thanks for helping build TypeNative — a TypeScript-to-Go transpiler that ships
8
8
 
9
9
  - **Add a missing feature** — pick a ❌ row in [conformance.md](conformance.md) and make it ✅.
10
10
  - **Fix a bug** — failing probe, wrong Go output, bad error message.
11
+ - **Make a hot path faster** — pick a slow row in [performance/README.md](performance/README.md). Quote `node scripts/performance.mjs <filter>` before and after in the PR, and add a probe if the path you sped up has none.
11
12
  - **Improve docs** — README, conformance matrix, code comments.
12
13
  - **Report issues** — open an issue with a minimal `.ts` repro, expected vs. actual output, and your `node --version` / `go version`.
13
14
 
@@ -114,7 +115,7 @@ npm run bootstrap:check # native/typenative must emit the same Go for sr
114
115
  node scripts/conformance-parallel.mjs --native # full suite through your new binary
115
116
  ```
116
117
 
117
- CI ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)) runs `npm run build`, `npm run check:go-types` and `npm run conformance:parallel` on Ubuntu, Windows and macOS (Node 24 + Go 1.26), plus a Linux job that builds the native compiler, runs `npm run bootstrap:check` and the suite through it. Probes that depend on the OS should hold on all three (branch on `process.platform` where Node itself differs). A probe that can't build on one of them (`go:log/syslog` has no Windows build) starts with `// conformance-skip: win32 (reason)`; the runners skip it there and list it.
118
+ CI ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)) runs `npm run build`, `npm run check:go-types` and `npm run conformance:parallel` on Ubuntu, Windows and macOS (Node 26 + Go 1.26), plus a Linux job that builds the native compiler, runs `npm run bootstrap:check` and the suite through it. Probes that depend on the OS should hold on all three (branch on `process.platform` where Node itself differs). A probe that can't build on one of them (`go:log/syslog` has no Windows build) starts with `// conformance-skip: win32 (reason)`; the runners skip it there and list it.
118
119
 
119
120
  ## Pull requests
120
121
 
package/README.md CHANGED
@@ -33,17 +33,17 @@ npx typenative --source hello.ts --script
33
33
  ## Why use TypeNative
34
34
 
35
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 ~15 ms vs ~100 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 ~1.9x faster than Node, and a `node:http` JSON server handles ~1.3x more requests per second with lower median latency.
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
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
39
  - **Reach into Go.** Import any Go package directly (`import { Println } from 'go:fmt'`) when you need something Node doesn't have.
40
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
41
 
42
- Numbers are medians from the [examples/](examples/) benchmarks (Windows 11, Ryzen 5 5500U, Node 24, Go 1.26); 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.
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
43
 
44
44
  ## Requirements
45
45
 
46
- - [Node.js v24](https://nodejs.org/en) or newer.
46
+ - [Node.js v26](https://nodejs.org/en) or newer.
47
47
  - [Go 1.26](https://go.dev/doc/install) or newer
48
48
 
49
49
  ## Install
@@ -116,7 +116,8 @@ Scaffolded `tsconfig.json` targets the TypeNative type surface:
116
116
  ```json
117
117
  {
118
118
  "compilerOptions": {
119
- "target": "es2020",
119
+ "target": "es2025",
120
+ "useDefineForClassFields": false,
120
121
  "lib": [],
121
122
  "types": ["typenative", "typenative/go", "typenative/npm"],
122
123
  "strict": true
@@ -126,6 +127,8 @@ Scaffolded `tsconfig.json` targets the TypeNative type surface:
126
127
 
127
128
  `lib: []` disables the standard TypeScript libraries, so `typenative`'s own declarations are the entire type surface, the compiler only accepts what actually transpiles.
128
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.
131
+
129
132
  ## CLI reference
130
133
 
131
134
  | Flag | Mode | Description |
@@ -289,7 +292,11 @@ each, live in [examples/](examples/). The flagships are
289
292
  unmodified source, matching Node's output on all 1,608 yaml-test-suite cases,
290
293
  and [marked-cli](examples/marked-cli/): the `marked` markdown parser's CLI,
291
294
  also from unmodified source, matching Node on all 2,859 cases of marked's spec
292
- suites (CommonMark, GFM, its own tests and ReDoS inputs).
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), matching Node on every parity fixture, 3.6x faster per file and
299
+ 1.7x faster on a 64 KB component file.
293
300
 
294
301
  ## How it works
295
302
 
@@ -306,10 +313,12 @@ main.ts --(type-check)--(parse)--> normalized JSON AST --(transpileToNative)-->
306
313
 
307
314
  `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`).
308
315
 
309
- 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`.
316
+ 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`.
310
317
 
311
318
  When adding a feature: add a probe, link it from [conformance.md](conformance.md), and keep the ✅/❌ matrix honest gaps are documented, not hidden.
312
319
 
320
+ `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).
321
+
313
322
  ## Self-hosted native compiler
314
323
 
315
324
  TypeNative compiles itself. `src/main.ts` transpiles to Go and builds into a `typenative` binary that needs no Node.js at runtime and emits the same Go as the npm package:
package/bin/cli.js CHANGED
@@ -79,6 +79,7 @@ import { VERSION } from './version.js';
79
79
  release: args.release,
80
80
  gui: args.gui,
81
81
  cover: args.cover,
82
+ profile: args.profile,
82
83
  emitGo: args.emitGo
83
84
  });
84
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;
@@ -30,6 +72,8 @@ Options:
30
72
  --gui Windowed app: no console window on Windows (ignored elsewhere)
31
73
  --cover Build with coverage counters, for go:runtime/coverage
32
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
33
77
  --emit-go <dir> Write the generated Go (and go.mod) to <dir> instead of building
34
78
  --no-typecheck Skip type-checking
35
79
  -h, --help Show this help
@@ -52,6 +96,7 @@ export function parseCliArgs(argv) {
52
96
  release: false,
53
97
  gui: false,
54
98
  cover: false,
99
+ profile: false,
55
100
  source: null,
56
101
  output: null,
57
102
  target: null,
@@ -82,6 +127,8 @@ export function parseCliArgs(argv) {
82
127
  args.gui = true;
83
128
  else if (arg === '--cover')
84
129
  args.cover = true;
130
+ else if (arg === '--profile')
131
+ args.profile = true;
85
132
  else if (arg === '--source' || arg === '--output' || arg === '--target' || arg === '--emit-go') {
86
133
  if (value === null) {
87
134
  if (i + 1 >= argv.length || argv[i + 1].startsWith('--')) {
@@ -484,12 +531,23 @@ export function run(opts) {
484
531
  else if (existing.endsWith('.go') && (!opts.emitGo || fs.readFileSync(file, 'utf-8').startsWith(GENERATED_HEADER)))
485
532
  fs.rmSync(file);
486
533
  }
487
- 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));
488
542
  const goFiles = ['code.go'];
489
543
  for (const [filename, content] of transpileResult.files) {
490
- fs.writeFileSync(path.join(outDir, filename), content);
544
+ fs.writeFileSync(path.join(outDir, filename), profiled(content));
491
545
  goFiles.push(filename);
492
546
  }
547
+ if (opts.profile) {
548
+ fs.writeFileSync(path.join(outDir, 'tn_profile.go'), PROFILE_GO);
549
+ goFiles.push('tn_profile.go');
550
+ }
493
551
  if (sourceDir)
494
552
  copyEmbeds(sourceDir, transpileResult.embeds, outDir);
495
553
  // Third-party Go modules the program imports (see vendorXText / vendorGoModules)
@@ -666,7 +724,8 @@ function getTsConfig() {
666
724
  const tsConfig = {
667
725
  include: ['**/*.ts'],
668
726
  compilerOptions: {
669
- target: 'es2020',
727
+ target: 'es2025',
728
+ useDefineForClassFields: false,
670
729
  lib: [],
671
730
  types: ['typenative', 'typenative/go', 'typenative/npm'],
672
731
  rootDir: '.',
package/bin/main.js CHANGED
@@ -56,6 +56,7 @@ import { VERSION } from './version.js';
56
56
  release: args.release,
57
57
  gui: args.gui,
58
58
  cover: args.cover,
59
+ profile: args.profile,
59
60
  emitGo: args.emitGo
60
61
  });
61
62
  })();
package/bin/node/core.js CHANGED
@@ -7,6 +7,44 @@ 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
+ case func([]byte):
43
+ if a, ok := tnInvokeAt(args, 0).([]byte); ok && f != nil {
44
+ f(a)
45
+ return nil
46
+ }
47
+ }
10
48
  fv := reflect.ValueOf(fn)
11
49
  if !fv.IsValid() || fv.Kind() != reflect.Func || fv.IsNil() {
12
50
  return nil
@@ -35,6 +73,14 @@ func TnInvoke(fn interface{}, args ...interface{}) interface{} {
35
73
  return nil
36
74
  }
37
75
 
76
+ // args[i], or nil past the end (a missing argument is undefined)
77
+ func tnInvokeAt(args []interface{}, i int) interface{} {
78
+ if i < len(args) {
79
+ return args[i]
80
+ }
81
+ return nil
82
+ }
83
+
38
84
  func tnInvokeArg(a interface{}, t reflect.Type) reflect.Value {
39
85
  if a == nil {
40
86
  return reflect.Zero(t)