typenative 0.1.1 → 0.1.2
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/bin/transpiler.js +1320 -79
- package/conformance.md +80 -71
- package/package.json +1 -1
- package/tsparser/main.go +17 -1
- package/tsparser/tsparser.exe +2 -2
package/conformance.md
CHANGED
|
@@ -19,8 +19,8 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
19
19
|
| Nullable types (`T \| null`, `T \| undefined`) | ✅ | [syntax-null-undefined.ts](conformance/syntax-null-undefined.ts) | Transpiled to Go pointer types |
|
|
20
20
|
| `bigint` | ✅ | [syntax-bigint.ts](conformance/syntax-bigint.ts) | `2n` literals → `*big.Int`; `**` → `.Exp`, comparisons via `.Cmp` |
|
|
21
21
|
| `symbol` | ✅ | [syntax-symbols.ts](conformance/syntax-symbols.ts) | `Symbol()` → unique `*TnSymbol` pointers, usable as record keys |
|
|
22
|
-
| `object` type |
|
|
23
|
-
| `void` / `never` |
|
|
22
|
+
| `object` type | ✅ | [syntax-object-type.ts](conformance/syntax-object-type.ts) | `object` → `interface{}` |
|
|
23
|
+
| `void` / `never` | ✅ | [syntax-void-never.ts](conformance/syntax-void-never.ts) | No return value in Go |
|
|
24
24
|
|
|
25
25
|
## Variables & destructuring
|
|
26
26
|
|
|
@@ -40,8 +40,8 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
40
40
|
| Tuples | ✅ | [syntax-tuples.ts](conformance/syntax-tuples.ts) | `[string, number]` fixed-length arrays |
|
|
41
41
|
| Top-level / module-scope variables | ✅ | [syntax-top-level-scope.ts](conformance/syntax-top-level-scope.ts) | Functions see main-file top-level variables |
|
|
42
42
|
| Numeric separators | ✅ | [syntax-numeric-separators.ts](conformance/syntax-numeric-separators.ts) | `1_000_000` |
|
|
43
|
-
| Hex / octal / binary literals |
|
|
44
|
-
| `var` declarations (hoisting) |
|
|
43
|
+
| Hex / octal / binary literals | ✅ | [syntax-numeric-literals.ts](conformance/syntax-numeric-literals.ts) | `0xFF`, `0o17`, `0b1010`, `1e3` |
|
|
44
|
+
| `var` declarations (hoisting) | ✅ | [syntax-var.ts](conformance/syntax-var.ts) | Function- and module-level `var` |
|
|
45
45
|
| `using` / `await using` declarations | ❌ | — | Explicit resource management; no probe yet |
|
|
46
46
|
|
|
47
47
|
## Operators
|
|
@@ -65,9 +65,9 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
65
65
|
| `instanceof` | ✅ | [syntax-instanceof.ts](conformance/syntax-instanceof.ts) | Class instance checks |
|
|
66
66
|
| JS truthiness | ✅ | [syntax-optional-params.ts](conformance/syntax-optional-params.ts) | `if (str)`, `!count`, `a \|\| fallback` on any type |
|
|
67
67
|
| Loose equality (`==`) | ✅ | [semantics-loose-equality.ts](conformance/semantics-loose-equality.ts) | `bool`/`number`/`string` mixtures coerce like JS (`TnNumber`/`TnParseFloat`) |
|
|
68
|
-
| Optional call (`fn?.()`) |
|
|
69
|
-
| Comma operator |
|
|
70
|
-
| `void` operator |
|
|
68
|
+
| Optional call (`fn?.()`) | ✅ | [syntax-optional-call.ts](conformance/syntax-optional-call.ts) | Nil check on the function value; result is nullable |
|
|
69
|
+
| Comma operator | ✅ | [syntax-comma-operator.ts](conformance/syntax-comma-operator.ts) | In `for` headers (`i = 0, j = 10` / `i++, j--`) |
|
|
70
|
+
| `void` operator | ✅ | [syntax-void-operator.ts](conformance/syntax-void-operator.ts) | Evaluates, then `nil` |
|
|
71
71
|
| `new.target` | ❌ | — | No probe yet |
|
|
72
72
|
|
|
73
73
|
## Control flow
|
|
@@ -108,12 +108,13 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
108
108
|
| Destructured parameters | ✅ | [syntax-destructuring-params.ts](conformance/syntax-destructuring-params.ts) | `function f({ a, b }: T)`, `([x, y]: number[])` |
|
|
109
109
|
| Contextual object-literal arguments | ✅ | [syntax-contextual-arguments.ts](conformance/syntax-contextual-arguments.ts) | Struct type inferred from parameter / return type |
|
|
110
110
|
| Recursion | ✅ | [syntax-recursion.ts](conformance/syntax-recursion.ts) | Direct self-recursion |
|
|
111
|
+
| Recursive arrow functions | ✅ | [syntax-recursive-arrow.ts](conformance/syntax-recursive-arrow.ts) | `const f = () => … f() …` → declared, then assigned |
|
|
111
112
|
| Generators (`function*` / `yield` / `yield*`) | ✅ | [syntax-generators.ts](conformance/syntax-generators.ts) | `function*` runs in a goroutine sending yields over a channel; `for...of` ranges it |
|
|
112
|
-
| Async generators (`async function*`) |
|
|
113
|
+
| Async generators (`async function*`) | ✅ | [syntax-async-generators.ts](conformance/syntax-async-generators.ts) | Goroutine + channel, consumed with `for await` |
|
|
113
114
|
| Custom iterators (`Symbol.iterator`) | ✅ | [syntax-custom-iterators.ts](conformance/syntax-custom-iterators.ts) | `*[Symbol.iterator]()` → a `Symbol_iterator()` channel method |
|
|
114
115
|
| `as const` assertions | ✅ | [syntax-as-const.ts](conformance/syntax-as-const.ts) | Erased during transpilation |
|
|
115
|
-
| Function overloads |
|
|
116
|
-
| `this` parameter (`function f(this: T)`) |
|
|
116
|
+
| Function overloads | ✅ | [syntax-function-overloads.ts](conformance/syntax-function-overloads.ts) | Signatures are erased; the implementation is emitted |
|
|
117
|
+
| `this` parameter (`function f(this: T)`) | ✅ | [syntax-this-parameter.ts](conformance/syntax-this-parameter.ts) | Erased |
|
|
117
118
|
| `arguments` object | ❌ | — | No probe yet |
|
|
118
119
|
|
|
119
120
|
## Classes & interfaces
|
|
@@ -130,14 +131,14 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
130
131
|
| Getters (object literals) | ✅ | [syntax-object-getters.ts](conformance/syntax-object-getters.ts) | Getter closures stored as function fields; reads invoke them |
|
|
131
132
|
| Object-literal methods | ✅ | [syntax-object-methods.ts](conformance/syntax-object-methods.ts) | Method closures stored as function fields capturing the instance (`this` → the object) |
|
|
132
133
|
| Private `#` fields | ✅ | [syntax-class-private-fields.ts](conformance/syntax-class-private-fields.ts) | `#secret` → a plain (name-mangled) struct field |
|
|
133
|
-
| Access modifiers (`private` / `protected` / `public` on members) |
|
|
134
|
+
| Access modifiers (`private` / `protected` / `public` on members) | ✅ | [syntax-access-modifiers.ts](conformance/syntax-access-modifiers.ts) | `private` / `protected` / `public` are erased |
|
|
134
135
|
| Abstract classes | ✅ | [syntax-class-abstract.ts](conformance/syntax-class-abstract.ts) | Abstract members skipped; concrete methods copied onto subclasses |
|
|
135
|
-
| Static initialization blocks (`static {}`) |
|
|
136
|
-
| Class expressions (`const C = class {}`) |
|
|
136
|
+
| Static initialization blocks (`static {}`) | ✅ | [syntax-static-blocks.ts](conformance/syntax-static-blocks.ts) | Go `func init()` |
|
|
137
|
+
| Class expressions (`const C = class {}`) | ✅ | [syntax-class-expressions.ts](conformance/syntax-class-expressions.ts) | `const C = class {…}` becomes a class named after the variable |
|
|
137
138
|
| Interfaces | ✅ | [syntax-class-implements.ts](conformance/syntax-class-implements.ts) | Transpiled to Go interfaces |
|
|
138
139
|
| Optional properties | ✅ | [syntax-optional-chaining.ts](conformance/syntax-optional-chaining.ts) | `prop?: Type` in interfaces/types |
|
|
139
140
|
| Type-aware method dispatch | ✅ | [semantics-method-dispatch.ts](conformance/semantics-method-dispatch.ts) | Class `.push()` / `.length` not confused with array builtins |
|
|
140
|
-
| Index signatures (`[key: string]: T`) |
|
|
141
|
+
| Index signatures (`[key: string]: T`) | ✅ | [syntax-index-signatures.ts](conformance/syntax-index-signatures.ts) | `{ [k: K]: V }` is `Record<K, V>` (an ordered Go map) |
|
|
141
142
|
|
|
142
143
|
## Generics
|
|
143
144
|
|
|
@@ -145,9 +146,9 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
145
146
|
| ------------------------------------------------------------- | :----: | ---------------------------------------------------------------------- | ---------------------------------- |
|
|
146
147
|
| Generic functions | ✅ | [syntax-generic-functions.ts](conformance/syntax-generic-functions.ts) | Type parameters → Go generics; call sites infer from arguments |
|
|
147
148
|
| Generic classes | ✅ | [syntax-generic-classes.ts](conformance/syntax-generic-classes.ts) | Type parameters via Go generics |
|
|
148
|
-
| Generic constraints (`<T extends U>`) |
|
|
149
|
-
| Default type parameters (`<T = D>`) |
|
|
150
|
-
| Generic interfaces / type aliases |
|
|
149
|
+
| Generic constraints (`<T extends U>`) | ✅ | [syntax-generic-constraints.ts](conformance/syntax-generic-constraints.ts) | Object-type bounds become `any`; properties of `T` values read dynamically |
|
|
150
|
+
| Default type parameters (`<T = D>`) | ✅ | [syntax-generic-defaults.ts](conformance/syntax-generic-defaults.ts) | Defaults are erased; Go infers from arguments |
|
|
151
|
+
| Generic interfaces / type aliases | ✅ | [syntax-generic-interfaces.ts](conformance/syntax-generic-interfaces.ts) | Go generic structs; literals instantiate them (`Box[float64]{…}`) |
|
|
151
152
|
| `const` type parameters / variance annotations (`in` / `out`) | ❌ | — | No probe yet |
|
|
152
153
|
|
|
153
154
|
## Enums
|
|
@@ -156,7 +157,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
156
157
|
| ------------------------------------- | :----: | ------------------------------------------------------------ | -------------------------------------------- |
|
|
157
158
|
| Numeric enums | ✅ | [syntax-enum-numeric.ts](conformance/syntax-enum-numeric.ts) | Numeric members are `float64` constants; string enums keep a named type |
|
|
158
159
|
| String enums | ✅ | [syntax-enum-string.ts](conformance/syntax-enum-string.ts) | `enum` declarations and member access |
|
|
159
|
-
| `const enum` |
|
|
160
|
+
| `const enum` | ✅ | [syntax-const-enum.ts](conformance/syntax-const-enum.ts) | Compiled like a regular enum |
|
|
160
161
|
| Computed / heterogeneous enum members | ❌ | — | `enum E { A = f(), B = 's' }`; no probe yet |
|
|
161
162
|
|
|
162
163
|
## Type-system features
|
|
@@ -170,19 +171,21 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
170
171
|
| Self-host contextual typing | ✅ | [syntax-selfhost-context.ts](conformance/syntax-selfhost-context.ts) | Object/array literals typed from context, `Record` literals, `in`, `any` params |
|
|
171
172
|
| Decorators (`@`) | ❌ | — | No probe yet |
|
|
172
173
|
| Namespaces / `module` blocks | ❌ | — | No probe yet |
|
|
173
|
-
| `override` modifier |
|
|
174
|
-
| `readonly` modifier (properties, `readonly T[]`) |
|
|
175
|
-
| `satisfies` operator |
|
|
176
|
-
| `keyof` / mapped /
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
|
|
|
184
|
-
|
|
|
185
|
-
|
|
|
174
|
+
| `override` modifier | ✅ | [syntax-override.ts](conformance/syntax-override.ts) | Erased |
|
|
175
|
+
| `readonly` modifier (properties, `readonly T[]`) | ✅ | [syntax-readonly.ts](conformance/syntax-readonly.ts) | Erased (`readonly T[]` → `[]T`) |
|
|
176
|
+
| `satisfies` operator | ✅ | [syntax-satisfies.ts](conformance/syntax-satisfies.ts) | Checked by tsc, erased; the type guides literals |
|
|
177
|
+
| `keyof` / mapped types | ✅ | [syntax-keyof-mapped-types.ts](conformance/syntax-keyof-mapped-types.ts) | `keyof` → `string`; mapped types → structs (literal keys) or maps |
|
|
178
|
+
| Conditional types | ✅ | [syntax-conditional-types.ts](conformance/syntax-conditional-types.ts) | Resolved to their branch's Go type |
|
|
179
|
+
| `infer` types | ✅ | [syntax-infer-types.ts](conformance/syntax-infer-types.ts) | Resolved to their branch's Go type |
|
|
180
|
+
| `import type` / `export type` | ✅ | [syntax-import-type.ts](conformance/syntax-import-type.ts) | Type-only imports are erased |
|
|
181
|
+
| Intersection types (`A & B`) | ✅ | [syntax-intersection-types.ts](conformance/syntax-intersection-types.ts) | Object types merge into one struct |
|
|
182
|
+
| Literal types (`'a' \| 'b'`) | [syntax-literal-types.ts](conformance/syntax-literal-types.ts) | String literal unions → `string` | No probe yet |
|
|
183
|
+
| Tuple optional / rest / labeled elements | ✅ | [syntax-tuple-elements.ts](conformance/syntax-tuple-elements.ts) | Tuples are slices |
|
|
184
|
+
| Indexed access types (`T['k']`) | ✅ | [syntax-indexed-access-types.ts](conformance/syntax-indexed-access-types.ts) | `T['k']` resolves to the member type |
|
|
185
|
+
| Type-level `typeof` (`typeof obj`) | ✅ | [syntax-type-typeof.ts](conformance/syntax-type-typeof.ts) | The variable's Go type |
|
|
186
|
+
| Template literal types | ✅ | [syntax-template-literal-types.ts](conformance/syntax-template-literal-types.ts) | Template literal types → `string` |
|
|
187
|
+
| Utility types (`Partial`, `Pick`, `Omit`, …) | ✅ | [syntax-utility-types.ts](conformance/syntax-utility-types.ts) | `Partial` / `Required` / `Readonly` / `Pick` / `Omit` / `NonNullable` → the base type |
|
|
188
|
+
| Assertion functions (`asserts x is T`) | ✅ | [syntax-assertion-functions.ts](conformance/syntax-assertion-functions.ts) | No return value |
|
|
186
189
|
| Callable / construct signatures (`type F = { (): void }`) | ❌ | — | No probe yet |
|
|
187
190
|
| JSX / `.tsx` syntax | ❌ | — | No probe yet |
|
|
188
191
|
| Ambient declarations (`declare`, `.d.ts`, `x!: T`) | ❌ | — | No probe yet |
|
|
@@ -193,7 +196,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
193
196
|
| Feature | Status | Probe | Notes |
|
|
194
197
|
| -------------------------------------------------- | :----: | ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
195
198
|
| Named imports | ✅ | [syntax-import-go.ts](conformance/syntax-import-go.ts) | `import { x } from './file'` |
|
|
196
|
-
| Import renaming (`import { x as y }`) |
|
|
199
|
+
| Import renaming (`import { x as y }`) | ✅ | [syntax-import-renaming.ts](conformance/syntax-import-renaming.ts) | Local file imports |
|
|
197
200
|
| Named exports (`export const` / `export function`) | ✅ | [syntax-import-local.ts](conformance/syntax-import-local.ts) | Helper [import-local-helper.ts](conformance/import-local-helper.ts) exports `multiply` |
|
|
198
201
|
| Default imports | ✅ | [syntax-import-go.ts](conformance/syntax-import-go.ts) | `import x from 'pkg'` — namespace stripped in output |
|
|
199
202
|
| Namespace imports | ✅ | [syntax-import-go.ts](conformance/syntax-import-go.ts) | `import * as x from 'pkg'` |
|
|
@@ -214,10 +217,12 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
214
217
|
| `async` / `await` | ✅ | [syntax-async-await.ts](conformance/syntax-async-await.ts) | Async functions send returns over a channel; `await` receives; pending work drains before exit |
|
|
215
218
|
| `Promise` constructor / `.then` | ✅ | [syntax-promise-then.ts](conformance/syntax-promise-then.ts) | `new Promise` executor runs in a goroutine; `.then` consumes the channel on a wait group |
|
|
216
219
|
| `Promise.all` | ✅ | [syntax-promise-all.ts](conformance/syntax-promise-all.ts) | `TnPromiseAll` drains every promise channel into a slice |
|
|
217
|
-
| `Promise.resolve`
|
|
218
|
-
| `Promise.
|
|
219
|
-
| `
|
|
220
|
-
| `
|
|
220
|
+
| `Promise.resolve` | ✅ | [lib-promise-resolve.ts](conformance/lib-promise-resolve.ts) | Buffered channel holding the value |
|
|
221
|
+
| `Promise.reject` / `.catch` / `.finally` | ✅ | [lib-promise-catch.ts](conformance/lib-promise-catch.ts) | Rejected promises are closed channels with a reason; `await` rethrows |
|
|
222
|
+
| `Promise.race` / `allSettled` / `any` | ✅ | [lib-promise-combinators.ts](conformance/lib-promise-combinators.ts) | Goroutine per promise; first settled / all settled / first fulfilled |
|
|
223
|
+
| `clearTimeout` | ✅ | [lib-timers.ts](conformance/lib-timers.ts) | `TnClearTimeout` stops the timer |
|
|
224
|
+
| `setInterval` / `clearInterval` | ✅ | [lib-set-interval.ts](conformance/lib-set-interval.ts) | `time.Ticker`; the process lives until cleared |
|
|
225
|
+
| `queueMicrotask` | ✅ | [lib-queue-microtask.ts](conformance/lib-queue-microtask.ts) | Runs after the current synchronous code (end of main or a timer callback) |
|
|
221
226
|
| `setTimeout` | ✅ | [lib-set-timeout.ts](conformance/lib-set-timeout.ts) | `time.AfterFunc` registered on a wait group the process waits on |
|
|
222
227
|
|
|
223
228
|
## Semantics (JS behaviour preserved)
|
|
@@ -237,6 +242,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
|
|
|
237
242
|
| String-number concatenation order | ✅ | [semantics-string-number-concat.ts](conformance/semantics-string-number-concat.ts) | `'a' + 1 + 2` vs `1 + 2 + 'a'` |
|
|
238
243
|
| Array truthiness | ✅ | [semantics-array-truthy.ts](conformance/semantics-array-truthy.ts) | Empty array is truthy |
|
|
239
244
|
| Loop closures capture per-iteration `let` | ✅ | [semantics-loop-closures.ts](conformance/semantics-loop-closures.ts) | |
|
|
245
|
+
| Functions stored in Records | ✅ | [semantics-record-functions.ts](conformance/semantics-record-functions.ts) | `rec.fn()` → `rec.Get("fn")()`, also for names like `get` / `sort` |
|
|
240
246
|
|
|
241
247
|
## Standard library
|
|
242
248
|
|
|
@@ -249,8 +255,8 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
249
255
|
| API | Status | Probe | Notes |
|
|
250
256
|
| ---------------------------------- | :----: | ------------------------------------------------------ | ------------------------------------------------------ |
|
|
251
257
|
| `console.log` | ✅ | [lib-console-log.ts](conformance/lib-console-log.ts) | Mapped to `fmt.Println` |
|
|
252
|
-
| `console.error` |
|
|
253
|
-
| `console.warn` |
|
|
258
|
+
| `console.error` | ✅ | [lib-console-error.ts](conformance/lib-console-error.ts) | `fmt.Fprintln(os.Stderr, ...)` |
|
|
259
|
+
| `console.warn` | ✅ | [lib-console-error.ts](conformance/lib-console-error.ts) | Mapped to stderr like `console.error` |
|
|
254
260
|
| `console.time` / `console.timeEnd` | ✅ | [lib-console-time.ts](conformance/lib-console-time.ts) | Via `time.Now` / `time.Since` |
|
|
255
261
|
|
|
256
262
|
### `Math`
|
|
@@ -262,11 +268,11 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
262
268
|
| `Math.min` / `Math.max` | ✅ | [lib-math-min-max.ts](conformance/lib-math-min-max.ts) | Go builtins `min` / `max` |
|
|
263
269
|
| `Math.max(...arr)` / spread & variadic | ✅ | [lib-math-min-max.ts](conformance/lib-math-min-max.ts) | Spread and any number of arguments via `slices.Max` / `max` |
|
|
264
270
|
| `Math.random` | ✅ | [lib-math-random.ts](conformance/lib-math-random.ts) | Mapped to `rand.Float64()` |
|
|
265
|
-
| `Math.log` / `log2` / `log10` |
|
|
266
|
-
| `Math.sin` / `cos` / `tan` |
|
|
267
|
-
| `Math.trunc` / `sign` |
|
|
268
|
-
| Constants (`Math.PI`, `Math.E`, …) |
|
|
269
|
-
| `Math.asin` / `acos` / `atan` / `atan2` / `hypot` / `cbrt` / `exp` |
|
|
271
|
+
| `Math.log` / `log2` / `log10` | ✅ | [lib-math-functions.ts](conformance/lib-math-functions.ts) | `math.Log` / `math.Log2` / `math.Log10` |
|
|
272
|
+
| `Math.sin` / `cos` / `tan` | ✅ | [lib-math-functions.ts](conformance/lib-math-functions.ts) | `math.Sin` / `math.Cos` / `math.Tan` |
|
|
273
|
+
| `Math.trunc` / `sign` | ✅ | [lib-math-functions.ts](conformance/lib-math-functions.ts) | `math.Trunc` / inline sign check |
|
|
274
|
+
| Constants (`Math.PI`, `Math.E`, …) | ✅ | [lib-math-constants.ts](conformance/lib-math-constants.ts) | `math.Pi`, `math.E`, `math.Sqrt2`, … |
|
|
275
|
+
| `Math.asin` / `acos` / `atan` / `atan2` / `hypot` / `cbrt` / `exp` | ✅ | [lib-math-more.ts](conformance/lib-math-more.ts) | Corresponding `math` functions |
|
|
270
276
|
|
|
271
277
|
### `JSON`
|
|
272
278
|
|
|
@@ -281,9 +287,9 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
281
287
|
| ---------------------------------------------------------- | :----: | ---------------------------------------------------------- | ------------------------------------------------------------------- |
|
|
282
288
|
| `Object.keys` / `values` / `entries` | ✅ | [lib-object-helpers.ts](conformance/lib-object-helpers.ts) | Map key/value iteration helpers; typed results for maps and records |
|
|
283
289
|
| `Object.assign` | ✅ | [lib-object-assign.ts](conformance/lib-object-assign.ts) | Sources (structs, maps, dynamic objects) copied into an ordered map |
|
|
284
|
-
| `Object.freeze` / `seal` / `isFrozen` |
|
|
285
|
-
| `Object.fromEntries` |
|
|
286
|
-
| `Object.hasOwn` / `defineProperty` / `getOwnPropertyNames` |
|
|
290
|
+
| `Object.freeze` / `seal` / `isFrozen` | ✅ | [lib-object-freeze.ts](conformance/lib-object-freeze.ts) | Integrity level tracked by identity; writes rejected by `Readonly<T>` types |
|
|
291
|
+
| `Object.fromEntries` | ✅ | [lib-object-from-entries.ts](conformance/lib-object-from-entries.ts) | `TnFromEntries` → dynamic object |
|
|
292
|
+
| `Object.hasOwn` / `defineProperty` / `getOwnPropertyNames` | ✅ | [lib-object-own.ts](conformance/lib-object-own.ts) | Maps, dynamic objects and typed objects (literal keys); `{ value }` descriptors |
|
|
287
293
|
|
|
288
294
|
### `String`
|
|
289
295
|
|
|
@@ -305,7 +311,7 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
305
311
|
| `match` / `matchAll` / `search` | ✅ | [syntax-top-level-scope.ts](conformance/syntax-top-level-scope.ts) | Via `regexp` package (`String.match` with groups) |
|
|
306
312
|
| `at` (negative indices) | ✅ | [lib-array-at.ts](conformance/lib-array-at.ts) | Supports negative indices |
|
|
307
313
|
| Unicode length / iteration | ✅ | [lib-string-unicode.ts](conformance/lib-string-unicode.ts) | `.length` counts runes; `[...str]` spreads runes |
|
|
308
|
-
| `String.raw` |
|
|
314
|
+
| `String.raw` | ✅ | [lib-string-raw.ts](conformance/lib-string-raw.ts) | Raw template text with values interpolated |
|
|
309
315
|
| `normalize` | ❌ | — | Unicode normalization; no probe yet |
|
|
310
316
|
|
|
311
317
|
### `Array`
|
|
@@ -332,10 +338,11 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
332
338
|
| `entries` / `keys` / `values` | ✅ | [lib-array-entries.ts](conformance/lib-array-entries.ts) | `[index, value]` pairs destructured in `for...of` |
|
|
333
339
|
| `length` truncation (`arr.length = 0`) | ✅ | [syntax-top-level-scope.ts](conformance/syntax-top-level-scope.ts) | Clear via length assignment |
|
|
334
340
|
| `filter(Boolean)` | ✅ | [syntax-top-level-scope.ts](conformance/syntax-top-level-scope.ts) | Constructor as predicate |
|
|
335
|
-
| `concat` |
|
|
336
|
-
| `reduceRight` |
|
|
337
|
-
| `copyWithin` |
|
|
338
|
-
| Change-preserving copies (`toSorted` / `toReversed` / `
|
|
341
|
+
| `concat` | ✅ | [lib-array-concat.ts](conformance/lib-array-concat.ts) | Arrays flattened one level, values appended |
|
|
342
|
+
| `reduceRight` | ✅ | [lib-array-reduce-right.ts](conformance/lib-array-reduce-right.ts) | `reduce` over a reversed copy |
|
|
343
|
+
| `copyWithin` | ✅ | [lib-array-copy-within.ts](conformance/lib-array-copy-within.ts) | Go `copy` (overlap-safe) |
|
|
344
|
+
| Change-preserving copies (`toSorted` / `toReversed` / `with`) | ✅ | [lib-array-copies.ts](conformance/lib-array-copies.ts) | Clone, then sort / reverse / set |
|
|
345
|
+
| `toSpliced` | ✅ | [lib-array-to-spliced.ts](conformance/lib-array-to-spliced.ts) | `slices.Concat` of the kept parts |
|
|
339
346
|
|
|
340
347
|
### `Map` / `Set`
|
|
341
348
|
|
|
@@ -345,9 +352,9 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
345
352
|
| `Map` iteration (`for...of`, destructuring) | ✅ | [lib-map-iteration.ts](conformance/lib-map-iteration.ts) | Key/value iteration, `Object.entries()` unwrapping |
|
|
346
353
|
| `Set` (`add` / `has` / `delete` / `size`) | ✅ | [lib-set.ts](conformance/lib-set.ts) | `Set<T>` → Go `map[T]struct{}`; constructor with values |
|
|
347
354
|
| `Set` iteration / spread | ✅ | [syntax-top-level-scope.ts](conformance/syntax-top-level-scope.ts) | `for...of`, `[...set]` |
|
|
348
|
-
| `Map.clear` / `Set.clear` |
|
|
349
|
-
| `WeakMap` / `WeakSet` |
|
|
350
|
-
| Set operations (`union` / `intersection` / `difference`) |
|
|
355
|
+
| `Map.clear` / `Set.clear` | ✅ | [lib-map-clear.ts](conformance/lib-map-clear.ts) | `TnMap.Clear()` |
|
|
356
|
+
| `WeakMap` / `WeakSet` | ✅ | [lib-weak-collections.ts](conformance/lib-weak-collections.ts) | Same as `Map` / `Set` (weakness is not observable) |
|
|
357
|
+
| Set operations (`union` / `intersection` / `difference`) | ✅ | [lib-set-operations.ts](conformance/lib-set-operations.ts) | Plus `symmetricDifference` / `isSubsetOf` / `isSupersetOf` / `isDisjointFrom` |
|
|
351
358
|
|
|
352
359
|
### `Number`
|
|
353
360
|
|
|
@@ -357,8 +364,8 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
357
364
|
| `toFixed` | ✅ | [lib-number-format.ts](conformance/lib-number-format.ts) | `n.toFixed(2)` via `strconv.FormatFloat` |
|
|
358
365
|
| `parseInt` / `parseFloat` / `Number()` | ✅ | [lib-number-parse.ts](conformance/lib-number-parse.ts) | Mapped to Go's `strconv` package |
|
|
359
366
|
| `Number.isInteger` / `isNaN` / `MAX_SAFE_INTEGER` | ✅ | [lib-number-checks.ts](conformance/lib-number-checks.ts) | Number predicates and constants |
|
|
360
|
-
| `Number.EPSILON` / `isFinite` / `toPrecision` |
|
|
361
|
-
| `String()` / `Boolean()` conversions |
|
|
367
|
+
| `Number.EPSILON` / `isFinite` / `toPrecision` | ✅ | [lib-number-misc.ts](conformance/lib-number-misc.ts) | `toPrecision` → `strconv.FormatFloat(x, 'g', n, 64)` |
|
|
368
|
+
| `String()` / `Boolean()` conversions | ✅ | [lib-conversions.ts](conformance/lib-conversions.ts) | JS formatting / truthiness |
|
|
362
369
|
|
|
363
370
|
### `Date`
|
|
364
371
|
|
|
@@ -366,7 +373,7 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
366
373
|
| ------------------------------------------------ | :----: | ---------------------------------------------- | ----------------------------- |
|
|
367
374
|
| `new Date()` / `getTime` / `toISOString` | ✅ | [lib-date.ts](conformance/lib-date.ts) | `new Date(ms)` → `time.UnixMilli`; `getTime`/`toISOString` mapped to `time.Time` |
|
|
368
375
|
| `Date.now()` | ✅ | [lib-date-now.ts](conformance/lib-date-now.ts) | `time.Now().UnixMilli()` |
|
|
369
|
-
| Component getters (`getFullYear`, `getMonth`, …) |
|
|
376
|
+
| Component getters (`getFullYear`, `getMonth`, …) | ✅ | [lib-date-getters.ts](conformance/lib-date-getters.ts) | Local and `getUTC*` getters, `Date.UTC` |
|
|
370
377
|
|
|
371
378
|
### `RegExp`
|
|
372
379
|
|
|
@@ -381,8 +388,8 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
381
388
|
| Named groups | ✅ | [lib-regex-named-groups.ts](conformance/lib-regex-named-groups.ts) | `(?<name>` → `(?P<name>`; `exec` returns a match with `.groups` |
|
|
382
389
|
| Global `exec` loop (`/g` + `lastIndex`) | ✅ | [lib-regex-global-exec.ts](conformance/lib-regex-global-exec.ts) | /g regexes carry `lastIndex` state in the `TnRegex` wrapper |
|
|
383
390
|
| Lookbehind | ✅ | [lib-regex-lookbehind.ts](conformance/lib-regex-lookbehind.ts) | Lookaround patterns run on the backtracking engine |
|
|
384
|
-
| Remaining flags (`s` / `u` / `y`) & `source` / `flags` |
|
|
385
|
-
| `split` with RegExp |
|
|
391
|
+
| Remaining flags (`s` / `u` / `y`) & `source` / `flags` | ✅ | [lib-regex-more-flags.ts](conformance/lib-regex-more-flags.ts) | Sticky matching, `\u{…}` escapes, `lastIndex` / `source` / `flags` / flag getters |
|
|
392
|
+
| `split` with RegExp | ✅ | [lib-regex-split.ts](conformance/lib-regex-split.ts) | `re.Split(s, -1)` |
|
|
386
393
|
|
|
387
394
|
### `Promise` / timers
|
|
388
395
|
|
|
@@ -390,10 +397,12 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
390
397
|
| ---------------------------------------------------- | :----: | ------------------------------------------------------------ | ------------------------------------------------------------------- |
|
|
391
398
|
| `Promise` constructor / `.then` | ✅ | [syntax-promise-then.ts](conformance/syntax-promise-then.ts) | Channel lowering works (see [Async & timing](#async--timing)) |
|
|
392
399
|
| `Promise.all` | ✅ | [syntax-promise-all.ts](conformance/syntax-promise-all.ts) | Channel lowering works (see [Async & timing](#async--timing)) |
|
|
393
|
-
| `Promise.resolve`
|
|
394
|
-
| `Promise.
|
|
395
|
-
| `
|
|
396
|
-
| `
|
|
400
|
+
| `Promise.resolve` | ✅ | [lib-promise-resolve.ts](conformance/lib-promise-resolve.ts) | Buffered channel holding the value |
|
|
401
|
+
| `Promise.reject` / `.catch` / `.finally` | ✅ | [lib-promise-catch.ts](conformance/lib-promise-catch.ts) | Rejected promises are closed channels with a reason; `await` rethrows |
|
|
402
|
+
| `Promise.race` / `allSettled` / `any` | ✅ | [lib-promise-combinators.ts](conformance/lib-promise-combinators.ts) | Goroutine per promise; first settled / all settled / first fulfilled |
|
|
403
|
+
| `clearTimeout` | ✅ | [lib-timers.ts](conformance/lib-timers.ts) | `TnClearTimeout` stops the timer |
|
|
404
|
+
| `setInterval` / `clearInterval` | ✅ | [lib-set-interval.ts](conformance/lib-set-interval.ts) | `time.Ticker`; the process lives until cleared |
|
|
405
|
+
| `queueMicrotask` | ✅ | [lib-queue-microtask.ts](conformance/lib-queue-microtask.ts) | Runs after the current synchronous code (end of main or a timer callback) |
|
|
397
406
|
| `setTimeout` | ✅ | [lib-set-timeout.ts](conformance/lib-set-timeout.ts) | Lowered to `time.AfterFunc` (see [Async & timing](#async--timing)) |
|
|
398
407
|
|
|
399
408
|
### Misc globals
|
|
@@ -403,13 +412,13 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
403
412
|
| `assert` | ✅ | [lib-console-log.ts](conformance/lib-console-log.ts) | Transpiled to `panic` on failure |
|
|
404
413
|
| `process.argv` / `process.platform` | ✅ | [lib-process.ts](conformance/lib-process.ts) | Mapped to `os.Args` / `runtime.GOOS` |
|
|
405
414
|
| `process.env` | ✅ | [syntax-top-level-scope.ts](conformance/syntax-top-level-scope.ts) | Environment variable access |
|
|
406
|
-
| `process.exit` |
|
|
407
|
-
| `process.cwd()` |
|
|
408
|
-
| `Infinity` |
|
|
409
|
-
| Global `isNaN` / `isFinite` |
|
|
410
|
-
| `encodeURIComponent` / `decodeURIComponent` |
|
|
411
|
-
| `structuredClone` |
|
|
412
|
-
| `globalThis` |
|
|
415
|
+
| `process.exit` | ✅ | [lib-process-exit.ts](conformance/lib-process-exit.ts) | `os.Exit` |
|
|
416
|
+
| `process.cwd()` | ✅ | [lib-process-cwd.ts](conformance/lib-process-cwd.ts) | `os.Getwd()` |
|
|
417
|
+
| `Infinity` | ✅ | [lib-globals.ts](conformance/lib-globals.ts) | `math.Inf(1)` |
|
|
418
|
+
| Global `isNaN` / `isFinite` | ✅ | [lib-globals.ts](conformance/lib-globals.ts) | `math.IsNaN` / `math.IsInf` |
|
|
419
|
+
| `encodeURIComponent` / `decodeURIComponent` | ✅ | [lib-uri.ts](conformance/lib-uri.ts) | `TnEncodeURIComponent` / `url.PathUnescape` |
|
|
420
|
+
| `structuredClone` | ✅ | [lib-structured-clone.ts](conformance/lib-structured-clone.ts) | Reflection deep copy |
|
|
421
|
+
| `globalThis` | ✅ | [lib-global-this.ts](conformance/lib-global-this.ts) | `globalThis.x` is the global `x`; `(globalThis as any)` is a dynamic object |
|
|
413
422
|
|
|
414
423
|
### Node builtins (`node:*`)
|
|
415
424
|
|
|
@@ -417,7 +426,7 @@ Every standard-library API TypeNative ports, split by module. Per
|
|
|
417
426
|
| ------------------------------------------------------------------------------------ | :----: | ------------------------------------------------ | ----------------------------------------------------- |
|
|
418
427
|
| `node:path` (`join`, `dirname`, `basename`, `extname`, `resolve`) | ✅ | [lib-node-path.ts](conformance/lib-node-path.ts) | Mapped to Go `path`/`filepath` |
|
|
419
428
|
| `node:fs` (`read/write/append/exists/mkdir/readdir/copy/rm/unlink`) | ✅ | [lib-node-fs.ts](conformance/lib-node-fs.ts) | Via Go helpers |
|
|
420
|
-
| `node:url` (`fileURLToPath`, `pathToFileURL`) |
|
|
429
|
+
| `node:url` (`fileURLToPath`, `pathToFileURL`) | ✅ | [lib-node-url.ts](conformance/lib-node-url.ts) | `TnFileURLToPath` / `TnPathToFileURL` |
|
|
421
430
|
| `node:os` (`platform`, `homedir`, `tmpdir`) | ✅ | [lib-node-fs.ts](conformance/lib-node-fs.ts) | `platform()` covered; `homedir`/`tmpdir` unprobed |
|
|
422
431
|
| `node:child_process` (`exec`, `execSync`, `spawnSync`, `spawnInherit`) | ✅ | [lib-node-fs.ts](conformance/lib-node-fs.ts) | Sync API shape, stdio-inherit runs |
|
|
423
432
|
| `node:readline` (`question`) | ❌ | — | Declared (TypeNative sync extension) but no probe yet |
|
package/package.json
CHANGED
package/tsparser/main.go
CHANGED
|
@@ -19,14 +19,19 @@ import (
|
|
|
19
19
|
"github.com/buke/typescript-go-internal/pkg/ast"
|
|
20
20
|
"github.com/buke/typescript-go-internal/pkg/core"
|
|
21
21
|
"github.com/buke/typescript-go-internal/pkg/parser"
|
|
22
|
+
"github.com/buke/typescript-go-internal/pkg/scanner"
|
|
22
23
|
)
|
|
23
24
|
|
|
25
|
+
// The parsed source, for template raw text
|
|
26
|
+
var sourceText string
|
|
27
|
+
|
|
24
28
|
func main() {
|
|
25
29
|
sourceBytes, err := io.ReadAll(os.Stdin)
|
|
26
30
|
if err != nil {
|
|
27
31
|
fmt.Fprintln(os.Stderr, "read stdin:", err)
|
|
28
32
|
os.Exit(1)
|
|
29
33
|
}
|
|
34
|
+
sourceText = string(sourceBytes)
|
|
30
35
|
sourceFile := parser.ParseSourceFile(
|
|
31
36
|
ast.SourceFileParseOptions{FileName: "/main.ts"},
|
|
32
37
|
string(sourceBytes),
|
|
@@ -128,7 +133,6 @@ func serializeNode(n *ast.Node) any {
|
|
|
128
133
|
ast.KindTemplateTail, ast.KindJsxText:
|
|
129
134
|
obj["text"] = n.Text()
|
|
130
135
|
}
|
|
131
|
-
|
|
132
136
|
// Binding-pattern holes (`[a, , b]`): ts-go parses them as an empty
|
|
133
137
|
// BindingElement; the TypeScript API exposes them as OmittedExpression
|
|
134
138
|
if n.Kind == ast.KindBindingElement {
|
|
@@ -141,6 +145,18 @@ func serializeNode(n *ast.Node) any {
|
|
|
141
145
|
if data.IsValid() {
|
|
142
146
|
collectFields(data, obj)
|
|
143
147
|
}
|
|
148
|
+
// Template pieces: rawText is the source between their delimiters
|
|
149
|
+
// (`…`, `…${, }…${, }…`), with line endings normalized like JS
|
|
150
|
+
switch n.Kind {
|
|
151
|
+
case ast.KindNoSubstitutionTemplateLiteral, ast.KindTemplateHead, ast.KindTemplateMiddle, ast.KindTemplateTail:
|
|
152
|
+
start, end := scanner.SkipTrivia(sourceText, n.Pos())+1, n.End()-1
|
|
153
|
+
if n.Kind == ast.KindTemplateHead || n.Kind == ast.KindTemplateMiddle {
|
|
154
|
+
end--
|
|
155
|
+
}
|
|
156
|
+
if start <= end && end <= len(sourceText) {
|
|
157
|
+
obj["rawText"] = strings.ReplaceAll(sourceText[start:end], "\r\n", "\n")
|
|
158
|
+
}
|
|
159
|
+
}
|
|
144
160
|
return obj
|
|
145
161
|
}
|
|
146
162
|
|
package/tsparser/tsparser.exe
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/tsparser/tsparser.exe
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 37232640 bytes
|
|
4
|
+
sha256: 52a159d7760b1b54c809ccdf9f9c2913aacde6acbd3793f9aa877562cf86d3ff
|