typenative 0.0.21 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +29 -0
- package/.github/workflows/npm-publish-github-packages.yml +3 -3
- package/CHANGELOG.md +81 -0
- package/CONTRIBUTION.md +130 -0
- package/README.md +258 -183
- package/bin/index.js +2 -3
- package/bin/parse-node.js +2 -2
- package/bin/transpiler.js +6914 -1686
- package/conformance.md +651 -0
- package/package.json +10 -41
- package/tsparser/main.go +2 -2
- package/tsparser/tsparser.exe +2 -2
- package/TODO.md +0 -34
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
conformance:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 24
|
|
16
|
+
cache: npm
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-go@v5
|
|
19
|
+
with:
|
|
20
|
+
go-version: '1.23'
|
|
21
|
+
|
|
22
|
+
- run: npm ci
|
|
23
|
+
|
|
24
|
+
- run: npm run build
|
|
25
|
+
|
|
26
|
+
- run: npm ci
|
|
27
|
+
working-directory: conformance
|
|
28
|
+
|
|
29
|
+
- run: npm run conformance
|
|
@@ -27,11 +27,11 @@ jobs:
|
|
|
27
27
|
node-version: 24
|
|
28
28
|
- uses: actions/setup-go@v5
|
|
29
29
|
with:
|
|
30
|
-
go-version: '1.
|
|
30
|
+
go-version: '1.23'
|
|
31
31
|
- run: npm ci
|
|
32
32
|
- run: npm ci
|
|
33
|
-
working-directory:
|
|
34
|
-
- run: npm
|
|
33
|
+
working-directory: conformance
|
|
34
|
+
- run: npm run conformance
|
|
35
35
|
|
|
36
36
|
release:
|
|
37
37
|
needs: test
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,87 @@ All notable changes to TypeNative will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.1] - 2026-10-10
|
|
9
|
+
|
|
10
|
+
The conformance suite is fully green: all 147 probes pass (up from 95/147), through both the dev
|
|
11
|
+
CLI (`node bin/cli.js`) and the self-hosted native compiler (`npm run conformance -- --native`).
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **Language**: array/object destructuring with defaults and elision, computed keys, `for...in`,
|
|
16
|
+
labeled loops (`continue outer` / `break outer`), `as const`, type guards (`p is T`),
|
|
17
|
+
generators (`function*` / `yield` / `yield*`) and `*[Symbol.iterator]()` custom iterators,
|
|
18
|
+
`async`/`await` with `new Promise`, `.then` and `Promise.all` (lowered to goroutines over
|
|
19
|
+
channels, with pending callbacks and timers drained before exit), `setTimeout`
|
|
20
|
+
- **Modules**: `import.meta.url` — the `file://` URL of the running program
|
|
21
|
+
(`os.Executable` through the `pathToFileURL` lowering)
|
|
22
|
+
- **Classes**: inheritance with `super` (methods copied onto subclasses for `this` dispatch),
|
|
23
|
+
abstract classes, `#private` fields, static members typed from initializers, getters/setters
|
|
24
|
+
(`c.v` reads/writes rewrite to `Get_v()`/`Set_v()`), interface `extends` (inherited properties
|
|
25
|
+
flattened into the derived struct), object-literal methods and getters
|
|
26
|
+
- **Errors**: `throw new Error` / `new Error(message)` produce a real error value — custom error
|
|
27
|
+
classes via `extends Error`, `instanceof` and `.message` on caught values
|
|
28
|
+
- **Typing**: generic functions via Go generics (call sites infer type arguments), numeric enums
|
|
29
|
+
as plain numbers, tagged templates, JS loose equality (`0 == false`) with `bool`/number/string
|
|
30
|
+
coercion, `p is T` predicates returning `bool`
|
|
31
|
+
- **Runtime values**: `bigint` (`2n ** 64n` etc. via `math/big`) and `symbol` (unique pointers,
|
|
32
|
+
usable as record keys)
|
|
33
|
+
- **Library**: array `splice`, `fill`, `entries`, `flatMap`, `findLast`/`findLastIndex`,
|
|
34
|
+
`lastIndexOf`, `new Array<T>(n)`, `Array.from`, `join()` defaulting to `","`, in-place
|
|
35
|
+
`reverse`; `charCodeAt`/`String.fromCharCode`/`localeCompare`; `Date` (`new Date(ms)`,
|
|
36
|
+
`getTime`, `toISOString`, `Date.now()`); `Object.assign`; `.length` counts UTF-8 code points
|
|
37
|
+
and `[...str]` spreads runes
|
|
38
|
+
- **Regex**: `/g` regexes carry `lastIndex` state (`re.exec` loops terminate); named groups
|
|
39
|
+
(`(?<name>` → `(?P<name>`, `exec` returns a match with `.groups`); backreferences and
|
|
40
|
+
lookbehind/lookahead run on a small backtracking engine (RE2 does not support them)
|
|
41
|
+
- **Semantics**: arrays are references — `const b = a; b.push(3)` is visible through `a`
|
|
42
|
+
(array variables hold `*[]T`)
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- `JSON.stringify` serializes through reflection, so unexported (auto-generated) struct fields
|
|
47
|
+
are included
|
|
48
|
+
- `Object.assign` copies sources (structs, maps, dynamic objects) into an ordered map
|
|
49
|
+
- `throw` panics with a `TnError` value carrying `.message` instead of a bare string
|
|
50
|
+
|
|
51
|
+
## [0.1.0] - 2026-10-09
|
|
52
|
+
|
|
53
|
+
TypeNative compiles itself: `src/main.ts` builds into a native `typenative` binary that passes the
|
|
54
|
+
whole test suite and regenerates its own Go source identically (stage-1/stage-2 bootstrap).
|
|
55
|
+
|
|
56
|
+
### Added
|
|
57
|
+
|
|
58
|
+
- **Native compiler**: `npm run build:native` builds `native/typenative` and `native/tsparser`
|
|
59
|
+
- **`any` / `unknown` at runtime**: property and index access, truthiness, equality (objects by
|
|
60
|
+
identity), method calls, spreads and conversions to typed values via a small Go runtime
|
|
61
|
+
(`TnGet`, `TnSet`, `TnAs`, …) — no guessed types
|
|
62
|
+
- **Language**: object spread, `??=`, `in`, `typeof`, `continue`, optional and destructured
|
|
63
|
+
parameters, constructor parameter properties, `return` inside `try`/`catch`, object type
|
|
64
|
+
aliases and inline object types → Go structs, `Record<K, V>` and dictionaries → Go maps
|
|
65
|
+
- **Typing**: contextual types for object/array/function literals, narrowing of `T | undefined`,
|
|
66
|
+
JS truthiness, `??` chains, nullable ternaries, optional chains across calls
|
|
67
|
+
- **Library**: `toFixed`, `Math.max(...arr)`, `sort` with comparators, `flat`, typed
|
|
68
|
+
`Object.keys`/`values`, regex `replace` (`/g`, `$1`/`$&`, function replacers), `match`/`split`
|
|
69
|
+
with regexes, `Array.isArray`, `console.warn`, `fs.unlinkSync`, `process.env['X']`
|
|
70
|
+
- Tests 33–50
|
|
71
|
+
|
|
72
|
+
### Changed
|
|
73
|
+
|
|
74
|
+
- **Go 1.23 or newer is required** (generated code uses `slices`/`maps` iterator helpers)
|
|
75
|
+
- `process.platform` reports Node's names (`win32`, `darwin`, `linux`)
|
|
76
|
+
- `JSON.stringify` no longer escapes `<`, `>`, `&` (like JS)
|
|
77
|
+
- Out-of-range array/string reads give zero values instead of panicking (JS `undefined`)
|
|
78
|
+
- Imports and helpers are emitted in sorted order
|
|
79
|
+
- Map, Set and Record keep insertion order (like JS); objects are references (Go pointers)
|
|
80
|
+
|
|
81
|
+
### Fixed
|
|
82
|
+
|
|
83
|
+
- The test suite never ran (scripts called `bin/index.js`, which has no entry point); it now runs
|
|
84
|
+
through `bin/cli.js`
|
|
85
|
+
- Phase 3c regressions (19 tests): AST kind names, missing parent links, `extends` detection
|
|
86
|
+
- Main-file top-level variables were invisible to functions
|
|
87
|
+
- `spawnSync` with `stdio: 'inherit'` dropped its arguments
|
|
88
|
+
|
|
8
89
|
## [0.0.21] - 2026-09-06
|
|
9
90
|
|
|
10
91
|
Self-hosting milestone: the compiler no longer depends on `execa`, `fs-extra`, or `nanoid`, and the
|
package/CONTRIBUTION.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Contributing to TypeNative
|
|
2
|
+
|
|
3
|
+
Thanks for helping build TypeNative — a TypeScript-to-Go transpiler that ships native binaries. Contributions of all sizes are welcome: new language features, standard-library coverage, bug fixes, docs, and probes.
|
|
4
|
+
|
|
5
|
+
> New here? Read [README.md](README.md) first — it explains what TypeNative is, how the pipeline works, and the repo layout.
|
|
6
|
+
|
|
7
|
+
## Ways to contribute
|
|
8
|
+
|
|
9
|
+
- **Add a missing feature** — pick a ❌ row in [conformance.md](conformance.md) and make it ✅.
|
|
10
|
+
- **Fix a bug** — failing probe, wrong Go output, bad error message.
|
|
11
|
+
- **Improve docs** — README, conformance matrix, code comments.
|
|
12
|
+
- **Report issues** — open an issue with a minimal `.ts` repro, expected vs. actual output, and your `node --version` / `go version`.
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
- [Node.js v24](https://nodejs.org/en) or newer.
|
|
17
|
+
- [Go 1.26](https://go.dev/doc/install) or newer — hard minimum (`tsparser/go.mod` declares `go 1.26.0`).
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
git clone https://github.com/danisss9/typenative.git
|
|
23
|
+
cd typenative
|
|
24
|
+
npm ci
|
|
25
|
+
npm run build # tsc -> bin/
|
|
26
|
+
npm run conformance # full probe suite, must be green before you start
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## How a feature gets added
|
|
30
|
+
|
|
31
|
+
Every supported feature follows the same four-step loop. Do all four — a transpiler change without a probe (or vice versa) will not be merged.
|
|
32
|
+
|
|
33
|
+
### 1. Write a probe in `conformance/`
|
|
34
|
+
|
|
35
|
+
One file per feature, named by area:
|
|
36
|
+
|
|
37
|
+
| Prefix | Meaning | Example |
|
|
38
|
+
| ------ | ------- | ------- |
|
|
39
|
+
| `syntax-` | Language syntax | `syntax-optional-chaining.ts` |
|
|
40
|
+
| `semantics-` | Runtime behavior | `semantics-loose-equality.ts` |
|
|
41
|
+
| `lib-` | Standard-library API | `lib-map.ts` |
|
|
42
|
+
|
|
43
|
+
Probe conventions:
|
|
44
|
+
|
|
45
|
+
- Self-contained — no imports except the module under test, no external files.
|
|
46
|
+
- Exercise the feature with `console.log` **and** verify with `assert(condition, 'message')`.
|
|
47
|
+
- A passing probe transpiles, compiles with `go build`, runs, and exits `0`. Anything else is a failure.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
// conformance/lib-map.ts
|
|
51
|
+
const m = new Map<string, number>([['a', 1]]);
|
|
52
|
+
m.set('b', 2);
|
|
53
|
+
assert(m.size === 2 && m.get('a') === 1 && m.has('b') && !m.has('c'), 'map');
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Run just your probe while iterating:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
node scripts/conformance.mjs lib-map # substring filter
|
|
60
|
+
node scripts/conformance.mjs --native lib-map # same, via self-hosted binary
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Extend the ambient types in `types/`
|
|
64
|
+
|
|
65
|
+
The `.d.ts` files are the type-checking contract for user code. If your feature adds API surface, declare it:
|
|
66
|
+
|
|
67
|
+
- `types/typenative.d.ts` — core JS subset (`Array`, `Map`, `Set`, `JSON`, `Math`, `RegExp`, …).
|
|
68
|
+
- `types/typenative-npm.d.ts` — `node:*` shims (`fs`, `path`, `os`, `child_process`, …).
|
|
69
|
+
- `types/typenative-go.d.ts` — `go:*` bridges (`fmt`, `strings`, `strconv`).
|
|
70
|
+
|
|
71
|
+
No signature → user code won't type-check → the feature doesn't exist.
|
|
72
|
+
|
|
73
|
+
### 3. Implement in `src/transpiler.ts`
|
|
74
|
+
|
|
75
|
+
- Match on `node.kind === 'Xxx'` strings (never the `typescript` enum) so the same code consumes Node- and Go-produced ASTs.
|
|
76
|
+
- Emit a warning, not a crash, for anything still unsupported: `console.warn('[TypeNative] Unsupported syntax: …')`.
|
|
77
|
+
- Keep the transpiler free of Node-only dependencies (see below).
|
|
78
|
+
|
|
79
|
+
### 4. Document in `conformance.md`
|
|
80
|
+
|
|
81
|
+
Add or flip the matrix row and link your probe. Keep ✅/❌ honest — known gaps stay visible, and the [roadmap](conformance.md#roadmap-known-limitations) lists structural limitations.
|
|
82
|
+
|
|
83
|
+
## The transpilability rule
|
|
84
|
+
|
|
85
|
+
This is the one rule that breaks the build if ignored: **`src/index.ts`, `src/transpiler.ts`, `src/main.ts`, `src/prompt.ts`, and `src/parse-native.ts` must transpile with TypeNative itself.** That means:
|
|
86
|
+
|
|
87
|
+
- ❌ No `inquirer`, no async Node-only APIs, no unmapped modules in those files.
|
|
88
|
+
- ✅ Node-only code lives in `src/cli.ts` (prompts) and `src/parse-node.ts` (`typescript` package) and is injected at the boundary — e.g. `run({ ..., parse: parseAstJson })`.
|
|
89
|
+
- ✅ Prompts in transpilable code go through `src/prompt.ts` (`node:readline` → Go helper).
|
|
90
|
+
|
|
91
|
+
If you need a new capability in transpilable code, add the mapping (transpiler + `types/` shim) first, then use it.
|
|
92
|
+
|
|
93
|
+
## Code style
|
|
94
|
+
|
|
95
|
+
- Prettier config is in [.prettierrc.json](.prettierrc.json): 100-char width, 2-space indent, single quotes, semicolons, no trailing commas.
|
|
96
|
+
- Match surrounding code. Small, focused diffs beat refactors — don't reformat unrelated files.
|
|
97
|
+
- Comment *why*, not *what*. The codebase already documents module roles in file headers (`src/parse-node.ts`, `tsparser/main.go`, …) — update the header if you change a module's role.
|
|
98
|
+
|
|
99
|
+
## Testing
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
npm run build # must pass: tsc with strict mode
|
|
103
|
+
npm run conformance # full suite via Node CLI — must be 100% green
|
|
104
|
+
node scripts/conformance.mjs <filter> # iterate on one area
|
|
105
|
+
node scripts/conformance.mjs --native <filter> # parity via self-hosted binary
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
If you touched anything transpilable, also verify self-hosting:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
npm run build:native # builds native/tsparser + native/typenative
|
|
112
|
+
node scripts/conformance.mjs --native # full suite through your new binary
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
CI ([`.github/workflows/ci.yml`](.github/workflows/ci.yml)) runs `npm ci` → `npm run build` → `npm run conformance` on Ubuntu (Node 24 + Go). Match it locally before pushing.
|
|
116
|
+
|
|
117
|
+
## Pull requests
|
|
118
|
+
|
|
119
|
+
1. Fork, branch from `main` (`feat/<probe-name>`, `fix/<what>`, `docs/<what>`).
|
|
120
|
+
2. One feature per PR. Include: probe + types + transpiler + `conformance.md` row.
|
|
121
|
+
3. Describe: what TypeScript now transpiles, sample input/output Go if non-obvious, and conformance results (`total x/y`, plus `--native` if applicable).
|
|
122
|
+
4. Keep CI green — a red suite is the fastest way to get a review delayed.
|
|
123
|
+
|
|
124
|
+
## Releases
|
|
125
|
+
|
|
126
|
+
Releases are cut from `TypeNative_*` tags via trusted publishing ([release workflow](.github/workflows/npm-publish-github-packages.yml)). Don't bump `package.json` versions in PRs — the tag drives the version.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
By contributing, you agree your changes are MIT-licensed like the rest of the project. See [LICENSE](LICENSE).
|