typenative 0.4.1 → 0.5.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 (151) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +62 -22
  3. package/ROUND2-HANDOFF.md +200 -0
  4. package/bin/cli.js +1 -0
  5. package/bin/index.js +13 -2
  6. package/bin/main.js +1 -0
  7. package/bin/node/assert.js +2 -2
  8. package/bin/node/async_hooks.js +1 -1
  9. package/bin/node/buffer.js +16 -5
  10. package/bin/node/child_process.js +7 -7
  11. package/bin/node/cluster.js +3 -3
  12. package/bin/node/crypto_keys.js +21 -21
  13. package/bin/node/dgram.js +1 -1
  14. package/bin/node/diagnostics_channel.js +3 -3
  15. package/bin/node/dns.js +2 -2
  16. package/bin/node/events.js +3 -3
  17. package/bin/node/fetch.js +2 -2
  18. package/bin/node/fs.js +3 -3
  19. package/bin/node/fs_watch.js +5 -5
  20. package/bin/node/http.js +3 -3
  21. package/bin/node/http2.js +3 -3
  22. package/bin/node/net.js +8 -8
  23. package/bin/node/path.js +17 -3
  24. package/bin/node/process.js +34 -11
  25. package/bin/node/readline.js +1 -1
  26. package/bin/node/registry.js +4 -1
  27. package/bin/node/sqlite.js +6 -6
  28. package/bin/node/stream.js +81 -15
  29. package/bin/node/stream_web.js +10 -10
  30. package/bin/node/system_extra.js +3 -3
  31. package/bin/node/test.js +674 -366
  32. package/bin/node/test_coverage.js +187 -0
  33. package/bin/node/test_report.js +1392 -0
  34. package/bin/node/test_run.js +575 -0
  35. package/bin/node/timers.js +4 -4
  36. package/bin/node/tls.js +5 -5
  37. package/bin/node/util.js +31 -7
  38. package/bin/node/util_extra.js +7 -7
  39. package/bin/node/webview.js +654 -0
  40. package/bin/node/worker_threads.js +1 -1
  41. package/bin/node/zlib.js +3 -3
  42. package/bin/parse-node.js +4 -0
  43. package/bin/transpiler.js +10390 -1178
  44. package/bin/version.js +1 -1
  45. package/conformance.md +468 -340
  46. package/examples/README.md +47 -10
  47. package/examples/desktop-notes/README.md +108 -0
  48. package/examples/desktop-notes/bench.mjs +125 -0
  49. package/examples/desktop-notes/main.ts +131 -0
  50. package/examples/desktop-notes/package-lock.json +726 -0
  51. package/examples/desktop-notes/package.json +9 -0
  52. package/examples/desktop-notes/ui.ts +176 -0
  53. package/examples/dupe-finder/README.md +76 -0
  54. package/examples/dupe-finder/bench.mjs +120 -0
  55. package/examples/dupe-finder/main.ts +87 -0
  56. package/examples/mandelbrot-png/README.md +65 -0
  57. package/examples/mandelbrot-png/bench.mjs +95 -0
  58. package/examples/mandelbrot-png/main.ts +98 -0
  59. package/examples/mandelbrot-png/preview.png +0 -0
  60. package/examples/marked-cli/README.md +159 -0
  61. package/examples/marked-cli/bench.mjs +178 -0
  62. package/examples/marked-cli/main.ts +292 -0
  63. package/examples/marked-cli/parity.mjs +185 -0
  64. package/examples/marked-cli/vendor/marked/LICENSE +44 -0
  65. package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
  66. package/examples/todo-cli/README.md +69 -0
  67. package/examples/todo-cli/bench.mjs +89 -0
  68. package/examples/todo-cli/main.ts +92 -0
  69. package/examples/yaml-cli/README.md +136 -0
  70. package/examples/yaml-cli/bench.mjs +265 -0
  71. package/examples/yaml-cli/main.ts +29 -0
  72. package/examples/yaml-cli/parity.mjs +156 -0
  73. package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
  74. package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
  75. package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
  76. package/govendor/github.com/jchv/go-webview2/README.md +21 -0
  77. package/govendor/github.com/jchv/go-webview2/common.go +84 -0
  78. package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
  79. package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
  80. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
  81. package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
  82. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
  83. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
  84. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
  85. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
  86. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
  87. package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
  88. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
  89. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
  90. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
  91. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
  92. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
  93. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
  94. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
  95. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
  96. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
  97. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
  98. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
  99. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
  100. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
  101. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
  102. package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
  103. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
  104. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
  105. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
  106. package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
  107. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
  108. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
  109. package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
  110. package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
  111. package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
  112. package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
  113. package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
  114. package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
  115. package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
  116. package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
  117. package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
  118. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
  119. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
  120. package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
  121. package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
  122. package/govendor/github.com/jchv/go-winloader/README.md +124 -0
  123. package/govendor/github.com/jchv/go-winloader/common.go +11 -0
  124. package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
  125. package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
  126. package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
  127. package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
  128. package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
  129. package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
  130. package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
  131. package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
  132. package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
  133. package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
  134. package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
  135. package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
  136. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
  137. package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
  138. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
  139. package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
  140. package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
  141. package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
  142. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
  143. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
  144. package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
  145. package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
  146. package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
  147. package/govendor/manifest.txt +3 -1
  148. package/package.json +1 -1
  149. package/tsparser/main.go +4 -0
  150. package/types/typenative-npm.d.ts +190 -2
  151. package/types/typenative.d.ts +98 -31
