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.
- package/bin/node/assert.js +2 -2
- package/bin/node/child_process.js +66 -8
- package/bin/node/fs.js +1012 -4
- package/bin/node/histogram.js +1991 -0
- package/bin/node/process.js +14 -2
- package/bin/node/sqlite.js +1488 -5
- package/bin/node/stream.js +2 -1
- package/bin/node/system_extra.js +3 -270
- package/bin/node/test.js +39 -1
- package/bin/node/test_report.js +47 -1
- package/bin/node/test_run.js +57 -2
- package/bin/node/util.js +8 -5
- package/bin/node/webassembly.js +20 -5
- package/bin/node/webview.js +3257 -244
- package/bin/node/zlib.js +118 -14
- package/bin/node/zlib_iter.js +585 -0
- package/bin/transpiler.js +1370 -258
- package/bin/version.js +1 -1
- package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
- package/package.json +10 -1
- package/types/tsconfig.json +17 -0
- package/types/typenative-npm.d.ts +492 -12
- package/types/typenative.d.ts +88 -2
- package/.gitattributes +0 -1
- package/.github/workflows/ci.yml +0 -68
- package/.github/workflows/npm-publish-github-packages.yml +0 -88
- package/CHANGELOG.md +0 -1746
- package/CONTRIBUTION.md +0 -133
- package/conformance.md +0 -1497
- package/examples/README.md +0 -114
- package/examples/angular-templates/README.md +0 -141
- package/examples/angular-templates/bench.mjs +0 -173
- package/examples/angular-templates/dom-type-globals.d.ts +0 -21
- package/examples/angular-templates/dom-type-stubs.ts +0 -21
- package/examples/angular-templates/main.ts +0 -135
- package/examples/angular-templates/parity.mjs +0 -157
- package/examples/angular-templates/run-node.mjs +0 -69
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
- package/examples/desktop-notes/README.md +0 -106
- package/examples/desktop-notes/bench.mjs +0 -125
- package/examples/desktop-notes/main.ts +0 -131
- package/examples/desktop-notes/package-lock.json +0 -726
- package/examples/desktop-notes/package.json +0 -9
- package/examples/desktop-notes/ui.ts +0 -176
- package/examples/dupe-finder/README.md +0 -78
- package/examples/dupe-finder/bench.mjs +0 -120
- package/examples/dupe-finder/main.ts +0 -87
- package/examples/fibonacci/README.md +0 -89
- package/examples/fibonacci/bench.mjs +0 -87
- package/examples/fibonacci/main.ts +0 -21
- package/examples/hello-world/README.md +0 -62
- package/examples/hello-world/bench.mjs +0 -66
- package/examples/hello-world/main.ts +0 -7
- package/examples/json-server/README.md +0 -132
- package/examples/json-server/bench.mjs +0 -263
- package/examples/json-server/main.ts +0 -67
- package/examples/mandelbrot-png/README.md +0 -63
- package/examples/mandelbrot-png/bench.mjs +0 -95
- package/examples/mandelbrot-png/main.ts +0 -98
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +0 -174
- package/examples/marked-cli/bench.mjs +0 -178
- package/examples/marked-cli/main.ts +0 -410
- package/examples/marked-cli/parity.mjs +0 -185
- package/examples/marked-cli/vendor/marked/LICENSE +0 -44
- package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
- package/examples/openai-chat/README.md +0 -148
- package/examples/openai-chat/bench.mjs +0 -175
- package/examples/openai-chat/main.ts +0 -488
- package/examples/react-compiler/README.md +0 -185
- package/examples/react-compiler/bench.mjs +0 -181
- package/examples/react-compiler/main.ts +0 -324
- package/examples/react-compiler/parity.mjs +0 -362
- package/examples/react-compiler/run-node.mjs +0 -90
- package/examples/react-compiler/vendor/babel/LICENSE +0 -22
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
- package/examples/react-compiler/vendor/charcodes/package.json +0 -25
- package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
- package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
- package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
- package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
- package/examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt +0 -20
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/picocolors/LICENSE +0 -15
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
- package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
- package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
- package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
- package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
- package/examples/react-compiler/vendor/zod/LICENSE +0 -21
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
- package/examples/react-compiler/vendor.mjs +0 -688
- package/examples/todo-cli/README.md +0 -69
- package/examples/todo-cli/bench.mjs +0 -89
- package/examples/todo-cli/main.ts +0 -92
- package/examples/yaml-cli/README.md +0 -152
- package/examples/yaml-cli/bench.mjs +0 -265
- package/examples/yaml-cli/main.ts +0 -251
- package/examples/yaml-cli/parity.mjs +0 -156
- package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
- package/performance/README.md +0 -248
- package/performance/any-dynamic.ts +0 -21
- package/performance/any-record-view.ts +0 -20
- package/performance/arr-for-of.ts +0 -29
- package/performance/arr-hof.ts +0 -21
- package/performance/arr-push-index.ts +0 -15
- package/performance/arr-push-local.ts +0 -39
- package/performance/arr-slice-concat.ts +0 -24
- package/performance/arr-sort.ts +0 -21
- package/performance/async-await.ts +0 -24
- package/performance/async-promise-all.ts +0 -38
- package/performance/bigint-arith.ts +0 -36
- package/performance/buf-encode.ts +0 -29
- package/performance/class-accessors.ts +0 -48
- package/performance/class-dispatch.ts +0 -52
- package/performance/date-format.ts +0 -18
- package/performance/events-emit.ts +0 -27
- package/performance/exc-throw-rare.ts +0 -25
- package/performance/exc-try-catch.ts +0 -26
- package/performance/fn-closures.ts +0 -29
- package/performance/fn-recursion-tree.ts +0 -31
- package/performance/fn-rest-spread.ts +0 -43
- package/performance/gen-for-of.ts +0 -46
- package/performance/gen-next.ts +0 -32
- package/performance/iter-helpers.ts +0 -38
- package/performance/json-any.ts +0 -30
- package/performance/json-roundtrip.ts +0 -27
- package/performance/map-delete.ts +0 -24
- package/performance/map-iterate.ts +0 -26
- package/performance/map-number-keys.ts +0 -37
- package/performance/map-string-keys.ts +0 -22
- package/performance/num-arith-loop.ts +0 -14
- package/performance/num-bitwise.ts +0 -21
- package/performance/num-hash-imul.ts +0 -36
- package/performance/num-mod-int.ts +0 -16
- package/performance/num-to-string.ts +0 -16
- package/performance/obj-alloc.ts +0 -32
- package/performance/obj-keys-entries.ts +0 -44
- package/performance/obj-optional-chain.ts +0 -42
- package/performance/obj-record-dict.ts +0 -24
- package/performance/obj-spread-destructure.ts +0 -40
- package/performance/regex-exec.ts +0 -29
- package/performance/regex-replace-fn.ts +0 -24
- package/performance/regex-site.ts +0 -28
- package/performance/set-ops.ts +0 -20
- package/performance/str-char-scan.ts +0 -35
- package/performance/str-concat-plus.ts +0 -18
- package/performance/str-concat.ts +0 -24
- package/performance/str-methods.ts +0 -24
- package/performance/str-short-scan.ts +0 -26
- package/performance/str-split-join.ts +0 -23
- package/performance/str-switch-compare.ts +0 -50
- package/performance/str-template.ts +0 -16
- package/performance/str-unicode.ts +0 -25
- package/performance/typed-array.ts +0 -30
- package/performance/union-switch.ts +0 -57
- package/performance/union-typeof.ts +0 -40
- package/performance/wasm-call.ts +0 -63
- package/tsparser/check.go +0 -158
- package/tsparser/go.mod +0 -14
- package/tsparser/go.sum +0 -22
- package/tsparser/main.go +0 -363
- package/tsparser/tsparser.exe +0 -4
package/performance/wasm-call.ts
DELETED
|
@@ -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
|
-
}
|
package/tsparser/tsparser.exe
DELETED