typenative 0.1.2 → 0.2.0
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/.gitattributes +1 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/npm-publish-github-packages.yml +1 -1
- package/CHANGELOG.md +247 -0
- package/CONTRIBUTION.md +1 -1
- package/README.md +30 -21
- package/bin/cli.js +3 -1
- package/bin/go/bridge.js +919 -0
- package/bin/go/convert.js +238 -0
- package/bin/go/metadata.js +211 -0
- package/bin/go/overrides.js +68 -0
- package/bin/go/stdlib.generated.js +175 -0
- package/bin/index.js +98 -6
- package/bin/main.js +4 -1
- package/bin/node/assert.js +344 -0
- package/bin/node/async_hooks.js +273 -0
- package/bin/node/buffer.js +765 -0
- package/bin/node/child_process.js +600 -0
- package/bin/node/cluster.js +1002 -0
- package/bin/node/console.js +121 -0
- package/bin/node/core.js +111 -0
- package/bin/node/crypto.js +414 -0
- package/bin/node/crypto_keys.js +2685 -0
- package/bin/node/dgram.js +388 -0
- package/bin/node/diagnostics_channel.js +534 -0
- package/bin/node/dns.js +635 -0
- package/bin/node/events.js +743 -0
- package/bin/node/fetch.js +737 -0
- package/bin/node/fs.js +998 -0
- package/bin/node/http.js +1500 -0
- package/bin/node/http2.js +688 -0
- package/bin/node/net.js +1143 -0
- package/bin/node/os.js +257 -0
- package/bin/node/path.js +758 -0
- package/bin/node/process.js +316 -0
- package/bin/node/punycode.js +195 -0
- package/bin/node/querystring.js +143 -0
- package/bin/node/readline.js +299 -0
- package/bin/node/registry.js +161 -0
- package/bin/node/sqlite.js +1142 -0
- package/bin/node/stream.js +1221 -0
- package/bin/node/stream_web.js +2259 -0
- package/bin/node/string_decoder.js +101 -0
- package/bin/node/system_extra.js +661 -0
- package/bin/node/test.js +1068 -0
- package/bin/node/timers.js +250 -0
- package/bin/node/tls.js +719 -0
- package/bin/node/url.js +861 -0
- package/bin/node/util.js +1311 -0
- package/bin/node/util_extra.js +599 -0
- package/bin/node/worker_threads.js +745 -0
- package/bin/node/zlib.js +263 -0
- package/bin/parse-native.js +3 -2
- package/bin/parse-node.js +18 -2
- package/bin/transpiler.js +3529 -597
- package/bin/version.js +2 -0
- package/conformance.md +724 -258
- package/govendor/github.com/ncruces/go-sqlite3/LICENSE +21 -0
- package/govendor/github.com/ncruces/go-sqlite3/README.md +121 -0
- package/govendor/github.com/ncruces/go-sqlite3/backup.go +132 -0
- package/govendor/github.com/ncruces/go-sqlite3/blob.go +266 -0
- package/govendor/github.com/ncruces/go-sqlite3/config.go +397 -0
- package/govendor/github.com/ncruces/go-sqlite3/conn.go +540 -0
- package/govendor/github.com/ncruces/go-sqlite3/conn_127.go +93 -0
- package/govendor/github.com/ncruces/go-sqlite3/const.go +436 -0
- package/govendor/github.com/ncruces/go-sqlite3/context.go +222 -0
- package/govendor/github.com/ncruces/go-sqlite3/error.go +182 -0
- package/govendor/github.com/ncruces/go-sqlite3/ext.go +153 -0
- package/govendor/github.com/ncruces/go-sqlite3/func.go +309 -0
- package/govendor/github.com/ncruces/go-sqlite3/go.mod +3 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk.go +29 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk_other.go +13 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk_unix.go +57 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/errutil/error.go +41 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/alloc.go +128 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/const.go +122 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/error.go +77 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem.go +116 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_other.go +34 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_unix.go +87 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_windows.go +149 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mmap_unix.go +80 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mmap_windows.go +129 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/sys_windows.go +60 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap.go +82 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap_sys.go +113 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap_vfs.go +181 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/testenv/env.go +55 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/json.go +54 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/json_v2.go +54 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/math.go +29 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/page.go +5 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/parse.go +142 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/pointer.go +3 -0
- package/govendor/github.com/ncruces/go-sqlite3/internal/util/reflect.go +10 -0
- package/govendor/github.com/ncruces/go-sqlite3/json.go +100 -0
- package/govendor/github.com/ncruces/go-sqlite3/json_v2.go +116 -0
- package/govendor/github.com/ncruces/go-sqlite3/pointer.go +13 -0
- package/govendor/github.com/ncruces/go-sqlite3/quote.go +140 -0
- package/govendor/github.com/ncruces/go-sqlite3/stmt.go +692 -0
- package/govendor/github.com/ncruces/go-sqlite3/time.go +360 -0
- package/govendor/github.com/ncruces/go-sqlite3/txn.go +374 -0
- package/govendor/github.com/ncruces/go-sqlite3/value.go +212 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/README.md +133 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/api.go +239 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/cksm.go +143 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/const.go +256 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/file.go +260 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/filename.go +187 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/lock.go +128 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/lock_other.go +23 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/map.go +63 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/map_other.go +13 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go +110 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go +131 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_dotlk.go +140 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go +56 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_linux.go +117 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_ofd.go +59 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std.go +50 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_alloc.go +19 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_atomic.go +9 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_rw.go +13 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_sync.go +9 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_temp.go +16 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_unix.go +108 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go +180 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/registry.go +48 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm.go +26 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go +258 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_copy.go +90 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_dotlk.go +168 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_memlk.go +52 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_ofd.go +185 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_other.go +21 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_windows.go +124 -0
- package/govendor/github.com/ncruces/go-sqlite3/vfs/vfs.go +455 -0
- package/govendor/github.com/ncruces/go-sqlite3/vtab.go +677 -0
- package/govendor/github.com/ncruces/go-sqlite3/wrap.go +48 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/LICENSE +18 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/README.md +11 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/go.mod +3 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/libc.go +215 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/sqlite3.dat +0 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/sqlite3.go +157903 -0
- package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/tools.sh +38 -0
- package/govendor/github.com/ncruces/julianday/LICENSE +21 -0
- package/govendor/github.com/ncruces/julianday/README.md +9 -0
- package/govendor/github.com/ncruces/julianday/go.mod +3 -0
- package/govendor/github.com/ncruces/julianday/julianday.go +124 -0
- package/govendor/golang.org/x/sys/LICENSE +27 -0
- package/govendor/golang.org/x/sys/PATENTS +22 -0
- package/govendor/golang.org/x/sys/go.mod +3 -0
- package/govendor/golang.org/x/sys/unix/README.md +184 -0
- package/govendor/golang.org/x/sys/unix/affinity_linux.go +189 -0
- package/govendor/golang.org/x/sys/unix/aliases.go +13 -0
- package/govendor/golang.org/x/sys/unix/asm_aix_ppc64.s +17 -0
- package/govendor/golang.org/x/sys/unix/asm_bsd_386.s +27 -0
- package/govendor/golang.org/x/sys/unix/asm_bsd_amd64.s +27 -0
- package/govendor/golang.org/x/sys/unix/asm_bsd_arm.s +27 -0
- package/govendor/golang.org/x/sys/unix/asm_bsd_arm64.s +27 -0
- package/govendor/golang.org/x/sys/unix/asm_bsd_ppc64.s +29 -0
- package/govendor/golang.org/x/sys/unix/asm_bsd_riscv64.s +27 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_386.s +65 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_amd64.s +57 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_arm.s +56 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_arm64.s +50 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_loong64.s +51 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_mips64x.s +54 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_mipsx.s +52 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_ppc64x.s +42 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_riscv64.s +47 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_s390x.s +54 -0
- package/govendor/golang.org/x/sys/unix/asm_openbsd_mips64.s +29 -0
- package/govendor/golang.org/x/sys/unix/asm_solaris_amd64.s +17 -0
- package/govendor/golang.org/x/sys/unix/asm_zos_s390x.s +382 -0
- package/govendor/golang.org/x/sys/unix/auxv.go +36 -0
- package/govendor/golang.org/x/sys/unix/auxv_unsupported.go +13 -0
- package/govendor/golang.org/x/sys/unix/bluetooth_linux.go +36 -0
- package/govendor/golang.org/x/sys/unix/bpxsvc_zos.go +657 -0
- package/govendor/golang.org/x/sys/unix/bpxsvc_zos.s +192 -0
- package/govendor/golang.org/x/sys/unix/cap_freebsd.go +195 -0
- package/govendor/golang.org/x/sys/unix/constants.go +13 -0
- package/govendor/golang.org/x/sys/unix/dev_aix_ppc.go +26 -0
- package/govendor/golang.org/x/sys/unix/dev_aix_ppc64.go +28 -0
- package/govendor/golang.org/x/sys/unix/dev_darwin.go +24 -0
- package/govendor/golang.org/x/sys/unix/dev_dragonfly.go +30 -0
- package/govendor/golang.org/x/sys/unix/dev_freebsd.go +30 -0
- package/govendor/golang.org/x/sys/unix/dev_linux.go +42 -0
- package/govendor/golang.org/x/sys/unix/dev_netbsd.go +29 -0
- package/govendor/golang.org/x/sys/unix/dev_openbsd.go +29 -0
- package/govendor/golang.org/x/sys/unix/dev_zos.go +28 -0
- package/govendor/golang.org/x/sys/unix/dirent.go +102 -0
- package/govendor/golang.org/x/sys/unix/endian_big.go +9 -0
- package/govendor/golang.org/x/sys/unix/endian_little.go +9 -0
- package/govendor/golang.org/x/sys/unix/env_unix.go +31 -0
- package/govendor/golang.org/x/sys/unix/fcntl.go +36 -0
- package/govendor/golang.org/x/sys/unix/fcntl_darwin.go +24 -0
- package/govendor/golang.org/x/sys/unix/fcntl_linux_32bit.go +13 -0
- package/govendor/golang.org/x/sys/unix/fdset.go +27 -0
- package/govendor/golang.org/x/sys/unix/gccgo.go +59 -0
- package/govendor/golang.org/x/sys/unix/gccgo_c.c +44 -0
- package/govendor/golang.org/x/sys/unix/gccgo_linux_amd64.go +20 -0
- package/govendor/golang.org/x/sys/unix/ifreq_linux.go +145 -0
- package/govendor/golang.org/x/sys/unix/ioctl_linux.go +341 -0
- package/govendor/golang.org/x/sys/unix/ioctl_signed.go +74 -0
- package/govendor/golang.org/x/sys/unix/ioctl_unsigned.go +74 -0
- package/govendor/golang.org/x/sys/unix/ioctl_zos.go +71 -0
- package/govendor/golang.org/x/sys/unix/mkall.sh +250 -0
- package/govendor/golang.org/x/sys/unix/mkerrors.sh +807 -0
- package/govendor/golang.org/x/sys/unix/mmap_nomremap.go +13 -0
- package/govendor/golang.org/x/sys/unix/mremap.go +57 -0
- package/govendor/golang.org/x/sys/unix/pagesize_unix.go +15 -0
- package/govendor/golang.org/x/sys/unix/pledge_openbsd.go +111 -0
- package/govendor/golang.org/x/sys/unix/ptrace_darwin.go +11 -0
- package/govendor/golang.org/x/sys/unix/ptrace_ios.go +11 -0
- package/govendor/golang.org/x/sys/unix/race.go +30 -0
- package/govendor/golang.org/x/sys/unix/race0.go +25 -0
- package/govendor/golang.org/x/sys/unix/readdirent_getdents.go +12 -0
- package/govendor/golang.org/x/sys/unix/readdirent_getdirentries.go +19 -0
- package/govendor/golang.org/x/sys/unix/readv_unix.go +103 -0
- package/govendor/golang.org/x/sys/unix/sockcmsg_dragonfly.go +16 -0
- package/govendor/golang.org/x/sys/unix/sockcmsg_linux.go +85 -0
- package/govendor/golang.org/x/sys/unix/sockcmsg_unix.go +106 -0
- package/govendor/golang.org/x/sys/unix/sockcmsg_unix_other.go +46 -0
- package/govendor/golang.org/x/sys/unix/sockcmsg_zos.go +58 -0
- package/govendor/golang.org/x/sys/unix/symaddr_zos_s390x.s +75 -0
- package/govendor/golang.org/x/sys/unix/syscall.go +86 -0
- package/govendor/golang.org/x/sys/unix/syscall_aix.go +582 -0
- package/govendor/golang.org/x/sys/unix/syscall_aix_ppc.go +52 -0
- package/govendor/golang.org/x/sys/unix/syscall_aix_ppc64.go +83 -0
- package/govendor/golang.org/x/sys/unix/syscall_bsd.go +609 -0
- package/govendor/golang.org/x/sys/unix/syscall_darwin.go +711 -0
- package/govendor/golang.org/x/sys/unix/syscall_darwin_amd64.go +50 -0
- package/govendor/golang.org/x/sys/unix/syscall_darwin_arm64.go +50 -0
- package/govendor/golang.org/x/sys/unix/syscall_darwin_libSystem.go +26 -0
- package/govendor/golang.org/x/sys/unix/syscall_dragonfly.go +359 -0
- package/govendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go +56 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd.go +455 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd_386.go +64 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go +64 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd_arm.go +60 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd_arm64.go +60 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd_riscv64.go +60 -0
- package/govendor/golang.org/x/sys/unix/syscall_hurd.go +30 -0
- package/govendor/golang.org/x/sys/unix/syscall_hurd_386.go +28 -0
- package/govendor/golang.org/x/sys/unix/syscall_illumos.go +78 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux.go +2574 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_386.go +313 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_alarm.go +12 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_amd64.go +144 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go +12 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_arm.go +218 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_arm64.go +188 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_gc.go +14 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_gc_386.go +16 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_gc_arm.go +13 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go +30 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go +20 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_loong64.go +220 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_mips64x.go +187 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_mipsx.go +173 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_ppc.go +203 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go +114 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_riscv64.go +193 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_s390x.go +295 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +111 -0
- package/govendor/golang.org/x/sys/unix/syscall_netbsd.go +388 -0
- package/govendor/golang.org/x/sys/unix/syscall_netbsd_386.go +37 -0
- package/govendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go +37 -0
- package/govendor/golang.org/x/sys/unix/syscall_netbsd_arm.go +37 -0
- package/govendor/golang.org/x/sys/unix/syscall_netbsd_arm64.go +37 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd.go +346 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_386.go +41 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go +41 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_arm.go +41 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_arm64.go +41 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_libc.go +26 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_mips64.go +39 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_ppc64.go +41 -0
- package/govendor/golang.org/x/sys/unix/syscall_openbsd_riscv64.go +41 -0
- package/govendor/golang.org/x/sys/unix/syscall_solaris.go +1183 -0
- package/govendor/golang.org/x/sys/unix/syscall_solaris_amd64.go +27 -0
- package/govendor/golang.org/x/sys/unix/syscall_unix.go +619 -0
- package/govendor/golang.org/x/sys/unix/syscall_unix_gc.go +14 -0
- package/govendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go +22 -0
- package/govendor/golang.org/x/sys/unix/syscall_zos_s390x.go +3213 -0
- package/govendor/golang.org/x/sys/unix/sysvshm_linux.go +20 -0
- package/govendor/golang.org/x/sys/unix/sysvshm_unix.go +51 -0
- package/govendor/golang.org/x/sys/unix/sysvshm_unix_other.go +13 -0
- package/govendor/golang.org/x/sys/unix/timestruct.go +76 -0
- package/govendor/golang.org/x/sys/unix/unveil_openbsd.go +51 -0
- package/govendor/golang.org/x/sys/unix/vgetrandom_linux.go +13 -0
- package/govendor/golang.org/x/sys/unix/vgetrandom_unsupported.go +11 -0
- package/govendor/golang.org/x/sys/unix/xattr_bsd.go +280 -0
- package/govendor/golang.org/x/sys/unix/zerrors_aix_ppc.go +1384 -0
- package/govendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go +1385 -0
- package/govendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +1922 -0
- package/govendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +1922 -0
- package/govendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go +1737 -0
- package/govendor/golang.org/x/sys/unix/zerrors_freebsd_386.go +2042 -0
- package/govendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go +2039 -0
- package/govendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go +2033 -0
- package/govendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go +2033 -0
- package/govendor/golang.org/x/sys/unix/zerrors_freebsd_riscv64.go +2147 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux.go +4209 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_386.go +882 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +882 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_arm.go +887 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +884 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +874 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips.go +888 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +888 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +888 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +888 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +940 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +944 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +944 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +884 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +943 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +992 -0
- package/govendor/golang.org/x/sys/unix/zerrors_netbsd_386.go +1779 -0
- package/govendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go +1769 -0
- package/govendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go +1758 -0
- package/govendor/golang.org/x/sys/unix/zerrors_netbsd_arm64.go +1769 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_386.go +1905 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go +1905 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go +1905 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_arm64.go +1905 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_mips64.go +1905 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_ppc64.go +1904 -0
- package/govendor/golang.org/x/sys/unix/zerrors_openbsd_riscv64.go +1903 -0
- package/govendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go +1556 -0
- package/govendor/golang.org/x/sys/unix/zerrors_zos_s390x.go +990 -0
- package/govendor/golang.org/x/sys/unix/zptrace_armnn_linux.go +40 -0
- package/govendor/golang.org/x/sys/unix/zptrace_linux_arm64.go +17 -0
- package/govendor/golang.org/x/sys/unix/zptrace_mipsnn_linux.go +49 -0
- package/govendor/golang.org/x/sys/unix/zptrace_mipsnnle_linux.go +49 -0
- package/govendor/golang.org/x/sys/unix/zptrace_x86_linux.go +79 -0
- package/govendor/golang.org/x/sys/unix/zsymaddr_zos_s390x.s +364 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go +1461 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go +1420 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go +1188 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go +1069 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +2728 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +799 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +2728 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +799 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go +1666 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +1886 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +1886 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +1886 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +1886 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_riscv64.go +1886 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go +101 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux.go +2267 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_386.go +469 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +636 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_arm.go +584 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go +535 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go +469 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +636 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +630 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go +619 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +636 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +641 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +687 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +687 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go +531 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +478 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +631 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +1848 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +1848 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +1848 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +1848 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_386.s +719 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.s +719 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.s +719 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.s +719 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.s +719 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_ppc64.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_ppc64.s +862 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_riscv64.go +2407 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_riscv64.s +719 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +2217 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_zos_s390x.go +3458 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go +280 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go +280 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go +280 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_arm64.go +280 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_mips64.go +280 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_ppc64.go +280 -0
- package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_riscv64.go +281 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go +439 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go +437 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go +316 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go +393 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go +393 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go +393 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_arm64.go +393 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_riscv64.go +393 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_386.go +470 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +394 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +434 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +337 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go +334 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +454 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +384 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +384 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +454 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +461 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +433 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +433 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +338 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +399 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +413 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go +274 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go +274 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go +274 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_arm64.go +274 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go +219 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go +219 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go +219 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_arm64.go +218 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_mips64.go +221 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_ppc64.go +217 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_riscv64.go +218 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_zos_s390x.go +2852 -0
- package/govendor/golang.org/x/sys/unix/ztypes_aix_ppc.go +353 -0
- package/govendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go +357 -0
- package/govendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go +878 -0
- package/govendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go +878 -0
- package/govendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go +473 -0
- package/govendor/golang.org/x/sys/unix/ztypes_freebsd_386.go +651 -0
- package/govendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go +656 -0
- package/govendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go +642 -0
- package/govendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go +636 -0
- package/govendor/golang.org/x/sys/unix/ztypes_freebsd_riscv64.go +638 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux.go +6547 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_386.go +747 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +761 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_arm.go +741 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +740 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +741 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips.go +746 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +743 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +743 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +746 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +754 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +749 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +749 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +828 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +763 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +744 -0
- package/govendor/golang.org/x/sys/unix/ztypes_netbsd_386.go +585 -0
- package/govendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go +593 -0
- package/govendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go +590 -0
- package/govendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go +593 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_386.go +568 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go +568 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go +575 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go +568 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go +568 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_ppc64.go +570 -0
- package/govendor/golang.org/x/sys/unix/ztypes_openbsd_riscv64.go +570 -0
- package/govendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go +516 -0
- package/govendor/golang.org/x/sys/unix/ztypes_zos_s390x.go +552 -0
- package/govendor/golang.org/x/sys/windows/aliases.go +13 -0
- package/govendor/golang.org/x/sys/windows/dll_windows.go +380 -0
- package/govendor/golang.org/x/sys/windows/env_windows.go +57 -0
- package/govendor/golang.org/x/sys/windows/eventlog.go +20 -0
- package/govendor/golang.org/x/sys/windows/exec_windows.go +248 -0
- package/govendor/golang.org/x/sys/windows/memory_windows.go +48 -0
- package/govendor/golang.org/x/sys/windows/mkerrors.bash +70 -0
- package/govendor/golang.org/x/sys/windows/mkknownfolderids.bash +27 -0
- package/govendor/golang.org/x/sys/windows/mksyscall.go +9 -0
- package/govendor/golang.org/x/sys/windows/race.go +30 -0
- package/govendor/golang.org/x/sys/windows/race0.go +25 -0
- package/govendor/golang.org/x/sys/windows/security_windows.go +1537 -0
- package/govendor/golang.org/x/sys/windows/service.go +257 -0
- package/govendor/golang.org/x/sys/windows/setupapi_windows.go +1425 -0
- package/govendor/golang.org/x/sys/windows/str.go +22 -0
- package/govendor/golang.org/x/sys/windows/syscall.go +104 -0
- package/govendor/golang.org/x/sys/windows/syscall_windows.go +1952 -0
- package/govendor/golang.org/x/sys/windows/types_windows.go +4058 -0
- package/govendor/golang.org/x/sys/windows/types_windows_386.go +35 -0
- package/govendor/golang.org/x/sys/windows/types_windows_amd64.go +34 -0
- package/govendor/golang.org/x/sys/windows/types_windows_arm.go +35 -0
- package/govendor/golang.org/x/sys/windows/types_windows_arm64.go +34 -0
- package/govendor/golang.org/x/sys/windows/zerrors_windows.go +9468 -0
- package/govendor/golang.org/x/sys/windows/zknownfolderids_windows.go +149 -0
- package/govendor/golang.org/x/sys/windows/zsyscall_windows.go +4828 -0
- package/govendor/manifest.txt +7 -0
- package/package.json +6 -1
- package/tsparser/main.go +37 -3
- package/tsparser/tsparser.exe +2 -2
- package/types/typenative-go.d.ts +15159 -5
- package/types/typenative-npm.d.ts +2637 -30
- package/types/typenative.d.ts +1092 -56
package/bin/go/bridge.js
ADDED
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
// Go bridge: name resolution and emitters for `go:*` imports.
|
|
2
|
+
//
|
|
3
|
+
// Resolves package members (default, namespace and named imports), emits
|
|
4
|
+
// calls with argument/result conversion, struct construction, field access
|
|
5
|
+
// and method calls through the metadata method set.
|
|
6
|
+
//
|
|
7
|
+
// Kept in a plain style because this file is part of the self-hosted
|
|
8
|
+
// compiler and must transpile with TypeNative.
|
|
9
|
+
import { goPackage, goTypeInfo, allGoPaths } from './metadata.js';
|
|
10
|
+
import { toGo, fromGo, mustCall, checkCall, isGoNumericKind } from './convert.js';
|
|
11
|
+
import { isSyncCallback, isBlockingCall, goPathAliases } from './overrides.js';
|
|
12
|
+
let services = {
|
|
13
|
+
pkg: (_name) => { },
|
|
14
|
+
helper: (_id) => { },
|
|
15
|
+
temp: (prefix) => prefix,
|
|
16
|
+
typeOf: (_node) => '',
|
|
17
|
+
visit: (_node) => '',
|
|
18
|
+
categoryOf: (_node) => '',
|
|
19
|
+
goTypeOf: (_node) => 'interface{}',
|
|
20
|
+
isIdentifier: (_node) => false,
|
|
21
|
+
isPropertyAccess: (_node) => false,
|
|
22
|
+
isArrowFunction: (_node) => false,
|
|
23
|
+
isFunctionExpression: (_node) => false,
|
|
24
|
+
isObjectLiteral: (_node) => false,
|
|
25
|
+
declareLocal: (_name, _goType) => { }
|
|
26
|
+
};
|
|
27
|
+
export function bindBridgeServices(s) {
|
|
28
|
+
services = s;
|
|
29
|
+
}
|
|
30
|
+
// Local import name → Go package path ('strings' → 'strings').
|
|
31
|
+
const localToPath = {};
|
|
32
|
+
// Local name → qualified member ('Sprintf' → 'fmt.Sprintf').
|
|
33
|
+
const memberAliases = {};
|
|
34
|
+
// Package path → local qualifier used in emitted code.
|
|
35
|
+
const pathToLocal = {};
|
|
36
|
+
export function resetGoBridge() {
|
|
37
|
+
for (const key of Object.keys(localToPath))
|
|
38
|
+
delete localToPath[key];
|
|
39
|
+
for (const key of Object.keys(memberAliases))
|
|
40
|
+
delete memberAliases[key];
|
|
41
|
+
for (const key of Object.keys(pathToLocal))
|
|
42
|
+
delete pathToLocal[key];
|
|
43
|
+
}
|
|
44
|
+
export function registerGoImport(path, qualifier, defaultName, namespaceName, named) {
|
|
45
|
+
pathToLocal[path] = qualifier;
|
|
46
|
+
if (defaultName) {
|
|
47
|
+
localToPath[defaultName] = path;
|
|
48
|
+
if (defaultName !== qualifier)
|
|
49
|
+
memberAliases[defaultName] = qualifier;
|
|
50
|
+
}
|
|
51
|
+
if (namespaceName) {
|
|
52
|
+
localToPath[namespaceName] = path;
|
|
53
|
+
if (namespaceName !== qualifier)
|
|
54
|
+
memberAliases[namespaceName] = qualifier;
|
|
55
|
+
}
|
|
56
|
+
for (const entry of named) {
|
|
57
|
+
memberAliases[entry.local] = `${qualifier}.${entry.imported}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Register a go:builtin local name (ref/chan/GoError have no Go import).
|
|
61
|
+
export function registerGoBuiltin(local, imported) {
|
|
62
|
+
memberAliases[local] = `go:builtin.${imported}`;
|
|
63
|
+
}
|
|
64
|
+
// Qualifier used in emitted code for a package path.
|
|
65
|
+
export function goQualifier(path) {
|
|
66
|
+
if (pathToLocal[path])
|
|
67
|
+
return pathToLocal[path];
|
|
68
|
+
const info = goPackage(path);
|
|
69
|
+
const name = info ? info.name : (path.split('/').pop() ?? path);
|
|
70
|
+
return goPathAliases[path] ?? name;
|
|
71
|
+
}
|
|
72
|
+
// Register the qualifier for a package pulled in only as a type reference.
|
|
73
|
+
export function ensureGoQualifier(path) {
|
|
74
|
+
if (!pathToLocal[path]) {
|
|
75
|
+
pathToLocal[path] = goQualifier(path);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Package path of a local namespace name, '' when none.
|
|
79
|
+
export function goPathOf(local) {
|
|
80
|
+
// Own keys only: a local named `constructor` must not hit Object.prototype.
|
|
81
|
+
return Object.hasOwn(localToPath, local) ? localToPath[local] : '';
|
|
82
|
+
}
|
|
83
|
+
// Qualified member of a local name ('Sprintf' → 'fmt.Sprintf'), '' when none.
|
|
84
|
+
export function goMemberOf(local) {
|
|
85
|
+
return Object.hasOwn(memberAliases, local) ? memberAliases[local] : '';
|
|
86
|
+
}
|
|
87
|
+
// Ensure the packages named by a Go type are imported (cross-package
|
|
88
|
+
// result types like hash.Hash32 need their own import).
|
|
89
|
+
export function ensureGoTypePackages(goType) {
|
|
90
|
+
if (!goType)
|
|
91
|
+
return;
|
|
92
|
+
const cleaned = goType.replace(/\[[^\]]*\]/g, ' ').replace(/[*,{}()]/g, ' ');
|
|
93
|
+
for (const part of cleaned.split(/\s+/)) {
|
|
94
|
+
if (!part || part === 'error' || part === 'any' || part === 'interface{}')
|
|
95
|
+
continue;
|
|
96
|
+
const dot = part.lastIndexOf('.');
|
|
97
|
+
if (dot < 0)
|
|
98
|
+
continue;
|
|
99
|
+
const path = part.slice(0, dot);
|
|
100
|
+
if (knownPaths[path]) {
|
|
101
|
+
services.pkg(path);
|
|
102
|
+
ensureGoQualifier(path);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let knownPaths = {};
|
|
107
|
+
export function initKnownPaths() {
|
|
108
|
+
knownPaths = {};
|
|
109
|
+
for (const p of allGoPaths())
|
|
110
|
+
knownPaths[p] = true;
|
|
111
|
+
}
|
|
112
|
+
// Split 'qualifier.Member' into path + member using the import table.
|
|
113
|
+
export function splitGoMember(qualified) {
|
|
114
|
+
const dot = qualified.indexOf('.');
|
|
115
|
+
if (dot < 0)
|
|
116
|
+
return null;
|
|
117
|
+
const qualifier = qualified.slice(0, dot);
|
|
118
|
+
const member = qualified.slice(dot + 1);
|
|
119
|
+
for (const path of Object.keys(pathToLocal)) {
|
|
120
|
+
if (pathToLocal[path] === qualifier)
|
|
121
|
+
return { path, member };
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
// Rewrite a metadata Go type with the emitted qualifiers
|
|
126
|
+
// (*compress/gzip.Writer → *gzip.Writer, *net/url.URL → *tnurl.URL).
|
|
127
|
+
export function goLocalType(goType) {
|
|
128
|
+
if (!goType)
|
|
129
|
+
return goType;
|
|
130
|
+
let out = goType;
|
|
131
|
+
for (const path of Object.keys(pathToLocal)) {
|
|
132
|
+
const qualifier = pathToLocal[path];
|
|
133
|
+
out = out.split(path + '.').join(qualifier + '.');
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
// Whether an identifier or property access refers to a Go bridge member.
|
|
138
|
+
export function isGoMember(node) {
|
|
139
|
+
if (services.isIdentifier(node)) {
|
|
140
|
+
return goMemberOf(node.text) !== '';
|
|
141
|
+
}
|
|
142
|
+
if (services.isPropertyAccess(node)) {
|
|
143
|
+
const base = node.expression;
|
|
144
|
+
if (services.isIdentifier(base) && goPathOf(base.text))
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
// Emitted qualifier + member for a callee expression.
|
|
150
|
+
function calleeTarget(callee) {
|
|
151
|
+
if (services.isIdentifier(callee)) {
|
|
152
|
+
const qualified = goMemberOf(callee.text);
|
|
153
|
+
if (!qualified)
|
|
154
|
+
return null;
|
|
155
|
+
const split = splitGoMember(qualified);
|
|
156
|
+
if (!split)
|
|
157
|
+
return null;
|
|
158
|
+
return { path: split.path, member: split.member, qualifier: goQualifier(split.path) };
|
|
159
|
+
}
|
|
160
|
+
if (services.isPropertyAccess(callee)) {
|
|
161
|
+
const base = callee.expression;
|
|
162
|
+
if (!services.isIdentifier(base))
|
|
163
|
+
return null;
|
|
164
|
+
const path = goPathOf(base.text);
|
|
165
|
+
if (!path)
|
|
166
|
+
return null;
|
|
167
|
+
return { path, member: callee.name.text, qualifier: goQualifier(path) };
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
// Local name of a go:builtin function (ref/chan), '' when none.
|
|
172
|
+
function goBuiltinName(callee) {
|
|
173
|
+
if (services.isIdentifier(callee)) {
|
|
174
|
+
const qualified = goMemberOf(callee.text);
|
|
175
|
+
if (qualified && qualified.startsWith('go:builtin.')) {
|
|
176
|
+
return qualified.slice('go:builtin.'.length);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return '';
|
|
180
|
+
}
|
|
181
|
+
// Whether the node is a go:builtin ref<T>(init?) call.
|
|
182
|
+
export function isGoRefCall(node) {
|
|
183
|
+
return !!node && node.kind === 'CallExpression' && goBuiltinName(node.expression) === 'ref';
|
|
184
|
+
}
|
|
185
|
+
// go:builtin calls: ref<T>(init?) → new(T), chan<T>(size?) → make(chan T).
|
|
186
|
+
function visitGoBuiltinCall(node) {
|
|
187
|
+
const name = goBuiltinName(node.expression);
|
|
188
|
+
if (!name)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (name === 'ref') {
|
|
191
|
+
const typeArg = (node.typeArguments ?? [])[0];
|
|
192
|
+
const goType = typeArg ? services.goTypeOf(typeArg) : 'interface{}';
|
|
193
|
+
const arg = (node.arguments ?? [])[0];
|
|
194
|
+
if (arg) {
|
|
195
|
+
return `func() *${goType} { v := ${services.goTypeOf(typeArg ?? arg)}(${services.visit(arg)}); return &v }()`;
|
|
196
|
+
}
|
|
197
|
+
return `new(${goType})`;
|
|
198
|
+
}
|
|
199
|
+
if (name === 'chan') {
|
|
200
|
+
const size = (node.arguments ?? [])[0];
|
|
201
|
+
// Element type from the contextual annotation is unavailable here;
|
|
202
|
+
// default to interface{} (callers annotate: const ch: GoChan<T> = ...).
|
|
203
|
+
if (size)
|
|
204
|
+
return `make(chan interface{}, int(${services.visit(size)}))`;
|
|
205
|
+
return 'make(chan interface{})';
|
|
206
|
+
}
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
// Emit a call of a Go package function with argument/result conversion.
|
|
210
|
+
export function visitGoCall(node) {
|
|
211
|
+
const builtin = visitGoBuiltinCall(node);
|
|
212
|
+
if (builtin !== undefined)
|
|
213
|
+
return builtin;
|
|
214
|
+
const target = calleeTarget(node.expression);
|
|
215
|
+
if (!target)
|
|
216
|
+
return undefined;
|
|
217
|
+
const info = goPackage(target.path);
|
|
218
|
+
if (!info)
|
|
219
|
+
return undefined;
|
|
220
|
+
const fn = info.funcs[target.member];
|
|
221
|
+
if (!fn)
|
|
222
|
+
return undefined;
|
|
223
|
+
services.pkg(target.path);
|
|
224
|
+
const argNodes = node.arguments ?? [];
|
|
225
|
+
// Generic functions: params with the inferred type args (callbacks get
|
|
226
|
+
// concrete signatures: maps.DeleteFunc's func(K, V) bool).
|
|
227
|
+
let params = fn.params;
|
|
228
|
+
if (fn.tparams.length > 0) {
|
|
229
|
+
const subst = inferTypeArgs(fn, argNodes);
|
|
230
|
+
const substituted = [];
|
|
231
|
+
for (const p of fn.params)
|
|
232
|
+
substituted.push({ name: p.name, goType: substituteType(p.goType, subst) });
|
|
233
|
+
params = substituted;
|
|
234
|
+
}
|
|
235
|
+
const args = emitGoArgs(argNodes, params, fn.variadic, target.path, target.member);
|
|
236
|
+
let call = `${target.qualifier}.${target.member}(${args.join(', ')})`;
|
|
237
|
+
const results = instantiateResults(fn, argNodes);
|
|
238
|
+
for (const r of results)
|
|
239
|
+
ensureGoTypePackages(r);
|
|
240
|
+
if (isBlockingCall(target.path, target.member)) {
|
|
241
|
+
call = emitBlocking(call, results, isStatement(node));
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
call = emitResults(call, results, isStatement(node));
|
|
245
|
+
}
|
|
246
|
+
return call;
|
|
247
|
+
}
|
|
248
|
+
// Substitute a generic function's type params from the argument types
|
|
249
|
+
// (slices.Values[Slice ~[]E, E any](s Slice) iter.Seq[E] on a []float64
|
|
250
|
+
// arg → iter.Seq[float64]). Type params nothing pins down become any.
|
|
251
|
+
function instantiateResults(fn, argNodes) {
|
|
252
|
+
if (fn.tparams.length === 0)
|
|
253
|
+
return fn.results;
|
|
254
|
+
const subst = inferTypeArgs(fn, argNodes);
|
|
255
|
+
return fn.results.map((r) => substituteType(r, subst));
|
|
256
|
+
}
|
|
257
|
+
function inferTypeArgs(fn, argNodes) {
|
|
258
|
+
const cores = {};
|
|
259
|
+
for (let i = 0; i < fn.tparams.length; i++) {
|
|
260
|
+
cores[fn.tparams[i]] = fn.tcores[i] ?? '';
|
|
261
|
+
}
|
|
262
|
+
const subst = {};
|
|
263
|
+
for (let i = 0; i < argNodes.length && fn.params.length > 0; i++) {
|
|
264
|
+
const param = fn.params[Math.min(i, fn.params.length - 1)];
|
|
265
|
+
unifyParam(param.goType.replace(/^\.\.\./, ''), services.typeOf(argNodes[i]) ?? '', subst, cores);
|
|
266
|
+
}
|
|
267
|
+
for (const tp of fn.tparams) {
|
|
268
|
+
if (!Object.hasOwn(subst, tp))
|
|
269
|
+
subst[tp] = 'any';
|
|
270
|
+
}
|
|
271
|
+
return subst;
|
|
272
|
+
}
|
|
273
|
+
function unifyParam(paramType, argType, subst, cores) {
|
|
274
|
+
if (!paramType || !argType)
|
|
275
|
+
return;
|
|
276
|
+
// TS arrays are slice references.
|
|
277
|
+
if (argType.startsWith('*[]'))
|
|
278
|
+
argType = argType.slice(1);
|
|
279
|
+
// A type param: bind it, then match its constraint's core type
|
|
280
|
+
// (Map ~map[K]V binds K and V too).
|
|
281
|
+
// Object.hasOwn: a missing key reads as '' (not undefined) once self-hosted.
|
|
282
|
+
if (Object.hasOwn(cores, paramType)) {
|
|
283
|
+
if (!Object.hasOwn(subst, paramType))
|
|
284
|
+
subst[paramType] = argType;
|
|
285
|
+
if (cores[paramType])
|
|
286
|
+
unifyParam(cores[paramType], argType, subst, cores);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (paramType.startsWith('[]') && argType.startsWith('[]')) {
|
|
290
|
+
unifyParam(paramType.slice(2), argType.slice(2), subst, cores);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (paramType.startsWith('*') && argType.startsWith('*')) {
|
|
294
|
+
unifyParam(paramType.slice(1), argType.slice(1), subst, cores);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (paramType.startsWith('map[') && argType.startsWith('map[')) {
|
|
298
|
+
const p = splitMapType(paramType);
|
|
299
|
+
const a = splitMapType(argType);
|
|
300
|
+
if (p && a) {
|
|
301
|
+
unifyParam(p[0], a[0], subst, cores);
|
|
302
|
+
unifyParam(p[1], a[1], subst, cores);
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// Generic named types: iter.Seq[E] against iter.Seq[float64].
|
|
307
|
+
const pOpen = paramType.indexOf('[');
|
|
308
|
+
const aOpen = argType.indexOf('[');
|
|
309
|
+
if (pOpen > 0 && aOpen > 0 && paramType.slice(0, pOpen) === argType.slice(0, aOpen) && paramType.endsWith(']') && argType.endsWith(']')) {
|
|
310
|
+
const pArgs = splitTopLevel(paramType.slice(pOpen + 1, -1));
|
|
311
|
+
const aArgs = splitTopLevel(argType.slice(aOpen + 1, -1));
|
|
312
|
+
for (let i = 0; i < pArgs.length && i < aArgs.length; i++)
|
|
313
|
+
unifyParam(pArgs[i], aArgs[i], subst, cores);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// 'map[K]V' → ['K', 'V'].
|
|
317
|
+
function splitMapType(goType) {
|
|
318
|
+
let depth = 0;
|
|
319
|
+
for (let i = 4; i < goType.length; i++) {
|
|
320
|
+
const ch = goType[i];
|
|
321
|
+
if (ch === '[')
|
|
322
|
+
depth++;
|
|
323
|
+
else if (ch === ']') {
|
|
324
|
+
if (depth === 0)
|
|
325
|
+
return [goType.slice(4, i), goType.slice(i + 1)];
|
|
326
|
+
depth--;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
// Replace type-param identifiers (not selector or path parts) in a Go type.
|
|
332
|
+
function substituteType(goType, subst) {
|
|
333
|
+
let out = '';
|
|
334
|
+
let i = 0;
|
|
335
|
+
while (i < goType.length) {
|
|
336
|
+
const ch = goType[i];
|
|
337
|
+
if (/[A-Za-z_]/.test(ch)) {
|
|
338
|
+
let j = i + 1;
|
|
339
|
+
while (j < goType.length && /[A-Za-z0-9_]/.test(goType[j]))
|
|
340
|
+
j++;
|
|
341
|
+
const word = goType.slice(i, j);
|
|
342
|
+
const prev = i > 0 ? goType[i - 1] : '';
|
|
343
|
+
// A selector (pkg.Name) or path part, but `...S` is a variadic param.
|
|
344
|
+
const selector = prev === '/' || (prev === '.' && !goType.slice(0, i).endsWith('...'));
|
|
345
|
+
out += !selector && Object.hasOwn(subst, word) ? subst[word] : word;
|
|
346
|
+
i = j;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
out += ch;
|
|
350
|
+
i++;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
// Whether the call node is used as a bare statement (its value discarded).
|
|
356
|
+
function isStatement(node) {
|
|
357
|
+
return !!node.parent && node.parent.kind === 'ExpressionStatement';
|
|
358
|
+
}
|
|
359
|
+
// Emit converted arguments.
|
|
360
|
+
function emitGoArgs(nodes, params, variadic, path, funcName) {
|
|
361
|
+
const out = [];
|
|
362
|
+
const intArgs = formatIntArgs(nodes, params, variadic);
|
|
363
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
364
|
+
const node = nodes[i];
|
|
365
|
+
const param = params[i] ?? params[params.length - 1];
|
|
366
|
+
// Callback arguments become Go closures with the exact signature.
|
|
367
|
+
if (param !== undefined &&
|
|
368
|
+
(services.isArrowFunction(node) || services.isFunctionExpression(node)) &&
|
|
369
|
+
isFuncType(param.goType)) {
|
|
370
|
+
out.push(emitCallback(node, param.goType, path, funcName));
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (param === undefined) {
|
|
374
|
+
out.push(services.visit(node));
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
let paramType = param.goType;
|
|
378
|
+
const isVariadicSlot = !!variadic && i >= params.length - 1;
|
|
379
|
+
if (isVariadicSlot) {
|
|
380
|
+
paramType = paramType.startsWith('...') ? paramType.slice(3) : paramType;
|
|
381
|
+
}
|
|
382
|
+
else if (paramType.startsWith('...')) {
|
|
383
|
+
paramType = paramType.slice(3);
|
|
384
|
+
}
|
|
385
|
+
// A slice filling a variadic slot spreads (f([a, b]) → f(a, b)).
|
|
386
|
+
const fromTypeEarly = services.typeOf(node) ?? '';
|
|
387
|
+
const fromSlice = fromTypeEarly.startsWith('*[]') ? fromTypeEarly.slice(1) : fromTypeEarly;
|
|
388
|
+
// `...any` takes the array as one value (fmt.Sprintf('%v', arr)).
|
|
389
|
+
const anyVariadic = paramType === 'any' || paramType === 'interface{}';
|
|
390
|
+
if (isVariadicSlot && !anyVariadic && fromSlice.startsWith('[]') && node.kind !== 'SpreadElement') {
|
|
391
|
+
out.push(`${services.visit(node)}...`);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
// Empty array literal into a slice slot: emit the typed empty literal.
|
|
395
|
+
if (paramType.startsWith('[]') &&
|
|
396
|
+
node.kind === 'ArrayLiteralExpression' &&
|
|
397
|
+
(node.elements ?? []).length === 0) {
|
|
398
|
+
out.push(`${paramType}{}`);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const visited = services.visit(node);
|
|
402
|
+
const fromType = services.typeOf(node) ?? '';
|
|
403
|
+
if (intArgs.includes(i) && fromType === 'float64') {
|
|
404
|
+
out.push(`int64(${visited})`);
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
ensureGoTypePackages(paramType);
|
|
408
|
+
out.push(toGo(visited, fromType, paramType));
|
|
409
|
+
}
|
|
410
|
+
// Trailing error params already thrown upstream (template.Must(t)):
|
|
411
|
+
// pad with nil so Go's Must wrappers type-check.
|
|
412
|
+
for (let i = nodes.length; i < params.length; i++) {
|
|
413
|
+
const paramType = params[i].goType;
|
|
414
|
+
if (paramType === 'error') {
|
|
415
|
+
out.push('nil');
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return out;
|
|
422
|
+
}
|
|
423
|
+
// printf-style calls (`format string, a ...any`) with a literal format:
|
|
424
|
+
// the argument indexes that feed an integer verb (%d %x %o %b %c %U). TS
|
|
425
|
+
// numbers are float64, which those verbs reject, so they pass as int64.
|
|
426
|
+
function formatIntArgs(nodes, params, variadic) {
|
|
427
|
+
const flags = [];
|
|
428
|
+
if (!variadic || params.length < 2)
|
|
429
|
+
return flags;
|
|
430
|
+
const last = params[params.length - 1].goType;
|
|
431
|
+
if (last !== '...any' && last !== '...interface{}')
|
|
432
|
+
return flags;
|
|
433
|
+
const formatIndex = params.length - 2;
|
|
434
|
+
if (params[formatIndex].name !== 'format' || params[formatIndex].goType !== 'string')
|
|
435
|
+
return flags;
|
|
436
|
+
const formatNode = nodes[formatIndex];
|
|
437
|
+
if (!formatNode || (formatNode.kind !== 'StringLiteral' && formatNode.kind !== 'NoSubstitutionTemplateLiteral'))
|
|
438
|
+
return flags;
|
|
439
|
+
const format = formatNode.text ?? '';
|
|
440
|
+
let arg = formatIndex + 1;
|
|
441
|
+
for (let i = 0; i < format.length; i++) {
|
|
442
|
+
if (format[i] !== '%')
|
|
443
|
+
continue;
|
|
444
|
+
i++;
|
|
445
|
+
// Flags, width, precision; `*` consumes an argument.
|
|
446
|
+
while (i < format.length && '+-# 0123456789.*[]'.indexOf(format[i]) >= 0) {
|
|
447
|
+
if (format[i] === '*')
|
|
448
|
+
arg++;
|
|
449
|
+
i++;
|
|
450
|
+
}
|
|
451
|
+
if (i >= format.length || format[i] === '%')
|
|
452
|
+
continue;
|
|
453
|
+
if ('dxXobcOU'.indexOf(format[i]) >= 0)
|
|
454
|
+
flags.push(arg);
|
|
455
|
+
arg++;
|
|
456
|
+
}
|
|
457
|
+
return flags;
|
|
458
|
+
}
|
|
459
|
+
// Wrap results: (T, error) throws, error-only throws as a statement and
|
|
460
|
+
// yields the error value in value position, tuples pass through.
|
|
461
|
+
function emitResults(call, results, asStatement = false) {
|
|
462
|
+
if (results.length === 0)
|
|
463
|
+
return call;
|
|
464
|
+
const last = results[results.length - 1];
|
|
465
|
+
if (last === 'error') {
|
|
466
|
+
const core = results.slice(0, -1);
|
|
467
|
+
if (core.length === 0) {
|
|
468
|
+
if (asStatement)
|
|
469
|
+
return checkCall(call);
|
|
470
|
+
return call;
|
|
471
|
+
}
|
|
472
|
+
const wrapped = mustCall(call, core.length);
|
|
473
|
+
if (asStatement)
|
|
474
|
+
return wrapped;
|
|
475
|
+
if (core.length === 1)
|
|
476
|
+
return fromGo(wrapped, core[0]);
|
|
477
|
+
// (A, B, error): pack the two values into a slice.
|
|
478
|
+
const temps = core.map((_, i) => `__v${i}`);
|
|
479
|
+
return `func() []interface{} { ${temps.join(', ')} := ${wrapped}; return []interface{}{${packTuple(temps, core)}} }()`;
|
|
480
|
+
}
|
|
481
|
+
if (results.length === 1) {
|
|
482
|
+
if (asStatement)
|
|
483
|
+
return call;
|
|
484
|
+
return fromGo(call, results[0]);
|
|
485
|
+
}
|
|
486
|
+
// Multiple values: pack into a slice (TS tuple). Multi-value calls can't
|
|
487
|
+
// appear in a composite literal, so go through temps.
|
|
488
|
+
if (asStatement)
|
|
489
|
+
return call;
|
|
490
|
+
const temps = results.map((_, i) => `__v${i}`);
|
|
491
|
+
return `func() []interface{} { ${temps.join(', ')} := ${call}; return []interface{}{${packTuple(temps, results)}} }()`;
|
|
492
|
+
}
|
|
493
|
+
// Tuple elements read as TS-facing values (ints → float64), matching
|
|
494
|
+
// goTupleTypes so destructuring can assert them back.
|
|
495
|
+
function packTuple(temps, types) {
|
|
496
|
+
return temps.map((t, i) => fromGo(t, types[i])).join(', ');
|
|
497
|
+
}
|
|
498
|
+
// TS-facing element types of a multi-value Go call ((A, B) or
|
|
499
|
+
// (A, B, error)); undefined for anything else.
|
|
500
|
+
export function goTupleTypes(node) {
|
|
501
|
+
if (!node || node.kind !== 'CallExpression')
|
|
502
|
+
return undefined;
|
|
503
|
+
const results = goCallResults(node);
|
|
504
|
+
if (results === undefined)
|
|
505
|
+
return undefined;
|
|
506
|
+
const core = results.length > 0 && results[results.length - 1] === 'error' ? results.slice(0, -1) : results;
|
|
507
|
+
if (core.length < 2)
|
|
508
|
+
return undefined;
|
|
509
|
+
return core.map((t) => goResultType([t]) ?? 'interface{}');
|
|
510
|
+
}
|
|
511
|
+
// Go result types of a call of a Go function or method, undefined when it is not one
|
|
512
|
+
function goCallResults(node) {
|
|
513
|
+
const target = calleeTarget(node.expression);
|
|
514
|
+
if (target) {
|
|
515
|
+
const fn = goPackage(target.path)?.funcs[target.member];
|
|
516
|
+
if (fn)
|
|
517
|
+
return instantiateResults(fn, node.arguments ?? []);
|
|
518
|
+
return undefined;
|
|
519
|
+
}
|
|
520
|
+
if (services.isPropertyAccess(node.expression)) {
|
|
521
|
+
const recvType = services.typeOf(node.expression.expression);
|
|
522
|
+
const method = recvType !== '' ? goMethodInfo(recvType, node.expression.name.text) : null;
|
|
523
|
+
if (method)
|
|
524
|
+
return method.results;
|
|
525
|
+
}
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
528
|
+
// Wrap a blocking call so it runs on a goroutine while the baton holder
|
|
529
|
+
// pumps pending loop tasks.
|
|
530
|
+
function emitBlocking(call, results, asStatement = false) {
|
|
531
|
+
services.helper('goBlocking');
|
|
532
|
+
const wrapped = `tnGoBlocking(func() interface{} { return ${call} })`;
|
|
533
|
+
return emitResults(wrapped, results, asStatement);
|
|
534
|
+
}
|
|
535
|
+
function isFuncType(goType) {
|
|
536
|
+
return goType.startsWith('func(') || goTypeInfo(goType) !== null && goTypeInfo(goType)?.kind === 'func';
|
|
537
|
+
}
|
|
538
|
+
// Go result type of a TS closure emitted as a Go callback; the transpiler
|
|
539
|
+
// converts its `return` values to it. Stored on the node itself: the
|
|
540
|
+
// self-hosted compiler's AST nodes are Go maps, which can't be map keys.
|
|
541
|
+
export function goCallbackResultType(fn) {
|
|
542
|
+
const result = fn.tnGoCallbackResult;
|
|
543
|
+
return typeof result === 'string' ? result : undefined;
|
|
544
|
+
}
|
|
545
|
+
// Emit a TS closure as a Go closure with the exact Go signature. Params
|
|
546
|
+
// the TS body sees as numbers (Go ints) are re-declared as float64.
|
|
547
|
+
function emitCallback(node, goType, path, funcName) {
|
|
548
|
+
const sig = parseFuncSig(goType);
|
|
549
|
+
if (!sig)
|
|
550
|
+
return services.visit(node);
|
|
551
|
+
const params = [];
|
|
552
|
+
const prelude = [];
|
|
553
|
+
for (let i = 0; i < sig.params.length; i++) {
|
|
554
|
+
const declared = (node.parameters ?? [])[i];
|
|
555
|
+
const name = declared && services.isIdentifier(declared.name) ? services.visit(declared.name) : `_`;
|
|
556
|
+
const paramType = stripParamName(sig.params[i]);
|
|
557
|
+
ensureGoTypePackages(paramType);
|
|
558
|
+
const tsType = goResultType([paramType]) ?? paramType;
|
|
559
|
+
if (name !== '_' && tsType !== paramType) {
|
|
560
|
+
const raw = services.temp('p');
|
|
561
|
+
params.push(`${raw} ${goLocalType(paramType)}`);
|
|
562
|
+
prelude.push(`${name} := ${fromGo(raw, paramType)}; _ = ${name}`);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
params.push(`${name} ${goLocalType(paramType)}`);
|
|
566
|
+
}
|
|
567
|
+
if (name !== '_')
|
|
568
|
+
services.declareLocal(name, tsType);
|
|
569
|
+
}
|
|
570
|
+
void isSyncCallback(path, funcName);
|
|
571
|
+
const result = sig.results.length === 1 ? sig.results[0] : '';
|
|
572
|
+
if (result) {
|
|
573
|
+
ensureGoTypePackages(result);
|
|
574
|
+
node.tnGoCallbackResult = result;
|
|
575
|
+
}
|
|
576
|
+
const resultDecl = sig.results.length > 0 ? ' ' + sig.results.map((r) => goLocalType(r)).join(', ') : '';
|
|
577
|
+
const head = `func(${params.join(', ')})${resultDecl}`;
|
|
578
|
+
const pre = prelude.length > 0 ? prelude.join('; ') + '; ' : '';
|
|
579
|
+
if (node.body && node.body.kind === 'Block') {
|
|
580
|
+
return `${head} { ${pre}${services.visit(node.body)} }`;
|
|
581
|
+
}
|
|
582
|
+
const body = services.visit(node.body);
|
|
583
|
+
if (!result)
|
|
584
|
+
return `${head} { ${pre}${body} }`;
|
|
585
|
+
return `${head} { ${pre}return ${toGo(body, services.typeOf(node.body) ?? '', result)} }`;
|
|
586
|
+
}
|
|
587
|
+
// "name T" → "T" (metadata signatures keep parameter names).
|
|
588
|
+
function stripParamName(param) {
|
|
589
|
+
const p = param.trim();
|
|
590
|
+
let depth = 0;
|
|
591
|
+
for (let i = 0; i < p.length; i++) {
|
|
592
|
+
const ch = p[i];
|
|
593
|
+
if (ch === '[' || ch === '(' || ch === '{')
|
|
594
|
+
depth++;
|
|
595
|
+
else if (ch === ']' || ch === ')' || ch === '}')
|
|
596
|
+
depth--;
|
|
597
|
+
else if (ch === ' ' && depth === 0) {
|
|
598
|
+
const head = p.slice(0, i);
|
|
599
|
+
const rest = p.slice(i + 1).trim();
|
|
600
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(head) && rest && head !== 'func' && head !== 'chan' && head !== 'map')
|
|
601
|
+
return rest;
|
|
602
|
+
return p;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return p;
|
|
606
|
+
}
|
|
607
|
+
function parseFuncSig(goType) {
|
|
608
|
+
if (!goType.startsWith('func(')) {
|
|
609
|
+
const info = goTypeInfo(goType);
|
|
610
|
+
if (!info || info.kind !== 'func')
|
|
611
|
+
return null;
|
|
612
|
+
goType = info.under;
|
|
613
|
+
}
|
|
614
|
+
if (!goType.startsWith('func('))
|
|
615
|
+
return null;
|
|
616
|
+
const rest = goType.slice(4);
|
|
617
|
+
let depth = 0;
|
|
618
|
+
for (let i = 0; i < rest.length; i++) {
|
|
619
|
+
if (rest[i] === '(')
|
|
620
|
+
depth++;
|
|
621
|
+
else if (rest[i] === ')') {
|
|
622
|
+
depth--;
|
|
623
|
+
if (depth === 0) {
|
|
624
|
+
const params = rest.slice(1, i);
|
|
625
|
+
const results = rest.slice(i + 1).trim();
|
|
626
|
+
return { params: splitTopLevel(results ? params : params), results: parseResultList(results) };
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
function splitTopLevel(s) {
|
|
633
|
+
const out = [];
|
|
634
|
+
let depth = 0;
|
|
635
|
+
let start = 0;
|
|
636
|
+
for (let i = 0; i < s.length; i++) {
|
|
637
|
+
const ch = s[i];
|
|
638
|
+
if (ch === '[' || ch === '(' || ch === '{')
|
|
639
|
+
depth++;
|
|
640
|
+
else if (ch === ']' || ch === ')' || ch === '}')
|
|
641
|
+
depth--;
|
|
642
|
+
else if (ch === ',' && depth === 0) {
|
|
643
|
+
out.push(s.slice(start, i).trim());
|
|
644
|
+
start = i + 1;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
const tail = s.slice(start).trim();
|
|
648
|
+
if (tail)
|
|
649
|
+
out.push(tail);
|
|
650
|
+
return out;
|
|
651
|
+
}
|
|
652
|
+
function parseResultList(s) {
|
|
653
|
+
s = s.trim();
|
|
654
|
+
if (!s)
|
|
655
|
+
return [];
|
|
656
|
+
if (s.startsWith('(') && s.endsWith(')'))
|
|
657
|
+
s = s.slice(1, -1);
|
|
658
|
+
return splitTopLevel(s);
|
|
659
|
+
}
|
|
660
|
+
// Infer the Go type of a bridge expression.
|
|
661
|
+
export function inferGoType(node) {
|
|
662
|
+
if (node && node.kind === 'CallExpression') {
|
|
663
|
+
const builtinName = goBuiltinName(node.expression);
|
|
664
|
+
if (builtinName === 'chan')
|
|
665
|
+
return 'chan interface{}';
|
|
666
|
+
if (builtinName === 'ref') {
|
|
667
|
+
const typeArg = (node.typeArguments ?? [])[0];
|
|
668
|
+
const goType = typeArg ? services.goTypeOf(typeArg) : 'interface{}';
|
|
669
|
+
return `*${goType}`;
|
|
670
|
+
}
|
|
671
|
+
const target = calleeTarget(node.expression);
|
|
672
|
+
if (target) {
|
|
673
|
+
const info = goPackage(target.path);
|
|
674
|
+
const fn = info?.funcs[target.member];
|
|
675
|
+
if (fn)
|
|
676
|
+
return goResultType(instantiateResults(fn, node.arguments ?? []));
|
|
677
|
+
// Conversion to a package type: token.Token(n) has its methods back.
|
|
678
|
+
if (info && Object.hasOwn(info.types, target.member))
|
|
679
|
+
return `${target.path}.${target.member}`;
|
|
680
|
+
}
|
|
681
|
+
// Method call on a Go-typed receiver.
|
|
682
|
+
if (services.isPropertyAccess(node.expression)) {
|
|
683
|
+
const recvType = services.typeOf(node.expression.expression);
|
|
684
|
+
if (recvType !== '') {
|
|
685
|
+
const method = goMethodInfo(recvType, node.expression.name.text);
|
|
686
|
+
if (method)
|
|
687
|
+
return goResultType(method.results);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
if (services.isIdentifier(node)) {
|
|
693
|
+
const qualified = goMemberOf(node.text);
|
|
694
|
+
if (!qualified)
|
|
695
|
+
return undefined;
|
|
696
|
+
if (qualified.startsWith('go:builtin.'))
|
|
697
|
+
return undefined;
|
|
698
|
+
if (qualified === 'go:builtin')
|
|
699
|
+
return undefined;
|
|
700
|
+
const split = splitGoMember(qualified);
|
|
701
|
+
if (!split)
|
|
702
|
+
return undefined;
|
|
703
|
+
const info = goPackage(split.path);
|
|
704
|
+
if (!info)
|
|
705
|
+
return undefined;
|
|
706
|
+
// A package qualifier alone has no value type.
|
|
707
|
+
if (split.member === goQualifier(split.path))
|
|
708
|
+
return undefined;
|
|
709
|
+
const fn = info.funcs[split.member];
|
|
710
|
+
if (fn)
|
|
711
|
+
return goResultType(fn.results);
|
|
712
|
+
const c = info.consts[split.member];
|
|
713
|
+
if (c) {
|
|
714
|
+
if (c.kind === 'typed' && c.goType)
|
|
715
|
+
return c.goType;
|
|
716
|
+
if (c.kind === 'string')
|
|
717
|
+
return 'string';
|
|
718
|
+
if (c.kind === 'bool')
|
|
719
|
+
return 'bool';
|
|
720
|
+
return 'float64';
|
|
721
|
+
}
|
|
722
|
+
const v = info.vars[split.member];
|
|
723
|
+
if (v)
|
|
724
|
+
return v.goType;
|
|
725
|
+
const t = info.types[split.member];
|
|
726
|
+
if (t)
|
|
727
|
+
return split.member;
|
|
728
|
+
return undefined;
|
|
729
|
+
}
|
|
730
|
+
if (services.isPropertyAccess(node)) {
|
|
731
|
+
const base = node.expression;
|
|
732
|
+
const member = node.name.text;
|
|
733
|
+
// Package member (pkg.Func, pkg.Const, pkg.Var, pkg.Type).
|
|
734
|
+
if (services.isIdentifier(base)) {
|
|
735
|
+
const path = goPathOf(base.text);
|
|
736
|
+
if (path) {
|
|
737
|
+
const info = goPackage(path);
|
|
738
|
+
if (!info)
|
|
739
|
+
return undefined;
|
|
740
|
+
const fn = info.funcs[member];
|
|
741
|
+
if (fn)
|
|
742
|
+
return goResultType(fn.results);
|
|
743
|
+
const c = info.consts[member];
|
|
744
|
+
if (c)
|
|
745
|
+
return constGoType(path, member);
|
|
746
|
+
const v = info.vars[member];
|
|
747
|
+
if (v)
|
|
748
|
+
return v.goType;
|
|
749
|
+
const t = info.types[member];
|
|
750
|
+
if (t)
|
|
751
|
+
return member;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
// Field or method on a Go-typed receiver (any base shape).
|
|
755
|
+
const recvType = services.typeOf(base);
|
|
756
|
+
if (recvType !== '') {
|
|
757
|
+
const field = goFieldType(recvType, member);
|
|
758
|
+
// Reads convert like results (int fields read as float64).
|
|
759
|
+
if (field)
|
|
760
|
+
return goResultType([field]);
|
|
761
|
+
const method = goMethodInfo(recvType, member);
|
|
762
|
+
if (method)
|
|
763
|
+
return goResultType(method.results);
|
|
764
|
+
}
|
|
765
|
+
return undefined;
|
|
766
|
+
}
|
|
767
|
+
return undefined;
|
|
768
|
+
}
|
|
769
|
+
function goResultType(results) {
|
|
770
|
+
if (results.length === 0)
|
|
771
|
+
return undefined;
|
|
772
|
+
const last = results[results.length - 1];
|
|
773
|
+
const core = last === 'error' ? results.slice(0, -1) : results;
|
|
774
|
+
if (core.length === 0)
|
|
775
|
+
return 'error';
|
|
776
|
+
if (core.length === 1) {
|
|
777
|
+
const t = core[0];
|
|
778
|
+
if (isGoNumericKind(t) && t !== 'float64')
|
|
779
|
+
return 'float64';
|
|
780
|
+
// Numeric slices read back as []float64 (fromGo); []byte stays.
|
|
781
|
+
if (t.startsWith('[]')) {
|
|
782
|
+
const elem = t.slice(2);
|
|
783
|
+
if (elem !== 'byte' && elem !== 'uint8' && elem !== 'float64' && isGoNumericKind(elem))
|
|
784
|
+
return '[]float64';
|
|
785
|
+
}
|
|
786
|
+
return t;
|
|
787
|
+
}
|
|
788
|
+
return '[]interface{}';
|
|
789
|
+
}
|
|
790
|
+
function constGoType(path, name) {
|
|
791
|
+
const info = goPackage(path);
|
|
792
|
+
const c = info?.consts[name];
|
|
793
|
+
if (!c)
|
|
794
|
+
return 'float64';
|
|
795
|
+
if (c.kind === 'typed' && c.goType)
|
|
796
|
+
return c.goType;
|
|
797
|
+
if (c.kind === 'string')
|
|
798
|
+
return 'string';
|
|
799
|
+
if (c.kind === 'bool')
|
|
800
|
+
return 'bool';
|
|
801
|
+
return 'float64';
|
|
802
|
+
}
|
|
803
|
+
// Field type of a Go struct value.
|
|
804
|
+
export function goFieldType(recvType, field) {
|
|
805
|
+
const info = goTypeInfo(recvType);
|
|
806
|
+
if (!info)
|
|
807
|
+
return undefined;
|
|
808
|
+
for (const f of info.fields) {
|
|
809
|
+
if (f.name === field)
|
|
810
|
+
return f.goType;
|
|
811
|
+
}
|
|
812
|
+
return undefined;
|
|
813
|
+
}
|
|
814
|
+
// Method info of a Go type (value or pointer receiver).
|
|
815
|
+
export function goMethodInfo(recvType, method) {
|
|
816
|
+
const info = goTypeInfo(recvType);
|
|
817
|
+
if (!info)
|
|
818
|
+
return null;
|
|
819
|
+
let found = null;
|
|
820
|
+
for (const m of info.methods) {
|
|
821
|
+
if (m.name === method)
|
|
822
|
+
found = m;
|
|
823
|
+
}
|
|
824
|
+
if (!found) {
|
|
825
|
+
for (const m of info.ifaceMethods) {
|
|
826
|
+
if (m.name === method)
|
|
827
|
+
found = m;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
if (!found || info.tparams.length === 0)
|
|
831
|
+
return found;
|
|
832
|
+
// Generic receiver (unique.Handle[string]): substitute its type args.
|
|
833
|
+
const open = recvType.indexOf('[');
|
|
834
|
+
if (open < 0 || !recvType.endsWith(']'))
|
|
835
|
+
return found;
|
|
836
|
+
const args = splitTopLevel(recvType.slice(open + 1, -1));
|
|
837
|
+
const subst = {};
|
|
838
|
+
for (let i = 0; i < info.tparams.length && i < args.length; i++)
|
|
839
|
+
subst[info.tparams[i]] = args[i];
|
|
840
|
+
const params = [];
|
|
841
|
+
for (const p of found.params)
|
|
842
|
+
params.push({ name: p.name, goType: substituteType(p.goType, subst) });
|
|
843
|
+
const substituted = {
|
|
844
|
+
name: found.name,
|
|
845
|
+
ptr: found.ptr,
|
|
846
|
+
params,
|
|
847
|
+
results: found.results.map((r) => substituteType(r, subst))
|
|
848
|
+
};
|
|
849
|
+
return substituted;
|
|
850
|
+
}
|
|
851
|
+
// Emit a method call on a Go value with conversion.
|
|
852
|
+
export function visitGoMethod(node, recv, recvType) {
|
|
853
|
+
if (!services.isPropertyAccess(node.expression))
|
|
854
|
+
return undefined;
|
|
855
|
+
const method = node.expression.name.text;
|
|
856
|
+
const info = goMethodInfo(recvType, method);
|
|
857
|
+
if (!info)
|
|
858
|
+
return undefined;
|
|
859
|
+
const args = emitGoArgs(node.arguments ?? [], info.params, false, '', '');
|
|
860
|
+
const call = `${recv}.${method}(${args.join(', ')})`;
|
|
861
|
+
for (const r of info.results)
|
|
862
|
+
ensureGoTypePackages(r);
|
|
863
|
+
return emitResults(call, info.results, isStatement(node));
|
|
864
|
+
}
|
|
865
|
+
// Emit `new pkg.T({...})` as a Go composite literal.
|
|
866
|
+
export function visitGoNew(node, path, typeName) {
|
|
867
|
+
const info = goPackage(path);
|
|
868
|
+
if (!info)
|
|
869
|
+
return undefined;
|
|
870
|
+
const type = info.types[typeName];
|
|
871
|
+
if (!type)
|
|
872
|
+
return undefined;
|
|
873
|
+
const qualifier = goQualifier(path);
|
|
874
|
+
const first = (node.arguments ?? [])[0];
|
|
875
|
+
if (first && services.isObjectLiteral(first)) {
|
|
876
|
+
const entries = [];
|
|
877
|
+
for (const prop of first.properties ?? []) {
|
|
878
|
+
const name = prop.name ? services.visit(prop.name) : '';
|
|
879
|
+
const fieldType = fieldGoTypeOf(type, prop.name?.text ?? '');
|
|
880
|
+
const isClosure = services.isArrowFunction(prop.initializer) || services.isFunctionExpression(prop.initializer);
|
|
881
|
+
if (fieldType && isClosure && isFuncType(fieldType)) {
|
|
882
|
+
// Func fields (httptrace.ClientTrace hooks) get the exact signature.
|
|
883
|
+
entries.push(`${name}: ${emitCallback(prop.initializer, fieldType, path, typeName)}`);
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
const fromType = services.typeOf(prop.initializer) ?? '';
|
|
887
|
+
let value = services.visit(prop.initializer);
|
|
888
|
+
if (fieldType && fromType === `*${fieldType}`) {
|
|
889
|
+
// new pkix.Name({...}) into a value field: dereference.
|
|
890
|
+
value = `*${value}`;
|
|
891
|
+
}
|
|
892
|
+
else if (fieldType) {
|
|
893
|
+
ensureGoTypePackages(fieldType);
|
|
894
|
+
value = toGo(value, fromType, fieldType);
|
|
895
|
+
}
|
|
896
|
+
entries.push(`${name}: ${value}`);
|
|
897
|
+
}
|
|
898
|
+
const ptr = hasPtrReceiver(type);
|
|
899
|
+
const lit = `${qualifier}.${typeName}{${entries.join(', ')}}`;
|
|
900
|
+
// Parenthesized so a method call binds to the pointer: (&T{}).M().
|
|
901
|
+
return ptr ? `(&${lit})` : lit;
|
|
902
|
+
}
|
|
903
|
+
const empty = `${qualifier}.${typeName}{}`;
|
|
904
|
+
return hasPtrReceiver(type) ? `(&${empty})` : empty;
|
|
905
|
+
}
|
|
906
|
+
function fieldGoTypeOf(type, field) {
|
|
907
|
+
for (const f of type.fields) {
|
|
908
|
+
if (f.name === field)
|
|
909
|
+
return f.goType;
|
|
910
|
+
}
|
|
911
|
+
return undefined;
|
|
912
|
+
}
|
|
913
|
+
function hasPtrReceiver(type) {
|
|
914
|
+
for (const m of type.methods) {
|
|
915
|
+
if (m.ptr)
|
|
916
|
+
return true;
|
|
917
|
+
}
|
|
918
|
+
return false;
|
|
919
|
+
}
|