typenative 0.7.0 → 0.7.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.
Files changed (217) hide show
  1. package/bin/node/assert.js +2 -2
  2. package/bin/node/child_process.js +66 -8
  3. package/bin/node/fs.js +1012 -4
  4. package/bin/node/histogram.js +1991 -0
  5. package/bin/node/process.js +14 -2
  6. package/bin/node/sqlite.js +1488 -5
  7. package/bin/node/stream.js +2 -1
  8. package/bin/node/system_extra.js +3 -270
  9. package/bin/node/test.js +39 -1
  10. package/bin/node/test_report.js +47 -1
  11. package/bin/node/test_run.js +57 -2
  12. package/bin/node/util.js +8 -5
  13. package/bin/node/webassembly.js +20 -5
  14. package/bin/node/webview.js +3257 -244
  15. package/bin/node/zlib.js +118 -14
  16. package/bin/node/zlib_iter.js +585 -0
  17. package/bin/transpiler.js +1370 -258
  18. package/bin/version.js +1 -1
  19. package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
  20. package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
  21. package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
  22. package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
  23. package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
  24. package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
  25. package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
  26. package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
  27. package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
  28. package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
  29. package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
  30. package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
  31. package/package.json +10 -1
  32. package/types/tsconfig.json +17 -0
  33. package/types/typenative-npm.d.ts +492 -12
  34. package/types/typenative.d.ts +88 -2
  35. package/.gitattributes +0 -1
  36. package/.github/workflows/ci.yml +0 -68
  37. package/.github/workflows/npm-publish-github-packages.yml +0 -88
  38. package/CHANGELOG.md +0 -1746
  39. package/CONTRIBUTION.md +0 -133
  40. package/conformance.md +0 -1497
  41. package/examples/README.md +0 -114
  42. package/examples/angular-templates/README.md +0 -141
  43. package/examples/angular-templates/bench.mjs +0 -173
  44. package/examples/angular-templates/dom-type-globals.d.ts +0 -21
  45. package/examples/angular-templates/dom-type-stubs.ts +0 -21
  46. package/examples/angular-templates/main.ts +0 -135
  47. package/examples/angular-templates/parity.mjs +0 -157
  48. package/examples/angular-templates/run-node.mjs +0 -69
  49. package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
  50. package/examples/desktop-notes/README.md +0 -106
  51. package/examples/desktop-notes/bench.mjs +0 -125
  52. package/examples/desktop-notes/main.ts +0 -131
  53. package/examples/desktop-notes/package-lock.json +0 -726
  54. package/examples/desktop-notes/package.json +0 -9
  55. package/examples/desktop-notes/ui.ts +0 -176
  56. package/examples/dupe-finder/README.md +0 -78
  57. package/examples/dupe-finder/bench.mjs +0 -120
  58. package/examples/dupe-finder/main.ts +0 -87
  59. package/examples/fibonacci/README.md +0 -89
  60. package/examples/fibonacci/bench.mjs +0 -87
  61. package/examples/fibonacci/main.ts +0 -21
  62. package/examples/hello-world/README.md +0 -62
  63. package/examples/hello-world/bench.mjs +0 -66
  64. package/examples/hello-world/main.ts +0 -7
  65. package/examples/json-server/README.md +0 -132
  66. package/examples/json-server/bench.mjs +0 -263
  67. package/examples/json-server/main.ts +0 -67
  68. package/examples/mandelbrot-png/README.md +0 -63
  69. package/examples/mandelbrot-png/bench.mjs +0 -95
  70. package/examples/mandelbrot-png/main.ts +0 -98
  71. package/examples/mandelbrot-png/preview.png +0 -0
  72. package/examples/marked-cli/README.md +0 -174
  73. package/examples/marked-cli/bench.mjs +0 -178
  74. package/examples/marked-cli/main.ts +0 -410
  75. package/examples/marked-cli/parity.mjs +0 -185
  76. package/examples/marked-cli/vendor/marked/LICENSE +0 -44
  77. package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
  78. package/examples/openai-chat/README.md +0 -148
  79. package/examples/openai-chat/bench.mjs +0 -175
  80. package/examples/openai-chat/main.ts +0 -488
  81. package/examples/react-compiler/README.md +0 -185
  82. package/examples/react-compiler/bench.mjs +0 -181
  83. package/examples/react-compiler/main.ts +0 -324
  84. package/examples/react-compiler/parity.mjs +0 -362
  85. package/examples/react-compiler/run-node.mjs +0 -90
  86. package/examples/react-compiler/vendor/babel/LICENSE +0 -22
  87. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
  88. package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
  89. package/examples/react-compiler/vendor/charcodes/package.json +0 -25
  90. package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
  91. package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
  92. package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
  93. package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
  94. package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
  95. package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
  96. package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
  97. package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
  98. package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
  99. package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
  100. package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
  101. package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
  102. package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
  103. package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
  104. package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
  105. package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
  106. package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
  107. package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
  108. package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
  109. package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
  110. package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
  111. package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
  112. package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
  113. package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
  114. package/examples/react-compiler/vendor/zod/LICENSE +0 -21
  115. package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
  116. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
  117. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
  118. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
  119. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
  120. package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
  121. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
  122. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
  123. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
  124. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
  125. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
  126. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
  127. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
  128. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
  129. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
  130. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
  131. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
  132. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
  133. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
  134. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
  135. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
  136. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
  137. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
  138. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
  139. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
  140. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
  141. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
  142. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
  143. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
  144. package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
  145. package/examples/react-compiler/vendor.mjs +0 -688
  146. package/examples/todo-cli/README.md +0 -69
  147. package/examples/todo-cli/bench.mjs +0 -89
  148. package/examples/todo-cli/main.ts +0 -92
  149. package/examples/yaml-cli/README.md +0 -152
  150. package/examples/yaml-cli/bench.mjs +0 -265
  151. package/examples/yaml-cli/main.ts +0 -251
  152. package/examples/yaml-cli/parity.mjs +0 -156
  153. package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
  154. package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
  155. package/performance/README.md +0 -248
  156. package/performance/any-dynamic.ts +0 -21
  157. package/performance/any-record-view.ts +0 -20
  158. package/performance/arr-for-of.ts +0 -29
  159. package/performance/arr-hof.ts +0 -21
  160. package/performance/arr-push-index.ts +0 -15
  161. package/performance/arr-push-local.ts +0 -39
  162. package/performance/arr-slice-concat.ts +0 -24
  163. package/performance/arr-sort.ts +0 -21
  164. package/performance/async-await.ts +0 -24
  165. package/performance/async-promise-all.ts +0 -38
  166. package/performance/bigint-arith.ts +0 -36
  167. package/performance/buf-encode.ts +0 -29
  168. package/performance/class-accessors.ts +0 -48
  169. package/performance/class-dispatch.ts +0 -52
  170. package/performance/date-format.ts +0 -18
  171. package/performance/events-emit.ts +0 -27
  172. package/performance/exc-throw-rare.ts +0 -25
  173. package/performance/exc-try-catch.ts +0 -26
  174. package/performance/fn-closures.ts +0 -29
  175. package/performance/fn-recursion-tree.ts +0 -31
  176. package/performance/fn-rest-spread.ts +0 -43
  177. package/performance/gen-for-of.ts +0 -46
  178. package/performance/gen-next.ts +0 -32
  179. package/performance/iter-helpers.ts +0 -38
  180. package/performance/json-any.ts +0 -30
  181. package/performance/json-roundtrip.ts +0 -27
  182. package/performance/map-delete.ts +0 -24
  183. package/performance/map-iterate.ts +0 -26
  184. package/performance/map-number-keys.ts +0 -37
  185. package/performance/map-string-keys.ts +0 -22
  186. package/performance/num-arith-loop.ts +0 -14
  187. package/performance/num-bitwise.ts +0 -21
  188. package/performance/num-hash-imul.ts +0 -36
  189. package/performance/num-mod-int.ts +0 -16
  190. package/performance/num-to-string.ts +0 -16
  191. package/performance/obj-alloc.ts +0 -32
  192. package/performance/obj-keys-entries.ts +0 -44
  193. package/performance/obj-optional-chain.ts +0 -42
  194. package/performance/obj-record-dict.ts +0 -24
  195. package/performance/obj-spread-destructure.ts +0 -40
  196. package/performance/regex-exec.ts +0 -29
  197. package/performance/regex-replace-fn.ts +0 -24
  198. package/performance/regex-site.ts +0 -28
  199. package/performance/set-ops.ts +0 -20
  200. package/performance/str-char-scan.ts +0 -35
  201. package/performance/str-concat-plus.ts +0 -18
  202. package/performance/str-concat.ts +0 -24
  203. package/performance/str-methods.ts +0 -24
  204. package/performance/str-short-scan.ts +0 -26
  205. package/performance/str-split-join.ts +0 -23
  206. package/performance/str-switch-compare.ts +0 -50
  207. package/performance/str-template.ts +0 -16
  208. package/performance/str-unicode.ts +0 -25
  209. package/performance/typed-array.ts +0 -30
  210. package/performance/union-switch.ts +0 -57
  211. package/performance/union-typeof.ts +0 -40
  212. package/performance/wasm-call.ts +0 -63
  213. package/tsparser/check.go +0 -158
  214. package/tsparser/go.mod +0 -14
  215. package/tsparser/go.sum +0 -22
  216. package/tsparser/main.go +0 -363
  217. package/tsparser/tsparser.exe +0 -4
