typenative 0.1.2 → 0.1.3

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/conformance.md CHANGED
@@ -42,7 +42,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
42
42
  | Numeric separators | ✅ | [syntax-numeric-separators.ts](conformance/syntax-numeric-separators.ts) | `1_000_000` |
43
43
  | Hex / octal / binary literals | ✅ | [syntax-numeric-literals.ts](conformance/syntax-numeric-literals.ts) | `0xFF`, `0o17`, `0b1010`, `1e3` |
44
44
  | `var` declarations (hoisting) | ✅ | [syntax-var.ts](conformance/syntax-var.ts) | Function- and module-level `var` |
45
- | `using` / `await using` declarations | ❌ | — | Explicit resource management; no probe yet |
45
+ | `using` / `await using` declarations | ✅ | [syntax-using.ts](conformance/syntax-using.ts) | Disposed in reverse order when the block ends (`defer`); `[Symbol.dispose]` methods |
46
46
 
47
47
  ## Operators
48
48
 
@@ -68,7 +68,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
68
68
  | Optional call (`fn?.()`) | ✅ | [syntax-optional-call.ts](conformance/syntax-optional-call.ts) | Nil check on the function value; result is nullable |
69
69
  | Comma operator | ✅ | [syntax-comma-operator.ts](conformance/syntax-comma-operator.ts) | In `for` headers (`i = 0, j = 10` / `i++, j--`) |
70
70
  | `void` operator | ✅ | [syntax-void-operator.ts](conformance/syntax-void-operator.ts) | Evaluates, then `nil` |
71
- | `new.target` | ❌ | — | No probe yet |
71
+ | `new.target` | ✅ | [syntax-new-target.ts](conformance/syntax-new-target.ts) | Constructors pass the target class name through `super()` chains |
72
72
 
73
73
  ## Control flow
74
74
 
@@ -82,7 +82,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
82
82
  | `break` | ✅ | [syntax-if-switch.ts](conformance/syntax-if-switch.ts), [syntax-do-while.ts](conformance/syntax-do-while.ts) | In switch cases and loops |
83
83
  | `for...of` loops | ✅ | [syntax-loops.ts](conformance/syntax-loops.ts), [syntax-for-of-string.ts](conformance/syntax-for-of-string.ts) | Arrays, Maps, Sets, strings, tuples; `Object.entries()` unwrapping |
84
84
  | `for...in` loops | ✅ | [syntax-for-in.ts](conformance/syntax-for-in.ts) | Key range over records/maps |
