typenative 0.4.0 → 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.
- package/.github/workflows/ci.yml +2 -0
- package/CHANGELOG.md +372 -0
- package/CONTRIBUTION.md +1 -1
- package/README.md +62 -22
- package/ROUND2-HANDOFF.md +200 -0
- package/bin/cli.js +2 -0
- package/bin/go/bridge.js +74 -14
- package/bin/go/convert.js +48 -0
- package/bin/go/metadata.js +13 -4
- package/bin/go/overrides.js +4 -6
- package/bin/go/stdlib.generated.js +2 -0
- package/bin/index.js +130 -2
- package/bin/main.js +2 -0
- package/bin/node/assert.js +2 -2
- package/bin/node/async_hooks.js +1 -1
- package/bin/node/buffer.js +16 -5
- package/bin/node/child_process.js +57 -9
- package/bin/node/cluster.js +44 -6
- package/bin/node/core.js +1 -1
- package/bin/node/crypto.js +205 -4
- package/bin/node/crypto_keys.js +21 -21
- package/bin/node/dgram.js +231 -7
- package/bin/node/diagnostics_channel.js +3 -3
- package/bin/node/dns.js +472 -9
- package/bin/node/errno_tables.js +445 -0
- package/bin/node/events.js +3 -3
- package/bin/node/fetch.js +2 -2
- package/bin/node/fs.js +24 -17
- package/bin/node/fs_watch.js +5 -5
- package/bin/node/http.js +131 -33
- package/bin/node/http2.js +7 -4
- package/bin/node/module_v8.js +142 -0
- package/bin/node/net.js +17 -14
- package/bin/node/path.js +17 -3
- package/bin/node/process.js +274 -9
- package/bin/node/readline.js +272 -1
- package/bin/node/registry.js +5 -1
- package/bin/node/sqlite.js +65 -17
- package/bin/node/stream.js +220 -22
- package/bin/node/stream_web.js +10 -10
- package/bin/node/system_extra.js +3 -3
- package/bin/node/test.js +834 -234
- package/bin/node/test_coverage.js +187 -0
- package/bin/node/test_report.js +1392 -0
- package/bin/node/test_run.js +575 -0
- package/bin/node/timers.js +4 -4
- package/bin/node/tls.js +5 -5
- package/bin/node/url.js +23 -5
- package/bin/node/util.js +49 -8
- package/bin/node/util_extra.js +13 -37
- package/bin/node/webview.js +654 -0
- package/bin/node/worker_threads.js +80 -20
- package/bin/node/zlib.js +3 -3
- package/bin/parse-node.js +4 -0
- package/bin/transpiler.js +14457 -1723
- package/bin/typecheck-node.js +1 -0
- package/bin/version.js +1 -1
- package/conformance.md +1153 -884
- package/examples/README.md +47 -10
- package/examples/desktop-notes/README.md +108 -0
- package/examples/desktop-notes/bench.mjs +125 -0
- package/examples/desktop-notes/main.ts +131 -0
- package/examples/desktop-notes/package-lock.json +726 -0
- package/examples/desktop-notes/package.json +9 -0
- package/examples/desktop-notes/ui.ts +176 -0
- package/examples/dupe-finder/README.md +76 -0
- package/examples/dupe-finder/bench.mjs +120 -0
- package/examples/dupe-finder/main.ts +87 -0
- package/examples/json-server/README.md +31 -29
- package/examples/json-server/bench.mjs +130 -38
- package/examples/mandelbrot-png/README.md +65 -0
- package/examples/mandelbrot-png/bench.mjs +95 -0
- package/examples/mandelbrot-png/main.ts +98 -0
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +159 -0
- package/examples/marked-cli/bench.mjs +178 -0
- package/examples/marked-cli/main.ts +292 -0
- package/examples/marked-cli/parity.mjs +185 -0
- package/examples/marked-cli/vendor/marked/LICENSE +44 -0
- package/examples/marked-cli/vendor/marked/VENDOR.md +26 -0
- package/examples/todo-cli/README.md +69 -0
- package/examples/todo-cli/bench.mjs +89 -0
- package/examples/todo-cli/main.ts +92 -0
- package/examples/yaml-cli/README.md +136 -0
- package/examples/yaml-cli/bench.mjs +265 -0
- package/examples/yaml-cli/main.ts +29 -0
- package/examples/yaml-cli/parity.mjs +156 -0
- package/examples/yaml-cli/vendor/yaml/LICENSE +13 -0
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +25 -0
- package/govendor/github.com/jchv/go-webview2/LICENSE +22 -0
- package/govendor/github.com/jchv/go-webview2/README.md +21 -0
- package/govendor/github.com/jchv/go-webview2/common.go +84 -0
- package/govendor/github.com/jchv/go-webview2/go.mod +3 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32.go +194 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_386.go +14 -0
- package/govendor/github.com/jchv/go-webview2/internal/w32/w32_64bit.go +15 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_COLOR.go +8 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_KEY_EVENT_KIND.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_MOVE_FOCUS_REASON.go +9 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_PHYSICAL_KEY_STATUS.go +10 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/COREWEBVIEW2_WEB_RESOURCE_CONTEXT.go +23 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventArgs.go +78 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2AcceleratorKeyPressedEventHandler.go +52 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller.go +132 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Controller2.go +74 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventArgs.go +17 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2NavigationCompletedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2Settings.go +270 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequest.go +43 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventArgs.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceRequestedEventHandler.go +48 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2WebResourceResponse.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_2.go +21 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebView2_3.go +60 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/ICoreWebViewSettings.go +396 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium.go +361 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_386.go +24 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_amd64.go +22 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/chromium_arm64.go +26 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc.go +13 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go17.go +51 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/comproc_go18.go +16 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/corewebview2.go +411 -0
- package/govendor/github.com/jchv/go-webview2/pkg/edge/guid.go +223 -0
- package/govendor/github.com/jchv/go-webview2/webview.go +482 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/README.md +3 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module.go +153 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_386.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_amd64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/module_arm64.go +6 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/arm64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x64/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-webview2/webviewloader/sdk/x86/WebView2Loader.dll +0 -0
- package/govendor/github.com/jchv/go-winloader/LICENSE.md +7 -0
- package/govendor/github.com/jchv/go-winloader/README.md +124 -0
- package/govendor/github.com/jchv/go-winloader/common.go +11 -0
- package/govendor/github.com/jchv/go-winloader/go.mod +3 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/loader.go +25 -0
- package/govendor/github.com/jchv/go-winloader/internal/loader/machine.go +53 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/cache.go +42 -0
- package/govendor/github.com/jchv/go-winloader/internal/memloader/loader.go +253 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/export.go +76 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/format.go +522 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/import.go +106 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/module.go +91 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/reloc.go +177 -0
- package/govendor/github.com/jchv/go-winloader/internal/pe/util.go +40 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/common.go +55 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_other.go +71 -0
- package/govendor/github.com/jchv/go-winloader/internal/vmem/memory_windows.go +179 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_other.go +17 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/hacks_windows.go +73 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/loader_windows.go +64 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/machine_windows.go +32 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_386.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_amd64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/internal/winloader/nativearch_arm64.go +9 -0
- package/govendor/github.com/jchv/go-winloader/loader_other.go +24 -0
- package/govendor/github.com/jchv/go-winloader/loader_windows.go +33 -0
- package/govendor/manifest.txt +3 -1
- package/package.json +1 -1
- package/tsparser/main.go +4 -0
- package/types/typenative-go.d.ts +23 -0
- package/types/typenative-npm.d.ts +359 -7
- package/types/typenative.d.ts +283 -42
package/.github/workflows/ci.yml
CHANGED
|
@@ -39,6 +39,8 @@ jobs:
|
|
|
39
39
|
# The self-hosted compiler: same probes, and it must reproduce its own Go
|
|
40
40
|
native:
|
|
41
41
|
runs-on: ubuntu-latest
|
|
42
|
+
# Normally ~5–8 min (the self-compile is ~2); fail fast if a probe runs away
|
|
43
|
+
timeout-minutes: 25
|
|
42
44
|
steps:
|
|
43
45
|
- uses: actions/checkout@v4
|
|
44
46
|
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,378 @@ 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
|
+
|
|
181
|
+
## [0.4.1] - 2026-10-24
|
|
182
|
+
|
|
183
|
+
Node-accurate JSON (`stringify` with spacing and replacers, `parse` with a reviver, and JSON
|
|
184
|
+
modules), regexes with JS semantics that no longer re-scan the whole string on global matches,
|
|
185
|
+
`Date` and error-stack parity, generator iterator helpers, `go:embed` and
|
|
186
|
+
`go:runtime/coverage`, seven more Go bridge packages, and `async` calls that start when the
|
|
187
|
+
statement runs.
|
|
188
|
+
|
|
189
|
+
### Added
|
|
190
|
+
|
|
191
|
+
- **`JSON.stringify`:**
|
|
192
|
+
- `space` (number or string) with Node's layout
|
|
193
|
+
- replacer functions and key lists
|
|
194
|
+
- `toJSON()` methods
|
|
195
|
+
- Dates as ISO strings, `Map` / `Set` as `{}`
|
|
196
|
+
- `TypeError`s for circular structures and bigints
|
|
197
|
+
- **`JSON.parse`:** reviver, and a `SyntaxError` for invalid JSON (it returned `null`)
|
|
198
|
+
- **Arrays:** writing past the end grows the array
|
|
199
|
+
- **Classes:** polymorphic `this` return types (fluent builders), and `obj[key]` on class
|
|
200
|
+
instances and typed objects
|
|
201
|
+
- **Generators:** iterator helpers (`map`, `filter`, `take`, `drop`, `flatMap`, `toArray`,
|
|
202
|
+
`forEach`, `some`, `every`, `find`, `reduce`), `Iterator.from` and `next()`
|
|
203
|
+
- **Weak references:** `WeakRef` / `FinalizationRegistry`
|
|
204
|
+
- **`Date`:**
|
|
205
|
+
- `new Date(string)` (ISO and the formats `toString` / `toUTCString` produce), and
|
|
206
|
+
`new Date(y, m, d, …)` in local time
|
|
207
|
+
- `Date.parse`, the setters (`setHours`, `setUTCDate`, …), `getTimezoneOffset`
|
|
208
|
+
- `toUTCString`, `toLocale*String` (en-US)
|
|
209
|
+
- Node's `toString` format for `String(date)` and templates
|
|
210
|
+
- Invalid Dates (`getTime()` is `NaN`)
|
|
211
|
+
- **Errors:** `err.stack` lists the TS frames (`at fn (file.ts:line)`); `AggregateError`
|
|
212
|
+
- **Functions:** `fn.bind`, `fn.name`, `fn.length`; `apply` on non-variadic functions, and
|
|
213
|
+
`call` / `apply` on function declarations
|
|
214
|
+
- **Statics:** `Promise.withResolvers`, `Promise.try`, `Object.is`, `Object.groupBy`,
|
|
215
|
+
`Map.groupBy`, `Array.of`, `Symbol.for` / `keyFor` / `description`, `BigInt()`,
|
|
216
|
+
`BigInt.asIntN` / `asUintN`
|
|
217
|
+
- **`Number`:** `toExponential`, `isSafeInteger`, `parseInt` / `parseFloat`, `MIN_VALUE`,
|
|
218
|
+
`NEGATIVE_INFINITY`
|
|
219
|
+
- **`Math`:** `fround`, `imul`, `clz32`, `asinh` / `acosh` / `atanh`, `sumPrecise`
|
|
220
|
+
- **`String`:** `codePointAt`, `String.fromCodePoint`, `substr`, `trimLeft` / `trimRight`,
|
|
221
|
+
`isWellFormed` / `toWellFormed`, `toLocaleUpperCase` / `toLocaleLowerCase`, `split` limit,
|
|
222
|
+
`lastIndexOf` position
|
|
223
|
+
- **`process`:** `stdout.columns` / `rows` / `getWindowSize()` (and `stderr`),
|
|
224
|
+
`stdin.setRawMode` / `isRaw` (undone at exit), `umask`, on Linux, macOS, FreeBSD and Windows
|
|
225
|
+
- **`node:readline`:** `emitKeypressEvents` and `'keypress'` events (Node's key decoder)
|
|
226
|
+
- **`node:child_process`:** `spawn` `detached`, `child.unref()` / `ref()`
|
|
227
|
+
- **`node:dgram`:** multicast (`addMembership` / `dropMembership`, `setMulticastInterface`), and
|
|
228
|
+
`setBroadcast` / `setTTL` / `setMulticastTTL` / `setMulticastLoopback` take effect (they were
|
|
229
|
+
accepted and ignored)
|
|
230
|
+
- **Errors:** `err.errno` and `util.getSystemErrorName` / `Message` / `Map` use Node's numbers for
|
|
231
|
+
the target OS (libuv's table: `ENOENT` is `-4058` on Windows, `ECONNREFUSED` `-61` on macOS) and
|
|
232
|
+
libuv's messages; `getSystemErrorMap` has all 85 entries in Node's order
|
|
233
|
+
- **`node:dns`:** `resolveAny` / `resolveCaa` / `resolveNaptr` / `resolvePtr` / `resolveSoa`,
|
|
234
|
+
`resolve4` / `resolve6` with `{ ttl: true }`, and the `Resolver` `tries` option
|
|
235
|
+
- **`node:module`** (`builtinModules`, `isBuiltin`), **`node:v8`** (`getHeapStatistics`,
|
|
236
|
+
`serialize` / `deserialize`) and **`node:sea`** (`isSea`)
|
|
237
|
+
- **`node:crypto`:** `Hash` / `Hmac` as streams; AES key wrap ciphers (`id-aes*-wrap`,
|
|
238
|
+
`id-aes*-wrap-pad`)
|
|
239
|
+
- **`node:http`:** `res.addTrailers()`
|
|
240
|
+
- **JSON modules:** `import data from './x.json' with { type: 'json' }` and
|
|
241
|
+
`createRequire(import.meta.url)('./x.json')`, read at compile time
|
|
242
|
+
- **Workers and `fork` for another file:** `new Worker('./worker.ts')` / `fork('./child.ts')` compile
|
|
243
|
+
that file into the binary as a second entry point, run in the child process
|
|
244
|
+
- **`node:test`:** `--test-name-pattern`, `--test-skip-pattern`, `--test-only` and
|
|
245
|
+
`--test-reporter` (`tap`, `spec`, `dot`, `junit`) from `NODE_OPTIONS`; Node's notice for `.only`
|
|
246
|
+
without `--test-only`
|
|
247
|
+
- **`node:stream`:** `'readable'` events and Node's `read()` / `read(size)`
|
|
248
|
+
- **`node:sqlite`:** statements are finalized once garbage-collected (they lived until
|
|
249
|
+
`db.close()`); `db.serialize()` / `db.deserialize()`
|
|
250
|
+
- **Go bridges:** a probe for every bridged `go:` package, new ones for `debug/*`, `log/syslog`,
|
|
251
|
+
`math/cmplx`, `net/http/fcgi`, `net/rpc`, `net/rpc/jsonrpc`, `net/smtp`, `testing/cryptotest`,
|
|
252
|
+
`testing/slogtest` and `testing/synctest`. Along with them:
|
|
253
|
+
- `pkg.T` in type annotations is the Go type (`let d: dwarf.Data | null = null`,
|
|
254
|
+
`(t: testing.T) => …`)
|
|
255
|
+
- `ref.value` can be written (`r.value = x`), also through `GoRef<T>` parameters, so TS classes
|
|
256
|
+
can be `net/rpc` services
|
|
257
|
+
- `chan<T>()` makes a `chan T`
|
|
258
|
+
- TS records pass where Go takes a `map[K]V`
|
|
259
|
+
- callbacks whose Go signature returns `(T, error)`
|
|
260
|
+
- **`go:embed`:** `embed.string(path)`, `embed.bytes(path)` and `embed.files(...patterns)` (an
|
|
261
|
+
`embed.FS`) compile to `//go:embed` vars; the CLI copies the files next to the Go sources
|
|
262
|
+
- **`go:runtime/coverage`**, with a `--cover` CLI option that builds with coverage counters. Probes
|
|
263
|
+
can pass CLI options with a first line like `// conformance-flags: --cover`
|
|
264
|
+
|
|
265
|
+
### Fixed
|
|
266
|
+
|
|
267
|
+
- **Regex performance:** global `replace` / `split` / `matchAll` and backreference or
|
|
268
|
+
lookaround patterns no longer re-scan the whole string for every match (quadratic on long
|
|
269
|
+
input); the self-hosted compiler builds itself ~10× faster
|
|
270
|
+
- **Regex empty matches:** `/g` patterns can match empty at the end of input
|
|
271
|
+
(`'abc'.replace(/x*/g, '-')` is `-a-b-c-`)
|
|
272
|
+
- **Regex `split`:** follows JS: capture groups are included (`'a1b'.split(/(\d)/)` is `a`,
|
|
273
|
+
`1`, `b`), `limit` is honored, and empty matches split like JS
|
|
274
|
+
(`'aXbXXc'.split(/(?<=X)/)` is `aX`, `bX`, `X`, `c`)
|
|
275
|
+
- **Match `.index`:** `exec`, `match` and `matchAll` results have `.index` (a compile error
|
|
276
|
+
before); `search` returns a character index (it returned a byte offset)
|
|
277
|
+
- **`match` with `/g`:** returns every match (it returned the first match's groups)
|
|
278
|
+
- **Arrays as strings:** `arr.toString()`, `String(arr)` and `` `${arr}` `` join elements with
|
|
279
|
+
commas (they printed Go's `[a b]`)
|
|
280
|
+
- **`node:dns`:** `resolve(name, 'PTR')` queries the name's PTR records (it did a reverse lookup)
|
|
281
|
+
- **Templates:** `${err}` on an `Error` builds and prints `Name: message` (`null` when null)
|
|
282
|
+
- **`Date` annotations:** `let d: Date`, `Date` parameters, return types, fields and `as Date`
|
|
283
|
+
compiled to an undefined Go type
|
|
284
|
+
- **Named imports of Node values:** `import { METHODS } from 'node:http'` keeps its array type
|
|
285
|
+
(`METHODS.includes(…)` compiled as a string method)
|
|
286
|
+
- **`console.log` / `inspect`:** Maps and Sets nested in objects print as `Map(n) {…}` /
|
|
287
|
+
`Set(n) {…}` (string-keyed Maps printed as plain objects)
|
|
288
|
+
- **Worker messages / `v8.deserialize`:** Sets arrive as Sets and both pass `instanceof`
|
|
289
|
+
- **`Array<T>` / `ReadonlyArray<T>` annotations** compiled to an undefined Go type
|
|
290
|
+
- **`stream.push(cond ? text : null)`:** a nullable string is a chunk or the end of the stream
|
|
291
|
+
(`null` through it never ended the stream)
|
|
292
|
+
- **`hmac.digest()` a second time** returns an empty result, as in Node (it threw)
|
|
293
|
+
- **Destructured callback parameters** (`([k, v]) => …`, `({ a }) => …`) in `map` / `filter` & co.
|
|
294
|
+
were unsupported syntax
|
|
295
|
+
- **`[...map]`, `map.entries()`** and **`{ ...record, k: v }`** (such as `{ ...process.env }`)
|
|
296
|
+
did not build
|
|
297
|
+
- **`+` on two dynamic values** concatenates when one is a string (`'a' + 1` gave `1`)
|
|
298
|
+
- **`Object.keys` / `values` / `entries` and `for...in`** on typed objects (interfaces, object
|
|
299
|
+
literals, class instances) did not build
|
|
300
|
+
- **`JSON.parse`:** objects keep the text's key order (they came out sorted)
|
|
301
|
+
- **Indexing a typed array held as `any`** (`record.list[1].id`) gave `undefined`
|
|
302
|
+
- **Worker / IPC messages and `v8.deserialize`:** objects keep their key order (they arrived
|
|
303
|
+
sorted), records arrive as plain objects rather than `Map`s, and both convert to typed
|
|
304
|
+
`Record` fields
|
|
305
|
+
- **Optional method calls as statements** (`port?.postMessage(x)`) on `void` methods, and
|
|
306
|
+
`process.send?.(…)` / `process.disconnect?.()`, did not build
|
|
307
|
+
- **Dates:** local getters on `new Date(ms)` used UTC
|
|
308
|
+
- **Async arrows:** async arrows kept as values return promises (`return` of a plain value didn't
|
|
309
|
+
build)
|
|
310
|
+
- **`.then` on async calls:** the call starts when the statement runs, like JS (it started inside
|
|
311
|
+
the background goroutine, where `exec()` registering its listeners off the event loop could
|
|
312
|
+
race it)
|
|
313
|
+
- **Maps:** `[...map.keys()]` / `[...map.values()]` build
|
|
314
|
+
- **Optional chains:** comparing an optional chain or an `any` value with `null` / `undefined`
|
|
315
|
+
sees a nil pointer inside it
|
|
316
|
+
- **`length` fields:** `obj.length` on an object with its own `length` field read it (it compiled
|
|
317
|
+
to Go's `len()`)
|
|
318
|
+
- **Error casts:** `(err as Error)` works on instances of custom error classes
|
|
319
|
+
- **`any` variables:**
|
|
320
|
+
- a variable declared `any` / `unknown` with a primitive initializer is dynamic:
|
|
321
|
+
`const s: any = '6'; s - 1` builds, and reassigning another type works
|
|
322
|
+
- `==` between `any` values coerces like JS
|
|
323
|
+
- `<T>x` converts like `x as T`
|
|
324
|
+
- **Class members:**
|
|
325
|
+
- `#x` and `x` in one class no longer collide
|
|
326
|
+
- private fields and static properties stay out of `JSON.stringify`
|
|
327
|
+
|
|
328
|
+
Programs that built Go that didn't compile, or computed a wrong value, with no TypeNative error:
|
|
329
|
+
|
|
330
|
+
- **Classes:**
|
|
331
|
+
- methods without a return-type annotation compiled as returning nothing; they now infer it
|
|
332
|
+
like functions do, including returns nested in `if` / loops / `switch` / `try`
|
|
333
|
+
- field initializers ran before `super()` and the parameter properties, so
|
|
334
|
+
`d = this.k * 2` read `0`
|
|
335
|
+
- static members and getters / setters are inherited (`Child.make()`, `super.v`)
|
|
336
|
+
- private accessors (`get #x()`), `static #x` and `#x in obj` work
|
|
337
|
+
- async methods are lowered like async functions
|
|
338
|
+
- `instanceof Map` / `Set` / `Date` / `Array` work, and `instanceof Parent` is true for
|
|
339
|
+
subclass instances
|
|
340
|
+
- **Control flow:**
|
|
341
|
+
- a `switch` that covers every case without `default` builds; so does any statement after a
|
|
342
|
+
`switch`
|
|
343
|
+
- labeled blocks support `break label`
|
|
344
|
+
- **Async:** `return otherPromise()` in an async function settles with the awaited value, and
|
|
345
|
+
unannotated async functions build
|
|
346
|
+
- **Values and operators:**
|
|
347
|
+
- numeric enum reverse mapping (`Color[0]`)
|
|
348
|
+
- string enum members concatenate and print as strings (`console.log` printed `'a'`)
|
|
349
|
+
- bigint bitwise and shift operators
|
|
350
|
+
- Date arithmetic and ordering (`b - a`, `+d`, `a < b`)
|
|
351
|
+
- `any` operands of `-` / `*` / `/` convert like JS (`'6' - 1` is `5`)
|
|
352
|
+
- **Objects:**
|
|
353
|
+
- object-literal setters (they were dropped)
|
|
354
|
+
- repeated interfaces / enums, and an interface named like a class, merge
|
|
355
|
+
- `Object.hasOwn` / `defineProperty` with a computed key build instead of crashing the
|
|
356
|
+
compiler
|
|
357
|
+
- unsupported decorators and descriptors are reported as diagnostics instead of crashes
|
|
358
|
+
- **Go bridges:** a blocking call (`time.Sleep`) inside a callback failed to build, a panic in
|
|
359
|
+
one was swallowed, and `time.Sleep` hung inside a `synctest` bubble
|
|
360
|
+
- **`for (;;)`** without an initializer or update crashed the compiler
|
|
361
|
+
|
|
362
|
+
### Documentation
|
|
363
|
+
|
|
364
|
+
- `conformance.md` separates ❌ (not implemented yet, feasible) from 🚫 (will not be implemented)
|
|
365
|
+
and explains why for each row. Several rows that were ❌ for "impossible" reasons are now
|
|
366
|
+
marked feasible: terminal size and raw mode, `umask`, `getCallSites`, workers and `fork` for
|
|
367
|
+
another file, and freeing SQLite statements on GC
|
|
368
|
+
- Rows for gaps the matrix didn't list, each checked by compiling a small program. Among them:
|
|
369
|
+
- Date parsing, setters and arithmetic
|
|
370
|
+
- `JSON.stringify` `space` / replacer / `toJSON`
|
|
371
|
+
- `err.stack`, `bind`, `Intl`, `Temporal`, `WeakRef`
|
|
372
|
+
- class methods without a return-type annotation
|
|
373
|
+
- field initializers that run too early
|
|
374
|
+
- `instanceof Map` / `Date`
|
|
375
|
+
- static and accessor inheritance
|
|
376
|
+
- A "Roadmap: known limitations" section, which the link in CONTRIBUTION.md pointed to
|
|
377
|
+
- The Go bridges table has no ⚠️ ("typed, no probe yet") status any more. A probe that can't run on
|
|
378
|
+
a platform opts out with a first line like `// conformance-skip: win32 (reason)`
|
|
379
|
+
- `go:plugin`, `go:unsafe`, `go:runtime/race` and `go:runtime/cgo` are 🚫 (cgo or raw memory),
|
|
380
|
+
each with the reason
|
|
381
|
+
|
|
10
382
|
## [0.4.0] - 2026-10-19
|
|
11
383
|
|
|
12
384
|
A fuller CLI (`--target` cross-compilation, `--release`, `--emit-go`), typed arrays, Brotli and
|
package/CONTRIBUTION.md
CHANGED
|
@@ -114,7 +114,7 @@ npm run bootstrap:check # native/typenative must emit the same Go for sr
|
|
|
114
114
|
node scripts/conformance-parallel.mjs --native # full suite through your new binary
|
|
115
115
|
```
|
|
116
116
|
|
|
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).
|
|
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
118
|
|
|
119
119
|
## Pull requests
|
|
120
120
|
|
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
|
|
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
|
|
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
|
|
120
|
-
|
|
|
121
|
-
| `--source <file>`
|
|
122
|
-
| `--output <path>`
|
|
123
|
-
| `--script`
|
|
124
|
-
| `--new`
|
|
125
|
-
| `--no-typecheck`
|
|
126
|
-
| `--target <os/arch>` | build
|
|
127
|
-
| `--release`
|
|
128
|
-
| `--
|
|
129
|
-
|
|
|
130
|
-
| `-
|
|
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)
|
|
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
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
|
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
|
|
327
|
+
MIT [LICENSE](LICENSE).
|