typenative 0.5.0 → 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 (144) 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 +271 -1
  4. package/CONTRIBUTION.md +2 -1
  5. package/README.md +15 -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 +41 -0
  10. package/bin/node/events.js +15 -10
  11. package/bin/node/process.js +13 -0
  12. package/bin/node/punycode.js +2 -2
  13. package/bin/node/timers.js +4 -2
  14. package/bin/node/url.js +1 -1
  15. package/bin/parse-node.js +2 -2
  16. package/bin/regex_vm.js +2057 -0
  17. package/bin/transpiler.js +17225 -4830
  18. package/bin/typecheck-node.js +2 -1
  19. package/bin/version.js +1 -1
  20. package/conformance.md +57 -15
  21. package/examples/README.md +46 -23
  22. package/examples/angular-templates/README.md +139 -0
  23. package/examples/angular-templates/bench.mjs +173 -0
  24. package/examples/angular-templates/dom-type-globals.d.ts +21 -0
  25. package/examples/angular-templates/dom-type-stubs.ts +21 -0
  26. package/examples/angular-templates/main.ts +135 -0
  27. package/examples/angular-templates/parity.mjs +157 -0
  28. package/examples/angular-templates/run-node.mjs +69 -0
  29. package/examples/angular-templates/vendor/angular/compiler/LICENSE +21 -0
  30. package/examples/desktop-notes/README.md +11 -13
  31. package/examples/dupe-finder/README.md +7 -5
  32. package/examples/fibonacci/README.md +7 -7
  33. package/examples/hello-world/README.md +6 -6
  34. package/examples/json-server/README.md +19 -18
  35. package/examples/mandelbrot-png/README.md +11 -13
  36. package/examples/marked-cli/README.md +38 -37
  37. package/examples/openai-chat/README.md +148 -0
  38. package/examples/openai-chat/bench.mjs +175 -0
  39. package/examples/openai-chat/main.ts +488 -0
  40. package/examples/react-compiler/README.md +170 -0
  41. package/examples/react-compiler/bench.mjs +181 -0
  42. package/examples/react-compiler/main.ts +158 -0
  43. package/examples/react-compiler/parity.mjs +362 -0
  44. package/examples/react-compiler/run-node.mjs +88 -0
  45. package/examples/react-compiler/vendor/babel/LICENSE +22 -0
  46. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +15 -0
  47. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +51 -0
  48. package/examples/react-compiler/vendor/charcodes/package.json +25 -0
  49. package/examples/react-compiler/vendor/invariant/LICENSE +21 -0
  50. package/examples/react-compiler/vendor/invariant/invariant.cjs +51 -0
  51. package/examples/react-compiler/vendor/invariant/invariant.d.cts +11 -0
  52. package/examples/react-compiler/vendor/invariant/types/LICENSE +21 -0
  53. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +19 -0
  54. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +19 -0
  55. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +19 -0
  56. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +19 -0
  57. package/examples/react-compiler/vendor/js-tokens/LICENSE +21 -0
  58. package/examples/react-compiler/vendor/js-tokens/index.cjs +23 -0
  59. package/examples/react-compiler/vendor/js-tokens/index.d.cts +13 -0
  60. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +20 -0
  61. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +337 -0
  62. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +384 -0
  63. package/examples/react-compiler/vendor/jsesc/types/LICENSE +21 -0
  64. package/examples/react-compiler/vendor/picocolors/LICENSE +15 -0
  65. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +75 -0
  66. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +5 -0
  67. package/examples/react-compiler/vendor/picocolors/types.d.ts +51 -0
  68. package/examples/react-compiler/vendor/react-compiler/LICENSE +21 -0
  69. package/examples/react-compiler/vendor/stubs/babel-core.ts +31 -0
  70. package/examples/react-compiler/vendor/stubs/debug.ts +18 -0
  71. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +13 -0
  72. package/examples/react-compiler/vendor/stubs/pretty-format.ts +18 -0
  73. package/examples/react-compiler/vendor/zod/LICENSE +21 -0
  74. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +9 -0
  75. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +5 -0
  76. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +49 -0
  77. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +48 -0
  78. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +50 -0
  79. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +6 -0
  80. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +126 -0
  81. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +39 -0
  82. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +12 -0
  83. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +78 -0
  84. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +2 -0
  85. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +12 -0
  86. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +12 -0
  87. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +131 -0
  88. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +54 -0
  89. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +12 -0
  90. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +40 -0
  91. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +12 -0
  92. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +76 -0
  93. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +76 -0
  94. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +27 -0
  95. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +27 -0
  96. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +13 -0
  97. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +61 -0
  98. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +38 -0
  99. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +20 -0
  100. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +5 -0
  101. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +8 -0
  102. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +11 -0
  103. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +20 -0
  104. package/examples/react-compiler/vendor.mjs +688 -0
  105. package/examples/todo-cli/README.md +9 -9
  106. package/examples/yaml-cli/README.md +38 -28
  107. package/package.json +8 -5
  108. package/performance/README.md +195 -0
  109. package/performance/any-dynamic.ts +21 -0
  110. package/performance/any-record-view.ts +20 -0
  111. package/performance/arr-hof.ts +21 -0
  112. package/performance/arr-push-index.ts +15 -0
  113. package/performance/arr-sort.ts +21 -0
  114. package/performance/async-await.ts +24 -0
  115. package/performance/class-dispatch.ts +52 -0
  116. package/performance/events-emit.ts +27 -0
  117. package/performance/exc-throw-rare.ts +25 -0
  118. package/performance/exc-try-catch.ts +26 -0
  119. package/performance/fn-closures.ts +29 -0
  120. package/performance/fn-recursion-tree.ts +31 -0
  121. package/performance/gen-for-of.ts +46 -0
  122. package/performance/json-roundtrip.ts +27 -0
  123. package/performance/map-delete.ts +24 -0
  124. package/performance/map-string-keys.ts +22 -0
  125. package/performance/num-arith-loop.ts +14 -0
  126. package/performance/num-bitwise.ts +21 -0
  127. package/performance/num-mod-int.ts +16 -0
  128. package/performance/num-to-string.ts +16 -0
  129. package/performance/obj-alloc.ts +32 -0
  130. package/performance/regex-exec.ts +29 -0
  131. package/performance/regex-site.ts +28 -0
  132. package/performance/set-ops.ts +20 -0
  133. package/performance/str-char-scan.ts +35 -0
  134. package/performance/str-concat-plus.ts +18 -0
  135. package/performance/str-concat.ts +24 -0
  136. package/performance/str-short-scan.ts +26 -0
  137. package/performance/str-split-join.ts +23 -0
  138. package/performance/str-template.ts +16 -0
  139. package/performance/union-switch.ts +57 -0
  140. package/tsparser/check.go +2 -1
  141. package/tsparser/main.go +1 -0
  142. package/types/typenative-npm.d.ts +3 -2
  143. package/types/typenative.d.ts +42 -12
  144. 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
