typenative 0.0.19 → 0.0.21
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/npm-publish-github-packages.yml +13 -5
- package/CHANGELOG.md +59 -0
- package/README.md +45 -20
- package/TODO.md +30 -25
- package/bin/cli.js +62 -0
- package/bin/index.js +104 -132
- package/bin/main.js +31 -0
- package/bin/parse-native.js +37 -0
- package/bin/parse-node.js +110 -0
- package/bin/prompt.js +29 -0
- package/bin/transpiler.js +1416 -288
- package/package.json +8 -7
- package/tsparser/go.mod +14 -0
- package/tsparser/go.sum +22 -0
- package/tsparser/main.go +279 -0
- package/tsparser/tsparser.exe +0 -0
- package/types/typenative-npm.d.ts +44 -0
- package/types/typenative.d.ts +99 -1
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# Triggered by tags matching "TypeNative_{version}" (e.g. TypeNative_0.0.18)
|
|
2
2
|
# Runs tests, creates a GitHub release, and publishes to npm.
|
|
3
3
|
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
4
|
+
# Uses npm Trusted Publishing (OIDC) — no NPM_TOKEN secret needed.
|
|
5
|
+
# One-time setup on npmjs.com:
|
|
6
|
+
# typenative package page → Settings → Publishing access → Trusted Publisher → Connect GitHub
|
|
7
|
+
# - Organization or user: danisss9
|
|
8
|
+
# - Repository: typenative
|
|
9
|
+
# - Workflow filename: npm-publish-github-packages.yml
|
|
10
|
+
# - Environment name: (leave blank)
|
|
11
|
+
# Requires npm >= 11.5.1 (ensured below) and the `id-token: write` permission.
|
|
7
12
|
|
|
8
13
|
name: Release & Publish
|
|
9
14
|
|
|
@@ -61,6 +66,9 @@ jobs:
|
|
|
61
66
|
node-version: 24
|
|
62
67
|
registry-url: https://registry.npmjs.org/
|
|
63
68
|
|
|
69
|
+
# Trusted Publishing (OIDC) requires npm >= 11.5.1 — ensure we have it
|
|
70
|
+
- run: npm install -g npm@latest
|
|
71
|
+
|
|
64
72
|
- name: Extract version from tag
|
|
65
73
|
id: version
|
|
66
74
|
run: echo "VERSION=${GITHUB_REF_NAME#TypeNative_}" >> $GITHUB_OUTPUT
|
|
@@ -70,6 +78,6 @@ jobs:
|
|
|
70
78
|
|
|
71
79
|
- run: npm ci
|
|
72
80
|
|
|
81
|
+
# Authenticates via OIDC (id-token: write) — no NODE_AUTH_TOKEN needed.
|
|
82
|
+
# Provenance is included automatically; the flag is kept for explicitness.
|
|
73
83
|
- run: npm publish --provenance --access public
|
|
74
|
-
env:
|
|
75
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,65 @@ 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.0.21] - 2026-09-06
|
|
9
|
+
|
|
10
|
+
Self-hosting milestone: the compiler no longer depends on `execa`, `fs-extra`, or `nanoid`, and the
|
|
11
|
+
TypeScript parser is decoupled behind an injectable, normalized JSON AST — produced either by the
|
|
12
|
+
`typescript` npm package (dev CLI) or by the new Go-native `tsparser` tool (self-hosted binary).
|
|
13
|
+
Verified: all 33 test specs transpile identically through both parser paths, and the compiler now
|
|
14
|
+
transpiles its own source all the way to `go build`.
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **`node:fs` mappings**: `readFileSync`, `writeFileSync`, `appendFileSync`, `existsSync`, `mkdirSync`, `readdirSync`, `copyFileSync`, `rmSync` → Go helpers (`TnReadFile`, `TnWriteFile`, …)
|
|
19
|
+
- **`node:url` mappings**: `fileURLToPath`, `pathToFileURL`
|
|
20
|
+
- **`node:os` mappings**: `platform` (returns `win32`/`darwin`/linux like Node), `homedir`, `tmpdir`
|
|
21
|
+
- **`node:child_process` mappings**: sync `exec`/`execSync`/`spawnSync` shaped like Node's `spawnSync` (`{ stdout, stderr, status }`); `{ stdio: 'inherit' }` runs with the parent's stdio (`TnRunInherit`); `{ input }` pipes stdin (`TnExecInput`)
|
|
22
|
+
- **`node:readline` mapping**: synchronous `question(prompt)` for interactive native prompts (`TnQuestion`, single buffered stdin reader)
|
|
23
|
+
- **`process.env.X`** → `TnGetenv("X")`
|
|
24
|
+
- **Go helper registry**: node-stdlib helpers are emitted once into the main output file with correct per-file import scoping (helpers register their Go packages lazily; import lists are computed after function bodies are visited)
|
|
25
|
+
- **`tsparser/` Go tool**: parses TypeScript via `github.com/buke/typescript-go-internal` (native Go port of the TypeScript parser — no embedded JS runtime) and emits a normalized JSON AST with TypeScript-API kind and field names
|
|
26
|
+
- **`src/parse-node.ts`**: Node adapter producing the identical JSON AST from the `typescript` npm package; verified byte-identical against `tsparser` on all test specs and all compiler sources
|
|
27
|
+
- **`src/parse-native.ts`**: self-hosted parser client (spawns the `tsparser` binary, `TYPENATIVE_TSPARSER` env override)
|
|
28
|
+
- **Injectable parser**: `transpileToNative(code, { parse, readFile })` — the transpiler no longer imports `typescript`
|
|
29
|
+
- **Unbraced `if`/`else if`/`else` statements**: single-statement branches now emit valid Go blocks
|
|
30
|
+
- **`%` and `%=` on numbers** → `math.Mod`
|
|
31
|
+
- **`./x.js` → `x.ts` import resolution** for ES-style relative specifiers
|
|
32
|
+
- **Tests 31–32**: node-stdlib end-to-end spec (fs round-trip, os platform, shell exec) and subprocess/control-flow spec
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **CLI entry split**: `bin/cli.js` (npm `bin`) keeps inquirer for interactive Node use; the transpilable core lives in `src/index.ts` (`run`/`createProject`), with `src/main.ts` as the self-hosting entry and `src/prompt.ts` (transpilable sync prompts) replacing inquirer in native builds
|
|
37
|
+
- **Transpiler internals**: the `ts` typechecker is replaced by syntactic `typeNodeToText`; node predicates became plain `isX()` kind-string functions; operator tokens map through a kind-name table
|
|
38
|
+
- Dropped runtime dependencies: `execa`, `fs-extra`, `nanoid` (replaced by a local `goSafeId`)
|
|
39
|
+
|
|
40
|
+
## [0.0.20] - 2026-03-16
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- **Spread in array literals**: `[...arr1, ...arr2]` → `append(append([]T{}, arr1...), arr2...)`
|
|
45
|
+
- **Rest parameters**: `function(...args: T[])` → Go variadic `func(...args T)`
|
|
46
|
+
- **Spread in function calls**: `fn(...args)` → `fn(args...)`
|
|
47
|
+
- **Array destructuring**: `const [a, b] = arr` → Go index assignments
|
|
48
|
+
- **Object shorthand**: `{ name }` → `{ name: name }` in struct literals
|
|
49
|
+
- **Static class members**: `static method()` / `static prop` → `ClassName_method()` / `ClassName_prop` package-level declarations; `ClassName.method()` calls correctly resolve
|
|
50
|
+
- **Getters/Setters**: `get prop()` → `Get_prop()` method, `set prop(v)` → `Set_prop(v)` method
|
|
51
|
+
- **`for...in` loops**: `for (const k in obj)` → `for k := range obj`
|
|
52
|
+
- **`Object.entries()` in `for...of`**: `for (const [k, v] of Object.entries(map))` unwraps to `for k, v := range map`
|
|
53
|
+
- **Named function expression IIFEs**: `(function name() { ... })()` → anonymous `func() { ... }()`
|
|
54
|
+
- **`process` global**: `process.argv` → `os.Args`, `process.platform` → `runtime.GOOS`, `process.exit()` → `os.Exit()`, `process.cwd()` → `os.Getwd()`
|
|
55
|
+
- **`JSON.stringify()` / `JSON.parse()`**: mapped to `encoding/json` `Marshal`/`Unmarshal`
|
|
56
|
+
- **`Object.keys()` / `Object.values()` / `Object.entries()`**: map iteration helpers
|
|
57
|
+
- **Array methods**: `findIndex`, `every`, `forEach`, `reduce`, `pop`, `shift`, `unshift`, `reverse`, `sort`, `concat`, `flat`, `at`
|
|
58
|
+
- **String methods**: `padStart`, `padEnd`, `match`, `matchAll`, `search`, `at`
|
|
59
|
+
- **Math methods**: `log`, `log2`, `log10`, `sin`, `cos`, `tan`, `trunc`, `sign`
|
|
60
|
+
- **`console.error()`**: maps to `fmt.Fprintln(os.Stderr, ...)`
|
|
61
|
+
- **`String()` / `Number()` / `Boolean()`** conversion functions
|
|
62
|
+
- **Go reserved words protection**: `getSafeName()` now covers all Go keywords (`break`, `case`, `chan`, `continue`, `default`, `defer`, `else`, `fallthrough`, `for`, `func`, `go`, `goto`, `if`, `import`, `interface`, `map`, `package`, `range`, `return`, `select`, `struct`, `switch`, `type`, `var`)
|
|
63
|
+
- **Default import namespaces from npm/local packages**: `import ts from 'typescript'` registers `ts` as a stripped namespace so `ts.method()` → `method()`
|
|
64
|
+
- **Better unsupported syntax warnings**: `console.warn` with syntax kind name and source snippet instead of `console.log`
|
|
65
|
+
- **Type definitions (`typenative.d.ts`)**: added `findIndex`, `every`, `forEach`, `reduce`, `pop`, `shift`, `unshift`, `reverse`, `sort`, `flat`, `concat`, `at` to `Array`; `padStart`, `padEnd`, `match`, `matchAll`, `search`, `at` to `String`; added `JSON`, `Object`, `Process`, extended `Math` and `Console`
|
|
66
|
+
|
|
8
67
|
## [0.0.19] - 2026-03-07
|
|
9
68
|
|
|
10
69
|
### Added
|
package/README.md
CHANGED
|
@@ -29,10 +29,13 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
29
29
|
|
|
30
30
|
**Variables & Objects**
|
|
31
31
|
|
|
32
|
-
| Feature
|
|
33
|
-
|
|
|
34
|
-
| Variable declarations
|
|
35
|
-
| Object literals
|
|
32
|
+
| Feature | Supported | Notes |
|
|
33
|
+
| ---------------------- | :-------: | ----------------------------------------------- |
|
|
34
|
+
| Variable declarations | ✅ | `let` and `const` |
|
|
35
|
+
| Object literals | ✅ | Transpiled to Go struct literals |
|
|
36
|
+
| Object shorthand | ✅ | `{ name }` → `{ name: name }` |
|
|
37
|
+
| Array destructuring | ✅ | `const [a, b] = arr` |
|
|
38
|
+
| Object destructuring | ✅ | `const { x, y } = obj` |
|
|
36
39
|
|
|
37
40
|
**Operators**
|
|
38
41
|
|
|
@@ -42,6 +45,7 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
42
45
|
| Comparison operators | ✅ | `==`, `!=`, `===`, `!==`, etc. |
|
|
43
46
|
| Logical operators | ✅ | `&&`, `\|\|` |
|
|
44
47
|
| Increment/Decrement | ✅ | `++`, `--` |
|
|
48
|
+
| Spread operator | ✅ | `[...arr]`, `fn(...args)` |
|
|
45
49
|
| Non-null assertion (`!`) | ✅ | Stripped during transpilation |
|
|
46
50
|
| Ternary expressions | ✅ | `condition ? a : b` |
|
|
47
51
|
| Nullish coalescing | ✅ | `??` operator |
|
|
@@ -54,21 +58,22 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
54
58
|
| If/Else statements | ✅ | Fully supported |
|
|
55
59
|
| Switch statements | ✅ | Case and default statements |
|
|
56
60
|
| For loops | ✅ | Standard `for` loops |
|
|
57
|
-
| For...of loops | ✅ |
|
|
61
|
+
| For...of loops | ✅ | Arrays, Maps, Sets; `Object.entries()` unwrapping |
|
|
62
|
+
| For...in loops | ✅ | Iterates keys via Go `range` |
|
|
58
63
|
| While loops | ✅ | Transpiled to Go's `for` loops |
|
|
59
64
|
| Do...while loops | ✅ | Implemented with conditional break |
|
|
60
65
|
| Try/Catch/Finally | ✅ | `throw` → `panic`; catch/finally via `defer`/`recover` |
|
|
61
66
|
|
|
62
67
|
**Data Structures & Array Methods**
|
|
63
68
|
|
|
64
|
-
| Feature | Supported | Notes
|
|
65
|
-
| -------------------------- | :-------: |
|
|
66
|
-
| Arrays | ✅ | Basic array operations
|
|
67
|
-
| Array methods | ✅ | `push`, `join`, `slice`
|
|
68
|
-
| Higher-order array methods | ✅ | `.map()`, `.filter()`, `.some()`, `.find()`
|
|
69
|
-
| Method chaining | ✅ |
|
|
70
|
-
| Map | ✅ | `Map<K, V>` → Go `map[K]V`; `.set()`, `.get()`, `.has()`, `.delete()`, `.clear()`, `.size`
|
|
71
|
-
| Set | ✅ | `Set<T>` → Go `map[T]struct{}`; `.add()`, `.has()`, `.delete()`, `.clear()`, `.size`
|
|
69
|
+
| Feature | Supported | Notes |
|
|
70
|
+
| -------------------------- | :-------: | --------------------------------------------------------------------------------------------- |
|
|
71
|
+
| Arrays | ✅ | Basic array operations |
|
|
72
|
+
| Array methods | ✅ | `push`, `pop`, `shift`, `unshift`, `join`, `slice`, `concat`, `reverse`, `sort`, `flat`, `at` |
|
|
73
|
+
| Higher-order array methods | ✅ | `.map()`, `.filter()`, `.some()`, `.find()`, `.findIndex()`, `.every()`, `.forEach()`, `.reduce()` |
|
|
74
|
+
| Method chaining | ✅ | e.g. `.map(...).filter(...).join(...)` |
|
|
75
|
+
| Map | ✅ | `Map<K, V>` → Go `map[K]V`; `.set()`, `.get()`, `.has()`, `.delete()`, `.clear()`, `.size` |
|
|
76
|
+
| Set | ✅ | `Set<T>` → Go `map[T]struct{}`; `.add()`, `.has()`, `.delete()`, `.clear()`, `.size` |
|
|
72
77
|
|
|
73
78
|
**Functions**
|
|
74
79
|
|
|
@@ -76,10 +81,12 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
76
81
|
| ---------------------------- | :-------: | ----------------------------------------------------------- |
|
|
77
82
|
| Function declarations | ✅ | Transpiled to Go functions |
|
|
78
83
|
| Arrow functions | ✅ | Transpiled to anonymous functions |
|
|
84
|
+
| IIFEs | ✅ | `(() => { ... })()` and `(function name() { ... })()` |
|
|
79
85
|
| Closures over mutable state | ✅ | Functions capturing and mutating outer variables |
|
|
80
86
|
| Function types | ✅ | `() => number`, `(x: number) => string` as type annotations |
|
|
81
87
|
| Generics (functions/classes) | ✅ | Type parameters via Go generics |
|
|
82
88
|
| Default parameter values | ✅ | `function(x = defaultValue)` |
|
|
89
|
+
| Rest parameters | ✅ | `function(...args: T[])` → Go variadic |
|
|
83
90
|
|
|
84
91
|
**Classes & Interfaces**
|
|
85
92
|
|
|
@@ -87,6 +94,8 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
87
94
|
| ------------------- | :-------: | -------------------------------------------------------------- |
|
|
88
95
|
| Classes | ✅ | Transpiled to Go structs with constructor and receiver methods |
|
|
89
96
|
| Class inheritance | ✅ | `extends` via embedded structs, `super()` supported |
|
|
97
|
+
| Static members | ✅ | `static method()` / `static prop` → package-level declarations |
|
|
98
|
+
| Getters / Setters | ✅ | `get prop()` → `Get_prop()`, `set prop(v)` → `Set_prop(v)` |
|
|
90
99
|
| Interfaces | ✅ | Transpiled to Go interfaces, supports `extends` |
|
|
91
100
|
| Optional properties | ✅ | `prop?: Type` in interfaces/types |
|
|
92
101
|
| Enums | ✅ | `enum` declarations and member access |
|
|
@@ -104,9 +113,16 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
104
113
|
| Feature | Supported | Notes |
|
|
105
114
|
| --------------------- | :-------: | ----------------------------------------------------- |
|
|
106
115
|
| console.log | ✅ | Mapped to `fmt.Println` |
|
|
116
|
+
| console.error | ✅ | Mapped to `fmt.Fprintln(os.Stderr, ...)` |
|
|
107
117
|
| console.time/timeEnd | ✅ | Performance measurement via `time.Now` / `time.Since` |
|
|
108
118
|
| assert | ✅ | Transpiled to `panic` on failure |
|
|
109
119
|
| parseInt / parseFloat | ✅ | Mapped to Go's `strconv` package |
|
|
120
|
+
| JSON.stringify | ✅ | Mapped to `encoding/json` `Marshal` / `MarshalIndent` |
|
|
121
|
+
| JSON.parse | ✅ | Mapped to `encoding/json` `Unmarshal` |
|
|
122
|
+
| Object.keys/values | ✅ | Map key/value iteration helpers |
|
|
123
|
+
| process.argv | ✅ | Mapped to `os.Args` |
|
|
124
|
+
| process.platform | ✅ | Mapped to `runtime.GOOS` |
|
|
125
|
+
| process.exit | ✅ | Mapped to `os.Exit` |
|
|
110
126
|
|
|
111
127
|
**Math Methods**
|
|
112
128
|
|
|
@@ -116,6 +132,9 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
116
132
|
| Math.floor / ceil / round | ✅ | Mapped to `math.Floor`, `math.Ceil`, `math.Round` |
|
|
117
133
|
| Math.abs / sqrt / pow | ✅ | Mapped to corresponding `math` functions |
|
|
118
134
|
| Math.min / max | ✅ | Mapped to `math.Min`, `math.Max` |
|
|
135
|
+
| Math.log / log2 / log10 | ✅ | Mapped to `math.Log`, `math.Log2`, `math.Log10` |
|
|
136
|
+
| Math.sin / cos / tan | ✅ | Mapped to `math.Sin`, `math.Cos`, `math.Tan` |
|
|
137
|
+
| Math.trunc / sign | ✅ | Mapped to `math.Trunc` and inline sign check |
|
|
119
138
|
|
|
120
139
|
**String Methods**
|
|
121
140
|
|
|
@@ -129,6 +148,9 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
129
148
|
| replace / replaceAll | ✅ | Via `strings` package |
|
|
130
149
|
| charAt / substring / slice | ✅ | Direct Go string indexing/slicing |
|
|
131
150
|
| concat / repeat | ✅ | String concatenation and `strings.Repeat` |
|
|
151
|
+
| padStart / padEnd | ✅ | Via `strings.Repeat` |
|
|
152
|
+
| match / matchAll / search | ✅ | Via `regexp` package |
|
|
153
|
+
| at | ✅ | Supports negative indices |
|
|
132
154
|
|
|
133
155
|
**Number / Object Methods**
|
|
134
156
|
|
|
@@ -147,12 +169,15 @@ TypeNative currently supports a focused subset of TypeScript syntax elements tha
|
|
|
147
169
|
|
|
148
170
|
**Modules & Imports**
|
|
149
171
|
|
|
150
|
-
| Feature | Supported | Notes
|
|
151
|
-
| ------------------------ | :-------: |
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
|
|
|
155
|
-
|
|
|
156
|
-
|
|
|
172
|
+
| Feature | Supported | Notes |
|
|
173
|
+
| ------------------------ | :-------: | ------------------------------------------------------------------ |
|
|
174
|
+
| Named imports | ✅ | `import { x } from './file'` |
|
|
175
|
+
| Default imports | ✅ | `import x from 'pkg'` — namespace stripped in output |
|
|
176
|
+
| Namespace imports | ✅ | `import * as x from 'pkg'` |
|
|
177
|
+
| Local file imports | ✅ | Relative paths transpiled to a separate Go file |
|
|
178
|
+
| Node.js built-in imports | ✅ | `import { join } from 'node:path'` mapped to Go stdlib |
|
|
179
|
+
| Go package imports | ✅ | `import { x } from 'go:pkg'` |
|
|
180
|
+
| npm package imports | ✅ | `import { x } from 'pkg'` mapped to Go module imports |
|
|
181
|
+
| Named exports | ✅ | `export function` / `export const` declarations |
|
|
157
182
|
|
|
158
183
|
TypeNative is currently in early development and new features are being added regularly. The goal for `1.0` release is for TypeNative to transpile itself.
|
package/TODO.md
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
# Self-Hosting Roadmap
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
| ------------------------------- | ------------------------------------------------------------------- |
|
|
5
|
-
| Default imports | `import inquirer from 'inquirer'`, `import fs from 'fs-extra'` |
|
|
6
|
-
| `process` global | `process.argv`, `process.platform` |
|
|
7
|
-
| Array `findIndex` | `process.argv.findIndex(a => a === '--script')` |
|
|
8
|
-
| `JSON.parse` / `JSON.stringify` | `JSON.parse(fs.readFileSync(...))`, `JSON.stringify(pckg, null, 2)` |
|
|
9
|
-
| Named async IIFE | `(async function main() { ... })()` |
|
|
3
|
+
Goal: TypeNative transpiles itself into a native Go binary (1.0 milestone).
|
|
10
4
|
|
|
11
|
-
|
|
5
|
+
## Done
|
|
6
|
+
- [x] node:fs mappings (read/write/append/exists/mkdir/readdir/copy/rm) via Go helpers
|
|
7
|
+
- [x] node:url (fileURLToPath/pathToFileURL), node:os (platform/homedir/tmpdir)
|
|
8
|
+
- [x] node:child_process (spawnSync-shaped sync API, stdio-inherit runs)
|
|
9
|
+
- [x] node:readline sync `question` (stdin prompts in native binaries)
|
|
10
|
+
- [x] Go helper-function registry emitted into the main output file
|
|
11
|
+
- [x] Per-file import scoping (imports registered after function-body visits)
|
|
12
|
+
- [x] Unbraced if/else-if/else statements, `%`/`%=` → math.Mod
|
|
13
|
+
- [x] nanoid/fs-extra/execa removed from src; inquirer isolated in Node-only cli.ts
|
|
14
|
+
- [x] Transpilable core: src/index.ts (run/createProject), src/prompt.ts, src/main.ts (self-host entry)
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
| Arrow function IIFE | `(() => { ... })()` |
|
|
20
|
-
| Array `findIndex` | `parameters.findIndex(p => !!p.initializer)` |
|
|
16
|
+
## Done (phase 3a/3b)
|
|
17
|
+
- [x] tsparser/ Go tool: parses TS via buke/typescript-go-internal (no JS runtime),
|
|
18
|
+
emits normalized JSON AST (kind + TS-spec field names)
|
|
19
|
+
- [x] src/parse-node.ts: Node adapter (typescript npm pkg → same JSON shape)
|
|
20
|
+
- [x] Verified byte-identical AST signatures across all 32 test specs AND all
|
|
21
|
+
compiler sources (incl. transpiler.ts, 521k-char signature)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
- [x] ts shim converted to plain isX() functions + string kind literals
|
|
24
|
+
(object-literal shim was itself untranspilable)
|
|
25
|
+
- [x] Phase 3c: transpiler.ts no longer imports `typescript` — consumes the JSON AST
|
|
26
|
+
via an injected parse function (ts shim keeps predicate call sites); operator
|
|
27
|
+
tokens, process.env, stdin-exec mappings added; verified identical Go output
|
|
28
|
+
via npm parser and Go-parser paths on all 33 test specs
|
|
29
|
+
- [ ] Phase 4: dogfood src/transpiler.ts (2.6k lines): regex /g semantics,
|
|
30
|
+
String.replace with function replacer, JSON.parse result typing, object spread,
|
|
31
|
+
Array.includes on untyped values, default-import namespace stripping (ts.x → x)
|
|
32
|
+
- [ ] import.meta.url lowering
|
|
33
|
+
- [ ] Phase 5: stage-1/stage-2 bootstrap + run test suite through the native binary
|
|
34
|
+
- [ ] Phase 5: CI self-hosting job; README/CHANGELOG updates
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Node CLI entry point (npm `bin`). Interactive prompts use inquirer here;
|
|
3
|
+
// the actual compiler logic lives in the transpilable src/index.ts.
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import { run, createProject } from './index.js';
|
|
6
|
+
import { parseAstJson } from './parse-node.js';
|
|
7
|
+
(async function main() {
|
|
8
|
+
const scriptMode = process.argv.findIndex((a) => a === '--script') > -1;
|
|
9
|
+
const newCommand = process.argv.findIndex((a) => a === '--new') > -1;
|
|
10
|
+
const sourceIndex = process.argv.findIndex((a) => a === '--source');
|
|
11
|
+
const source = sourceIndex > -1 ? process.argv[sourceIndex + 1] : null;
|
|
12
|
+
const outputIndex = process.argv.findIndex((a) => a === '--output');
|
|
13
|
+
const output = outputIndex > -1 ? process.argv[outputIndex + 1] : null;
|
|
14
|
+
const answers = await inquirer.prompt([
|
|
15
|
+
{
|
|
16
|
+
type: 'input',
|
|
17
|
+
name: 'projectName',
|
|
18
|
+
message: 'Enter Project Name:',
|
|
19
|
+
when: newCommand,
|
|
20
|
+
validate: (input) => input.trim() !== ''
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'confirm',
|
|
24
|
+
name: 'installDependencies',
|
|
25
|
+
message: 'Do you want to install dependencies?',
|
|
26
|
+
when: newCommand
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'input',
|
|
30
|
+
name: 'path',
|
|
31
|
+
message: 'Enter Path to typescript main file:',
|
|
32
|
+
when: !newCommand && !scriptMode && !source,
|
|
33
|
+
validate: (input) => input.trim() !== ''
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: 'input',
|
|
37
|
+
name: 'output',
|
|
38
|
+
message: 'Enter Output Path:',
|
|
39
|
+
when: !newCommand && !scriptMode && !output,
|
|
40
|
+
validate: (input) => input.trim() !== ''
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'editor',
|
|
44
|
+
name: 'tsCode',
|
|
45
|
+
message: 'Write your typescript code here:',
|
|
46
|
+
when: !newCommand && scriptMode && !source,
|
|
47
|
+
default: `console.log('Hello, World!');`
|
|
48
|
+
}
|
|
49
|
+
]);
|
|
50
|
+
if (newCommand) {
|
|
51
|
+
createProject(answers.projectName.trim(), answers.installDependencies);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const sourcePath = answers.tsCode ? null : (source ?? answers.path ?? null);
|
|
55
|
+
run({
|
|
56
|
+
source: sourcePath,
|
|
57
|
+
output: output ?? answers.output ?? null,
|
|
58
|
+
scriptMode,
|
|
59
|
+
tsCode: answers.tsCode ?? null,
|
|
60
|
+
parse: parseAstJson
|
|
61
|
+
});
|
|
62
|
+
})();
|