@@ -1,63 +0,0 @@
1
- // perf: calls from TypeScript into WebAssembly exports (i32 / f64 arithmetic, memory loads) and reads of the exported memory
2
- import { performance } from 'node:perf_hooks';
3
-
4
- // The module from conformance/lib-webassembly-basic.ts (its WAT is there): exports add, addf, load, bump, memory
5
- const wasm = new Uint8Array([
6
- 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x2a, 0x08, 0x60, 0x01, 0x7f, 0x00, 0x60,
7
- 0x00, 0x00, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x60, 0x02, 0x7e, 0x7e, 0x01, 0x7e, 0x60, 0x02,
8
- 0x7f, 0x7f, 0x02, 0x7f, 0x7f, 0x60, 0x02, 0x7c, 0x7c, 0x01, 0x7c, 0x60, 0x01, 0x7f, 0x01, 0x7f,
9
- 0x60, 0x00, 0x01, 0x7f, 0x02, 0x22, 0x03, 0x03, 0x65, 0x6e, 0x76, 0x03, 0x6c, 0x6f, 0x67, 0x00,
10
- 0x00, 0x03, 0x65, 0x6e, 0x76, 0x04, 0x66, 0x61, 0x69, 0x6c, 0x00, 0x01, 0x03, 0x65, 0x6e, 0x76,
11
- 0x05, 0x74, 0x77, 0x69, 0x63, 0x65, 0x00, 0x06, 0x03, 0x0b, 0x0a, 0x02, 0x03, 0x00, 0x01, 0x01,
12
- 0x04, 0x05, 0x06, 0x07, 0x06, 0x05, 0x04, 0x01, 0x01, 0x01, 0x04, 0x06, 0x06, 0x01, 0x7f, 0x01,
13
- 0x41, 0x05, 0x0b, 0x07, 0x67, 0x0c, 0x03, 0x61, 0x64, 0x64, 0x00, 0x03, 0x05, 0x61, 0x64, 0x64,
14
- 0x36, 0x34, 0x00, 0x04, 0x07, 0x63, 0x61, 0x6c, 0x6c, 0x4c, 0x6f, 0x67, 0x00, 0x05, 0x08, 0x63,
15
- 0x61, 0x6c, 0x6c, 0x46, 0x61, 0x69, 0x6c, 0x00, 0x06, 0x04, 0x74, 0x72, 0x61, 0x70, 0x00, 0x07,
16
- 0x06, 0x64, 0x69, 0x76, 0x72, 0x65, 0x6d, 0x00, 0x08, 0x04, 0x61, 0x64, 0x64, 0x66, 0x00, 0x09,
17
- 0x04, 0x6c, 0x6f, 0x61, 0x64, 0x00, 0x0a, 0x04, 0x62, 0x75, 0x6d, 0x70, 0x00, 0x0b, 0x08, 0x76,
18
- 0x69, 0x61, 0x54, 0x77, 0x69, 0x63, 0x65, 0x00, 0x0c, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79,
19
- 0x02, 0x00, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x03, 0x00, 0x0a, 0x54, 0x0a, 0x07,
20
- 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b, 0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x7c, 0x0b, 0x06,
21
- 0x00, 0x20, 0x00, 0x10, 0x00, 0x0b, 0x04, 0x00, 0x10, 0x01, 0x0b, 0x03, 0x00, 0x00, 0x0b, 0x0c,
22
- 0x00, 0x20, 0x00, 0x20, 0x01, 0x6d, 0x20, 0x00, 0x20, 0x01, 0x6f, 0x0b, 0x07, 0x00, 0x20, 0x00,
23
- 0x20, 0x01, 0xa0, 0x0b, 0x07, 0x00, 0x20, 0x00, 0x2d, 0x00, 0x00, 0x0b, 0x0b, 0x00, 0x23, 0x00,
24
- 0x41, 0x01, 0x6a, 0x24, 0x00, 0x23, 0x00, 0x0b, 0x09, 0x00, 0x20, 0x00, 0x10, 0x02, 0x41, 0x01,
25
- 0x6a, 0x0b, 0x0b, 0x08, 0x01, 0x00, 0x41, 0x10, 0x0b, 0x02, 0x68, 0x69, 0x00, 0x08, 0x04, 0x6d,
26
- 0x65, 0x74, 0x61, 0x01, 0x02, 0x03
27
- ]);
28
-
29
- type Api = {
30
- add(a: number, b: number): number;
31
- addf(a: number, b: number): number;
32
- load(at: number): number;
33
- bump(): number;
34
- };
35
-
36
- async function main(): Promise<void> {
37
- const imports = {
38
- env: {
39
- log: (_x: number) => {},
40
- fail: () => {},
41
- twice: (x: number) => x * 2
42
- }
43
- };
44
- const { instance } = await WebAssembly.instantiate(wasm, imports);
45
- const api = instance.exports as unknown as Api;
46
- const memory = instance.exports.memory as WebAssembly.Memory;
47
- const bytes = new Uint8Array(memory.buffer);
48
- for (let i = 0; i < 4096; i++) bytes[i] = (i * 31) & 255;
49
-
50
- const start = performance.now();
51
- let total = 0;
52
- for (let i = 0; i < 5_000_000; i++) {
53
- total += api.add(i & 1023, 7) & 255;
54
- total += api.addf(0.5, i & 3);
55
- total += api.load(i & 4095);
56
- if ((i & 255) === 0) total += api.bump() & 1;
57
- }
58
- const elapsed = performance.now() - start;
59
- console.log(`checksum: ${total}`);
60
- console.log(`elapsed: ${elapsed.toFixed(2)} ms`);
61
- }
62
-
63
- main();
package/tsparser/check.go DELETED
@@ -1,158 +0,0 @@
1
- // Type-checking for the self-hosted compiler (`tsparser --check`): the same
2
- // program the Node CLI checks with the typescript package (src/typecheck-node.ts),
3
- // built with typescript-go. Prints the errors as a JSON array.
4
- package main
5
-
6
- import (
7
- "context"
8
- "encoding/json"
9
- "fmt"
10
- "os"
11
-
12
- "github.com/buke/typescript-go-internal/pkg/ast"
13
- "github.com/buke/typescript-go-internal/pkg/bundled"
14
- "github.com/buke/typescript-go-internal/pkg/compiler"
15
- "github.com/buke/typescript-go-internal/pkg/core"
16
- "github.com/buke/typescript-go-internal/pkg/diagnostics"
17
- "github.com/buke/typescript-go-internal/pkg/diagnosticwriter"
18
- "github.com/buke/typescript-go-internal/pkg/locale"
19
- "github.com/buke/typescript-go-internal/pkg/scanner"
20
- "github.com/buke/typescript-go-internal/pkg/tsoptions"
21
- "github.com/buke/typescript-go-internal/pkg/tspath"
22
- "github.com/buke/typescript-go-internal/pkg/vfs"
23
- "github.com/buke/typescript-go-internal/pkg/vfs/osvfs"
24
- )
25
-
26
- // checkDiagnostic is one error, in the shape src/parse-native.ts reads
27
- // (file is absolute; line and column are 1-based, 0 for global errors)
28
- type checkDiagnostic struct {
29
- File string `json:"file"`
30
- Line int `json:"line"`
31
- Column int `json:"column"`
32
- Code int32 `json:"code"`
33
- Message string `json:"message"`
34
- }
35
-
36
- type configHost struct {
37
- fs vfs.FS
38
- cwd string
39
- }
40
-
41
- func (h configHost) FS() vfs.FS { return h.fs }
42
- func (h configHost) GetCurrentDirectory() string { return h.cwd }
43
-
44
- // The bundled declarations that replace the default lib (types/ in the package)
45
- var typenativeTypes = []string{"typenative.d.ts", "typenative-go.d.ts", "typenative-npm.d.ts"}
46
-
47
- // TS18003: "No inputs were found in config file" (only the entry is checked)
48
- const noInputsFound = 18003
49
-
50
- // runCheck type-checks entry with the nearest tsconfig.json's options (or
51
- // TypeNative's defaults) and prints the errors. The program's roots are the
52
- // entry plus the config's .d.ts files, so other entry points in the same
53
- // project don't redeclare each other's globals.
54
- func runCheck(entry string, typesDir string) {
55
- wd, err := os.Getwd()
56
- if err != nil {
57
- fmt.Fprintln(os.Stderr, "getwd:", err)
58
- os.Exit(1)
59
- }
60
- cwd := tspath.NormalizePath(wd)
61
- fs := bundled.WrapFS(osvfs.FS())
62
- entryPath := tspath.GetNormalizedAbsolutePath(entry, cwd)
63
- roots := []string{entryPath}
64
- out := []checkDiagnostic{}
65
-
66
- var options *core.CompilerOptions
67
- if configPath := findConfigFile(fs, tspath.GetDirectoryPath(entryPath)); configPath != "" {
68
- parsed, errs := tsoptions.GetParsedCommandLineOfConfigFile(configPath, &core.CompilerOptions{}, nil, configHost{fs, cwd}, nil)
69
- for _, d := range errs {
70
- out = append(out, toCheckDiagnostic(d))
71
- }
72
- if parsed == nil {
73
- printDiagnostics(out)
74
- return
75
- }
76
- for _, d := range parsed.Errors {
77
- if d.Code() != noInputsFound {
78
- out = append(out, toCheckDiagnostic(d))
79
- }
80
- }
81
- options = parsed.CompilerOptions()
82
- for _, name := range parsed.FileNames() {
83
- if tspath.IsDeclarationFileName(name) && name != entryPath {
84
- roots = append(roots, name)
85
- }
86
- }
87
- } else {
88
- options = &core.CompilerOptions{
89
- Target: core.ScriptTargetES2025,
90
- UseDefineForClassFields: core.TSFalse,
91
- Module: core.ModuleKindESNext,
92
- ModuleResolution: core.ModuleResolutionKindBundler,
93
- Lib: []string{},
94
- Types: []string{},
95
- Strict: core.TSTrue,
96
- NoImplicitAny: core.TSTrue,
97
- AllowSyntheticDefaultImports: core.TSTrue,
98
- AllowImportingTsExtensions: core.TSTrue,
99
- Jsx: core.JsxEmitPreserve,
100
- SkipLibCheck: core.TSTrue,
101
- }
102
- typesPath := tspath.GetNormalizedAbsolutePath(typesDir, cwd)
103
- for _, name := range typenativeTypes {
104
- roots = append(roots, tspath.CombinePaths(typesPath, name))
105
- }
106
- }
107
- options.NoEmit = core.TSTrue
108
-
109
- config := tsoptions.NewParsedCommandLine(options, roots, tspath.ComparePathsOptions{
110
- UseCaseSensitiveFileNames: fs.UseCaseSensitiveFileNames(),
111
- CurrentDirectory: cwd,
112
- })
113
- host := compiler.NewCompilerHost(cwd, fs, bundled.LibPath(), nil, nil)
114
- program := compiler.NewProgram(compiler.ProgramOptions{Config: config, Host: host})
115
- ctx := context.Background()
116
- for _, d := range compiler.GetDiagnosticsOfAnyProgram(ctx, program, nil, false, program.GetBindDiagnostics, program.GetSemanticDiagnostics) {
117
- if d.Category() == diagnostics.CategoryError {
118
- out = append(out, toCheckDiagnostic(d))
119
- }
120
- }
121
- printDiagnostics(out)
122
- }
123
-
124
- // findConfigFile walks up from dir to the nearest tsconfig.json
125
- func findConfigFile(fs vfs.FS, dir string) string {
126
- for {
127
- candidate := tspath.CombinePaths(dir, "tsconfig.json")
128
- if fs.FileExists(candidate) {
129
- return candidate
130
- }
131
- parent := tspath.GetDirectoryPath(dir)
132
- if parent == dir {
133
- return ""
134
- }
135
- dir = parent
136
- }
137
- }
138
-
139
- func toCheckDiagnostic(d *ast.Diagnostic) checkDiagnostic {
140
- out := checkDiagnostic{
141
- Code: d.Code(),
142
- Message: diagnosticwriter.FlattenDiagnosticMessage(&diagnosticwriter.ASTDiagnostic{Diagnostic: d}, "\n", locale.Default),
143
- }
144
- if file := d.File(); file != nil {
145
- line, character := scanner.GetECMALineAndUTF16CharacterOfPosition(file, d.Pos())
146
- out.File = file.FileName()
147
- out.Line = line + 1
148
- out.Column = int(character) + 1
149
- }
150
- return out
151
- }
152
-
153
- func printDiagnostics(out []checkDiagnostic) {
154
- if err := json.NewEncoder(os.Stdout).Encode(out); err != nil {
155
- fmt.Fprintln(os.Stderr, "encode:", err)
156
- os.Exit(1)
157
- }
158
- }
package/tsparser/go.mod DELETED
@@ -1,14 +0,0 @@
1
- module github.com/danisss9/typenative/tsparser
2
-
3
- go 1.26.0
4
-
5
- require github.com/buke/typescript-go-internal v0.0.2
6
-
7
- require (
8
- github.com/go-json-experiment/json v1.27.2 // indirect
9
- github.com/klauspost/cpuid/v2 v2.2.10 // indirect
10
- github.com/zeebo/xxh3 v1.1.0 // indirect
11
- golang.org/x/sync v0.20.0 // indirect
12
- golang.org/x/sys v0.43.0 // indirect
13
- golang.org/x/text v0.36.0 // indirect
14
- )
package/tsparser/go.sum DELETED
@@ -1,22 +0,0 @@
1
- github.com/buke/typescript-go-internal v0.0.2 h1:JTHAXQfj1HVN4eXh7XqUWZurxjowXoE+5Ud8QLS4uRg=
2
- github.com/buke/typescript-go-internal v0.0.2/go.mod h1:nZjFbdZyxx5D9s/GafAh6ESVUy3GMAjNMMMBjVEqDgc=
3
- github.com/go-json-experiment/json v1.27.2 h1:rZIyqYh+Qq+nEa+Y5iwohr8h7G/MfLJqu2CD4/ZONqM=
4
- github.com/go-json-experiment/json v1.27.2/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
5
- github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
6
- github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
7
- github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
8
- github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
9
- github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
10
- github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
11
- github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
12
- github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
13
- github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
14
- github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
15
- golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
16
- golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
17
- golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
18
- golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
19
- golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
20
- golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
21
- gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
22
- gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
package/tsparser/main.go DELETED
@@ -1,363 +0,0 @@
1
- // tsparser: parses TypeScript source into a normalized JSON AST.
2
- //
3
- // Used by TypeNative's self-hosting pipeline: the transpiled compiler calls
4
- // this tool (via node:child_process) instead of the `typescript` npm package.
5
- // The JSON shape mirrors the TypeScript API AST (kind + spec field names) so
6
- // the same transpiler code can consume ASTs from either source.
7
- //
8
- // Usage: tsparser < file.ts > ast.json
9
- //
10
- // tsparser --check <file.ts> <types dir> type-checks a program (see check.go)
11
- package main
12
-
13
- import (
14
- "encoding/json"
15
- "fmt"
16
- "io"
17
- "os"
18
- "reflect"
19
- "strings"
20
-
21
- "github.com/buke/typescript-go-internal/pkg/ast"
22
- "github.com/buke/typescript-go-internal/pkg/core"
23
- "github.com/buke/typescript-go-internal/pkg/parser"
24
- "github.com/buke/typescript-go-internal/pkg/scanner"
25
- )
26
-
27
- // The parsed source, for template raw text
28
- var sourceText string
29
-
30
- // The parsed file, for node positions
31
- var parsedFile *ast.SourceFile
32
-
33
- func main() {
34
- if len(os.Args) > 1 && os.Args[1] == "--check" {
35
- if len(os.Args) < 4 {
36
- fmt.Fprintln(os.Stderr, "usage: tsparser --check <file.ts> <types dir>")
37
- os.Exit(2)
38
- }
39
- runCheck(os.Args[2], os.Args[3])
40
- return
41
- }
42
- sourceBytes, err := io.ReadAll(os.Stdin)
43
- if err != nil {
44
- fmt.Fprintln(os.Stderr, "read stdin:", err)
45
- os.Exit(1)
46
- }
47
- sourceText = string(sourceBytes)
48
- // --tsx: parse JSX (.tsx sources)
49
- fileName, scriptKind := "/main.ts", core.ScriptKindTS
50
- for _, arg := range os.Args[1:] {
51
- if arg == "--tsx" {
52
- fileName, scriptKind = "/main.tsx", core.ScriptKindTSX
53
- }
54
- }
55
- sourceFile := parser.ParseSourceFile(
56
- ast.SourceFileParseOptions{FileName: fileName},
57
- string(sourceBytes),
58
- scriptKind,
59
- )
60
- parsedFile = sourceFile
61
- out := serializeNode(sourceFile.AsNode())
62
- enc := json.NewEncoder(os.Stdout)
63
- enc.SetIndent("", " ")
64
- if err := enc.Encode(out); err != nil {
65
- fmt.Fprintln(os.Stderr, "encode:", err)
66
- os.Exit(1)
67
- }
68
- }
69
-
70
-
71
- // var / let / const / using / await using (await using sets Const | Using)
72
- func declarationKind(flags ast.NodeFlags) string {
73
- switch {
74
- case flags&ast.NodeFlagsAwaitUsing == ast.NodeFlagsAwaitUsing:
75
- return "await using"
76
- case flags&ast.NodeFlagsUsing != 0:
77
- return "using"
78
- case flags&ast.NodeFlagsConst != 0:
79
- return "const"
80
- case flags&ast.NodeFlagsLet != 0:
81
- return "let"
82
- }
83
- return "var"
84
- }
85
-
86
- // Nodes currently being serialized (cycle guard).
87
- var inProgress = map[*ast.Node]bool{}
88
-
89
- // Nodes whose As<Kind> method name doesn't follow the naming patterns.
90
- var asMethodOverrides = map[string]string{
91
- "ForInStatement": "AsForInOrOfStatement",
92
- "ForOfStatement": "AsForInOrOfStatement",
93
- "ArrayBindingPattern": "AsBindingPattern",
94
- "ObjectBindingPattern": "AsBindingPattern",
95
- "CaseClause": "AsCaseOrDefaultClause",
96
- "DefaultClause": "AsCaseOrDefaultClause",
97
- "TypeAssertionExpression": "AsTypeAssertion",
98
- }
99
-
100
- // asData returns the typed data struct behind a node via its As<Kind> method.
101
- // Method names don't always match kind names exactly (GetAccessor →
102
- // AsGetAccessorDeclaration), so common suffixes are tried in order.
103
- func asData(n *ast.Node) reflect.Value {
104
- kind := n.Kind.String()
105
- if strings.HasPrefix(kind, "Kind") {
106
- kind = kind[4:] // KindIfStatement → IfStatement
107
- }
108
- nodeVal := reflect.ValueOf(n)
109
- candidates := []string{"As" + kind, "As" + kind + "Declaration", "As" + kind + "Expression", "As" + kind + "Statement", "As" + kind + "Node"}
110
- if override, ok := asMethodOverrides[kind]; ok {
111
- candidates = append([]string{override}, candidates...)
112
- }
113
- for _, candidate := range candidates {
114
- meth := nodeVal.MethodByName(candidate)
115
- if !meth.IsValid() {
116
- continue
117
- }
118
- results := meth.Call(nil)
119
- if len(results) == 0 {
120
- continue
121
- }
122
- v := results[0]
123
- if v.IsNil() {
124
- return reflect.Value{}
125
- }
126
- return v.Elem()
127
- }
128
- return reflect.Value{}
129
- }
130
-
131
- // serializeNode converts an ast.Node into a map: {kind, text?, <spec fields>}.
132
- // inProgress guards against cyclic *Node references (self/parent backlinks).
133
- func serializeNode(n *ast.Node) any {
134
- if n == nil {
135
- return nil
136
- }
137
- if inProgress[n] {
138
- return nil
139
- }
140
- inProgress[n] = true
141
- defer delete(inProgress, n)
142
- obj := map[string]any{"kind": strings.TrimPrefix(n.Kind.String(), "Kind")}
143
- setPosition(n, obj)
144
- // SourceFile bookkeeping fields are not part of the language AST
145
- if n.Kind == ast.KindSourceFile {
146
- statements := []any{}
147
- for _, stmt := range n.AsSourceFile().Statements.Nodes {
148
- if stmt != nil {
149
- statements = append(statements, serializeNode(stmt))
150
- }
151
- }
152
- obj["statements"] = statements
153
- return obj
154
- }
155
- // Names and modifiers live in unexported base fields — use accessors
156
- if name := n.Name(); name != nil {
157
- obj["name"] = serializeNode(name.AsNode())
158
- }
159
- if mods := n.Modifiers(); mods != nil {
160
- arr := []any{}
161
- for _, mod := range mods.Nodes {
162
- arr = append(arr, serializeNode(mod))
163
- }
164
- obj["modifiers"] = arr
165
- }
166
- switch n.Kind {
167
- case ast.KindIdentifier, ast.KindPrivateIdentifier, ast.KindStringLiteral,
168
- ast.KindNumericLiteral, ast.KindBigIntLiteral, ast.KindNoSubstitutionTemplateLiteral,
169
- ast.KindRegularExpressionLiteral, ast.KindTemplateHead, ast.KindTemplateMiddle,
170
- ast.KindTemplateTail:
171
- obj["text"] = n.Text()
172
- case ast.KindJsxText:
173
- // Node.Text() doesn't cover JsxText
174
- obj["text"] = n.AsJsxText().Text
175
- }
176
- if n.Kind == ast.KindVariableDeclarationList {
177
- obj["declarationKind"] = declarationKind(n.Flags)
178
- }
179
-
180
- // Binding-pattern holes (`[a, , b]`): ts-go parses them as an empty
181
- // BindingElement; the TypeScript API exposes them as OmittedExpression
182
- if n.Kind == ast.KindBindingElement {
183
- if be := n.AsBindingElement(); be != nil && be.Name() == nil && be.DotDotDotToken == nil {
184
- hole := map[string]any{"kind": "OmittedExpression"}
185
- setPosition(n, hole)
186
- return hole
187
- }
188
- }
189
-
190
- data := asData(n)
191
- if data.IsValid() {
192
- collectFields(data, obj)
193
- }
194
- // ts-go's PostfixToken is ? or !; the TypeScript API names a ! exclamationToken
195
- if tok, ok := obj["questionToken"].(map[string]any); ok && tok["kind"] == "ExclamationToken" {
196
- delete(obj, "questionToken")
197
- obj["exclamationToken"] = tok
198
- }
199
- // Template pieces: rawText is the source between their delimiters
200
- // (`…`, `…${, }…${, }…`), with line endings normalized like JS
201
- switch n.Kind {
202
- case ast.KindNoSubstitutionTemplateLiteral, ast.KindTemplateHead, ast.KindTemplateMiddle, ast.KindTemplateTail:
203
- start, end := scanner.SkipTrivia(sourceText, n.Pos())+1, n.End()-1
204
- if n.Kind == ast.KindTemplateHead || n.Kind == ast.KindTemplateMiddle {
205
- end--
206
- }
207
- if start <= end && end <= len(sourceText) {
208
- obj["rawText"] = strings.ReplaceAll(sourceText[start:end], "\r\n", "\n")
209
- }
210
- }
211
- return obj
212
- }
213
-
214
- // setPosition records the 1-based line and column of the node's first token
215
- // (columns count UTF-16 units, as in the TypeScript API); the transpiler maps
216
- // Go positions back to them
217
- func setPosition(n *ast.Node, obj map[string]any) {
218
- if n.Kind == ast.KindSourceFile || n.Pos() < 0 || parsedFile == nil {
219
- return
220
- }
221
- line, character := scanner.GetECMALineAndUTF16CharacterOfPosition(parsedFile, scanner.GetTokenPosOfNode(n, parsedFile, false))
222
- obj["line"] = line + 1
223
- obj["column"] = int(character) + 1
224
- // where it ends (exclusive): node:test coverage ranges
225
- endLine, endCharacter := scanner.GetECMALineAndUTF16CharacterOfPosition(parsedFile, n.End())
226
- obj["endLine"] = endLine + 1
227
- obj["endColumn"] = int(endCharacter) + 1
228
- }
229
-
230
- // collectFields serializes a typed data struct's fields into obj, recursing
231
- // into embedded base structs (DeclarationBase, FunctionLikeBase, ...) so their
232
- // fields are hoisted like the TypeScript API exposes them.
233
- func collectFields(data reflect.Value, obj map[string]any) {
234
- dt := data.Type()
235
- for i := 0; i < dt.NumField(); i++ {
236
- field := dt.Field(i)
237
- if !field.IsExported() {
238
- continue
239
- }
240
- // Embedded base structs are hoisted — except NodeDefault/Node, whose
241
- // fields (Kind/Flags/Loc/Parent) are parser bookkeeping, not AST
242
- if field.Anonymous && field.Type.Kind() == reflect.Struct {
243
- if field.Type.Name() != "NodeDefault" && field.Type.Name() != "Node" {
244
- collectFields(data.Field(i), obj)
245
- }
246
- continue
247
- }
248
- name, val, ok := serializeField(field.Name, data.Field(i))
249
- if ok {
250
- obj[name] = val
251
- }
252
- }
253
- }
254
-
255
- // serializeField normalizes one typed-struct field into the TS-spec JSON shape.
256
- func serializeField(name string, v reflect.Value) (string, any, bool) {
257
- if renamed, ok := fieldRenames[name]; ok {
258
- name = renamed
259
- } else {
260
- name = lowerFirst(name)
261
- }
262
- // Never emit parser bookkeeping fields from the embedded ast.Node
263
- switch name {
264
- case "kind", "flags", "loc", "parent", "id", "data":
265
- return "", nil, false
266
- }
267
- switch v.Kind() {
268
- case reflect.String:
269
- return lowerFirst(name), v.String(), true
270
- case reflect.Bool:
271
- return lowerFirst(name), v.Bool(), true
272
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
273
- // Operator/Token fields hold token kinds; emit the kind name (matches the
274
- // Node producer, which converts ts.SyntaxKind numbers to names)
275
- if name == "operator" || name == "token" { // prelude lowercased the field name
276
- kind := ast.Kind(v.Int())
277
- return lowerFirst(name), strings.TrimPrefix(kind.String(), "Kind"), true
278
- }
279
- return "", nil, false
280
- case reflect.Ptr:
281
- if v.IsNil() {
282
- return "", nil, false
283
- }
284
- if isNodePtr(v.Type()) {
285
- return lowerFirst(name), serializeNode(v.Interface().(*ast.Node)), true
286
- }
287
- // *NodeBody / *EntityName etc. are pointer-to-interface wrappers
288
- // whose dynamic value is a *Node
289
- if v.Type().Elem().Kind() == reflect.Interface {
290
- inner := v.Elem().Elem()
291
- if inner.IsValid() && inner.Kind() == reflect.Ptr && !inner.IsNil() {
292
- return lowerFirst(name), serializeNode(inner.Interface().(*ast.Node)), true
293
- }
294
- return "", nil, false
295
- }
296
- // e.g. *StatementList/*ArgumentList/*ModifierList → array of member
297
- // nodes, named after the field (statements/arguments/modifiers)
298
- if strings.HasSuffix(v.Type().Elem().Name(), "List") {
299
- var arr []any
300
- elem := v.Elem()
301
- nodesField := elem.FieldByName("Nodes")
302
- if nodesField.IsValid() && nodesField.Kind() == reflect.Slice {
303
- for _, child := range iterSlice(nodesField) {
304
- if child.Kind() == reflect.Ptr && isNodePtr(child.Type()) && !child.IsNil() {
305
- arr = append(arr, serializeNode(child.Interface().(*ast.Node)))
306
- }
307
- }
308
- }
309
- if len(arr) == 0 {
310
- return "", nil, false
311
- }
312
- return lowerFirst(name), arr, true
313
- }
314
- return "", nil, false
315
- case reflect.Slice:
316
- var arr []any
317
- for _, el := range iterSlice(v) {
318
- if el.Kind() == reflect.Ptr && isNodePtr(el.Type()) && !el.IsNil() {
319
- arr = append(arr, serializeNode(el.Interface().(*ast.Node)))
320
- }
321
- }
322
- if arr == nil {
323
- arr = []any{}
324
- }
325
- return lowerFirst(name), arr, true
326
- case reflect.Interface:
327
- if v.IsNil() {
328
- return "", nil, false
329
- }
330
- // Expression/Statement wrappers hold *Node underneath
331
- inner := v.Elem()
332
- if inner.Kind() == reflect.Ptr && isNodePtr(inner.Type()) && !inner.IsNil() {
333
- return lowerFirst(name), serializeNode(inner.Interface().(*ast.Node)), true
334
- }
335
- return "", nil, false
336
- }
337
- return "", nil, false
338
- }
339
-
340
- func isNodePtr(t reflect.Type) bool {
341
- return t == reflect.TypeOf((*ast.Node)(nil))
342
- }
343
-
344
- func iterSlice(v reflect.Value) []reflect.Value {
345
- out := make([]reflect.Value, 0, v.Len())
346
- for i := 0; i < v.Len(); i++ {
347
- out = append(out, v.Index(i))
348
- }
349
- return out
350
- }
351
-
352
- func lowerFirst(s string) string {
353
- if s == "" {
354
- return s
355
- }
356
- return strings.ToLower(s[:1]) + s[1:]
357
- }
358
-
359
- // Field renames to match the TypeScript API's names.
360
- var fieldRenames = map[string]string{
361
- "PostfixToken": "questionToken", // optional property `a?: string`
362
- "DefaultType": "default", // type parameter default `<S = any>`
363
- }
@@ -1,4 +0,0 @@
1
- [diffend] Oversized file quarantined before diffing.
2
- name: package/tsparser/tsparser.exe
3
- size: 37236736 bytes
4
- sha256: 325117ab33bbcf3ee1557ea5a7f5983e3aa5c9f217586bfdc9d7c33eb4d80ac2