@@ -5,7 +5,277 @@ All notable changes to TypeNative will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [0.6.0] - 2026-11-13
9
+
10
+ The React Compiler itself (`babel-plugin-react-compiler` + Babel + zod, ~470 vendored files)
11
+ compiles React components and hooks to their auto-memoized form, natively, and an
12
+ OpenAI-compatible chat client streams answers token by token. Getting there drove the round's
13
+ transpiler fixes: JS object identity and callee write-back across Go conversions, one
14
+ backtracking regex VM with JS semantics for every pattern, and module initialization in the
15
+ import graph's evaluation order. TypeNative now requires Node.js 26. A `--profile` flag
16
+ and two rounds of hot-path fixes (bitwise and `%` arithmetic, generators, Map / Set deletes,
17
+ class dispatch, async functions and `JSON.parse`) narrow the gap with Node on the large
18
+ examples: react-compiler runs 26% faster at 64 KB and angular-templates 17% faster.
19
+
20
+ ### Added
21
+
22
+ - **`--profile`:** the built program writes a CPU profile (`runtime/pprof`) to
23
+ `$TYPENATIVE_CPUPROFILE` (default `cpu.pprof`) when it exits, on every exit
24
+ path, for `go tool pprof`
25
+ - **Performance probes:** `num-bitwise`, `num-mod-int`, `map-delete`,
26
+ `gen-for-of`, `str-short-scan`, `str-concat-plus`, `regex-site`,
27
+ `events-emit`, `async-await` and `exc-throw-rare`, covering what the large
28
+ examples stress; `performance/README.md` lists each fixed and open cause
29
+ - **examples/react-compiler:** the React Compiler (`babel-plugin-react-compiler` + Babel 7.29 parser/traverse/generator + zod 4, ~470 vendored files) compiling
30
+ React components and hooks to their auto-memoized form, natively. The build
31
+ drove a series of transpiler and runtime fixes (below); every fixture in
32
+ `parity.mjs` — components, hooks, the compiler's pragmas, JSX outlining,
33
+ TypeScript syntax and the error paths — now matches Node byte for byte,
34
+ output, `// CompileSuccess` counts and error code frames included, and
35
+ `bench.mjs` reports per-call latency and scaling
36
+ - **JS object and array identity across Go conversions:** converting one
37
+ object to another struct type gives the same converted object every time
38
+ (Set / Map keys and `===` find it), and union and intersection members are
39
+ views of the same memory; arrays stay shared through any-typed fields,
40
+ getters, dynamic calls and `splice`; a callee's changes to a converted
41
+ argument — an array, a Map or Set, an object's fields, through an
42
+ override too — are written back to the caller's; `slice` copies
43
+ - **JS semantics at the edges:** object-literal getters stay live (also when
44
+ a function returns the literal as `{ value: T }`); `Object.prototype`
45
+ methods read as values (`const toString = {}.toString`) run through
46
+ `call` / `apply`; default parameters apply to an explicit or forwarded
47
+ `undefined`; `null` stays apart from `undefined` where a function tests
48
+ both; Map misses and unset optional enum fields fall back with `??`; keys
49
+ written as `undefined` are own keys for `Object.keys`; `x.at(i)` and
50
+ `?.push` work on arrays held as any
51
+ - **Regex `v` flag (`unicodeSets`):** the backtracking VM now reads v-flag
52
+ class set expressions: subtraction (`[\p{L}--[aeiou]]`), intersection
53
+ (`[\p{Lu}&&[A-F]]`), nested and negated classes, and `\q{…}` strings, which
54
+ are tried longest first. With `i`, each operand is case-folded before the set
55
+ operation, as in JS. `v` implies unicode mode, and `re.unicodeSets` reports
56
+ the flag. Until now these patterns went to RE2, which misread the class and
57
+ matched the wrong text. Properties of strings (`\p{RGI_Emoji}`) aren't
58
+ supported.
59
+ - **examples/openai-chat:** a chat client for any OpenAI-compatible
60
+ `/v1/chat/completions` API. Answers stream into the terminal token by token:
61
+ `fetch` with a streaming response body (`response.body.getReader()`),
62
+ hand-parsed server-sent events (`data:` lines, `[DONE]`, ignored keep-alive
63
+ comments), an `AbortController` timeout, Ctrl+C aborting the answer in flight,
64
+ and a `for await` readline REPL with `/clear` and `/system`. Targets the free
65
+ OpenRouter API by default (`google/gemma-4-31b-it:free`), and OpenAI, Ollama
66
+ or any other compatible server through `--base-url`. `bench.mjs` stands up a
67
+ local mock SSE API, checks Node and TypeNative stdout byte for byte, then
68
+ times full one-shot runs (1.2x faster per answer, 716 vs 875 ms median — both
69
+ runtimes mostly wait on the mock's paced chunks). The example works around
70
+ two catch-block sharp edges (`return`/`continue` inside `catch` compiles
71
+ wrong or not at all), documented in its README
72
+ - **conformance:** `lib-regex-engine`, `lib-string-long-slices` and
73
+ `semantics-dynamic-field-access`, with expected values checked against Node
74
+
75
+ ### Changed
76
+
77
+ - **Node 26 and ES2025:** TypeNative now requires Node.js 26 or newer
78
+ (`engines`), and CI runs on Node 26. Scaffolded projects (`--new`) and the
79
+ default type-check (no `tsconfig.json`) target `es2025` instead of `es2020`,
80
+ so target-gated syntax such as the regex `v` flag, regex modifiers and
81
+ duplicate named groups type-checks. `useDefineForClassFields: false` is set
82
+ alongside it to keep TypeScript's classic field order (parameter properties
83
+ before field initializers), which is what TypeNative compiles. Existing
84
+ projects that keep `target: es2020` are unaffected.
85
+ - **Regex engine:** every `TnRegex` now runs on one backtracking VM with JS
86
+ semantics (`src/regex_vm.ts`), replacing the closure-based backtracker and RE2
87
+ as the first choice. Programs compile lazily and once per pattern and flags. A
88
+ match allocates only its result, and first-byte sets, literal prefixes and
89
+ anchors reject most calls without running anything. RE2 stays as a fallback
90
+ for patterns it can run that exhaust the VM's step budget, so those keep their
91
+ linear-time guarantee. Regex literals used inline get the same engine; only
92
+ Node built-ins' arguments and `/(?<name>…)/.exec(s)` stay on plain RE2
93
+ - **Dynamic values:** property reads and writes on objects held as any go through
94
+ plans cached per type and key instead of reflection; a read consumed on the
95
+ spot doesn't box its value; `obj.list.push(x)` appends in place instead of
96
+ converting the array on every push; object-type conversions are compiled per
97
+ pair of types; `Object.assign` between objects uses the same plans; `switch`
98
+ on a dynamic value over string literals is a Go string switch
99
+ - **Strings:** long strings grown with `+=` on a dynamic value are amortized;
100
+ short ASCII strings need no code-point index
101
+ - **Performance:** on 10 MB of input, examples/marked-cli went from 5.5x to 1.6x
102
+ slower than Node and examples/yaml-cli from 3.8x to 1.9x (the native binary
103
+ now finishes first up to about 1–2 MB per run), and marked's ReDoS inputs from
104
+ over 72 s to 4.7 s in total
105
+ - **Hot paths:** bitwise operators no longer call `math.Mod` (`TnInt32`
106
+ converts in-range values directly, literal operands fold, nested bitwise
107
+ expressions stay int32); `%` on integers is an `int64` remainder; a sync
108
+ generator iterated by `for…of` runs as a Go range function instead of a
109
+ goroutine in lockstep (break and throw keep JS's `finally` / `catch`
110
+ semantics); `Map` / `Set` deletes are O(1) and key handling takes no
111
+ reflection; `s = s + …` appends in place like `s += …`; `charCodeAt` over
112
+ short strings no longer rescans the string; `toFixed` skips exact
113
+ 1100-digit formatting except on ties; any-typed objects read their map
114
+ first; `Record<string, any>` views of an any object share its map;
115
+ common listener shapes are called without reflection; regex literals
116
+ share their compiled program per site. Probe medians: bitwise 2160 →
117
+ 129 ms, `%` loops 4527 → 162 ms, generators 1843 → 12 ms (now 4.4x faster
118
+ than Node), `Set` churn 1556 → 97 ms. examples/react-compiler at 64 KB
119
+ runs 26% faster (7.5 s → 5.6 s, interleaved against the previous build)
120
+ - **Dispatch, async and JSON hot paths:** a generator method called on a
121
+ value typed as a base class or interface (`unit.ops()`) runs its push form
122
+ through `TnCallSeq_<m>`, lazily as JS does (it used to collect every value
123
+ before the loop ran), and spread / `Array.from` of a generator collect its
124
+ push form into a typed slice; a method call through a class or interface
125
+ hierarchy whose implementations share a signature goes through a typed
126
+ dispatcher, without boxing; async functions that never wait on anything
127
+ pending run on the caller's goroutine, and settling a promise no longer
128
+ allocates when nobody waits; `JSON.parse(text) as T[]` decodes straight
129
+ into `T` when the text matches it; `for` loop counters and bitwise-result
130
+ consts are Go integers. Probe medians: `async-await` 1985 → 201 ms,
131
+ `class-dispatch` 709 → 124 ms, `json-roundtrip` 347 → 97 ms, `num-bitwise`
132
+ 128 → 114 ms; examples/angular-templates at 64 KB runs 17% faster (721 →
133
+ 601 ms, interleaved against the previous build)
134
+
135
+ ### Fixed
136
+
137
+ - **`null` is not `undefined`:** `typeof null` is `"object"` (it gave
138
+ `"undefined"`), `String(null)` and `null` in `+` / template strings give
139
+ `"null"` (`String(null)` printed `<nil>`), and `null` declared or assigned
140
+ into an `any` / `unknown` variable stays JS null
141
+ - **Classes with `*[Symbol.iterator]()`:** instances destructure
142
+ (`const [a, b] = bag`, reading only as many values as are bound, so an
143
+ endless iterator ends and its `finally` runs), spread into call and `new`
144
+ arguments (`Math.max(...bag)`, `f(...bag)`), and `bag[Symbol.iterator]()`
145
+ is a generator of its own; subclasses inherit all of it. Spreads that are
146
+ not the only argument of a rest parameter (`f(1, ...xs, 2)`,
147
+ `f(...xs, ...ys)`) now compile, for arrays too
148
+ - **Spread of a generator into arguments:** `f(...gen())` into a rest
149
+ parameter failed to compile, and `xs.push(...unit.ops())` through a
150
+ dynamic receiver asserted the generator's channel to an array
151
+ - **`(-Infinity).toFixed(n)`** returns `"-Infinity"` (it printed `-Inf`)
152
+
153
+ - **Namespaces of types only:** `namespace Tokens { export interface Def … }`
154
+ is flattened like any namespace (`Tokens_Def`) instead of being dropped, so
155
+ `Tokens.Def` resolves to its declaration (an unmatched regex group stored in
156
+ one of its `string` fields stays `undefined` and `JSON.stringify` leaves it
157
+ out: marked's `--tokens` printed `"title": ""` for a link definition without
158
+ a title). Only type references `Ns.T` are rewritten for such a namespace, so
159
+ a class merged with it keeps its value reads (`Scope.x`, `typeof Scope.x`)
160
+
161
+ - **Converting an object to a wider struct no longer reads or writes past
162
+ it:** a conversion whose source struct's fields are a prefix of the
163
+ target's (a member held in a merged union's slot) used to view the source's
164
+ memory as the target, so the target's extra fields lay past the object — in
165
+ the next object, or in size-class slack the garbage collector doesn't scan
166
+ for pointers. Such a view is now made only where the object's memory is
167
+ known to cover the target: a union narrowed to a member and widened back,
168
+ or an object literal allocated union-sized (an object literal whose struct
169
+ is a strict prefix of merged unions now gets room for their fields, with
170
+ the pointer layout they share, so a member held in a union's slot stays the
171
+ one object). Every other such conversion copies, through the identity
172
+ cache. (A literal's struct read as the interface it matches plus the
173
+ interface's key list `__keys` read the key list from whatever followed
174
+ the literal: `JSON.stringify` crashed on marked's table cells)
175
+ - **Module initialization order:** a program's module-level code now runs in
176
+ the import graph's evaluation order, as JS evaluates it — each module after
177
+ the modules it imports, with an import cycle's back edge not waiting (the
178
+ way Node starts evaluating a cycle mid-way through a module). It used to be
179
+ the emission order, which a cycle (the React Compiler's entrypoint barrels,
180
+ zod's) evaluates differently, leaving re-exported values uninitialized.
181
+ Imports whose bindings the code never uses as values — which tsc's emit
182
+ elides — no longer order inits either
183
+ - **`new F(…)` on a constructor-function value** now has JS `new` semantics:
184
+ the function runs with `this` a fresh object, which it may return or fill
185
+ (zod's `$constructor` factories read `this`); it used to be a plain call,
186
+ so a function reading `this` saw nothing
187
+ - **`fn.bind(…)` on a function value held as any** returns a bound function
188
+ (with the bound `this` and prepended arguments) instead of failing with
189
+ "bind is not a function"
190
+ - **`Object.assign(fn, props)`** copies the properties onto the function
191
+ value, where `fn.prop` reads them, instead of dropping them
192
+ - **`C.prototype[k] = fn` with a computed key** adds the method to the
193
+ class's prototype (its instances call it with `this` the instance) instead
194
+ of failing
195
+ - **A dynamic array method whose name a class or object literal declares
196
+ too** (`values.map(…)` beside a `Result.map`) runs the array method on
197
+ arrays and dispatches to the class on class instances, decided at run time
198
+ - **`x ??= v` on a nullable array variable** tests the reference itself
199
+ instead of dereferencing it, which panicked when it was unset
200
+ - **An empty object literal (`{}`) is no longer a zero-size Go value** — Go
201
+ gives every zero-size value the same address, which made every `{}` in a
202
+ program one shared object (each zod schema's internals landed in one place,
203
+ every schema reading the last-written definition)
204
+ - **Properties set on dynamic objects** are keyed by the object itself, so a
205
+ garbage-collected object's address being reused cannot hand its properties
206
+ to the new object
207
+ - **`Object.assign`/spread into a fresh object** skips a struct's internal
208
+ `__`-prefixed fields
209
+ - **A property assigned a value its field's Go type can't hold** now replaces
210
+ the property, as in JS: the field reads as undefined and the value is kept
211
+ beside the object (`Object.defineProperty`-style visitors — Babel's traverse
212
+ `explode` replaces a visitor function with `{ enter: fn }`) instead of
213
+ leaving the stale value readable and dropping the assignment. Reads fall
214
+ through a nil reference field to what was set beside the object, and
215
+ `Object.defineProperty` with a getter/setter now defines a real accessor on
216
+ class instances too (Babel's ParseError computes its `message` in a getter
217
+ that self-assigns); it used to silently support them only on dynamic objects
218
+ - **A call's argument converted to a copy the callee changes** is written back
219
+ at every statement position (plain calls, `x = f(op)`, `const x = f(op)`,
220
+ `return f(op)`), including arguments written `node as SomeType` and calls
221
+ through a mixin's virtual table, when the callee mutates the parameter's
222
+ fields — directly or by passing it on to a function that does. The fields it
223
+ changes are copied back to the original object, and ones the original's type
224
+ has no slot for are kept beside it (Babel's parser passes its nodes between
225
+ `parseExport`/`maybeParseExportDeclaration` and reads the fields back on the
226
+ original); the copy's changes used to be lost, emptying the parse result
227
+ - **`arr.push(x)` on an array read out of a container** (`aliases[k].push(x)`,
228
+ a Map's array value) stores the appended array back into the container, as
229
+ push mutates it in JS; it used to append to a copy and drop it, which left
230
+ @babel/types' alias tables empty and its node validators rejecting every node
231
+ - **A class instance passed where an interface type is expected** converts
232
+ with the properties it carries beyond its class filling the interface's
233
+ fields (Babel's parser keeps `imported`/`local` of an import specifier on a
234
+ bare Node); the conversion used to build a zero-filled struct
235
+ - **`f?.call(thisArg, …)` on a function value** calls nothing when f is unset
236
+ (an optional callback parameter's Go func type is nil); it used to deref nil.
237
+ A `do { … = this.parseSubscript(…, state) } while (!state.stop)` also no
238
+ longer loops forever: the state object the callee writes through the
239
+ converted parameter is written back
240
+ - **An intersection type alias** (`ParseResult<File> = File & { … }`) compiles
241
+ to a struct with every member's fields, and an interface renamed for a
242
+ cross-module name collision still resolves its fields (and shadows a Node
243
+ global's type) through the original name — the parser's `File` used to
244
+ convert to a 3-field struct and Node's `File` global type leaked into Babel's
245
+ - **A nullable array parameter with a default** (`tokens: Token[] | null =
246
+ null`) reads as nil when absent instead of dereferencing nil
247
+ - Optional chain calls guard the receiver, and a function's result type drives
248
+ `return f(…)` conversions again after the write-back change
249
+ - **A destructured binding of an object's array field** binds the array
250
+ itself, as in JS: push/pop/splice through it mutate the field's array
251
+ (`const { context } = this.state` then `context.push(…)` in Babel's JSX
252
+ tokenizer); it used to bind a copy and drop every mutation, flattening the
253
+ tokenizer's element context stack
254
+ - **An array stored into a dynamic object is kept as a reference**, as JS
255
+ arrays are shared: a push through any binding of the value reaches the
256
+ object's entry (`(ids[name] = ids[name] || []).push(…)` building Babel
257
+ traverse's Scope binding tables); the push used to append to a copy and
258
+ never register a binding, which rejected every node in Scope's validators.
259
+ `push`/`pop`/`shift`/`unshift` work on such references held as any
260
+ - **`x.push(…)` on an expando-stored array** (a bare parser Node's `body`)
261
+ appends to the array the object holds; it used to append to a copy and drop
262
+ it, which emptied every statement list the compiler's lowering walked
263
+ - **A mixin virtual method call returns its implementations' result** even
264
+ when an abstract declaration types it `: void` (Babel:
265
+ `return this.parseObjPropValue(prop, …)` over an
266
+ `abstract parseObjPropValue(…): void`); the returned node used to be
267
+ dropped, which made the compiler lower every function body to nothing
268
+ - **conformance:parallel:** example builds get the 10-minute budget the
269
+ sequential runner already gave them (the vendored-package examples
270
+ transpile tens of thousands of lines and go build the result — the React
271
+ Compiler example used to be killed at 90 s and reported as a bare `exit 1`),
272
+ and the largest example runs alone before the pack
273
+ - `.`, `^` and `$` follow JS's line terminators in every regex, `[]` and `[^]`
274
+ mean what they do in JS, captures reset on each loop iteration, and `\p` is a
275
+ property only with the `u` flag
276
+ - `\k<name>` in a regex literal panicked in RE2
277
+ - Slices of a long non-ASCII string rebuilt its whole index each time, making a
278
+ lexer over non-ASCII input quadratic
9
279
 
10
280
  ## [0.5.0] - 2026-11-01
11
281
 
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,10 @@ 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) and is one runtime gap away from its benchmarks.
293
299
 
294
300
  ## How it works
295
301
 
@@ -306,10 +312,12 @@ main.ts --(type-check)--(parse)--> normalized JSON AST --(transpileToNative)-->
306
312
 
307
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`).
308
314
 
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`.
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`.
310
316
 
311
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.
312
318
 
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).
320
+
313
321
  ## Self-hosted native compiler
314
322
 
315
323
  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,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)
@@ -172,20 +172,25 @@ func (e *TnEventEmitter) removeAllListeners(event ...string) *TnEventEmitter {
172
172
  func (e *TnEventEmitter) emit(event string, args ...interface{}) bool {
173
173
  s := e.st()
174
174
  s.mu.Lock()
175
- list := append([]*tnListener{}, s.events[event]...)
175
+ // (listener lists are copy-on-write — adds append past this length, removals
176
+ // build a new slice — so the list as it is now is the emit's snapshot)
177
+ list := s.events[event]
176
178
  // once listeners are removed before they run
177
- kept := []*tnListener{}
178
- for _, l := range s.events[event] {
179
- if !l.once {
180
- kept = append(kept, l)
179
+ for i, l := range list {
180
+ if l.once {
181
+ kept := append([]*tnListener{}, list[:i]...)
182
+ for _, rest := range list[i+1:] {
183
+ if !rest.once {
184
+ kept = append(kept, rest)
185
+ }
186
+ }
187
+ e.setListeners(event, kept)
188
+ break
181
189
  }
182
190
  }
183
- if len(kept) != len(s.events[event]) {
184
- e.setListeners(event, kept)
185
- }
186
- monitors := []*tnListener{}
191
+ var monitors []*tnListener
187
192
  if event == "error" {
188
- monitors = append(monitors, s.events[TnErrorMonitor]...)
193
+ monitors = s.events[TnErrorMonitor]
189
194
  }
190
195
  capture := s.captureRejections
191
196
  s.mu.Unlock()
@@ -415,6 +415,19 @@ export function registerProcess(r) {
415
415
  return 'TnProcessArgv()';
416
416
  });
417
417
  value('execArgv', '[]string', () => '[]string{}');
418
+ // process itself as a value (let p = process || {}, picocolors'): an
419
+ // object of its common members, read dynamically
420
+ r.values['process'] = (_c) => {
421
+ use();
422
+ r.helper('osPlatform');
423
+ r.helper('dynamic');
424
+ r.pkg('os');
425
+ return 'func() *TnMap[string, interface{}] { __p := TnNewMap[string, interface{}](); __argv := []interface{}{}; for _, __a := range TnProcessArgv() { __argv = append(__argv, __a) }; __p.Set("argv", __argv); ' +
426
+ '__env := TnNewMap[string, interface{}](); __src := TnEnvMap(); for _, __k := range __src.Keys() { __env.Set(__k, __src.Get(__k)) }; __p.Set("env", __env); __p.Set("platform", TnOsPlatform()); ' +
427
+ '__out := TnNewMap[string, interface{}](); if TnIsTTY(os.Stdout) { __out.Set("isTTY", true) }; __p.Set("stdout", __out); ' +
428
+ '__p.Set("emitWarning", func(__w interface{}, __rest ...interface{}) { __t, _ := TnArg(__rest, 0).(string); TnProcessEmitWarning(__w, __t) }); return __p }()';
429
+ };
430
+ r.valueTypes['process'] = '*TnMap[string, interface{}]';
418
431
  value('argv0', 'string', () => {
419
432
  r.pkg('os');
420
433
  return 'os.Args[0]';