package/CHANGELOG.md CHANGED
@@ -7,6 +7,177 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-11-01
11
+
12
+ The `yaml` package's own CLI, compiled from its unmodified TypeScript source, as the first
13
+ flagship example: 100% output parity with Node on the yaml-test-suite in all four modes. Getting
14
+ there took transpiler fixes across the board, each with a conformance probe.
15
+
16
+ The second flagship example is the `marked` package's own CLI, compiled from marked's unmodified
17
+ TypeScript source: 100% output parity with Node on marked's spec suites (CommonMark, GFM and its
18
+ own tests, ReDoS inputs included) in three modes. Its fixes are listed under **marked** below.
19
+
20
+ ### Added
21
+
22
+ - **Native app windows:** programs can open webview windows through the
23
+ `@webviewjs/webview` API, so the same source runs under Node.js (the npm package) and compiled
24
+ (built in). Windows embeds the system WebView2 through the vendored, pure-Go
25
+ `jchv/go-webview2`; macOS and Linux, and Windows without the WebView2 runtime, open Chrome, Edge
26
+ or Chromium in app mode. No cgo, and cross-compiling still works. The macOS and Linux path builds
27
+ in CI but has not been run on those systems
28
+ - **`--gui`:** builds a windowed app with no console window on Windows (ignored for other targets)
29
+ - **examples/marked-cli:** marked v18.1.2 vendored unpatched (`vendor/marked/VENDOR.md`),
30
+ `main.ts` porting upstream's `bin/main.js`, `parity.mjs` (2,859 cases: marked's commonmark,
31
+ gfm, new, original and redos specs in default, `--no-gfm` and `--tokens` modes, compared byte
32
+ for byte with Node) and `bench.mjs` (per-call latency on marked's README, throughput on ~10 MB
33
+ of generated markdown)
34
+ - **marked:** function declarations inside functions and blocks (hoisted; async and generator
35
+ ones too); `f.apply` / `f.call` on functions held as `any`; `Ns.T` of a namespace another
36
+ module declares; generic interfaces used without type arguments, interfaces extending
37
+ `Omit<>` / `Pick<>` / `Partial<>`, open object types and array types with properties
38
+ (`T[] & { links: L }`); `process.stdout.write(data, callback)`; `split(sep, limit)` with a
39
+ RegExp
40
+
41
+ - **examples/yaml-cli:** yaml v3.0.0-2 vendored unpatched (`vendor/yaml/VENDOR.md`), `main.ts`
42
+ porting upstream's `bin.js`, `parity.mjs` (1,608 cases from yaml-test-suite data-2022-01-17
43
+ in default, `--json`, `valid` and `lex` modes, compared byte for byte with Node) and
44
+ `bench.mjs` (per-call latency on a docker-compose.yml, throughput on ~10 MB of generated
45
+ Kubernetes manifests)
46
+ - `new Map(iterable)` from Maps, iterators, generators and `Object.entries`; plain objects and
47
+ arrays as Map keys and Set members, by identity (they panicked as unhashable); generic type aliases
48
+ (`type WithId<T> = T & { id: number }`); instantiation expressions (`g<number>`) and explicit
49
+ type arguments in call results; `typeof f` as a function type
50
+ - `emitWarning(warning, type)`; `JSON.stringify(buffer)` as `{ type: 'Buffer', data }`
51
+
52
+ ### Changed
53
+
54
+ - **examples/desktop-notes:** the UI now opens in a real webview window under both Node.js and
55
+ TypeNative, instead of launching Edge or Chrome with `--app`. Closing the window ends the app
56
+ directly, so the `/api/bye` beacon and the heartbeat timeout are gone. Running it under Node.js
57
+ now needs `npm install` in the example folder
58
+
59
+ ### Fixed
60
+
61
+ - **marked — arrays:** arrays are shared as in JS: an object type's array field, an `any[]`
62
+ variable and a parameter holding one array see each other's pushes, also through `any`
63
+ (`tok.tokens.unshift(…)`); a method returning its array argument returns that array
64
+ - **marked — regexes:** JS escapes (`\xHH`, `\u{…}`, `\cJ`, `\p{…}`, `\k<name>`) and JS's
65
+ Unicode `\s` in every pattern, also in the backtracking engine; RegExp values stored in
66
+ objects, built at run time and called through `any`; regexes that look behind the match
67
+ (`^`, `\b`) at a non-zero offset; unmatched groups stay `undefined` through consts,
68
+ conditionals and `string` fields (left out of JSON)
69
+ - **marked — strings and objects:** `toUpperCase` / `toLowerCase` map case as JS does (`ß` →
70
+ `SS`, `İ` → `i̇`, final `ς`); `trim` uses JS's whitespace; `replace` with a `string | RegExp`
71
+ pattern or a function value; JSON key order of object literals that list keys in another
72
+ order than their type; `string | null` fields keep `null` and `undefined` apart (an optional
73
+ one is an any field; a required one is written as `null` by `JSON.stringify`)
74
+ - **marked — type inference:** `let x;` assigned on every path holds its value type; long call
75
+ chains on a fluent builder (`edit(re).replace(…).replace(…)…`) no longer take exponential time
76
+ (inference is memoized per query); module-level names a local shadows; a `for…of` whose body
77
+ never reads its variable compiles
78
+ - **marked — performance:** the regex backtracker works on byte offsets (no rune conversion of
79
+ the input per match), repeats a single character class without allocating and tests ASCII
80
+ against a table; regexes skip ahead with a first-byte prefilter (an anchored one fails at
81
+ once) instead of running RE2 over the rest of a long input; strings built with `+=` in a loop
82
+ are `strings.Builder`s. Rendering is now linear in the input
83
+ - **marked — self-hosting:** the native compiler builds and `npm run bootstrap:check` holds
84
+ with this round's changes: a function literal stored where a function type is expected takes
85
+ that type's (plain slice) array parameters, and a function value with array-reference
86
+ parameters is adapted where plain slices are expected; a string-method name that some object
87
+ literal's function also has (`x.startsWith(…)` on an any value) runs the string method on a
88
+ string; functions in a `Record<K, F>` dictionary no longer count as such methods; a `+=`
89
+ string accumulator used in a closure stays a plain string
90
+ - **Regexes:** unmatched groups are `undefined`; `new RegExp(src, 'g' | 'y')` keeps its flags;
91
+ `$&`, `` $` ``, `$'`, `$<name>` and `$$` replacements; replacer callbacks get the match offset
92
+ and the input
93
+ - **Objects:** `Object.assign({}, typed, overrides)` keeps the type and its function fields, and
94
+ an explicit `undefined` override clears; integer-like keys of plain objects come first;
95
+ `x.constructor` on any values; `null` in JSON and `any` data stays `null` (not `undefined`)
96
+ - **Classes:** a class picked at run time or passed as `new (…) => T` constructs; `this.name` in
97
+ an Error subclass; optional array parameters passed on to defaulted ones (`super(items)`);
98
+ `x as unknown as T[]` returns the value as is
99
+ - **Numbers:** `toFixed` rounds ties away from zero, also on `any` values and in callbacks
100
+ - **Control flow:** `for (; …; a, b)` with no initializer; function properties assigned twice;
101
+ unread `for (const [k, v] of map)` bindings; `instanceof Date` narrowing
102
+ - **Type inference:** user-defined type guards (`(t): t is string`) narrow their argument; a
103
+ conditional's branches are typed with the condition's narrowing; array callbacks' locals are
104
+ typed from their own declarations; `o?.m()` and `o?.push(x)` on any values don't call through
105
+ a nullish `o`; `flatMap` callbacks returning any values; a function declared to return
106
+ `T[] | undefined` keeps `undefined` (it was an empty array); `xs[i] ?? d` over
107
+ `(T | undefined)[]` elements; object literals assigned into any
108
+ slots stay extensible
109
+ - **Self-hosting:** the native compiler builds again (`npm run build:native`; it also failed on
110
+ 0.4.2's coverage code) and `npm run bootstrap:check` holds: it turns its own source into the
111
+ same Go as the Node CLI. The compiler's code no longer reads missing `Map` / `Record` keys
112
+ as `undefined` (natively they read as `''`)
113
+ - **Performance:** string positions on long inputs no longer rebuild their code-point index per
114
+ regex match (quadratic lexing); struct field lookups and struct-to-struct copies are cached
115
+
116
+ ## [0.4.2] - 2026-10-28
117
+
118
+ `node:test` reporters, `run()`, coverage, snapshots and member mocks; four runnable examples
119
+ with Node-vs-TypeNative benchmarks, examples type-checked and built by the conformance suite,
120
+ and compiler fixes for names that shadow Go types, rest destructuring, number formatting, and
121
+ `Number()` on optional values.
122
+
123
+ ### Added
124
+
125
+ - **`node:test`:**
126
+ - `run({ files })`: files with literal paths compile in as entry points and run as child
127
+ processes; their events stream back on a TestsStream — top-level numbering continues across
128
+ files, child output becomes `test:stdout` / `test:stderr`, per-file summaries and coverage
129
+ merge, and listeners get typed data (`run(…).on('test:fail', (data) => …)`)
130
+ - coverage with `--experimental-test-coverage`: programs that import `node:test` count what
131
+ runs over V8-style source ranges (functions, blocks, ternary arms, `&&` / `||` / `??`
132
+ operands, class field initializers), with `node:coverage ignore` comments, `--test-coverage-include` /
133
+ `-exclude` and the `-lines` / `-branches` / `-functions` thresholds; the lcov records and
134
+ the tap / spec coverage table match Node's output
135
+ - snapshots: `t.assert.snapshot` / `t.assert.fileSnapshot` with `--test-update-snapshots`
136
+ (Node's `<test file>.snapshot` format), `snapshot.setDefaultSnapshotSerializers` /
137
+ `setResolveSnapshotPath`; a missing file or entry names the update flag
138
+ - `mock.method` / `mock.getter` / `mock.setter` on object literals, class instances
139
+ (inherited members included, other instances unaffected) and namespace functions
140
+ (`console.log`, `Math.random`, …); `.mock` reads the call record, `t.mock` restores after
141
+ each test
142
+ - failing tests report their `location` (`file:line:col`) in TAP, spec and junit
143
+ - `--test-reporter-destination` pairs with `--test-reporter` (a file, `stdout` or `stderr`)
144
+ - **`node:test/reporters`:** `tap` / `dot` / `junit` as generator functions over an event
145
+ source (an array, an async generator, a stream such as `run()`'s) and `spec` / `lcov` as
146
+ Transform streams for `compose()` — Node's output, byte for byte
147
+ - **Streams:** `compose()` (pipe into a stream, or hand the source to a function — an async
148
+ generator over the chunks, a reporter), and `.on()` / `.once()` return the stream, for
149
+ chaining as in Node
150
+ - **Types:** `AsyncIterable<T>` / `AsyncIterableIterator<T>` / `AsyncGenerator<T>` map to
151
+ channels (like `Promise<T>`), so async-iterable parameters type-check
152
+ - **Examples:** `todo-cli`, `dupe-finder`, `mandelbrot-png` and `desktop-notes` (a notes app in an
153
+ Edge/Chrome app window), each with a Node-vs-TypeNative benchmark
154
+ - **Conformance:** every `examples/*/main.ts` is type-checked and built by the suite as
155
+ `example-<name>`
156
+
157
+ ### Changed
158
+
159
+ - `conformance.md` lists npm packages published only as JavaScript/CommonJS as 🚫 (their
160
+ implementations have no types to compile from), not ❌
161
+
162
+ ### Fixed
163
+
164
+ - **Object-literal methods:** reading one as a value (`const f = obj.method`) no longer calls
165
+ it; getters still run on read, including when destructured (`const { double } = calc`)
166
+ - **`node:stream`:** programs that use streams but not `util.inspect` compile again (a
167
+ `compose()` error message referenced `util.inspect`'s helper)
168
+ - **Names:** variables and parameters named like Go types (`string`, `bool`, `int32`, ...) no
169
+ longer shadow the type; methods named like Go builtins (`copy()`, `len()`, `static make`) are
170
+ callable (the declaration was renamed, the call wasn't), and inherited methods named like Go
171
+ keywords (`range()`) compile
172
+ - **Destructuring:** `const [a, ...rest] = arr` gives `rest` the remaining elements (it compiled to
173
+ a single element)
174
+ - **Numbers:** `String(n)`, templates and `JSON.stringify` print non-integers in plain notation
175
+ from `1e-6` up to `1e21` (`1761603012345.678`, not `1.761603012345678e+12`), and exponents
176
+ without padding (`1e-7`, not `1e-07`)
177
+ - **`Number()`:** converts optional strings and booleans (`Number(s)` with `s: string | undefined`
178
+ gave `NaN`)
179
+ - **Conformance:** the detached child-process probe no longer spawns Unix `sleep` on Windows
180
+
10
181
  ## [0.4.1] - 2026-10-24
11
182
 
12
183
  Node-accurate JSON (`stringify` with spacing and replacers, `parse` with a reviver, and JSON
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TypeNative
2
2
 
3
- TypeNative is a TypeScript-to-Go transpiler, it turns TypeScript into Go code and compiles it to a single-file native executable — no Node.js runtime, no bundler, just a binary. Write TypeScript, ship native binaries.
3
+ TypeNative is a TypeScript-to-Go transpiler, it turns TypeScript into Go code and compiles it to a single-file native executable, no Node.js runtime, no bundler, just a binary. Write TypeScript, ship native binaries.
4
4
 
5
5
  ```ts
6
6
  // hello.ts
@@ -18,6 +18,7 @@ npx typenative --source hello.ts --script
18
18
 
19
19
  ## Contents
20
20
 
21
+ - [Why use TypeNative](#why-use-typenative)
21
22
  - [Requirements](#requirements)
22
23
  - [Install](#install)
23
24
  - [Quick start](#quick-start)
@@ -29,6 +30,17 @@ npx typenative --source hello.ts --script
29
30
  - [Self-hosted native compiler](#self-hosted-native-compiler)
30
31
  - [License](#license)
31
32
 
33
+ ## Why use TypeNative
34
+
35
+ - **Ship one file.** The output is a single self-contained executable: no Node.js install, no `node_modules`, no bundler. Copy it to a server and run it, or cross-compile for Linux, macOS and Windows from any OS with `--target`.
36
+ - **Start instantly.** There is no runtime to boot and no JIT to warm up: a hello world starts in ~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.
38
+ - **Keep your TypeScript.** Same syntax, same types, and Node's own APIs (`node:fs`, `node:http`, `node:crypto`, …) with Node's signatures. The [examples](examples/) run unchanged under both `node` and TypeNative.
39
+ - **Reach into Go.** Import any Go package directly (`import { Println } from 'go:fmt'`) when you need something Node doesn't have.
40
+ - **Know what works.** Type errors and unsupported syntax are reported against your `.ts` lines before anything builds, and every supported feature is backed by a runnable probe in [conformance.md](conformance.md).
41
+
42
+ Numbers are medians from the [examples/](examples/) benchmarks (Windows 11, Ryzen 5 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.
43
+
32
44
  ## Requirements
33
45
 
34
46
  - [Node.js v24](https://nodejs.org/en) or newer.
@@ -112,22 +124,23 @@ Scaffolded `tsconfig.json` targets the TypeNative type surface:
112
124
  }
113
125
  ```
114
126
 
115
- `lib: []` disables the standard TypeScript libraries, so `typenative`'s own declarations are the entire type surface — the compiler only accepts what actually transpiles.
127
+ `lib: []` disables the standard TypeScript libraries, so `typenative`'s own declarations are the entire type surface, the compiler only accepts what actually transpiles.
116
128
 
117
129
  ## CLI reference
118
130
 
119
- | Flag | Mode | Description |
120
- | ----------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
121
- | `--source <file>` | build / script | TypeScript entry file. Relative imports (`./util`) and npm packages are resolved from its directory. |
122
- | `--output <path>` | build | Where to copy the compiled binary. If omitted with `--script`, the temp binary in `dist/` is executed and kept there. |
123
- | `--script` | run | Build to `dist/native(.exe)` and execute immediately with inherited stdio. Combine with `--source`, or omit `--source` to type code into the prompt. |
124
- | `--new` | scaffold | Create a new project directory (`main.ts`, `package.json`, `tsconfig.json`, `README.md`, `.gitignore`). |
125
- | `--no-typecheck` | build / script | Skip the type-check that runs before transpiling. |
126
- | `--target <os/arch>` | build | Cross-compile for another platform (`linux/amd64`, `linux/arm64`, `darwin/arm64`, `windows/amd64`, … — `go tool dist list` shows every pair). `--script` only runs host builds. |
127
- | `--release` | build / script | Smaller binary: strips symbols and file paths (`-trimpath -ldflags="-s -w"`). |
128
- | `--emit-go <dir>` | build | Write the generated Go (`code.go`, `go.mod`, vendored modules) to `<dir>` instead of building; `go build -C <dir>` builds it. |
129
- | `-h`, `--help` | | Print the options. |
130
- | `-v`, `--version` | | Print the TypeNative version. |
131
+ | Flag | Mode | Description |
132
+ | -------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | `--source <file>` | build / script | TypeScript entry file. Relative imports (`./util`) and npm packages are resolved from its directory. |
134
+ | `--output <path>` | build | Where to copy the compiled binary. If omitted with `--script`, the temp binary in `dist/` is executed and kept there. |
135
+ | `--script` | run | Build to `dist/native(.exe)` and execute immediately with inherited stdio. Combine with `--source`, or omit `--source` to type code into the prompt. |
136
+ | `--new` | scaffold | Create a new project directory (`main.ts`, `package.json`, `tsconfig.json`, `README.md`, `.gitignore`). |
137
+ | `--no-typecheck` | build / script | Skip the type-check that runs before transpiling. |
138
+ | `--target <os/arch>` | build | Cross-compile for another platform (`linux/amd64`, `linux/arm64`, `darwin/arm64`, `windows/amd64`, … `go tool dist list` shows every pair). `--script` only runs host builds. |
139
+ | `--release` | build / script | Smaller binary: strips symbols and file paths (`-trimpath -ldflags="-s -w"`). |
140
+ | `--gui` | build / script | A windowed app: no console window on Windows (`-ldflags=-H=windowsgui`). Ignored for other targets. |
141
+ | `--emit-go <dir>` | build | Write the generated Go (`code.go`, `go.mod`, vendored modules) to `<dir>` instead of building; `go build -C <dir>` builds it. |
142
+ | `-h`, `--help` | | Print the options. |
143
+ | `-v`, `--version` | | Print the TypeNative version. |
131
144
 
132
145
  The entry file can also be the last argument (`typenative main.ts --script`), and every option accepts `--flag=value`. Unknown options are an error (exit code `2`). Before building, the CLI checks that Go 1.26 or newer is on the `PATH`.
133
146
 
@@ -142,7 +155,7 @@ Errors point at your TypeScript, not the generated Go: `dist/code.go` carries Go
142
155
 
143
156
  ## Writing TypeNative-compatible TypeScript
144
157
 
145
- TypeNative supports a growing subset of TypeScript, not the whole language. The source of truth is [conformance.md](conformance.md) — every supported feature links to a runnable probe in [conformance/](conformance/).
158
+ TypeNative supports a growing subset of TypeScript, not the whole language. The source of truth is [conformance.md](conformance.md). Every supported feature links to a runnable probe in [conformance/](conformance/).
146
159
 
147
160
  **Language highlights that work today:**
148
161
 
@@ -169,7 +182,7 @@ TypeNative supports a growing subset of TypeScript, not the whole language. The
169
182
  | `JSON` | `parse` / `stringify` |
170
183
  | `RegExp` | Literals + `new RegExp()`, `test()`, `exec()` with named groups (`.groups`), flags `i`/`m`/`s`/`g`/`y`/`u`, stateful `lastIndex` for `/g` loops, `source`/`flags`/`global`/... properties. Backreferences, lookahead and lookbehind run on a small backtracking engine (RE2 does not support them) |
171
184
  | Globals | `setTimeout`/`clearTimeout`, `setInterval`/`clearInterval`, `queueMicrotask`, `structuredClone`, `globalThis`, `encodeURIComponent`/`decodeURIComponent`, `isNaN`/`isFinite`, `NaN`/`Infinity` |
172
- | `process` | `argv`, `platform` (→ Node-style names), `env`, `cwd`, `exit`, `exitCode`, `hrtime`, `stdout`/`stderr`/`stdin`, `on('exit')`, … (see [node:process](conformance.md#nodeprocess)) |
185
+ | `process` | `argv`, `platform` (→ Node-style names), `env`, `cwd`, `exit`, `exitCode`, `hrtime`, `stdout`/`stderr`/`stdin`, `on('exit')`, … (see [node:process](conformance.md#nodeprocess)) |
173
186
 
174
187
  **Node built-ins (import with the `node:` prefix, mapped to Go helpers):**
175
188
 
@@ -195,7 +208,7 @@ import { ToUpper } from 'go:strings';
195
208
  Println(Sprintf('hi %s', ToUpper('bob')));
196
209
  ```
197
210
 
198
- Any Go package can be imported this way (`import { X } from 'go:pkg'` → `pkg.X` with numeric conversion and throw-on-error results). The full standard library is declared for typechecking (`npm run gen:go`), with 154 packages probed — see [conformance.md](conformance.md#go-bridges-gostar).
211
+ Any Go package can be imported this way (`import { X } from 'go:pkg'` → `pkg.X` with numeric conversion and throw-on-error results). The full standard library is declared for typechecking (`npm run gen:go`), with 154 packages probed, see [conformance.md](conformance.md#go-bridges-gostar).
199
212
 
200
213
  **npm packages:**
201
214
 
@@ -247,9 +260,36 @@ c.inc();
247
260
  console.log(`count=${c.count} seen=${seen.get('a')}`);
248
261
  ```
249
262
 
250
- Complete, runnable projects — including Node-vs-TypeNative benchmarks for
251
- each — live in [examples/](examples/): a hello world (startup), a recursive
252
- fibonacci (CPU), and a JSON web server (`node:http` GET/POST).
263
+ A desktop app with a webview window:
264
+
265
+ ```ts
266
+ import { Application } from '@webviewjs/webview';
267
+
268
+ const app = new Application();
269
+ const win = app.createBrowserWindow({ title: 'Hello', width: 800, height: 600, logical: true });
270
+ win.createWebview({ html: '<h1>Hello from a native window</h1>' });
271
+ app.run();
272
+ ```
273
+
274
+ ```sh
275
+ npx typenative --source app.ts --output hello.exe --gui --release
276
+ ```
277
+
278
+ The same source runs under Node.js with the
279
+ [`@webviewjs/webview`](https://www.npmjs.com/package/@webviewjs/webview) npm
280
+ package; compiled programs need neither the package nor a C toolchain. On
281
+ Windows the window embeds the system WebView2. On macOS and Linux, and on
282
+ Windows without the WebView2 runtime, it's Chrome, Edge or Chromium in app mode.
283
+ [conformance.md](conformance.md#native-app-windows-webviewjswebview) lists the
284
+ supported API, and [desktop-notes](examples/desktop-notes/) is a complete app.
285
+
286
+ Complete, runnable projects, including Node-vs-TypeNative benchmarks for
287
+ each, live in [examples/](examples/). The flagships are
288
+ [yaml-cli](examples/yaml-cli/): the `yaml` package's own CLI compiled from its
289
+ unmodified source, matching Node's output on all 1,608 yaml-test-suite cases,
290
+ and [marked-cli](examples/marked-cli/): the `marked` markdown parser's CLI,
291
+ 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).
253
293
 
254
294
  ## How it works
255
295
 
@@ -268,7 +308,7 @@ main.ts --(type-check)--(parse)--> normalized JSON AST --(transpileToNative)-->
268
308
 
269
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`.
270
310
 
271
- When adding a feature: add a probe, link it from [conformance.md](conformance.md), and keep the ✅/❌ matrix honest — gaps are documented, not hidden.
311
+ When adding a feature: add a probe, link it from [conformance.md](conformance.md), and keep the ✅/❌ matrix honest gaps are documented, not hidden.
272
312
 
273
313
  ## Self-hosted native compiler
274
314
 
@@ -284,4 +324,4 @@ native/typenative --source app.ts --script
284
324
 
285
325
  ## License
286
326
 
287
- MIT — see [LICENSE](LICENSE).
327
+ MIT [LICENSE](LICENSE).
@@ -0,0 +1,200 @@
1
+ # Round 2 handoff: marked
2
+
3
+ You're picking up round 2 of 3 in a series of "flagship examples" for
4
+ TypeNative (a TypeScript-to-Go transpiler, repo `danisss9/TypeNative`). Each
5
+ round compiles a real, unmodified npm package's TypeScript source to a native
6
+ binary and proves its output matches Node byte for byte. Round 1 (the `yaml`
7
+ CLI) is done; round 3 is the Angular template parser. This round is
8
+ [marked](https://github.com/markedjs/marked).
9
+
10
+ If the original plan specifies something for round 2 that differs from this
11
+ brief, the plan wins.
12
+
13
+ ## Where things stand
14
+
15
+ - Round 1 is on branch `claude/brave-ride-d67lzw`, PR
16
+ [danisss9/TypeNative#30](https://github.com/danisss9/TypeNative/pull/30),
17
+ open and already merged with current `main`. Each round ships as its own
18
+ PR. If #30 hasn't merged when you start, branch from it (round 2 needs its
19
+ transpiler fixes); otherwise branch from `main`. Don't open a PR unless the
20
+ user asks.
21
+ - Use `examples/yaml-cli/` as the template for everything:
22
+ [main.ts](examples/yaml-cli/main.ts), [parity.mjs](examples/yaml-cli/parity.mjs),
23
+ [bench.mjs](examples/yaml-cli/bench.mjs), [README.md](examples/yaml-cli/README.md),
24
+ [vendor/yaml/VENDOR.md](examples/yaml-cli/vendor/yaml/VENDOR.md).
25
+ - State at handoff: conformance 523/523 under both the Node CLI and the
26
+ self-hosted native compiler; yaml parity 1608/1608; `bootstrap:check`
27
+ holds (56 Go files identical).
28
+
29
+ ## The target
30
+
31
+ | | |
32
+ | --- | --- |
33
+ | Upstream | https://github.com/markedjs/marked |
34
+ | Tag | `v18.1.2` (latest when this was written; use it unless the plan pins another) |
35
+ | Commit | `5beecae42b0beb07eaccc3a732560f56867a8301` |
36
+ | Source | `src/*.ts`, 11 files, about 4,070 lines, imports use `.ts` extensions |
37
+ | CLI | `bin/main.js` (JavaScript; imports the built `lib/marked.esm.js`) |
38
+ | License | MIT |
39
+
40
+ Things in the source that will matter:
41
+
42
+ - `src/rules.ts` is a large set of regexes (22 of them, two with lookbehind),
43
+ many composed at run time with `.replace()` on their `.source`. Expect the
44
+ regex translation and the backtracking engine to get a workout.
45
+ - `Lexer` / `Tokenizer` / `Parser` / `Renderer` classes, hooks and
46
+ extensions (`Instance.ts`), with `this`-bound callbacks.
47
+ - `bin/main.js` uses `fs.promises`, `createRequire`, `pathToFileURL`, dynamic
48
+ imports of `child_process` / `url`, and spawns `man` for `--help`.
49
+
50
+ ## Deliverables (same rules as round 1)
51
+
52
+ Layout: `examples/marked-cli/`
53
+
54
+ - `vendor/marked/`: `src/` and `LICENSE` copied byte for byte, plus
55
+ `VENDOR.md` with the tag, the commit and the patch list. The target is an
56
+ empty patch list.
57
+ - `main.ts`: a TypeScript port of `bin/main.js`, importing
58
+ `./vendor/marked/src/marked.ts` instead of the built bundle. It must run
59
+ under both `node main.ts` and TypeNative. For `--help`, matching Node's
60
+ behavior (spawning `man`) isn't required for parity; just keep it working.
61
+ - `parity.mjs`: runs every corpus case through Node and the native binary,
62
+ compares stdout, stderr and exit code byte for byte, prints the pass rate
63
+ and writes failures to `.cache/failures/`. Copy yaml-cli's, including its
64
+ `withoutStackFrames()` normalization (Node prints JS stack frames; a native
65
+ binary has none).
66
+ - `bench.mjs`: (a) per-call latency, (b) throughput, alternating Node and
67
+ native runs, checking the outputs are identical.
68
+ - `README.md` in the yaml-cli style. Report losses honestly too: yaml-cli is
69
+ 27x faster per call but 3.6x slower on 10 MB, and its README says so.
70
+
71
+ Corpora are fetched into a gitignored `.cache/` (`examples/*/.cache` is
72
+ already ignored), never committed.
73
+
74
+ **Proposed corpus** (confirm against the plan): marked's own spec suites at
75
+ the vendored tag.
76
+
77
+ - `test/specs/commonmark/commonmark.0.31.2.json`: 652 cases.
78
+ - `test/specs/gfm/gfm.0.29.json`: 28 cases.
79
+ - `test/specs/new/*.md`: about 223 cases.
80
+ - `test/specs/original/*.md`: 22 cases.
81
+ - `test/specs/redos/*`: 36 inputs, worth including with the 10 s timeout,
82
+ since they will expose any super-linear regex path.
83
+
84
+ Feed each case's markdown on stdin, in at least the default (GFM) mode and
85
+ with `--no-gfm` if the CLI supports it. Parity means native vs Node, not
86
+ native vs the spec's expected HTML; spec cases marked failing in marked
87
+ don't matter.
88
+
89
+ **Proposed benchmarks**:
90
+
91
+ - (a) A typical README (e.g. marked's own `README.md`) to HTML, 30 runs.
92
+ - (b) About 10 MB of generated markdown (headings, lists, tables, code
93
+ fences, links, emphasis) from a fixed-seed generator, 5 runs.
94
+
95
+ ## Hard rules
96
+
97
+ - No patches to upstream code. When a construct doesn't compile or behaves
98
+ differently, fix the transpiler generally. The only exception is something
99
+ `conformance.md` marks 🚫, documented in `VENDOR.md` with the reason.
100
+ - Every fix gets a probe in `conformance/` (it runs under TypeNative with an
101
+ `assert` global) and a row in `conformance.md` (✅ with the probe link; ❌
102
+ rows for gaps you find but don't fix).
103
+ - The self-hosted compiler must keep working: `npm run build:native &&
104
+ npm run bootstrap:check`.
105
+ - Docs per round: a row in `examples/README.md`, a line in the root README's
106
+ Examples section, and a CHANGELOG entry under `[Unreleased]`.
107
+ - Commit trailer, and never put a model name in commits, PRs or code:
108
+ ```
109
+ Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110
+ Claude-Session: https://claude.ai/code/session_012GsG7QUSC36HGJ9rohJ7A7
111
+ ```
112
+
113
+ ## Verification (run all of it before pushing)
114
+
115
+ 1. `npm run build`
116
+ 2. Compile the example: `node bin/cli.js --source examples/marked-cli/main.ts --output …`
117
+ 3. `cd examples/marked-cli && node parity.mjs` must report 100%.
118
+ 4. `node bench.mjs`
119
+ 5. `npm run conformance:parallel`
120
+ 6. `npm run build:native && npm run bootstrap:check`
121
+ 7. `node scripts/conformance.mjs --native`
122
+
123
+ ## Environment
124
+
125
+ ```bash
126
+ export PATH=/opt/nvm/versions/node/v24.22.2/bin:$PATH
127
+ export GOTOOLCHAIN=go1.26.0
128
+ ```
129
+
130
+ Without these you get "TypeNative needs Go 1.26 or newer" or an old Node.
131
+ Timings in this container: conformance:parallel about 7 min,
132
+ `conformance --native` about 5 min, bootstrap:check about 75 s,
133
+ build:native about 3 min.
134
+
135
+ ## Lessons from round 1 (read these; they will save hours)
136
+
137
+ **Working method**
138
+
139
+ - Write a small `tn.sh file.ts` that runs a snippet under Node and natively
140
+ and prints both. Most bugs reduce to five lines this way.
141
+ - `node bin/cli.js --source x.ts --emit-go DIR` writes the Go. Strip the
142
+ line directives with `sed 's#/\*line[^*]*\*/##g'` to read it.
143
+ - For a native panic, the recovered error loses the stack. Patch the
144
+ emitted Go's `TnCaught` to print `runtime/debug.Stack()`; import it under
145
+ an alias (`rtdbg`), since vendored code may already have a `debug`.
146
+ - Don't rebuild `bin/` while conformance runs: probes compile with it and
147
+ fail spuriously.
148
+ - Parity flakes are rare. If a parallel conformance job fails once but passes
149
+ alone (fs-watch timing, the big example build under load), rerun it alone
150
+ before chasing it.
151
+
152
+ **Self-hosting traps.** These cost the most time in round 1. The native
153
+ compiler (the transpiler compiled by itself) has known semantic gaps. Code
154
+ you add to `src/transpiler.ts` must avoid them, or `bootstrap:check` fails:
155
+
156
+ - `map.get(k)` on a missing key returns the zero value (`''`, `0`, `false`),
157
+ not `undefined`. So `m.get(k) ?? fallback` and `if (m.get(k) !== undefined)`
158
+ are wrong natively. Use `m.has(k) ? m.get(k) : undefined`. The same goes for
159
+ `Record` lookups (`Object.hasOwn(rec, k) ? rec[k] : undefined`) and for
160
+ `arr.find()`, which returns `''` for no match (use `filter()[0]` with a
161
+ length check).
162
+ - `bool || string` evaluates to a bool, not the string operand. Don't mix
163
+ types in `||` / `&&` value positions.
164
+ - A function returning `string | undefined` can yield `''` where JS yields
165
+ `undefined`; prefer `||` over `??` when `''` is never a valid value (Go
166
+ types never are).
167
+ - Object literals assigned into `any` slots become Go maps; those can now be
168
+ Map/Set keys (by identity), but don't rely on struct identity for them.
169
+ - To find a divergence: emit the same program's Go with both compilers
170
+ (`./native/typenative --emit-go` vs `node bin/cli.js --emit-go`) and diff
171
+ them, after stripping line directives. The first differing line usually
172
+ names the faulty inference rule.
173
+ - Helpers `untypedVariable()`, `declaredMemberType()` and
174
+ `getObjectFieldGoType()` already encode the `has()`-first pattern; reuse
175
+ them.
176
+
177
+ **Transpiler areas you'll likely touch for marked**
178
+
179
+ - Regexes: `TnRegex` (RE2, with a backtracking engine for lookarounds and
180
+ backreferences), sticky/global flags, `$` replacement patterns, replacer
181
+ callbacks (match, groups…, offset, input) and unmatched groups as
182
+ `undefined` all work now. `new RegExp(src, flags)` with `g`/`y` is
183
+ stateful. Composed regexes (`.source` edited with `.replace`) are new
184
+ territory.
185
+ - String positions are code points (UTF-16 units in the BMP), with a cached
186
+ index per long string. Long inputs scanned by regexes were quadratic until
187
+ round 1 fixed the cache eviction; watch for similar hotspots with a
188
+ profiler.
189
+ - Profiling: patch the emitted Go's `main()` to call
190
+ `pprof.StartCPUProfile` and `TnProcessExit` to stop it, then `go tool pprof
191
+ -top`. Round 1's wins were the string index cache, cached struct field
192
+ lookups, and resolving `typeof f` as a func type (direct calls instead of
193
+ reflection).
194
+
195
+ **Known gaps left open (❌ rows)**: a local alias of an array field doesn't
196
+ share pushes; an array read from an `any` object into a variable isn't
197
+ shared; `x?.m()` on an `any` value with a primitive result gives the zero
198
+ value instead of `undefined`; reading a missing `Record` / `Map` key of
199
+ primitives gives the zero value. Fix them if marked needs them, with
200
+ probes.
package/bin/cli.js CHANGED
@@ -77,6 +77,7 @@ import { VERSION } from './version.js';
77
77
  vendorDir: fileURLToPath(new URL('../govendor', import.meta.url)),
78
78
  target: args.target,
79
79
  release: args.release,
80
+ gui: args.gui,
80
81
  cover: args.cover,
81
82
  emitGo: args.emitGo
82
83
  });
package/bin/index.js CHANGED
@@ -27,6 +27,7 @@ Options:
27
27
  --target <os/arch> Cross-compile, e.g. linux/amd64, linux/arm64, darwin/arm64,
28
28
  windows/amd64 ('go tool dist list' shows every pair)
29
29
  --release Smaller binary: drop symbols and file paths
30
+ --gui Windowed app: no console window on Windows (ignored elsewhere)
30
31
  --cover Build with coverage counters, for go:runtime/coverage
31
32
  (set GOCOVERDIR to also write a profile at exit)
32
33
  --emit-go <dir> Write the generated Go (and go.mod) to <dir> instead of building
@@ -49,6 +50,7 @@ export function parseCliArgs(argv) {
49
50
  script: false,
50
51
  noTypeCheck: false,
51
52
  release: false,
53
+ gui: false,
52
54
  cover: false,
53
55
  source: null,
54
56
  output: null,
@@ -76,6 +78,8 @@ export function parseCliArgs(argv) {
76
78
  args.noTypeCheck = true;
77
79
  else if (arg === '--release')
78
80
  args.release = true;
81
+ else if (arg === '--gui')
82
+ args.gui = true;
79
83
  else if (arg === '--cover')
80
84
  args.cover = true;
81
85
  else if (arg === '--source' || arg === '--output' || arg === '--target' || arg === '--emit-go') {
@@ -404,7 +408,8 @@ export function run(opts) {
404
408
  tsx: !!sourcePath && sourcePath.endsWith('.tsx'),
405
409
  fileName: displayPath(entryPath),
406
410
  goFile: goFile,
407
- goos: targetOs
411
+ goos: targetOs,
412
+ cwd: process.cwd().split('\\').join('/')
408
413
  };
409
414
  if (sourceDir) {
410
415
  transpileOptions.readFile = (specifier, fromDir) => {
@@ -524,8 +529,14 @@ export function run(opts) {
524
529
  // is ~5 MB of Go) compile once, not again for every project directory
525
530
  if (opts.release || modules.length > 0)
526
531
  buildArgs.push('-trimpath');
532
+ // One value: go build keeps only the last -ldflags
533
+ const ldflags = [];
527
534
  if (opts.release)
528
- buildArgs.push('-ldflags=-s -w');
535
+ ldflags.push('-s', '-w');
536
+ if (opts.gui && targetOs === 'windows')
537
+ ldflags.push('-H=windowsgui');
538
+ if (ldflags.length > 0)
539
+ buildArgs.push(`-ldflags=${ldflags.join(' ')}`);
529
540
  // atomic counters: coverage.ClearCounters refuses the default 'set' mode
530
541
  if (opts.cover)
531
542
  buildArgs.push('-cover', '-covermode=atomic');
package/bin/main.js CHANGED
@@ -54,6 +54,7 @@ import { VERSION } from './version.js';
54
54
  vendorDir,
55
55
  target: args.target,
56
56
  release: args.release,
57
+ gui: args.gui,
57
58
  cover: args.cover,
58
59
  emitGo: args.emitGo
59
60
  });
@@ -121,7 +121,7 @@ func TnErrorText(e interface{}) string {
121
121
  if s, ok := e.(string); ok {
122
122
  return s
123
123
  }
124
- if msg, ok := TnGet(e, "message").(string); ok {
124
+ if msg, ok := TnGetValue(e, "message").(string); ok {
125
125
  return "Error: " + msg
126
126
  }
127
127
  return fmt.Sprint(e)
@@ -133,7 +133,7 @@ func TnErrorMatches(e interface{}, expected map[string]interface{}) bool {
133
133
  got := TnGet(e, key)
134
134
  if key == "message" {
135
135
  if _, ok := e.(*TnError); !ok {
136
- if m, ok := TnGet(e, "message").(string); ok {
136
+ if m, ok := TnGetValue(e, "message").(string); ok {
137
137
  got = m
138
138
  }
139
139
  }
@@ -14,7 +14,7 @@ type TnAsyncLocalStorage struct {
14
14
  func TnNewAsyncLocalStorage(options ...interface{}) *TnAsyncLocalStorage {
15
15
  als := &TnAsyncLocalStorage{}
16
16
  if len(options) > 0 && options[0] != nil {
17
- if n, ok := TnGet(options[0], "name").(string); ok {
17
+ if n, ok := TnGetValue(options[0], "name").(string); ok {
18
18
  als.name = n
19
19
  }
20
20
  }