85
- | `for await...of` | ❌ | — | Requires async iteration (see [Async & timing](#async--timing)) |
85
+ | `for await...of` | ✅ | [syntax-for-await.ts](conformance/syntax-for-await.ts) | Ranges over the async generator's channel |
86
86
  | `while` loops | ✅ | [syntax-loops.ts](conformance/syntax-loops.ts) | Transpiled to Go's `for` loops; assignment in condition |
87
87
  | `do...while` loops | ✅ | [syntax-do-while.ts](conformance/syntax-do-while.ts) | Implemented with conditional break |
88
88
  | Labeled loops | ✅ | [syntax-labeled-loops.ts](conformance/syntax-labeled-loops.ts) | `LabeledStatement` → Go labels; labeled `continue`/`break` |
@@ -115,7 +115,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
115
115
  | `as const` assertions | ✅ | [syntax-as-const.ts](conformance/syntax-as-const.ts) | Erased during transpilation |
116
116
  | Function overloads | ✅ | [syntax-function-overloads.ts](conformance/syntax-function-overloads.ts) | Signatures are erased; the implementation is emitted |
117
117
  | `this` parameter (`function f(this: T)`) | ✅ | [syntax-this-parameter.ts](conformance/syntax-this-parameter.ts) | Erased |
118
- | `arguments` object | ❌ | — | No probe yet |
118
+ | `arguments` object | ✅ | [syntax-arguments.ts](conformance/syntax-arguments.ts) | Functions reading it take extra arguments variadically (`[]interface{}`) |
119
119
 
120
120
  ## Classes & interfaces
121
121
 
@@ -149,7 +149,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
149
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
150
  | Default type parameters (`<T = D>`) | ✅ | [syntax-generic-defaults.ts](conformance/syntax-generic-defaults.ts) | Defaults are erased; Go infers from arguments |
151
151
  | Generic interfaces / type aliases | ✅ | [syntax-generic-interfaces.ts](conformance/syntax-generic-interfaces.ts) | Go generic structs; literals instantiate them (`Box[float64]{…}`) |
152
- | `const` type parameters / variance annotations (`in` / `out`) | ❌ | — | No probe yet |
152
+ | `const` type parameters / variance annotations (`in` / `out`) | ✅ | [syntax-const-type-parameters.ts](conformance/syntax-const-type-parameters.ts) | Erased; object literals of method interfaces use an adapter struct |
153
153
 
154
154
  ## Enums
155
155
 
@@ -158,7 +158,7 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
158
158
  | Numeric enums | ✅ | [syntax-enum-numeric.ts](conformance/syntax-enum-numeric.ts) | Numeric members are `float64` constants; string enums keep a named type |
159
159
  | String enums | ✅ | [syntax-enum-string.ts](conformance/syntax-enum-string.ts) | `enum` declarations and member access |
160
160
  | `const enum` | ✅ | [syntax-const-enum.ts](conformance/syntax-const-enum.ts) | Compiled like a regular enum |
161
- | Computed / heterogeneous enum members | ❌ | — | `enum E { A = f(), B = 's' }`; no probe yet |
161
+ | Computed / heterogeneous enum members | ✅ | [syntax-enum-computed.ts](conformance/syntax-enum-computed.ts) | Computed members assigned in source order; mixed enums keep each member's type |
162
162
 
163
163
  ## Type-system features
164
164
 
@@ -169,8 +169,8 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
169
169
  | Type guards (`is`) | ✅ | [syntax-type-guards.ts](conformance/syntax-type-guards.ts) | `p is T` → Go `bool`; `in` checks struct fields at runtime |
170
170
  | `as` assertions | ✅ | [syntax-type-aliases.ts](conformance/syntax-type-aliases.ts) | `x as T`, incl. angle-bracket syntax |
171
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 |
172
- | Decorators (`@`) | ❌ | — | No probe yet |
173
- | Namespaces / `module` blocks | ❌ | — | No probe yet |
172
+ | Decorators (`@`) | ✅ | [syntax-decorators.ts](conformance/syntax-decorators.ts) | Standard method & class decorators, applied in source order; `this` is the receiver |
173
+ | Namespaces / `module` blocks | ✅ | [syntax-namespaces.ts](conformance/syntax-namespaces.ts) | Flattened to prefixed declarations (`N.f` → `N_f`), nested and in types |
174
174
  | `override` modifier | ✅ | [syntax-override.ts](conformance/syntax-override.ts) | Erased |
175
175
  | `readonly` modifier (properties, `readonly T[]`) | ✅ | [syntax-readonly.ts](conformance/syntax-readonly.ts) | Erased (`readonly T[]` → `[]T`) |
176
176
  | `satisfies` operator | ✅ | [syntax-satisfies.ts](conformance/syntax-satisfies.ts) | Checked by tsc, erased; the type guides literals |
@@ -179,17 +179,17 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
179
179
  | `infer` types | ✅ | [syntax-infer-types.ts](conformance/syntax-infer-types.ts) | Resolved to their branch's Go type |
180
180
  | `import type` / `export type` | ✅ | [syntax-import-type.ts](conformance/syntax-import-type.ts) | Type-only imports are erased |
181
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 |
182
+ | Literal types (`'a' \| 'b'`) | ✅ | [syntax-literal-types.ts](conformance/syntax-literal-types.ts) | Erased; string/number/boolean literals map to their base Go types |
183
183
  | Tuple optional / rest / labeled elements | ✅ | [syntax-tuple-elements.ts](conformance/syntax-tuple-elements.ts) | Tuples are slices |
184
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
185
  | Type-level `typeof` (`typeof obj`) | ✅ | [syntax-type-typeof.ts](conformance/syntax-type-typeof.ts) | The variable's Go type |
186
186
  | Template literal types | ✅ | [syntax-template-literal-types.ts](conformance/syntax-template-literal-types.ts) | Template literal types → `string` |
187
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
188
  | Assertion functions (`asserts x is T`) | ✅ | [syntax-assertion-functions.ts](conformance/syntax-assertion-functions.ts) | No return value |
189
- | Callable / construct signatures (`type F = { (): void }`) | ❌ | — | No probe yet |
190
- | JSX / `.tsx` syntax | ❌ | — | No probe yet |
191
- | Ambient declarations (`declare`, `.d.ts`, `x!: T`) | ❌ | — | No probe yet |
192
- | `export =` / `import x = require()` | ❌ | — | No probe yet |
189
+ | Callable / construct signatures (`type F = { (): void }`) | ✅ | [syntax-callable-signatures.ts](conformance/syntax-callable-signatures.ts) | Function types; a class passed as a value is its constructor |
190
+ | JSX / `.tsx` syntax | ✅ | [syntax-jsx.tsx](conformance/syntax-jsx.tsx) | Renders to HTML strings (text escaped); components are calls with props |
191
+ | Ambient declarations (`declare`, `.d.ts`, `x!: T`) | ✅ | [syntax-ambient-declarations.ts](conformance/syntax-ambient-declarations.ts) | `declare` only types code; `declare const` is an unset variable |
192
+ | `export =` / `import x = require()` | ✅ | [syntax-export-equals.ts](conformance/syntax-export-equals.ts) | `import x = require()` is a namespace import |
193
193
 
194
194
  ## Modules & imports
195
195
 
@@ -205,9 +205,9 @@ self-hosted binary). Each ❌ row is a known gap with no passing probe yet.
205
205
  | Node.js built-in imports | ✅ | [lib-node-path.ts](conformance/lib-node-path.ts) | `import { join } from 'node:path'` mapped to Go stdlib (see [Standard library](#standard-library)) |
206
206
  | Go package imports | ✅ | [syntax-import-go.ts](conformance/syntax-import-go.ts) | `import { x } from 'go:pkg'` |
207
207
  | npm package imports | ✅ | [syntax-import-npm.ts](conformance/syntax-import-npm.ts) | `import { x } from 'pkg'` mapped to Go module imports |
208
- | Re-exports (`export { x } from`, `export *`) | ❌ | — | No probe yet |
209
- | Dynamic `import()` | ❌ | — | No probe yet |
210
- | Side-effect imports (`import './mod'`) | ❌ | — | No probe yet |
208
+ | Re-exports (`export { x } from`, `export *`) | ✅ | [syntax-re-exports.ts](conformance/syntax-re-exports.ts) | Re-exported files are included (one Go package) |
209
+ | Dynamic `import()` | ✅ | [syntax-dynamic-import.ts](conformance/syntax-dynamic-import.ts) | `const m = await import('./x')` is a namespace import |
210
+ | Side-effect imports (`import './mod'`) | ✅ | [syntax-side-effect-import.ts](conformance/syntax-side-effect-import.ts) | Module top-level statements run in Go's `init()` |
211
211
  | `import.meta.url` | ✅ | [syntax-import-meta.ts](conformance/syntax-import-meta.ts) | The `file://` URL of the running program (`os.Executable` → `pathToFileURL`) |
212
212
 
213
213
  ## Async & timing
@@ -312,7 +312,7 @@ Every standard-library API TypeNative ports, split by module. Per
312
312
  | `at` (negative indices) | ✅ | [lib-array-at.ts](conformance/lib-array-at.ts) | Supports negative indices |
313
313
  | Unicode length / iteration | ✅ | [lib-string-unicode.ts](conformance/lib-string-unicode.ts) | `.length` counts runes; `[...str]` spreads runes |
314
314
  | `String.raw` | ✅ | [lib-string-raw.ts](conformance/lib-string-raw.ts) | Raw template text with values interpolated |
315
- | `normalize` | ❌ | — | Unicode normalization; no probe yet |
315
+ | `normalize` | ✅ | [lib-string-normalize.ts](conformance/lib-string-normalize.ts) | `golang.org/x/text/unicode/norm`, copied from GOROOT's vendor tree (offline) |
316
316
 
317
317
  ### `Array`
318
318
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typenative",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Build native applications using Typescript.",
5
5
  "type": "module",
6
6
  "bin": {
package/tsparser/main.go CHANGED
@@ -32,10 +32,17 @@ func main() {
32
32
  os.Exit(1)
33
33
  }
34
34
  sourceText = string(sourceBytes)
35
+ // --tsx: parse JSX (.tsx sources)
36
+ fileName, scriptKind := "/main.ts", core.ScriptKindTS
37
+ for _, arg := range os.Args[1:] {
38
+ if arg == "--tsx" {
39
+ fileName, scriptKind = "/main.tsx", core.ScriptKindTSX
40
+ }
41
+ }
35
42
  sourceFile := parser.ParseSourceFile(
36
- ast.SourceFileParseOptions{FileName: "/main.ts"},
43
+ ast.SourceFileParseOptions{FileName: fileName},
37
44
  string(sourceBytes),
38
- core.ScriptKindTS,
45
+ scriptKind,
39
46
  )
40
47
  out := serializeNode(sourceFile.AsNode())
41
48
  enc := json.NewEncoder(os.Stdout)
@@ -47,6 +54,21 @@ func main() {
47
54
  }
48
55
 
49
56
 
57
+ // var / let / const / using / await using (await using sets Const | Using)
58
+ func declarationKind(flags ast.NodeFlags) string {
59
+ switch {
60
+ case flags&ast.NodeFlagsAwaitUsing == ast.NodeFlagsAwaitUsing:
61
+ return "await using"
62
+ case flags&ast.NodeFlagsUsing != 0:
63
+ return "using"
64
+ case flags&ast.NodeFlagsConst != 0:
65
+ return "const"
66
+ case flags&ast.NodeFlagsLet != 0:
67
+ return "let"
68
+ }
69
+ return "var"
70
+ }
71
+
50
72
  // Nodes currently being serialized (cycle guard).
51
73
  var inProgress = map[*ast.Node]bool{}
52
74
 
@@ -130,9 +152,16 @@ func serializeNode(n *ast.Node) any {
130
152
  case ast.KindIdentifier, ast.KindPrivateIdentifier, ast.KindStringLiteral,
131
153
  ast.KindNumericLiteral, ast.KindBigIntLiteral, ast.KindNoSubstitutionTemplateLiteral,
132
154
  ast.KindRegularExpressionLiteral, ast.KindTemplateHead, ast.KindTemplateMiddle,
133
- ast.KindTemplateTail, ast.KindJsxText:
155
+ ast.KindTemplateTail:
134
156
  obj["text"] = n.Text()
157
+ case ast.KindJsxText:
158
+ // Node.Text() doesn't cover JsxText
159
+ obj["text"] = n.AsJsxText().Text
160
+ }
161
+ if n.Kind == ast.KindVariableDeclarationList {
162
+ obj["declarationKind"] = declarationKind(n.Flags)
135
163
  }
164
+
136
165
  // Binding-pattern holes (`[a, , b]`): ts-go parses them as an empty
137
166
  // BindingElement; the TypeScript API exposes them as OmittedExpression
138
167
  if n.Kind == ast.KindBindingElement {
@@ -145,6 +174,11 @@ func serializeNode(n *ast.Node) any {
145
174
  if data.IsValid() {
146
175
  collectFields(data, obj)
147
176
  }
177
+ // ts-go's PostfixToken is ? or !; the TypeScript API names a ! exclamationToken
178
+ if tok, ok := obj["questionToken"].(map[string]any); ok && tok["kind"] == "ExclamationToken" {
179
+ delete(obj, "questionToken")
180
+ obj["exclamationToken"] = tok
181
+ }
148
182
  // Template pieces: rawText is the source between their delimiters
149
183
  // (`…`, `…${, }…${, }…`), with line endings normalized like JS
150
184
  switch n.Kind {
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/tsparser/tsparser.exe
3
- size: 37232640 bytes
4
- sha256: 52a159d7760b1b54c809ccdf9f9c2913aacde6acbd3793f9aa877562cf86d3ff
3
+ size: 37236736 bytes
4
+ sha256: 325117ab33bbcf3ee1557ea5a7f5983e3aa5c9f217586bfdc9d7c33eb4d80ac2
@@ -9,7 +9,7 @@ declare module 'node:path' {
9
9
  }
10
10
 
11
11
  declare module 'node:fs' {
12
- export function readFileSync(path: string): string;
12
+ export function readFileSync(path: string, encoding?: string): string;
13
13
  export function writeFileSync(path: string, content: string): void;
14
14
  export function appendFileSync(path: string, content: string): void;
15
15
  export function existsSync(path: string): boolean;
@@ -17,6 +17,7 @@ declare module 'node:fs' {
17
17
  export function readdirSync(path: string): string[];
18
18
  export function copyFileSync(src: string, dest: string): void;
19
19
  export function rmSync(path: string, options?: { recursive?: boolean }): void;
20
+ export function unlinkSync(path: string): void;
20
21
  }
21
22
 
22
23
  declare module 'node:url' {
@@ -38,8 +39,11 @@ declare module 'node:child_process' {
38
39
  }
39
40
  export function exec(command: string): ExecResult;
40
41
  export function execSync(command: string): string;
41
- export function spawnSync(file: string, args: string[], options?: object): ExecResult;
42
- export function spawnInherit(file: string, ...args: string[]): number;
42
+ export function spawnSync(
43
+ file: string,
44
+ args: string[],
45
+ options?: { stdio?: string; input?: string; encoding?: string }
46
+ ): ExecResult;
43
47
  }
44
48
 
45
49
  declare module 'node:readline' {