typenative 0.6.1 → 0.7.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/CHANGELOG.md +412 -0
- package/README.md +1 -1
- package/bin/cli.js +18 -8
- package/bin/go/overrides.js +21 -1
- package/bin/index.js +48 -25
- package/bin/main.js +2 -1
- package/bin/node/assert.js +54 -15
- package/bin/node/async_hooks.js +69 -10
- package/bin/node/buffer.js +321 -7
- package/bin/node/child_process.js +154 -8
- package/bin/node/cluster.js +436 -32
- package/bin/node/crypto.js +814 -5
- package/bin/node/crypto_curves.js +142 -0
- package/bin/node/crypto_keys.js +1147 -48
- package/bin/node/crypto_pem.js +313 -0
- package/bin/node/crypto_pkcs12.js +17 -0
- package/bin/node/dgram.js +161 -10
- package/bin/node/diagnostics_channel.js +5 -1
- package/bin/node/events.js +358 -8
- package/bin/node/ffi.js +933 -0
- package/bin/node/fs.js +334 -6
- package/bin/node/http.js +630 -55
- package/bin/node/http2.js +1141 -88
- package/bin/node/intl.js +4576 -0
- package/bin/node/intl_data.js +65412 -0
- package/bin/node/module_v8.js +155 -16
- package/bin/node/net.js +59 -10
- package/bin/node/path.js +5 -1
- package/bin/node/process.js +342 -3
- package/bin/node/readline.js +558 -8
- package/bin/node/registry.js +2 -0
- package/bin/node/sqlite.js +51 -2
- package/bin/node/stream.js +370 -32
- package/bin/node/stream_web.js +422 -15
- package/bin/node/system_extra.js +154 -1
- package/bin/node/temporal.js +96 -0
- package/bin/node/temporal_runtime.js +5075 -0
- package/bin/node/temporal_zones.js +460 -0
- package/bin/node/test.js +153 -8
- package/bin/node/test_coverage.js +58 -0
- package/bin/node/test_report.js +3 -3
- package/bin/node/test_run.js +7 -1
- package/bin/node/timers.js +123 -0
- package/bin/node/tls.js +346 -12
- package/bin/node/tls_roots.js +122 -0
- package/bin/node/typed_arrays.js +867 -93
- package/bin/node/url.js +657 -0
- package/bin/node/util.js +441 -2
- package/bin/node/util_extra.js +6 -0
- package/bin/node/wasi.js +214 -0
- package/bin/node/webassembly.js +1122 -0
- package/bin/node/websocket.js +763 -0
- package/bin/node/worker_threads.js +434 -52
- package/bin/node/zlib.js +338 -9
- package/bin/node/zlib_zip.js +2392 -0
- package/bin/transpiler.js +2083 -254
- package/bin/typecheck-node.js +49 -17
- package/bin/version.js +1 -1
- package/conformance.md +160 -113
- package/examples/README.md +21 -20
- package/examples/angular-templates/README.md +12 -12
- package/examples/desktop-notes/README.md +7 -7
- package/examples/dupe-finder/README.md +4 -4
- package/examples/fibonacci/README.md +6 -6
- package/examples/hello-world/README.md +4 -4
- package/examples/json-server/README.md +13 -12
- package/examples/mandelbrot-png/README.md +4 -4
- package/examples/marked-cli/README.md +16 -17
- package/examples/openai-chat/README.md +5 -5
- package/examples/react-compiler/README.md +10 -10
- package/examples/todo-cli/README.md +8 -8
- package/examples/yaml-cli/README.md +10 -10
- package/govendor/github.com/cloudflare/circl/.golangci.yaml +64 -0
- package/govendor/github.com/cloudflare/circl/.semgrepignore +1 -0
- package/govendor/github.com/cloudflare/circl/AGENTS.md +91 -0
- package/govendor/github.com/cloudflare/circl/CITATION.cff +30 -0
- package/govendor/github.com/cloudflare/circl/LICENSE +57 -0
- package/govendor/github.com/cloudflare/circl/Makefile +70 -0
- package/govendor/github.com/cloudflare/circl/README.md +206 -0
- package/govendor/github.com/cloudflare/circl/REVIEW.md +83 -0
- package/govendor/github.com/cloudflare/circl/codecov.yml +21 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve.go +104 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.go +30 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.h +111 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.s +194 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_generic.go +100 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_noasm.go +11 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/doc.go +19 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/key.go +46 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/table.go +460 -0
- package/govendor/github.com/cloudflare/circl/doc.go +8 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/constants.go +71 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/curve.go +90 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/isogeny.go +52 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/point.go +181 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/scalar.go +203 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twist.go +138 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twistPoint.go +135 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twistTables.go +216 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twist_basemult.go +62 -0
- package/govendor/github.com/cloudflare/circl/go.mod +3 -0
- package/govendor/github.com/cloudflare/circl/internal/conv/conv.go +173 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/doc.go +62 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/hashes.go +69 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/keccakf.go +391 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/rc.go +29 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/sha3.go +200 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/sha3_s390x.s +33 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/shake.go +119 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/xor.go +15 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/xor_generic.go +33 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/xor_unaligned.go +61 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp.go +164 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.go +43 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.h +591 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.s +75 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_generic.go +339 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_noasm.go +12 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fuzzer.go +75 -0
- package/govendor/github.com/cloudflare/circl/math/integer.go +16 -0
- package/govendor/github.com/cloudflare/circl/math/mlsbset/mlsbset.go +145 -0
- package/govendor/github.com/cloudflare/circl/math/mlsbset/power.go +64 -0
- package/govendor/github.com/cloudflare/circl/math/primes.go +34 -0
- package/govendor/github.com/cloudflare/circl/math/wnaf.go +84 -0
- package/govendor/github.com/cloudflare/circl/sign/ed448/ed448.go +417 -0
- package/govendor/github.com/cloudflare/circl/sign/ed448/signapi.go +89 -0
- package/govendor/github.com/cloudflare/circl/sign/sign.go +119 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/LICENSE +17 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/README.md +72 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/compressedbytepoints.go +18 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve.go +1310 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve_embedded.go +14 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve_precompute.go +14 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/doc.go +59 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdh.go +21 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/README.md +52 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/doc.go +42 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/error.go +134 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/signature.go +1001 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ellipticadaptor.go +296 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/error.go +67 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/field.go +1696 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/go.mod +3 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/loadprecomputed.go +91 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/modnscalar.go +1105 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/nonce.go +263 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/privkey.go +111 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/pubkey.go +236 -0
- package/govendor/github.com/ebitengine/purego/LICENSE +201 -0
- package/govendor/github.com/ebitengine/purego/README.md +124 -0
- package/govendor/github.com/ebitengine/purego/abi_amd64.h +99 -0
- package/govendor/github.com/ebitengine/purego/abi_arm64.h +39 -0
- package/govendor/github.com/ebitengine/purego/abi_loong64.h +60 -0
- package/govendor/github.com/ebitengine/purego/cdecl.go +11 -0
- package/govendor/github.com/ebitengine/purego/cgo.go +19 -0
- package/govendor/github.com/ebitengine/purego/dlerror.go +17 -0
- package/govendor/github.com/ebitengine/purego/dlfcn.go +99 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_android.go +34 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_darwin.go +20 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_freebsd.go +14 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_linux.go +16 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_netbsd.go +15 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_freebsd.go +11 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_linux.go +19 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_netbsd.go +11 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_playground.go +24 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_stubs.s +22 -0
- package/govendor/github.com/ebitengine/purego/func.go +780 -0
- package/govendor/github.com/ebitengine/purego/gen.go +6 -0
- package/govendor/github.com/ebitengine/purego/go.mod +3 -0
- package/govendor/github.com/ebitengine/purego/go_runtime.go +19 -0
- package/govendor/github.com/ebitengine/purego/internal/cgo/dlfcn_cgo_unix.go +56 -0
- package/govendor/github.com/ebitengine/purego/internal/cgo/empty.go +6 -0
- package/govendor/github.com/ebitengine/purego/internal/cgo/syscall_cgo_unix.go +49 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_amd64.h +99 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_arm64.h +39 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_loong64.h +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_ppc64x.h +195 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_riscv64.h +72 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_386.s +29 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_amd64.s +39 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_arm.s +58 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_arm64.s +35 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_loong64.s +38 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_ppc64le.s +79 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_riscv64.s +36 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_s390x.s +52 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/callbacks.go +93 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/doc.go +32 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/fakecgo.go +14 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/freebsd.go +27 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_darwin.go +86 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_freebsd.go +77 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_libinit.go +72 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_linux.go +77 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_netbsd.go +83 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_setenv.go +18 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_util.go +38 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/iscgo.go +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo.go +37 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_darwin.go +37 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_freebsd.go +27 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_linux.go +27 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_netbsd.go +36 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/linux.go +189 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/netbsd.go +23 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/setenv.go +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/threadentry_amd64.go +15 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/threadentry_noasm.go +24 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_386.s +130 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_amd64.s +124 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_arm.s +131 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_arm64.s +81 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_386.s +78 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_amd64.s +69 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_arm.s +69 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_arm64.s +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_loong64.s +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_ppc64le.s +69 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_riscv64.s +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_s390x.s +51 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_loong64.s +78 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_ppc64le.s +132 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_riscv64.s +76 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_s390x.s +158 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols.go +165 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_darwin.go +59 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_freebsd.go +48 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_linux.go +158 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_netbsd.go +59 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_darwin.s +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_freebsd.s +16 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_linux.s +46 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_netbsd.s +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_stubs.s +55 -0
- package/govendor/github.com/ebitengine/purego/internal/strings/strings.go +40 -0
- package/govendor/github.com/ebitengine/purego/is_ios.go +13 -0
- package/govendor/github.com/ebitengine/purego/nocgo.go +25 -0
- package/govendor/github.com/ebitengine/purego/struct_amd64.go +518 -0
- package/govendor/github.com/ebitengine/purego/struct_arm.go +100 -0
- package/govendor/github.com/ebitengine/purego/struct_arm64.go +757 -0
- package/govendor/github.com/ebitengine/purego/struct_loong64.go +244 -0
- package/govendor/github.com/ebitengine/purego/struct_other.go +54 -0
- package/govendor/github.com/ebitengine/purego/struct_ppc64le.go +180 -0
- package/govendor/github.com/ebitengine/purego/struct_riscv64.go +158 -0
- package/govendor/github.com/ebitengine/purego/struct_s390x.go +158 -0
- package/govendor/github.com/ebitengine/purego/sys_386.s +153 -0
- package/govendor/github.com/ebitengine/purego/sys_amd64.s +206 -0
- package/govendor/github.com/ebitengine/purego/sys_arm.s +153 -0
- package/govendor/github.com/ebitengine/purego/sys_arm64.s +133 -0
- package/govendor/github.com/ebitengine/purego/sys_loong64.s +131 -0
- package/govendor/github.com/ebitengine/purego/sys_ppc64le.s +126 -0
- package/govendor/github.com/ebitengine/purego/sys_riscv64.s +135 -0
- package/govendor/github.com/ebitengine/purego/sys_s390x.s +148 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_386.s +234 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_arm.s +99 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_arm64.s +75 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_loong64.s +79 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_ppc64le.s +114 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_riscv64.s +79 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_s390x.s +111 -0
- package/govendor/github.com/ebitengine/purego/syscall.go +95 -0
- package/govendor/github.com/ebitengine/purego/syscall_32bit.go +97 -0
- package/govendor/github.com/ebitengine/purego/syscall_cgo_linux.go +20 -0
- package/govendor/github.com/ebitengine/purego/syscall_notstackargs.go +55 -0
- package/govendor/github.com/ebitengine/purego/syscall_ppc64le.go +73 -0
- package/govendor/github.com/ebitengine/purego/syscall_stackargs_ppc64le.go +38 -0
- package/govendor/github.com/ebitengine/purego/syscall_stackargs_s390x.go +38 -0
- package/govendor/github.com/ebitengine/purego/syscall_unix.go +392 -0
- package/govendor/github.com/ebitengine/purego/syscall_windows.go +54 -0
- package/govendor/github.com/ebitengine/purego/zcallback_386.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_amd64.s +2014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_arm.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_arm64.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_loong64.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_ppc64le.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_riscv64.s +4051 -0
- package/govendor/github.com/ebitengine/purego/zcallback_s390x.s +4015 -0
- package/govendor/github.com/klauspost/compress/.gitattributes +3 -0
- package/govendor/github.com/klauspost/compress/.goreleaser.yml +132 -0
- package/govendor/github.com/klauspost/compress/AGENTS.md +106 -0
- package/govendor/github.com/klauspost/compress/LICENSE +304 -0
- package/govendor/github.com/klauspost/compress/README.md +766 -0
- package/govendor/github.com/klauspost/compress/SECURITY.md +25 -0
- package/govendor/github.com/klauspost/compress/compressible.go +85 -0
- package/govendor/github.com/klauspost/compress/fse/README.md +79 -0
- package/govendor/github.com/klauspost/compress/fse/bitreader.go +122 -0
- package/govendor/github.com/klauspost/compress/fse/bitwriter.go +167 -0
- package/govendor/github.com/klauspost/compress/fse/bytereader.go +47 -0
- package/govendor/github.com/klauspost/compress/fse/compress.go +685 -0
- package/govendor/github.com/klauspost/compress/fse/decompress.go +383 -0
- package/govendor/github.com/klauspost/compress/fse/fse.go +150 -0
- package/govendor/github.com/klauspost/compress/gen.sh +4 -0
- package/govendor/github.com/klauspost/compress/go.mod +3 -0
- package/govendor/github.com/klauspost/compress/huff0/README.md +89 -0
- package/govendor/github.com/klauspost/compress/huff0/bitreader.go +323 -0
- package/govendor/github.com/klauspost/compress/huff0/bitwriter.go +97 -0
- package/govendor/github.com/klauspost/compress/huff0/build_table.go +168 -0
- package/govendor/github.com/klauspost/compress/huff0/compress.go +747 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress.go +1188 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_amd64.go +128 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_amd64.s +3476 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_arm64.go +72 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_arm64.s +1648 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_asm.go +252 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_generic.go +278 -0
- package/govendor/github.com/klauspost/compress/huff0/huff0.go +337 -0
- package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo.go +34 -0
- package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo_amd64.go +10 -0
- package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo_amd64.s +34 -0
- package/govendor/github.com/klauspost/compress/internal/le/le.go +5 -0
- package/govendor/github.com/klauspost/compress/internal/le/unsafe_disabled.go +42 -0
- package/govendor/github.com/klauspost/compress/internal/le/unsafe_enabled.go +52 -0
- package/govendor/github.com/klauspost/compress/internal/regmask/regmask.go +50 -0
- package/govendor/github.com/klauspost/compress/internal/regmask/regmask_386.go +39 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/LICENSE +27 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/decode.go +264 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/decode_other.go +113 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/encode.go +291 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/encode_other.go +250 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/snappy.go +98 -0
- package/govendor/github.com/klauspost/compress/s2sx.mod +3 -0
- package/govendor/github.com/klauspost/compress/s2sx.sum +0 -0
- package/govendor/github.com/klauspost/compress/zstd/README.md +487 -0
- package/govendor/github.com/klauspost/compress/zstd/bitreader.go +176 -0
- package/govendor/github.com/klauspost/compress/zstd/bitwriter.go +151 -0
- package/govendor/github.com/klauspost/compress/zstd/blockdec.go +728 -0
- package/govendor/github.com/klauspost/compress/zstd/blockenc.go +923 -0
- package/govendor/github.com/klauspost/compress/zstd/blocktype_string.go +85 -0
- package/govendor/github.com/klauspost/compress/zstd/bytebuf.go +131 -0
- package/govendor/github.com/klauspost/compress/zstd/bytereader.go +82 -0
- package/govendor/github.com/klauspost/compress/zstd/decodeheader.go +261 -0
- package/govendor/github.com/klauspost/compress/zstd/decoder.go +995 -0
- package/govendor/github.com/klauspost/compress/zstd/decoder_options.go +213 -0
- package/govendor/github.com/klauspost/compress/zstd/dict.go +605 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_base.go +200 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_best.go +572 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_better.go +1262 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_dfast.go +1136 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_fast.go +892 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_jobs.go +352 -0
- package/govendor/github.com/klauspost/compress/zstd/encoder.go +881 -0
- package/govendor/github.com/klauspost/compress/zstd/encoder_options.go +422 -0
- package/govendor/github.com/klauspost/compress/zstd/framedec.go +404 -0
- package/govendor/github.com/klauspost/compress/zstd/frameenc.go +137 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder.go +333 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s +132 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s +148 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_asm.go +70 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go +71 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_encoder.go +701 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_predefined.go +168 -0
- package/govendor/github.com/klauspost/compress/zstd/hash.go +57 -0
- package/govendor/github.com/klauspost/compress/zstd/history.go +119 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/LICENSE.txt +22 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/README.md +71 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go +242 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s +210 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s +184 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_asm.go +11 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_other.go +75 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_safe.go +11 -0
- package/govendor/github.com/klauspost/compress/zstd/matchlen_amd64.go +15 -0
- package/govendor/github.com/klauspost/compress/zstd/matchlen_amd64.s +66 -0
- package/govendor/github.com/klauspost/compress/zstd/matchlen_generic.go +37 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec.go +620 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_amd64.go +115 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_amd64.s +4762 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_arm64.go +81 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_arm64.s +2919 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_asm.go +327 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_generic.go +258 -0
- package/govendor/github.com/klauspost/compress/zstd/seqenc.go +159 -0
- package/govendor/github.com/klauspost/compress/zstd/simple.go +54 -0
- package/govendor/github.com/klauspost/compress/zstd/snappy.go +447 -0
- package/govendor/github.com/klauspost/compress/zstd/zip.go +141 -0
- package/govendor/github.com/klauspost/compress/zstd/zstd.go +126 -0
- package/govendor/github.com/tetratelabs/wazero/.editorconfig +7 -0
- package/govendor/github.com/tetratelabs/wazero/.gitattributes +2 -0
- package/govendor/github.com/tetratelabs/wazero/.gitmodules +3 -0
- package/govendor/github.com/tetratelabs/wazero/CONTRIBUTING.md +75 -0
- package/govendor/github.com/tetratelabs/wazero/LICENSE +201 -0
- package/govendor/github.com/tetratelabs/wazero/Makefile +385 -0
- package/govendor/github.com/tetratelabs/wazero/NOTICE +2 -0
- package/govendor/github.com/tetratelabs/wazero/RATIONALE.md +1577 -0
- package/govendor/github.com/tetratelabs/wazero/README.md +135 -0
- package/govendor/github.com/tetratelabs/wazero/api/features.go +228 -0
- package/govendor/github.com/tetratelabs/wazero/api/wasm.go +766 -0
- package/govendor/github.com/tetratelabs/wazero/builder.go +367 -0
- package/govendor/github.com/tetratelabs/wazero/cache.go +123 -0
- package/govendor/github.com/tetratelabs/wazero/codecov.yml +9 -0
- package/govendor/github.com/tetratelabs/wazero/config.go +899 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/checkpoint.go +35 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/close.go +63 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/compilationworkers.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/experimental.go +41 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/features.go +39 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/importresolver.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/listener.go +324 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/memory.go +52 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/dir.go +92 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/errno.go +98 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/error.go +45 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/file.go +356 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/fs.go +292 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/oflag.go +70 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/poll.go +48 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno.go +106 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_notwindows.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_unsupported.go +7 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_windows.go +37 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/time.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/unimplemented.go +160 -0
- package/govendor/github.com/tetratelabs/wazero/fsconfig.go +213 -0
- package/govendor/github.com/tetratelabs/wazero/go.mod +3 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/args.go +97 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/clock.go +116 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/environ.go +100 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/fs.go +2015 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/poll.go +247 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/proc.go +44 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/random.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/sched.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/sock.go +188 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/wasi.go +314 -0
- package/govendor/github.com/tetratelabs/wazero/internal/descriptor/table.go +149 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/compiler.go +3884 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/format.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go +4963 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/operations.go +2978 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/signature.go +825 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/abi.go +170 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/backend.go +3 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/compiler.go +402 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/compiler_lower.go +226 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/go_call.go +33 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi.go +186 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_amd64.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_amd64.s +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_preamble.go +248 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_go_call.go +440 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/cond.go +168 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/ext.go +35 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/instr.go +2495 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/instr_encoding.go +1714 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/lower_constant.go +71 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/lower_mem.go +187 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine.go +3782 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_pro_epi_logue.go +334 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_regalloc.go +352 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_vec.go +992 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/operands.go +336 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/reg.go +181 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/stack.go +130 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi.go +376 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_arm64.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_arm64.s +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_preamble.go +233 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_go_call.go +430 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/cond.go +215 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/instr.go +2562 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/instr_encoding.go +2357 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_constant.go +301 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_instr.go +2227 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_instr_operands.go +340 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_mem.go +451 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine.go +631 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_pro_epi_logue.go +486 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_regalloc.go +351 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_relocation.go +128 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/reg.go +397 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/unwind_stack.go +84 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go +119 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/api.go +124 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/reg.go +123 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/regalloc.go +1189 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/regset.go +96 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/vdef.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/call_engine.go +884 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go +1008 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go +347 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_amd64.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_arm64.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_other.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go +663 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go +5045 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/misc.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/hostmodule.go +88 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_amd64.go +30 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_arm64.go +32 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_other.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/memmove.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/module_engine.go +403 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/basic_block.go +381 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/basic_block_sort.go +32 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/builder.go +790 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/cmp.go +107 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/funcref.go +12 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go +3024 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass.go +393 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass_blk_layouts.go +334 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass_cfg.go +313 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/signature.go +49 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/ssa.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/type.go +115 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/vs.go +114 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/debug_options.go +189 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/exitcode.go +150 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/offsetdata.go +248 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap.go +96 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap_disabled.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap_enabled.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/pool.go +215 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/ptr.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/queue.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/resetmap.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/checkpoint.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/close.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/compilationworkers.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/expctxkeys.go +2 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/importresolver.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/listener.go +7 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/memory.go +4 -0
- package/govendor/github.com/tetratelabs/wazero/internal/filecache/compilationcache.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/filecache/file_cache.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/ieee754/ieee754.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/internalapi/internal.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/leb128/leb128.go +285 -0
- package/govendor/github.com/tetratelabs/wazero/internal/moremath/moremath.go +271 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_amd64.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_arm64.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_unsupported.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/crypto.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_linux.go +72 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_other.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_unix.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_unsupported.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_windows.go +31 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/path.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/path_windows.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/platform.go +71 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/time.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/time_notwindows.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/time_windows.go +40 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sock/sock.go +89 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sock/sock_supported.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sock/sock_unsupported.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/fs.go +458 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/lazy.go +135 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/stdio.go +125 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/sys.go +228 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/adapter.go +105 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/datasync_linux.go +12 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/datasync_unsupported.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/dir.go +24 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/dirfs.go +137 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file.go +576 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_unix.go +39 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_unsupported.go +28 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_windows.go +133 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_darwin.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_darwin.s +8 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_linux.go +38 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_unsupported.go +18 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_windows.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_unix.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_unsupported.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_windows.go +28 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_unix.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_unsupported.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_windows.go +23 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/oflag.go +38 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_bsd.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_darwin.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_supported.go +30 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_unix.go +20 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_unsupported.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_windows.go +163 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/osfile.go +318 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_darwin.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_darwin.s +8 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_linux.go +57 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_unsupported.go +12 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_windows.go +224 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/readfs.go +117 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_unix.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_unsupported.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_windows.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock.go +186 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_supported.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_unix.go +48 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_unsupported.go +79 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_windows.go +80 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_supported.go +40 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_unsupported.go +40 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_windows.go +118 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sync.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sync_windows.go +20 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/syscall6_darwin.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_unix.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_unsupported.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_windows.go +25 -0
- package/govendor/github.com/tetratelabs/wazero/internal/u32/u32.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/u64/u64.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/version/version.go +52 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/args.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/clock.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/environ.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go +314 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/fs.go +164 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/poll.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/proc.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/random.go +3 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/rights.go +148 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/sched.go +3 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/sock.go +71 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/wasi.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/code.go +124 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/const_expr.go +116 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/custom.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/data.go +79 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/decoder.go +235 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/element.go +250 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/errors.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/export.go +32 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/function.go +56 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/global.go +50 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/header.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/import.go +68 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/limits.go +47 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/memory.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/names.go +151 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/section.go +309 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/table.go +79 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/value.go +97 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/const_expr.go +259 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/counts.go +53 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/engine.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/exception.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/func_validation.go +2804 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/function_definition.go +210 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/global.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/gofunc.go +279 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/host.go +179 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/instruction.go +1962 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/memory.go +475 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/memory_definition.go +128 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/module.go +1359 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/module_instance.go +251 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/module_instance_lookup.go +73 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/store.go +726 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/store_module_list.go +95 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/table.go +321 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go +170 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasmdebug/dwarf.go +225 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasmruntime/errors.go +54 -0
- package/govendor/github.com/tetratelabs/wazero/netlify.toml +15 -0
- package/govendor/github.com/tetratelabs/wazero/runtime.go +399 -0
- package/govendor/github.com/tetratelabs/wazero/sys/clock.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/sys/error.go +83 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat.go +105 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_bsd.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_posix.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_unsupported.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_windows.go +24 -0
- package/govendor/golang.org/x/crypto/LICENSE +27 -0
- package/govendor/golang.org/x/crypto/PATENTS +22 -0
- package/govendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go +46 -0
- package/govendor/golang.org/x/crypto/cryptobyte/asn1.go +825 -0
- package/govendor/golang.org/x/crypto/cryptobyte/builder.go +350 -0
- package/govendor/golang.org/x/crypto/cryptobyte/string.go +183 -0
- package/govendor/golang.org/x/crypto/go.mod +3 -0
- package/govendor/golang.org/x/crypto/pbkdf2/pbkdf2.go +30 -0
- package/govendor/golang.org/x/net/LICENSE +27 -0
- package/govendor/golang.org/x/net/PATENTS +22 -0
- package/govendor/golang.org/x/net/dns/dnsmessage/message.go +2733 -0
- package/govendor/golang.org/x/net/dns/dnsmessage/svcb.go +333 -0
- package/govendor/golang.org/x/net/go.mod +3 -0
- package/govendor/golang.org/x/net/http/httpguts/guts.go +50 -0
- package/govendor/golang.org/x/net/http/httpguts/httplex.go +347 -0
- package/govendor/golang.org/x/net/http2/README.md +19 -0
- package/govendor/golang.org/x/net/http2/ascii.go +65 -0
- package/govendor/golang.org/x/net/http2/ciphers.go +641 -0
- package/govendor/golang.org/x/net/http2/client_conn_pool.go +301 -0
- package/govendor/golang.org/x/net/http2/client_priority_go126.go +20 -0
- package/govendor/golang.org/x/net/http2/client_priority_go127.go +13 -0
- package/govendor/golang.org/x/net/http2/clientconn.go +57 -0
- package/govendor/golang.org/x/net/http2/config.go +171 -0
- package/govendor/golang.org/x/net/http2/config_go125.go +15 -0
- package/govendor/golang.org/x/net/http2/config_go126.go +15 -0
- package/govendor/golang.org/x/net/http2/databuffer.go +146 -0
- package/govendor/golang.org/x/net/http2/errors.go +145 -0
- package/govendor/golang.org/x/net/http2/flow.go +175 -0
- package/govendor/golang.org/x/net/http2/frame.go +1887 -0
- package/govendor/golang.org/x/net/http2/gotrack.go +181 -0
- package/govendor/golang.org/x/net/http2/hpack/encode.go +244 -0
- package/govendor/golang.org/x/net/http2/hpack/hpack.go +522 -0
- package/govendor/golang.org/x/net/http2/hpack/huffman.go +226 -0
- package/govendor/golang.org/x/net/http2/hpack/static_table.go +188 -0
- package/govendor/golang.org/x/net/http2/hpack/tables.go +426 -0
- package/govendor/golang.org/x/net/http2/http2.go +415 -0
- package/govendor/golang.org/x/net/http2/pipe.go +184 -0
- package/govendor/golang.org/x/net/http2/server.go +3239 -0
- package/govendor/golang.org/x/net/http2/server_common.go +268 -0
- package/govendor/golang.org/x/net/http2/server_wrap.go +217 -0
- package/govendor/golang.org/x/net/http2/transport.go +3084 -0
- package/govendor/golang.org/x/net/http2/transport_common.go +516 -0
- package/govendor/golang.org/x/net/http2/transport_wrap.go +583 -0
- package/govendor/golang.org/x/net/http2/unencrypted.go +32 -0
- package/govendor/golang.org/x/net/http2/write.go +381 -0
- package/govendor/golang.org/x/net/http2/writesched.go +253 -0
- package/govendor/golang.org/x/net/http2/writesched_common.go +90 -0
- package/govendor/golang.org/x/net/http2/writesched_priority_rfc7540.go +420 -0
- package/govendor/golang.org/x/net/http2/writesched_priority_rfc9218.go +226 -0
- package/govendor/golang.org/x/net/http2/writesched_random.go +81 -0
- package/govendor/golang.org/x/net/http2/writesched_roundrobin.go +121 -0
- package/govendor/golang.org/x/net/idna/idna.go +884 -0
- package/govendor/golang.org/x/net/idna/punycode.go +220 -0
- package/govendor/golang.org/x/net/idna/tables15.0.0.go +5144 -0
- package/govendor/golang.org/x/net/idna/tables17.0.0.go +5302 -0
- package/govendor/golang.org/x/net/idna/trie.go +51 -0
- package/govendor/golang.org/x/net/idna/trieval.go +119 -0
- package/govendor/golang.org/x/net/internal/httpcommon/README.md +7 -0
- package/govendor/golang.org/x/net/internal/httpcommon/ascii.go +53 -0
- package/govendor/golang.org/x/net/internal/httpcommon/gzip.go +132 -0
- package/govendor/golang.org/x/net/internal/httpcommon/headermap.go +115 -0
- package/govendor/golang.org/x/net/internal/httpcommon/request.go +503 -0
- package/govendor/golang.org/x/net/internal/httpsfv/httpsfv.go +665 -0
- package/govendor/golang.org/x/sys/cpu/asm_aix_ppc64.s +17 -0
- package/govendor/golang.org/x/sys/cpu/asm_darwin_arm64_gc.s +12 -0
- package/govendor/golang.org/x/sys/cpu/asm_darwin_x86_gc.s +17 -0
- package/govendor/golang.org/x/sys/cpu/byteorder.go +66 -0
- package/govendor/golang.org/x/sys/cpu/cpu.go +357 -0
- package/govendor/golang.org/x/sys/cpu/cpu_aix.go +33 -0
- package/govendor/golang.org/x/sys/cpu/cpu_arm.go +73 -0
- package/govendor/golang.org/x/sys/cpu/cpu_arm64.go +191 -0
- package/govendor/golang.org/x/sys/cpu/cpu_arm64.s +35 -0
- package/govendor/golang.org/x/sys/cpu/cpu_darwin_arm64.go +67 -0
- package/govendor/golang.org/x/sys/cpu/cpu_darwin_arm64_other.go +31 -0
- package/govendor/golang.org/x/sys/cpu/cpu_darwin_x86.go +61 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_arm64.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_riscv64.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_s390x.go +21 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_x86.go +15 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_x86.s +26 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_s390x.go +22 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c +37 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_x86.go +25 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux.go +15 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_arm.go +39 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_arm64.go +120 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_loong64.go +22 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_mips64x.go +22 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_noinit.go +9 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_ppc64x.go +34 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_riscv64.go +173 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_s390x.go +40 -0
- package/govendor/golang.org/x/sys/cpu/cpu_loong64.go +62 -0
- package/govendor/golang.org/x/sys/cpu/cpu_loong64.s +13 -0
- package/govendor/golang.org/x/sys/cpu/cpu_mips64x.go +15 -0
- package/govendor/golang.org/x/sys/cpu/cpu_mipsx.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_netbsd_amd64.go +47 -0
- package/govendor/golang.org/x/sys/cpu/cpu_netbsd_arm64.go +173 -0
- package/govendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.go +65 -0
- package/govendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.s +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_arm.go +9 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_arm64.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_mips64x.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_ppc64x.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_riscv64.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_x86.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_ppc64x.go +16 -0
- package/govendor/golang.org/x/sys/cpu/cpu_riscv64.go +33 -0
- package/govendor/golang.org/x/sys/cpu/cpu_riscv64.s +17 -0
- package/govendor/golang.org/x/sys/cpu/cpu_s390x.go +172 -0
- package/govendor/golang.org/x/sys/cpu/cpu_s390x.s +57 -0
- package/govendor/golang.org/x/sys/cpu/cpu_sparc64.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_wasm.go +17 -0
- package/govendor/golang.org/x/sys/cpu/cpu_windows.go +26 -0
- package/govendor/golang.org/x/sys/cpu/cpu_windows_arm64.go +38 -0
- package/govendor/golang.org/x/sys/cpu/cpu_x86.go +259 -0
- package/govendor/golang.org/x/sys/cpu/cpu_zos.go +10 -0
- package/govendor/golang.org/x/sys/cpu/cpu_zos_s390x.go +25 -0
- package/govendor/golang.org/x/sys/cpu/endian_big.go +10 -0
- package/govendor/golang.org/x/sys/cpu/endian_little.go +10 -0
- package/govendor/golang.org/x/sys/cpu/hwcap_linux.go +71 -0
- package/govendor/golang.org/x/sys/cpu/parse.go +55 -0
- package/govendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go +53 -0
- package/govendor/golang.org/x/sys/cpu/runtime_auxv.go +16 -0
- package/govendor/golang.org/x/sys/cpu/runtime_auxv_go121.go +18 -0
- package/govendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go +26 -0
- package/govendor/golang.org/x/sys/cpu/syscall_aix_ppc64_gc.go +35 -0
- package/govendor/golang.org/x/sys/cpu/syscall_darwin_arm64_gc.go +54 -0
- package/govendor/golang.org/x/sys/cpu/syscall_darwin_x86_gc.go +98 -0
- package/govendor/golang.org/x/sys/cpu/zcpu_windows.go +48 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_ppc64x.s +20 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_sparc64.s +48 -0
- package/govendor/golang.org/x/sys/unix/asm_zos_s390x.s +4 -186
- package/govendor/golang.org/x/sys/unix/bpxsvc_zos.s +9 -9
- package/govendor/golang.org/x/sys/unix/fcntl_darwin.go +2 -2
- package/govendor/golang.org/x/sys/unix/mkerrors.sh +1 -1
- package/govendor/golang.org/x/sys/unix/ptrace_zos.go +537 -0
- package/govendor/golang.org/x/sys/unix/ptrace_zos_singlestep.go +425 -0
- package/govendor/golang.org/x/sys/unix/syscall_darwin.go +1 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd.go +9 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux.go +20 -1
- package/govendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +3 -3
- package/govendor/golang.org/x/sys/unix/syscall_netbsd.go +9 -0
- package/govendor/golang.org/x/sys/unix/syscall_unix_gc.go +1 -1
- package/govendor/golang.org/x/sys/unix/syscall_zos_s390x.go +0 -4
- package/govendor/golang.org/x/sys/unix/xattr_bsd.go +12 -12
- package/govendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +6 -0
- package/govendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +6 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux.go +32 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_386.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_arm.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +11 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +11 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_riscv64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux.go +28 -1
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +3 -3
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_zos_s390x.go +13 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux.go +65 -36
- package/govendor/golang.org/x/sys/unix/ztypes_linux_386.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_arm.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +10 -5
- package/govendor/golang.org/x/sys/unix/ztypes_zos_s390x.go +78 -0
- package/govendor/golang.org/x/text/.gitattributes +10 -0
- package/govendor/golang.org/x/text/CONTRIBUTING.md +26 -0
- package/govendor/golang.org/x/text/LICENSE +27 -0
- package/govendor/golang.org/x/text/PATENTS +22 -0
- package/govendor/golang.org/x/text/README.md +81 -0
- package/govendor/golang.org/x/text/cases/cases.go +162 -0
- package/govendor/golang.org/x/text/cases/context.go +376 -0
- package/govendor/golang.org/x/text/cases/fold.go +34 -0
- package/govendor/golang.org/x/text/cases/icu.go +61 -0
- package/govendor/golang.org/x/text/cases/info.go +82 -0
- package/govendor/golang.org/x/text/cases/map.go +816 -0
- package/govendor/golang.org/x/text/cases/tables15.0.0.go +2527 -0
- package/govendor/golang.org/x/text/cases/tables17.0.0.go +2642 -0
- package/govendor/golang.org/x/text/cases/trieval.go +217 -0
- package/govendor/golang.org/x/text/codereview.cfg +1 -0
- package/govendor/golang.org/x/text/collate/collate.go +402 -0
- package/govendor/golang.org/x/text/collate/index.go +32 -0
- package/govendor/golang.org/x/text/collate/option.go +239 -0
- package/govendor/golang.org/x/text/collate/sort.go +81 -0
- package/govendor/golang.org/x/text/collate/tables.go +73789 -0
- package/govendor/golang.org/x/text/currency/common.go +67 -0
- package/govendor/golang.org/x/text/currency/currency.go +185 -0
- package/govendor/golang.org/x/text/currency/format.go +220 -0
- package/govendor/golang.org/x/text/currency/query.go +152 -0
- package/govendor/golang.org/x/text/currency/tables.go +2629 -0
- package/govendor/golang.org/x/text/doc.go +16 -0
- package/govendor/golang.org/x/text/feature/plural/common.go +70 -0
- package/govendor/golang.org/x/text/feature/plural/message.go +244 -0
- package/govendor/golang.org/x/text/feature/plural/plural.go +262 -0
- package/govendor/golang.org/x/text/feature/plural/tables.go +552 -0
- package/govendor/golang.org/x/text/go.mod +3 -0
- package/govendor/golang.org/x/text/internal/catmsg/catmsg.go +417 -0
- package/govendor/golang.org/x/text/internal/catmsg/codec.go +407 -0
- package/govendor/golang.org/x/text/internal/catmsg/varint.go +62 -0
- package/govendor/golang.org/x/text/internal/colltab/collelem.go +374 -0
- package/govendor/golang.org/x/text/internal/colltab/colltab.go +105 -0
- package/govendor/golang.org/x/text/internal/colltab/contract.go +145 -0
- package/govendor/golang.org/x/text/internal/colltab/iter.go +178 -0
- package/govendor/golang.org/x/text/internal/colltab/numeric.go +236 -0
- package/govendor/golang.org/x/text/internal/colltab/table.go +275 -0
- package/govendor/golang.org/x/text/internal/colltab/trie.go +159 -0
- package/govendor/golang.org/x/text/internal/colltab/weighter.go +31 -0
- package/govendor/golang.org/x/text/internal/format/format.go +41 -0
- package/govendor/golang.org/x/text/internal/format/parser.go +358 -0
- package/govendor/golang.org/x/text/internal/internal.go +49 -0
- package/govendor/golang.org/x/text/internal/language/common.go +16 -0
- package/govendor/golang.org/x/text/internal/language/compact/compact.go +61 -0
- package/govendor/golang.org/x/text/internal/language/compact/language.go +260 -0
- package/govendor/golang.org/x/text/internal/language/compact/parents.go +120 -0
- package/govendor/golang.org/x/text/internal/language/compact/tables.go +1015 -0
- package/govendor/golang.org/x/text/internal/language/compact/tags.go +91 -0
- package/govendor/golang.org/x/text/internal/language/compact.go +29 -0
- package/govendor/golang.org/x/text/internal/language/compose.go +167 -0
- package/govendor/golang.org/x/text/internal/language/coverage.go +28 -0
- package/govendor/golang.org/x/text/internal/language/language.go +627 -0
- package/govendor/golang.org/x/text/internal/language/lookup.go +412 -0
- package/govendor/golang.org/x/text/internal/language/match.go +226 -0
- package/govendor/golang.org/x/text/internal/language/parse.go +608 -0
- package/govendor/golang.org/x/text/internal/language/tables.go +3494 -0
- package/govendor/golang.org/x/text/internal/language/tags.go +48 -0
- package/govendor/golang.org/x/text/internal/match.go +67 -0
- package/govendor/golang.org/x/text/internal/number/common.go +55 -0
- package/govendor/golang.org/x/text/internal/number/decimal.go +500 -0
- package/govendor/golang.org/x/text/internal/number/format.go +533 -0
- package/govendor/golang.org/x/text/internal/number/number.go +152 -0
- package/govendor/golang.org/x/text/internal/number/pattern.go +485 -0
- package/govendor/golang.org/x/text/internal/number/roundingmode_string.go +30 -0
- package/govendor/golang.org/x/text/internal/number/tables.go +1219 -0
- package/govendor/golang.org/x/text/internal/stringset/set.go +86 -0
- package/govendor/golang.org/x/text/internal/tag/tag.go +100 -0
- package/govendor/golang.org/x/text/language/coverage.go +187 -0
- package/govendor/golang.org/x/text/language/display/dict.go +92 -0
- package/govendor/golang.org/x/text/language/display/display.go +420 -0
- package/govendor/golang.org/x/text/language/display/lookup.go +253 -0
- package/govendor/golang.org/x/text/language/display/tables.go +53114 -0
- package/govendor/golang.org/x/text/language/doc.go +98 -0
- package/govendor/golang.org/x/text/language/language.go +605 -0
- package/govendor/golang.org/x/text/language/match.go +735 -0
- package/govendor/golang.org/x/text/language/parse.go +258 -0
- package/govendor/golang.org/x/text/language/tables.go +298 -0
- package/govendor/golang.org/x/text/language/tags.go +145 -0
- package/govendor/golang.org/x/text/message/catalog/catalog.go +365 -0
- package/govendor/golang.org/x/text/message/catalog/dict.go +133 -0
- package/govendor/golang.org/x/text/secure/bidirule/bidirule.go +346 -0
- package/govendor/golang.org/x/text/transform/transform.go +709 -0
- package/govendor/golang.org/x/text/unicode/bidi/bidi.go +359 -0
- package/govendor/golang.org/x/text/unicode/bidi/bracket.go +335 -0
- package/govendor/golang.org/x/text/unicode/bidi/core.go +1050 -0
- package/govendor/golang.org/x/text/unicode/bidi/prop.go +206 -0
- package/govendor/golang.org/x/text/unicode/bidi/tables15.0.0.go +2042 -0
- package/govendor/golang.org/x/text/unicode/bidi/tables17.0.0.go +2135 -0
- package/govendor/golang.org/x/text/unicode/bidi/trieval.go +48 -0
- package/govendor/golang.org/x/text/unicode/norm/composition.go +524 -0
- package/govendor/golang.org/x/text/unicode/norm/forminfo.go +296 -0
- package/govendor/golang.org/x/text/unicode/norm/input.go +109 -0
- package/govendor/golang.org/x/text/unicode/norm/iter.go +454 -0
- package/govendor/golang.org/x/text/unicode/norm/normalize.go +613 -0
- package/govendor/golang.org/x/text/unicode/norm/readwriter.go +125 -0
- package/govendor/golang.org/x/text/unicode/norm/tables15.0.0.go +7907 -0
- package/govendor/golang.org/x/text/unicode/norm/tables17.0.0.go +8104 -0
- package/govendor/golang.org/x/text/unicode/norm/transform.go +89 -0
- package/govendor/golang.org/x/text/unicode/norm/trie.go +54 -0
- package/govendor/manifest.txt +11 -2
- package/package.json +2 -1
- package/performance/README.md +87 -35
- package/performance/arr-for-of.ts +29 -0
- package/performance/arr-push-local.ts +39 -0
- package/performance/arr-slice-concat.ts +24 -0
- package/performance/async-promise-all.ts +38 -0
- package/performance/bigint-arith.ts +36 -0
- package/performance/buf-encode.ts +29 -0
- package/performance/class-accessors.ts +48 -0
- package/performance/date-format.ts +18 -0
- package/performance/fn-rest-spread.ts +43 -0
- package/performance/gen-next.ts +32 -0
- package/performance/iter-helpers.ts +38 -0
- package/performance/json-any.ts +30 -0
- package/performance/map-iterate.ts +26 -0
- package/performance/map-number-keys.ts +37 -0
- package/performance/num-hash-imul.ts +36 -0
- package/performance/obj-keys-entries.ts +44 -0
- package/performance/obj-optional-chain.ts +42 -0
- package/performance/obj-record-dict.ts +24 -0
- package/performance/obj-spread-destructure.ts +40 -0
- package/performance/regex-replace-fn.ts +24 -0
- package/performance/str-methods.ts +24 -0
- package/performance/str-switch-compare.ts +50 -0
- package/performance/str-unicode.ts +25 -0
- package/performance/typed-array.ts +30 -0
- package/performance/union-typeof.ts +40 -0
- package/performance/wasm-call.ts +63 -0
- package/tsparser/go.mod +1 -1
- package/tsparser/go.sum +2 -2
- package/types/typenative-npm.d.ts +836 -69
- package/types/typenative.d.ts +1224 -23
- package/govendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go +0 -22
- package/govendor/golang.org/x/sys/windows/types_windows_arm.go +0 -35
package/bin/transpiler.js
CHANGED
|
@@ -20,7 +20,7 @@ import { registerCrypto } from './node/crypto.js';
|
|
|
20
20
|
import { registerCryptoKeys } from './node/crypto_keys.js';
|
|
21
21
|
import { registerZlib } from './node/zlib.js';
|
|
22
22
|
import { registerFsWatch } from './node/fs_watch.js';
|
|
23
|
-
import { registerTypedArrays, isTypedArrayGoType } from './node/typed_arrays.js';
|
|
23
|
+
import { registerTypedArrays, isTypedArrayGoType, isBigIntArrayGoType, TYPED_ARRAY_KINDS, BIGINT_ARRAY_KINDS } from './node/typed_arrays.js';
|
|
24
24
|
import { registerTimers } from './node/timers.js';
|
|
25
25
|
import { registerEvents } from './node/events.js';
|
|
26
26
|
import { registerStream } from './node/stream.js';
|
|
@@ -31,6 +31,11 @@ import { registerHttp } from './node/http.js';
|
|
|
31
31
|
import { registerTls } from './node/tls.js';
|
|
32
32
|
import { registerDgram } from './node/dgram.js';
|
|
33
33
|
import { registerSqlite } from './node/sqlite.js';
|
|
34
|
+
import { registerWebAssembly } from './node/webassembly.js';
|
|
35
|
+
import { registerWasi } from './node/wasi.js';
|
|
36
|
+
import { registerFfi } from './node/ffi.js';
|
|
37
|
+
import { registerTemporal } from './node/temporal.js';
|
|
38
|
+
import { registerIntl } from './node/intl.js';
|
|
34
39
|
import { registerWebview } from './node/webview.js';
|
|
35
40
|
import { registerFetch } from './node/fetch.js';
|
|
36
41
|
import { registerStreamWeb } from './node/stream_web.js';
|
|
@@ -39,6 +44,7 @@ import { registerTest } from './node/test.js';
|
|
|
39
44
|
import { registerWorkerThreads } from './node/worker_threads.js';
|
|
40
45
|
import { registerCluster } from './node/cluster.js';
|
|
41
46
|
import { registerHttp2 } from './node/http2.js';
|
|
47
|
+
import { registerWebSocket } from './node/websocket.js';
|
|
42
48
|
import { registerSystemExtra } from './node/system_extra.js';
|
|
43
49
|
import { registerModuleV8 } from './node/module_v8.js';
|
|
44
50
|
import { goStdlib } from './go/stdlib.generated.js';
|
|
@@ -1159,41 +1165,92 @@ function lowerMixinFactories(sourceFile) {
|
|
|
1159
1165
|
return;
|
|
1160
1166
|
const out = [];
|
|
1161
1167
|
const bases = [];
|
|
1168
|
+
// (the top-level classes, for a returned subclass: topLevelClassNames is
|
|
1169
|
+
// filled later)
|
|
1170
|
+
const declaredClassNames = new Set(sourceFile.statements
|
|
1171
|
+
.filter((s) => isClassDeclaration(s) && isIdentifier(s.name))
|
|
1172
|
+
.map((s) => s.name.text));
|
|
1162
1173
|
for (const st of sourceFile.statements) {
|
|
1163
1174
|
const decl = st.kind === 'VariableStatement' && (st.declarationList?.declarations ?? []).length === 1 ? st.declarationList.declarations[0] : undefined;
|
|
1164
|
-
|
|
1165
|
-
|
|
1175
|
+
// (a factory declared as a function (function Tagged(superClass: typeof Base) {…}),
|
|
1176
|
+
// an arrow or a function expression)
|
|
1177
|
+
const fn = decl ? decl.initializer : isFunctionDeclaration(st) ? st : undefined;
|
|
1178
|
+
if (!fn || !(isArrowFunction(fn) || isFunctionExpression(fn) || isFunctionDeclaration(fn))) {
|
|
1179
|
+
out.push(st);
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
const factoryName = decl
|
|
1183
|
+
? (isIdentifier(decl.name) ? decl.name.text : undefined)
|
|
1184
|
+
: (isIdentifier(fn.name) ? fn.name.text : undefined);
|
|
1185
|
+
const parameters = fn.parameters ?? [];
|
|
1186
|
+
const param = parameters.length === 1 && isIdentifier(parameters[0].name) ? parameters[0] : undefined;
|
|
1166
1187
|
let cls;
|
|
1167
|
-
if (
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1173
|
-
const clause = cls ? (cls.heritageClauses ?? []).find((c) => c.token === 'ExtendsKeyword') : undefined;
|
|
1174
|
-
const extendsParam = clause && isIdentifier(clause.types?.[0]?.expression) && clause.types[0].expression.text === param.name.text;
|
|
1175
|
-
// the base: typeof Base, or ClassWithMixin<typeof Base, …>
|
|
1176
|
-
let baseQuery = param?.type;
|
|
1177
|
-
if (isTypeReferenceNode(baseQuery) && (baseQuery.typeArguments ?? []).length > 0)
|
|
1178
|
-
baseQuery = baseQuery.typeArguments[0];
|
|
1179
|
-
const base = baseQuery?.kind === 'TypeQuery' && isIdentifier(baseQuery.exprName) ? baseQuery.exprName.text : undefined;
|
|
1180
|
-
if (!cls || !extendsParam || !base) {
|
|
1188
|
+
if (fn.body?.kind === 'ClassExpression')
|
|
1189
|
+
cls = fn.body;
|
|
1190
|
+
else if (isBlock(fn.body) && (fn.body.statements ?? []).length === 1 && fn.body.statements[0].kind === 'ReturnStatement' && fn.body.statements[0].expression?.kind === 'ClassExpression')
|
|
1191
|
+
cls = fn.body.statements[0].expression;
|
|
1192
|
+
if (!cls || !factoryName) {
|
|
1181
1193
|
out.push(st);
|
|
1182
1194
|
continue;
|
|
1183
1195
|
}
|
|
1196
|
+
const clause = (cls.heritageClauses ?? []).find((c) => c.token === 'ExtendsKeyword');
|
|
1197
|
+
const extendsParam = !!param && isIdentifier(clause?.types?.[0]?.expression) && clause.types[0].expression.text === param.name.text;
|
|
1184
1198
|
const at = { line: cls.line, column: cls.column };
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1199
|
+
if (extendsParam) {
|
|
1200
|
+
// the base: typeof Base, or ClassWithMixin<typeof Base, …>
|
|
1201
|
+
let baseQuery = param.type;
|
|
1202
|
+
if (isTypeReferenceNode(baseQuery) && (baseQuery.typeArguments ?? []).length > 0)
|
|
1203
|
+
baseQuery = baseQuery.typeArguments[0];
|
|
1204
|
+
const base = baseQuery?.kind === 'TypeQuery' && isIdentifier(baseQuery.exprName) ? baseQuery.exprName.text : undefined;
|
|
1205
|
+
if (!base) {
|
|
1206
|
+
out.push(st);
|
|
1207
|
+
continue;
|
|
1208
|
+
}
|
|
1209
|
+
const className = isIdentifier(cls.name) ? cls.name.text : `${factoryName}Mixin`;
|
|
1210
|
+
const declaration = {
|
|
1211
|
+
...cls,
|
|
1212
|
+
kind: 'ClassDeclaration',
|
|
1213
|
+
name: { kind: 'Identifier', text: className, ...at },
|
|
1214
|
+
heritageClauses: [{ ...clause, types: [{ ...clause.types[0], expression: { kind: 'Identifier', text: base, ...at } }] }],
|
|
1215
|
+
tnMixin: true,
|
|
1216
|
+
modifiers: (cls.modifiers ?? []).filter((m) => m.kind !== 'ExportKeyword' && m.kind !== 'DefaultKeyword')
|
|
1217
|
+
};
|
|
1218
|
+
if (decl) {
|
|
1219
|
+
decl.initializer = { kind: 'TnMixinFactory', expression: { kind: 'Identifier', text: className, ...at }, ...at };
|
|
1220
|
+
}
|
|
1221
|
+
else {
|
|
1222
|
+
// (a function declaration: the class it makes, over the class argument)
|
|
1223
|
+
const apply = { kind: 'TnMixinApply', mixinName: className, expression: { kind: 'Identifier', text: param.name.text, ...at }, ...at };
|
|
1224
|
+
fn.body = { kind: 'Block', statements: [{ kind: 'ReturnStatement', expression: apply, ...at }], ...at };
|
|
1225
|
+
fn.type = { kind: 'AnyKeyword', ...at };
|
|
1226
|
+
}
|
|
1227
|
+
bases.push(base);
|
|
1228
|
+
out.push(declaration, st);
|
|
1229
|
+
continue;
|
|
1230
|
+
}
|
|
1231
|
+
// a function declaration returning a subclass of a known class
|
|
1232
|
+
// (function Extra() { return class extends Base {…} }): a class of its own
|
|
1233
|
+
const fixedBase = isIdentifier(clause?.types?.[0]?.expression) ? clause.types[0].expression.text : undefined;
|
|
1234
|
+
const className = isIdentifier(cls.name) ? cls.name.text : `${factoryName}Class`;
|
|
1235
|
+
if (isFunctionDeclaration(fn) && fixedBase && declaredClassNames.has(fixedBase) && parameters.length === 0 && !declaredClassNames.has(className) &&
|
|
1236
|
+
(fn.body?.kind === 'ClassExpression' || (isBlock(fn.body) && (fn.body.statements ?? []).length === 1))) {
|
|
1237
|
+
const declaration = {
|
|
1238
|
+
...cls,
|
|
1239
|
+
kind: 'ClassDeclaration',
|
|
1240
|
+
name: { kind: 'Identifier', text: className, ...at },
|
|
1241
|
+
modifiers: (cls.modifiers ?? []).filter((m) => m.kind !== 'ExportKeyword' && m.kind !== 'DefaultKeyword'),
|
|
1242
|
+
parent: sourceFile
|
|
1243
|
+
};
|
|
1244
|
+
fn.body = {
|
|
1245
|
+
kind: 'Block',
|
|
1246
|
+
statements: [{ kind: 'ReturnStatement', expression: { kind: 'Identifier', text: className, ...at }, ...at }],
|
|
1247
|
+
...at
|
|
1248
|
+
};
|
|
1249
|
+
fn.type = { kind: 'AnyKeyword', ...at };
|
|
1250
|
+
out.push(declaration, st);
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1253
|
+
out.push(st);
|
|
1197
1254
|
}
|
|
1198
1255
|
sourceFile.statements = out;
|
|
1199
1256
|
// (the base, imported for its type, is extended as a value now)
|
|
@@ -1271,12 +1328,36 @@ function lowerModuleForms(node) {
|
|
|
1271
1328
|
});
|
|
1272
1329
|
}
|
|
1273
1330
|
}
|
|
1331
|
+
// const require = createRequire(import.meta.url): the names a module is
|
|
1332
|
+
// required through (const fs = require('node:fs') is import * as fs)
|
|
1333
|
+
const requireNames = new Set();
|
|
1334
|
+
if (node.kind === 'SourceFile') {
|
|
1335
|
+
for (const st of node.statements) {
|
|
1336
|
+
if (st.kind !== 'VariableStatement')
|
|
1337
|
+
continue;
|
|
1338
|
+
for (const d of st.declarationList?.declarations ?? []) {
|
|
1339
|
+
const callee = d.initializer?.kind === 'CallExpression' ? d.initializer.expression : undefined;
|
|
1340
|
+
const calleeName = isIdentifier(callee) ? callee.text : isPropertyAccessExpression(callee) ? callee.name.text : '';
|
|
1341
|
+
if (isIdentifier(d.name) && calleeName === 'createRequire')
|
|
1342
|
+
requireNames.add(d.name.text);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1274
1346
|
node.statements = node.statements.map((statement) => {
|
|
1275
1347
|
const namespaceImport = (name, specifier) => ({
|
|
1276
1348
|
kind: 'ImportDeclaration',
|
|
1277
1349
|
moduleSpecifier: specifier,
|
|
1278
1350
|
importClause: { kind: 'ImportClause', namedBindings: { kind: 'NamespaceImport', name } }
|
|
1279
1351
|
});
|
|
1352
|
+
// const x = require('spec') (not a JSON file, which is read as a value)
|
|
1353
|
+
if (requireNames.size > 0 && statement.kind === 'VariableStatement' && !hasModifier(statement, 'ExportKeyword')) {
|
|
1354
|
+
const decls = statement.declarationList?.declarations ?? [];
|
|
1355
|
+
const required = decls.length === 1 ? decls[0].initializer : undefined;
|
|
1356
|
+
if (required?.kind === 'CallExpression' && isIdentifier(required.expression) && requireNames.has(required.expression.text) &&
|
|
1357
|
+
isStringLiteral(required.arguments?.[0]) && !/\.json$/i.test(String(required.arguments[0].text)) && isIdentifier(decls[0].name)) {
|
|
1358
|
+
return { ...namespaceImport(decls[0].name, required.arguments[0]), line: statement.line, column: statement.column };
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1280
1361
|
if (statement.kind === 'ExportDeclaration' && statement.moduleSpecifier && !statement.isTypeOnly) {
|
|
1281
1362
|
const clause = statement.exportClause;
|
|
1282
1363
|
// (reexport: the module linker reads these as exports too)
|
|
@@ -2689,16 +2770,81 @@ function lowerExpandoFunctions(sourceFile) {
|
|
|
2689
2770
|
};
|
|
2690
2771
|
sourceFile.statements = sourceFile.statements.map((statement) => rewrite(statement));
|
|
2691
2772
|
}
|
|
2692
|
-
const DISPOSE_SYMBOLS = {
|
|
2773
|
+
const DISPOSE_SYMBOLS = {
|
|
2774
|
+
dispose: '__dispose', asyncDispose: '__asyncDispose', toPrimitive: '__toPrimitive', toStringTag: '__toStringTag'
|
|
2775
|
+
};
|
|
2693
2776
|
function getDisposeSymbolName(expr) {
|
|
2694
2777
|
if (!isPropertyAccessExpression(expr) || !isIdentifier(expr.expression) || expr.expression.text !== 'Symbol')
|
|
2695
2778
|
return undefined;
|
|
2696
2779
|
return ownEntry(DISPOSE_SYMBOLS, expr.name.text);
|
|
2697
2780
|
}
|
|
2781
|
+
// util.inspect.custom (inspect.custom, util.inspect.custom) or
|
|
2782
|
+
// Symbol.for('nodejs.util.inspect.custom') as a member name
|
|
2783
|
+
function isInspectCustomSymbol(expr) {
|
|
2784
|
+
if (!expr)
|
|
2785
|
+
return false;
|
|
2786
|
+
if (isPropertyAccessExpression(expr) && expr.name.text === 'custom') {
|
|
2787
|
+
const owner = expr.expression;
|
|
2788
|
+
return (isIdentifier(owner) && owner.text === 'inspect') || (isPropertyAccessExpression(owner) && owner.name.text === 'inspect');
|
|
2789
|
+
}
|
|
2790
|
+
return isCallExpression(expr) && isPropertyAccessExpression(expr.expression) && isIdentifier(expr.expression.expression) &&
|
|
2791
|
+
expr.expression.expression.text === 'Symbol' && expr.expression.name.text === 'for' &&
|
|
2792
|
+
isStringLiteral(expr.arguments?.[0]) && expr.arguments[0].text === 'nodejs.util.inspect.custom';
|
|
2793
|
+
}
|
|
2794
|
+
// Symbol.for(key) with this key
|
|
2795
|
+
function isRegisteredSymbol(expr, key) {
|
|
2796
|
+
return !!expr && isCallExpression(expr) && isPropertyAccessExpression(expr.expression) && isIdentifier(expr.expression.expression) &&
|
|
2797
|
+
expr.expression.expression.text === 'Symbol' && expr.expression.name.text === 'for' &&
|
|
2798
|
+
isStringLiteral(expr.arguments?.[0]) && expr.arguments[0].text === key;
|
|
2799
|
+
}
|
|
2800
|
+
// Symbol.for('nodejs.rejection') / (EventEmitter.)captureRejectionSymbol as
|
|
2801
|
+
// a member name: an EventEmitter subclass's captured-rejection handler
|
|
2802
|
+
function isRejectionSymbol(expr) {
|
|
2803
|
+
if (!expr)
|
|
2804
|
+
return false;
|
|
2805
|
+
if (isIdentifier(expr) && expr.text === 'captureRejectionSymbol')
|
|
2806
|
+
return true;
|
|
2807
|
+
if (isPropertyAccessExpression(expr) && expr.name.text === 'captureRejectionSymbol')
|
|
2808
|
+
return true;
|
|
2809
|
+
return isRegisteredSymbol(expr, 'nodejs.rejection');
|
|
2810
|
+
}
|
|
2811
|
+
// Symbol.asyncIterator: an async generator method is a channel like
|
|
2812
|
+
// Symbol.iterator's (for await reads it the same way)
|
|
2813
|
+
function isAsyncIteratorSymbol(expr) {
|
|
2814
|
+
return !!expr && isPropertyAccessExpression(expr) && isIdentifier(expr.expression) && expr.expression.text === 'Symbol' && expr.name.text === 'asyncIterator';
|
|
2815
|
+
}
|
|
2698
2816
|
// [Symbol.dispose]() { … } → __dispose() { … }; x[Symbol.dispose]() → x.__dispose()
|
|
2817
|
+
// (likewise toPrimitive / toStringTag, and a class's static [Symbol.hasInstance])
|
|
2699
2818
|
function lowerDisposeSymbols(node) {
|
|
2700
2819
|
for (const child of childNodes(node))
|
|
2701
2820
|
lowerDisposeSymbols(child);
|
|
2821
|
+
if (node.kind === 'ClassDeclaration' || node.kind === 'ClassExpression') {
|
|
2822
|
+
for (const member of node.members ?? []) {
|
|
2823
|
+
if (member.name?.kind === 'ComputedPropertyName' && isAsyncIteratorSymbol(member.name.expression)) {
|
|
2824
|
+
member.name.expression.name = { kind: 'Identifier', text: 'iterator' };
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
if (node.kind === 'ElementAccessExpression' && isAsyncIteratorSymbol(node.argumentExpression)) {
|
|
2829
|
+
node.argumentExpression.name = { kind: 'Identifier', text: 'iterator' };
|
|
2830
|
+
}
|
|
2831
|
+
if (node.name?.kind === 'ComputedPropertyName' && isMethodDeclaration(node) && hasModifier(node, 'StaticKeyword') &&
|
|
2832
|
+
isPropertyAccessExpression(node.name.expression) && isIdentifier(node.name.expression.expression) &&
|
|
2833
|
+
node.name.expression.expression.text === 'Symbol' && node.name.expression.name.text === 'hasInstance') {
|
|
2834
|
+
node.name = { kind: 'Identifier', text: '__hasInstance' };
|
|
2835
|
+
}
|
|
2836
|
+
if (node.name?.kind === 'ComputedPropertyName' && isInspectCustomSymbol(node.name.expression)) {
|
|
2837
|
+
node.name = { kind: 'Identifier', text: '__inspectCustom' };
|
|
2838
|
+
}
|
|
2839
|
+
if (node.name?.kind === 'ComputedPropertyName' && isMethodDeclaration(node) && isRejectionSymbol(node.name.expression)) {
|
|
2840
|
+
node.name = { kind: 'Identifier', text: '__nodejsRejection' };
|
|
2841
|
+
}
|
|
2842
|
+
// readable[Symbol.for('Stream.toAsyncStreamable')]() → readable.__toAsyncStreamable()
|
|
2843
|
+
if (node.kind === 'ElementAccessExpression' && isRegisteredSymbol(node.argumentExpression, 'Stream.toAsyncStreamable')) {
|
|
2844
|
+
node.kind = 'PropertyAccessExpression';
|
|
2845
|
+
node.name = { kind: 'Identifier', text: '__toAsyncStreamable' };
|
|
2846
|
+
delete node.argumentExpression;
|
|
2847
|
+
}
|
|
2702
2848
|
if (node.name?.kind === 'ComputedPropertyName') {
|
|
2703
2849
|
const name = getDisposeSymbolName(node.name.expression);
|
|
2704
2850
|
if (name) {
|
|
@@ -3515,6 +3661,7 @@ export function transpileToNative(code, options) {
|
|
|
3515
3661
|
diagnostics.length = 0;
|
|
3516
3662
|
goSafeIdSeed = 1;
|
|
3517
3663
|
consoleGroupsUsed = code.includes('console.group');
|
|
3664
|
+
arrayBufferStateUsed = /maxByteLength|\.(resize|grow|transfer|transferToFixedLength)\(/.test(code);
|
|
3518
3665
|
declaredFunctions.clear();
|
|
3519
3666
|
nestedFunctionNames.clear();
|
|
3520
3667
|
nullableArrayCache.clear();
|
|
@@ -3842,6 +3989,30 @@ func main() {
|
|
|
3842
3989
|
${outsideCode.trim()}
|
|
3843
3990
|
${LINE_RESET}
|
|
3844
3991
|
${helpersCode}`.trimEnd();
|
|
3992
|
+
if (options?.seaAssets && Object.keys(options.seaAssets).length > 0) {
|
|
3993
|
+
const entries = Object.entries(options.seaAssets)
|
|
3994
|
+
.map(([key, data]) => `\t${JSON.stringify(key)}: ${JSON.stringify(data)},`)
|
|
3995
|
+
.join('\n');
|
|
3996
|
+
localImportFiles.set('tn_sea.go', `${GENERATED_HEADER}
|
|
3997
|
+
package main
|
|
3998
|
+
|
|
3999
|
+
import "encoding/base64"
|
|
4000
|
+
|
|
4001
|
+
// node:sea's assets (--sea-config): contents base64-encoded, decoded once
|
|
4002
|
+
var tnSeaAssetData = map[string]string{
|
|
4003
|
+
${entries}
|
|
4004
|
+
}
|
|
4005
|
+
|
|
4006
|
+
func init() {
|
|
4007
|
+
tnSeaAssets = make(map[string][]byte, len(tnSeaAssetData))
|
|
4008
|
+
for key, data := range tnSeaAssetData {
|
|
4009
|
+
decoded, err := base64.StdEncoding.DecodeString(data)
|
|
4010
|
+
if err == nil {
|
|
4011
|
+
tnSeaAssets[key] = decoded
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
}`);
|
|
4015
|
+
}
|
|
3845
4016
|
return {
|
|
3846
4017
|
main: applyLineDirectives(finishLiteralSites(main), goFile),
|
|
3847
4018
|
files: localImportFiles,
|
|
@@ -4417,6 +4588,12 @@ function visitNode(node, options = {}) {
|
|
|
4417
4588
|
const mixinName = node.expression.text;
|
|
4418
4589
|
return `func(superClass interface{}) interface{} { return TnMixinClass(${toGoStringLiteral(originalTopNames.get(mixinName) ?? mixinName)}, superClass, TnMixinWrap_${mixinName}, TnMixinFields_${mixinName}) }`;
|
|
4419
4590
|
}
|
|
4591
|
+
else if (node.kind === 'TnMixinApply') {
|
|
4592
|
+
// (see lowerMixinFactories: a factory function body — the class extending
|
|
4593
|
+
// the class it was given)
|
|
4594
|
+
useHelper('classes');
|
|
4595
|
+
return `TnMixinClass(${toGoStringLiteral(originalTopNames.get(node.mixinName) ?? node.mixinName)}, ${toGoValueOfType(node.expression, 'interface{}')}, TnMixinWrap_${node.mixinName}, TnMixinFields_${node.mixinName})`;
|
|
4596
|
+
}
|
|
4420
4597
|
else if (node.kind === 'TnExtendClass') {
|
|
4421
4598
|
// (see lowerDynamicExtends)
|
|
4422
4599
|
useHelper('classes');
|
|
@@ -4494,8 +4671,8 @@ function visitNode(node, options = {}) {
|
|
|
4494
4671
|
if (isStringLiteral(node.argumentExpression)) {
|
|
4495
4672
|
return `${visit(node.expression)}[${visit(node.argumentExpression)}]`;
|
|
4496
4673
|
}
|
|
4497
|
-
// Typed array elements read as numbers (out of range: 0)
|
|
4498
|
-
if (isTypedArrayGoType(targetType) && !isAssignmentTarget(node)) {
|
|
4674
|
+
// Typed array elements read as numbers (out of range: 0); BigInt64Array's as bigints
|
|
4675
|
+
if ((isTypedArrayGoType(targetType) || isBigIntArrayGoType(targetType)) && !isAssignmentTarget(node)) {
|
|
4499
4676
|
return `${visit(node.expression)}.Get(${visit(node.argumentExpression)})`;
|
|
4500
4677
|
}
|
|
4501
4678
|
// Buffer / Uint8Array elements read as numbers
|
|
@@ -4565,6 +4742,10 @@ function visitNode(node, options = {}) {
|
|
|
4565
4742
|
useHelper('getenv');
|
|
4566
4743
|
return `TnGetenv("${node.name.text}")`;
|
|
4567
4744
|
}
|
|
4745
|
+
// ArrayBuffer state: resizable / growable / detached buffers
|
|
4746
|
+
const arrayBufferRead = !isCallee(node) && !isAssignmentTarget(node) ? visitArrayBufferProperty(node) : undefined;
|
|
4747
|
+
if (arrayBufferRead !== undefined)
|
|
4748
|
+
return arrayBufferRead;
|
|
4568
4749
|
if (!isCallee(node) && !isAssignmentTarget(node)) {
|
|
4569
4750
|
const nodeValue = visitNodeValue(node);
|
|
4570
4751
|
if (nodeValue !== undefined)
|
|
@@ -4588,6 +4769,11 @@ function visitNode(node, options = {}) {
|
|
|
4588
4769
|
}
|
|
4589
4770
|
if (hasDynamicProperties(node.expression) && node.name.text === 'length' && !isCallee(node)) {
|
|
4590
4771
|
useHelper('dynamic');
|
|
4772
|
+
// n?.length: undefined — not 0 — when n is nullish, or when the value
|
|
4773
|
+
// has no length (a plain record) — TnLength reads 0 for both
|
|
4774
|
+
if (hasQuestionDot(node)) {
|
|
4775
|
+
return `func() interface{} { __l := ${peekRead(visit(node.expression))}; if TnIsNil(__l) { return nil }; return TnGet(__l, "length") }()`;
|
|
4776
|
+
}
|
|
4591
4777
|
return `TnLength(${peekRead(visit(node.expression))})`;
|
|
4592
4778
|
}
|
|
4593
4779
|
// x.constructor of any value: its class (when it is a class instance)
|
|
@@ -4778,6 +4964,15 @@ function visitNode(node, options = {}) {
|
|
|
4778
4964
|
useHelper('regexMatch');
|
|
4779
4965
|
return `TnMatchIndex(${leftSide})`;
|
|
4780
4966
|
}
|
|
4967
|
+
// A DOMException's .code: its legacy number
|
|
4968
|
+
if (rightSide === 'code' && isDOMExceptionValue(node.expression) && !isCallee(node) && !isAssignmentTarget(node)) {
|
|
4969
|
+
return `${leftSide}.Get_domCode()`;
|
|
4970
|
+
}
|
|
4971
|
+
// A /d match array's .indices
|
|
4972
|
+
if (rightSide === 'indices' && leftGoType === '[]string' && !isCallee(node) && !isAssignmentTarget(node)) {
|
|
4973
|
+
useHelper('regexMatch');
|
|
4974
|
+
return `TnMatchIndices(${leftSide})`;
|
|
4975
|
+
}
|
|
4781
4976
|
if (leftGoType?.includes('struct{') &&
|
|
4782
4977
|
!isCallee(node) &&
|
|
4783
4978
|
getStructFieldGoType(leftGoType.replace(/^\*/, ''), node.name.text)?.startsWith('func')) {
|
|
@@ -4820,7 +5015,7 @@ function visitNode(node, options = {}) {
|
|
|
4820
5015
|
!leftGoType?.includes('struct{') &&
|
|
4821
5016
|
!leftGoType?.startsWith('*[]')) {
|
|
4822
5017
|
// (a plain function's this typed as a class: its getters too)
|
|
4823
|
-
const typedClass = leftGoType?.startsWith('*')
|
|
5018
|
+
const typedClass = leftGoType?.startsWith('*') ? leftGoType.slice(1).replace(/\[.*\]$/, '') : undefined;
|
|
4824
5019
|
const className = typedClass && classNames.has(typedClass)
|
|
4825
5020
|
? typedClass
|
|
4826
5021
|
: node.expression.kind === 'ThisKeyword'
|
|
@@ -4830,12 +5025,14 @@ function visitNode(node, options = {}) {
|
|
|
4830
5025
|
: undefined;
|
|
4831
5026
|
const accessorName = memberKey(node.name);
|
|
4832
5027
|
if (className && (classGetterMethods.has(`${className}.${accessorName}`) || classMember(className, 'get', accessorName))) {
|
|
5028
|
+
useNodeHelperForGetter(className, accessorName);
|
|
4833
5029
|
return `${leftSide}.Get_${rightSide}()`;
|
|
4834
5030
|
}
|
|
4835
5031
|
}
|
|
4836
5032
|
// Record/Map reads via dot syntax are key lookups; method callees keep their name
|
|
4837
5033
|
if ((objectType === 'Map' || objectType === 'Record') &&
|
|
4838
|
-
|
|
5034
|
+
// (a plain object's size is a key: wasm exports.size)
|
|
5035
|
+
(rightSide !== 'size' || objectType === 'Record') &&
|
|
4839
5036
|
rightSide !== 'length' &&
|
|
4840
5037
|
!isCallee(node) &&
|
|
4841
5038
|
!isAssignmentTarget(node)) {
|
|
@@ -5198,6 +5395,9 @@ function visitNode(node, options = {}) {
|
|
|
5198
5395
|
else if (node.initializer && isRegularExpressionLiteral(node.initializer)) {
|
|
5199
5396
|
variableTypes.set(node.name.text, 'RegExp');
|
|
5200
5397
|
}
|
|
5398
|
+
else if (node.initializer && isNodeRecordExpression(node.initializer)) {
|
|
5399
|
+
variableTypes.set(node.name.text, 'Record');
|
|
5400
|
+
}
|
|
5201
5401
|
// Array-typed variables hold references (*[]T)
|
|
5202
5402
|
if (node.type && !isInferredAny) {
|
|
5203
5403
|
setVarGoType(node.name.text, getType(node.type));
|
|
@@ -5231,9 +5431,10 @@ function visitNode(node, options = {}) {
|
|
|
5231
5431
|
(type === 'interface{}' && unwrapParentheses(node.initializer).kind === 'NullKeyword'))) {
|
|
5232
5432
|
initializer = `= ${toGoValueOfType(node.initializer, type)}`;
|
|
5233
5433
|
}
|
|
5234
|
-
else if (node.initializer && type.startsWith('func(') && (isFunctionExpression(unwrapParentheses(node.initializer)) || isArrowFunction(unwrapParentheses(node.initializer))
|
|
5235
|
-
|
|
5236
|
-
//
|
|
5434
|
+
else if (node.initializer && type.startsWith('func(') && (isFunctionExpression(unwrapParentheses(node.initializer)) || isArrowFunction(unwrapParentheses(node.initializer)) ||
|
|
5435
|
+
functionValueGoType(unwrapParentheses(node.initializer)).startsWith('func('))) {
|
|
5436
|
+
// (a function value — a literal or a declared function's name — into a
|
|
5437
|
+
// typed slot: adapted when its array parameters differ, see toGoValueOfType)
|
|
5237
5438
|
initializer = `= ${toGoValueOfType(node.initializer, type)}`;
|
|
5238
5439
|
}
|
|
5239
5440
|
// Array references take the address of the fresh array
|
|
@@ -5639,6 +5840,13 @@ function visitNode(node, options = {}) {
|
|
|
5639
5840
|
: 'nil';
|
|
5640
5841
|
return `func() []interface{} { ${srcVar} := ${source}; __n := int(${srcVar}.length); __out := make([]interface{}, 0, __n); for ${iVar} := 0; ${iVar} < __n; ${iVar}++ { __out = append(__out, ${itemExpr}) }; return __out }()`;
|
|
5641
5842
|
}
|
|
5843
|
+
// Array.fromAsync(source, mapFn?): a promise of the source's (awaited) values
|
|
5844
|
+
if (isPropertyAccessExpression(node.expression) &&
|
|
5845
|
+
isIdentifier(node.expression.expression) &&
|
|
5846
|
+
node.expression.expression.text === 'Array' &&
|
|
5847
|
+
node.expression.name.text === 'fromAsync') {
|
|
5848
|
+
return visitArrayFromAsync(node);
|
|
5849
|
+
}
|
|
5642
5850
|
const arrayHigherOrderCall = visitArrayHigherOrderCall(node);
|
|
5643
5851
|
if (arrayHigherOrderCall) {
|
|
5644
5852
|
return arrayHigherOrderCall;
|
|
@@ -5757,7 +5965,7 @@ function visitNode(node, options = {}) {
|
|
|
5757
5965
|
currentReceiverGoType = isPropertyAccessExpression(node.expression)
|
|
5758
5966
|
? inferExpressionType(node.expression.expression)
|
|
5759
5967
|
: undefined;
|
|
5760
|
-
const call = getCallString(safeCaller, args, typeArgs, objectType);
|
|
5968
|
+
const call = getCallString(safeCaller, args, typeArgs, objectType, node);
|
|
5761
5969
|
const arrayBacks = arrayCallWriteBacks ?? [];
|
|
5762
5970
|
arrayCallWriteBacks = abSaved;
|
|
5763
5971
|
return arrayBacks.length > 0 ? wrapArrayCallWriteBacks(node, call, arrayBacks) : call;
|
|
@@ -5800,6 +6008,11 @@ function visitNode(node, options = {}) {
|
|
|
5800
6008
|
const value = operandType.startsWith('*') ? `TnPtrValue(${visit(node.operand)})` : `interface{}(${visit(node.operand)})`;
|
|
5801
6009
|
return `${node.operator === 'MinusToken' ? '-' : ''}TnNumber(${value})`;
|
|
5802
6010
|
}
|
|
6011
|
+
// (+x of a class instance: its [Symbol.toPrimitive]('number') / valueOf)
|
|
6012
|
+
if (operandType.startsWith('*') && classNames.has(operandType.slice(1).replace(/\[.*$/, ''))) {
|
|
6013
|
+
useHelper('dynamic');
|
|
6014
|
+
return `${node.operator === 'MinusToken' ? '-' : ''}TnNumber(interface{}(${visit(node.operand)}))`;
|
|
6015
|
+
}
|
|
5803
6016
|
}
|
|
5804
6017
|
// -0: Go constant arithmetic has no negative zero
|
|
5805
6018
|
if (node.operator === 'MinusToken' && isNumericLiteral(node.operand) && Number(node.operand.text) === 0) {
|
|
@@ -5897,6 +6110,8 @@ function visitNode(node, options = {}) {
|
|
|
5897
6110
|
(node.right.text === 'Error' || BUILTIN_ERROR_NAMES.has(node.right.text)) &&
|
|
5898
6111
|
!classNames.has(node.right.text)) {
|
|
5899
6112
|
useHelper('error');
|
|
6113
|
+
if (node.right.text === 'QuotaExceededError')
|
|
6114
|
+
return `func() bool { __e, __ok := interface{}(${visit(node.left)}).(*TnError); return __ok && __e.dom && __e.Get_name() == "QuotaExceededError" }()`;
|
|
5900
6115
|
return `TnIsErrorOf(${visit(node.left)}, ${toGoStringLiteral(node.right.text)})`;
|
|
5901
6116
|
}
|
|
5902
6117
|
if (node.operatorToken.kind === 'InstanceOfKeyword' && isIdentifier(node.right) && node.right.text === 'Object' && !classNames.has('Object')) {
|
|
@@ -5908,10 +6123,15 @@ function visitNode(node, options = {}) {
|
|
|
5908
6123
|
// x instanceof Int32Array / URL / …: a Node global class's Go type
|
|
5909
6124
|
const nodeClassKey = nodeClassKeyOfName(node.right.text);
|
|
5910
6125
|
const nodeClass = nodeClassKey ? nodeRegistry.classes[nodeClassKey] : undefined;
|
|
5911
|
-
if (nodeClass)
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
6126
|
+
if (nodeClass)
|
|
6127
|
+
return nodeClassInstanceOf(node.left, nodeClassKey);
|
|
6128
|
+
}
|
|
6129
|
+
if (node.operatorToken.kind === 'InstanceOfKeyword' && isPropertyAccessExpression(node.right)) {
|
|
6130
|
+
// x instanceof WebAssembly.Memory / WebAssembly.RuntimeError: a Node
|
|
6131
|
+
// class reached through a namespace
|
|
6132
|
+
const nodeClassKey = resolveNodeKey(node.right);
|
|
6133
|
+
if (nodeClassKey && nodeRegistry.classes[nodeClassKey])
|
|
6134
|
+
return nodeClassInstanceOf(node.left, nodeClassKey);
|
|
5915
6135
|
}
|
|
5916
6136
|
if (node.operatorToken.kind === 'InstanceOfKeyword' && isIdentifier(node.right) && !classNames.has(node.right.text)) {
|
|
5917
6137
|
const builtinCheck = builtinInstanceOf(visit(node.left), node.right.text);
|
|
@@ -5928,6 +6148,13 @@ function visitNode(node, options = {}) {
|
|
|
5928
6148
|
useHelper('classes');
|
|
5929
6149
|
return `TnInstanceOf(${visit(node.left)}, ${visit(node.right)})`;
|
|
5930
6150
|
}
|
|
6151
|
+
if (node.operatorToken.kind === 'InstanceOfKeyword' && isIdentifier(node.right) && classHasStaticHasInstance(node.right.text)) {
|
|
6152
|
+
// (C decides: its static [Symbol.hasInstance](x))
|
|
6153
|
+
const callee = { kind: 'PropertyAccessExpression', expression: node.right, name: { kind: 'Identifier', text: '__hasInstance' } };
|
|
6154
|
+
const call = { kind: 'CallExpression', expression: callee, arguments: [node.left], parent: node.parent, line: node.line, column: node.column };
|
|
6155
|
+
callee.parent = call;
|
|
6156
|
+
return `TnTruthy(interface{}(${visit(call)}))`;
|
|
6157
|
+
}
|
|
5931
6158
|
if (node.operatorToken.kind === 'InstanceOfKeyword' && isIdentifier(node.right)) {
|
|
5932
6159
|
// x instanceof C: the runtime type is C's pointer type, or a subclass's
|
|
5933
6160
|
const rightClass = node.right.text;
|
|
@@ -6022,22 +6249,76 @@ function visitNode(node, options = {}) {
|
|
|
6022
6249
|
const bigRight = inferExpressionType(node.right);
|
|
6023
6250
|
if (bigLeft === '*tnbig.Int' || bigRight === '*tnbig.Int') {
|
|
6024
6251
|
useHelper('bigint');
|
|
6252
|
+
useHelper('dynamic');
|
|
6025
6253
|
let bl = visit(node.left);
|
|
6026
6254
|
let br = visit(node.right);
|
|
6255
|
+
const loose = node.operatorToken.kind === 'EqualsEqualsToken' || node.operatorToken.kind === 'ExclamationEqualsToken';
|
|
6027
6256
|
// number | bigint values (node:sqlite's changes): === is true only for an
|
|
6028
|
-
// equal bigint; other operators convert the dynamic side
|
|
6257
|
+
// equal bigint; other operators convert the dynamic side. JS == compares
|
|
6258
|
+
// a bigint's value with a number's or string's (5n == 5, 5n == '5')
|
|
6029
6259
|
const dynamicSide = bigLeft === 'interface{}' ? bl : bigRight === 'interface{}' ? br : '';
|
|
6030
6260
|
if (dynamicSide) {
|
|
6031
6261
|
const bigSide = dynamicSide === bl ? br : bl;
|
|
6032
6262
|
if (op === '==')
|
|
6033
|
-
return `TnBigSame(${dynamicSide}, ${bigSide})`;
|
|
6263
|
+
return loose ? `TnLooseEqual(interface{}(${dynamicSide}), interface{}(${bigSide}))` : `TnBigSame(${dynamicSide}, ${bigSide})`;
|
|
6034
6264
|
if (op === '!=')
|
|
6035
|
-
return `!TnBigSame(${dynamicSide}, ${bigSide})`;
|
|
6265
|
+
return loose ? `!TnLooseEqual(interface{}(${dynamicSide}), interface{}(${bigSide}))` : `!TnBigSame(${dynamicSide}, ${bigSide})`;
|
|
6266
|
+
// (the order compares the dynamic side — a bigint when it holds one —
|
|
6267
|
+
// against the big value as a number: NaN is never ordered, as in JS;
|
|
6268
|
+
// only arithmetic converts through TnToBigInt, which throws)
|
|
6269
|
+
const dynLeft = dynamicSide === bl;
|
|
6270
|
+
const order = `TnBigOrder(${dynamicSide}, TnNumber(${bigSide}))`;
|
|
6271
|
+
if (op === '<')
|
|
6272
|
+
return dynLeft ? `${order} == -1` : `${order} == 1`;
|
|
6273
|
+
if (op === '>')
|
|
6274
|
+
return dynLeft ? `${order} == 1` : `${order} == -1`;
|
|
6275
|
+
if (op === '<=')
|
|
6276
|
+
return dynLeft ? `func() bool { o := ${order}; return o == -1 || o == 0 }()` : `func() bool { o := ${order}; return o == 0 || o == 1 }()`;
|
|
6277
|
+
if (op === '>=')
|
|
6278
|
+
return dynLeft ? `func() bool { o := ${order}; return o == 0 || o == 1 }()` : `func() bool { o := ${order}; return o == 0 || o == -1 }()`;
|
|
6036
6279
|
if (dynamicSide === bl)
|
|
6037
6280
|
bl = `TnToBigInt(${bl})`;
|
|
6038
6281
|
else
|
|
6039
6282
|
br = `TnToBigInt(${br})`;
|
|
6040
6283
|
}
|
|
6284
|
+
// a static number (or NaN / ±Infinity, or an integer string) on the
|
|
6285
|
+
// other side (5n > 5, b == 5, b == '5'): == compares values (=== is
|
|
6286
|
+
// always false — different types), the order is exact; a value that
|
|
6287
|
+
// isn't a bigint at run time (an any variable reassigned) compares
|
|
6288
|
+
// by ToNumber, as JS does
|
|
6289
|
+
const bigFirst = bigLeft === '*tnbig.Int';
|
|
6290
|
+
const otherSide = bigFirst ? bigRight : bigLeft;
|
|
6291
|
+
const otherNode = bigFirst ? node.right : node.left;
|
|
6292
|
+
const otherU = unwrapParentheses(otherNode);
|
|
6293
|
+
const isStaticNumber = otherSide === 'float64' ||
|
|
6294
|
+
(isIdentifier(otherU) && ['NaN', 'Infinity'].includes(otherU.text) && !variableGoTypes.has(otherU.text) && !topLevelGoTypes.has(otherU.text));
|
|
6295
|
+
const otherIsString = otherSide === 'string';
|
|
6296
|
+
if ((isStaticNumber || otherIsString) && ['==', '!=', '<', '>', '<=', '>='].includes(op)) {
|
|
6297
|
+
const bigSide = bigFirst ? bl : br;
|
|
6298
|
+
const numberSide = bigFirst ? br : bl;
|
|
6299
|
+
if (op === '==') {
|
|
6300
|
+
if (loose)
|
|
6301
|
+
return otherIsString ? `TnBigLooseEqualStr(${bigSide}, ${numberSide})` : `TnBigLooseEqual(${bigSide}, ${numberSide})`;
|
|
6302
|
+
return 'false';
|
|
6303
|
+
}
|
|
6304
|
+
if (op === '!=') {
|
|
6305
|
+
if (loose)
|
|
6306
|
+
return otherIsString ? `!TnBigLooseEqualStr(${bigSide}, ${numberSide})` : `!TnBigLooseEqual(${bigSide}, ${numberSide})`;
|
|
6307
|
+
return 'true';
|
|
6308
|
+
}
|
|
6309
|
+
// (the order is the big value against the number's; the operands'
|
|
6310
|
+
// sides decide which comparison matches. A string compares by
|
|
6311
|
+
// ToNumber, as JS's relational operators read it)
|
|
6312
|
+
const order = `TnBigOrder(${bigSide}, ${otherIsString ? `TnNumber(${numberSide})` : numberSide})`;
|
|
6313
|
+
if (op === '<')
|
|
6314
|
+
return bigFirst ? `${order} == -1` : `${order} == 1`;
|
|
6315
|
+
if (op === '>')
|
|
6316
|
+
return bigFirst ? `${order} == 1` : `${order} == -1`;
|
|
6317
|
+
if (op === '<=')
|
|
6318
|
+
return bigFirst ? `${order} <= 0` : `func() bool { o := ${order}; return o == 0 || o == 1 }()`;
|
|
6319
|
+
if (op === '>=')
|
|
6320
|
+
return bigFirst ? `func() bool { o := ${order}; return o == 0 || o == 1 }()` : `func() bool { o := ${order}; return o == 0 || o == -1 }()`;
|
|
6321
|
+
}
|
|
6041
6322
|
// 'text ' + big: the bigint's decimal digits
|
|
6042
6323
|
if (op === '+' && (bigLeft === 'string' || bigRight === 'string')) {
|
|
6043
6324
|
return bigLeft === 'string' ? `${bl} + ${br}.String()` : `${bl}.String() + ${br}`;
|
|
@@ -6228,6 +6509,12 @@ function visitNode(node, options = {}) {
|
|
|
6228
6509
|
}
|
|
6229
6510
|
}
|
|
6230
6511
|
if (otherType && otherType !== 'nil' && !isNilableGoType(otherType)) {
|
|
6512
|
+
// rec[k] === undefined / rec.key === undefined / m.get(k) === undefined:
|
|
6513
|
+
// a missing key of a Record or Map reads undefined (a stored value of a
|
|
6514
|
+
// primitive type never is one), so the comparison is the key's presence
|
|
6515
|
+
const mapMissing = visitMapMissingKeyComparison(node, op, otherSide, otherType);
|
|
6516
|
+
if (mapMissing)
|
|
6517
|
+
return mapMissing;
|
|
6231
6518
|
return op === '!=' ? 'true' : 'false';
|
|
6232
6519
|
}
|
|
6233
6520
|
// JS loose equality across primitive types (ToNumber coercion)
|
|
@@ -6261,6 +6548,10 @@ function visitNode(node, options = {}) {
|
|
|
6261
6548
|
const goFieldAssignment = visitGoFieldAssignment(node, op);
|
|
6262
6549
|
if (goFieldAssignment !== undefined)
|
|
6263
6550
|
return goFieldAssignment;
|
|
6551
|
+
// big[i] = v on a BigInt64Array: Set wraps to 64 bits
|
|
6552
|
+
if (op === '=' && isElementAccessExpression(node.left) && isBigIntArrayGoType(inferExpressionType(node.left.expression))) {
|
|
6553
|
+
return `${visit(node.left.expression)}.Set(${visit(node.left.argumentExpression)}, ${toGoValueOfType(node.right, '*tnbig.Int')})`;
|
|
6554
|
+
}
|
|
6264
6555
|
// ta[i] = v / ta[i] op= v on a typed array: Set converts to the element type
|
|
6265
6556
|
if (isElementAccessExpression(node.left) && isTypedArrayGoType(inferExpressionType(node.left.expression))) {
|
|
6266
6557
|
const typedAssignment = visitTypedArrayAssignment(node.left, op, node.right);
|
|
@@ -7860,6 +8151,13 @@ function visitNode(node, options = {}) {
|
|
|
7860
8151
|
const list = errs ? toGoValueOfType(errs, '[]interface{}') : '[]interface{}{}';
|
|
7861
8152
|
return `func() *TnError { __e := TnNodeError("AggregateError", "", ${msg}); __e.props["errors"] = ${list}; return __e }()`;
|
|
7862
8153
|
}
|
|
8154
|
+
// new DOMException(message, name | options): a TnError marked as one
|
|
8155
|
+
if ((className === 'DOMException' || className === 'QuotaExceededError') && !classNames.has(className)) {
|
|
8156
|
+
useHelper('domException');
|
|
8157
|
+
const msg = (node.arguments ?? [])[0] ? toGoValueOfType(node.arguments[0], 'string') : '""';
|
|
8158
|
+
const opts = (node.arguments ?? [])[1] ? toGoValueOfType(node.arguments[1], 'interface{}') : 'nil';
|
|
8159
|
+
return `${className === 'DOMException' ? 'TnNewDOMException' : 'TnNewQuotaExceededError'}(${msg}, ${opts})`;
|
|
8160
|
+
}
|
|
7863
8161
|
// new TypeError(message) & co.: a TnError with that name
|
|
7864
8162
|
if (BUILTIN_ERROR_NAMES.has(className) && !classNames.has(className)) {
|
|
7865
8163
|
useHelper('error');
|
|
@@ -8000,12 +8298,16 @@ function visitNode(node, options = {}) {
|
|
|
8000
8298
|
const entries = (node.properties ?? [])
|
|
8001
8299
|
.map((p) => {
|
|
8002
8300
|
if (isPropertyAssignment(p))
|
|
8003
|
-
return
|
|
8301
|
+
return `__obj.Set(${propertyKeyString(p.name)}, ${visit(p.initializer)})`;
|
|
8004
8302
|
if (isShorthandPropertyAssignment(p))
|
|
8005
|
-
return
|
|
8303
|
+
return `__obj.Set(${mapKeyText(p.name)}, ${visit(p.name)})`;
|
|
8006
8304
|
return '';
|
|
8007
8305
|
})
|
|
8008
8306
|
.filter((e) => e);
|
|
8307
|
+
// (an ordered record, so the keys keep their order — a Go map's keys
|
|
8308
|
+
// come out sorted, and JS's Object.keys keeps insertion order)
|
|
8309
|
+
useHelper('orderedMap');
|
|
8310
|
+
const literal = `func() *TnMap[string, interface{}] { __obj := TnNewMap[string, interface{}](); ${entries.join('; ')}; return __obj }()`;
|
|
8009
8311
|
// x = {} for an any variable (Babel's addExtra: extra = {}; node.extra =
|
|
8010
8312
|
// extra; extra[key] = value): an ordered dynamic object — stored into a
|
|
8011
8313
|
// Record field it is that field's own object, so later keys reach it
|
|
@@ -8013,10 +8315,9 @@ function visitNode(node, options = {}) {
|
|
|
8013
8315
|
if (entries.length === 0 && (node.properties ?? []).length === 0 && isBinaryExpression(assignedParent) &&
|
|
8014
8316
|
assignedParent.operatorToken.kind === 'EqualsToken' && assignedParent.right === node && isIdentifier(unwrapParentheses(assignedParent.left)) &&
|
|
8015
8317
|
variableGoTypes.get(unwrapParentheses(assignedParent.left).text) === 'interface{}') {
|
|
8016
|
-
useHelper('orderedMap');
|
|
8017
8318
|
return 'TnNewMap[string, interface{}]()';
|
|
8018
8319
|
}
|
|
8019
|
-
return
|
|
8320
|
+
return literal;
|
|
8020
8321
|
}
|
|
8021
8322
|
const recordSpread = visitRecordSpreadLiteral(node);
|
|
8022
8323
|
if (recordSpread)
|
|
@@ -8743,6 +9044,12 @@ function toGoValueOfType(expr, goType) {
|
|
|
8743
9044
|
useHelper('slicePtr');
|
|
8744
9045
|
return `func() ${goType} { if __v, __ok := ${lookup.map}.Lookup(${lookup.key}); __ok { return TnSlicePtr(__v) }; return nil }()`;
|
|
8745
9046
|
}
|
|
9047
|
+
// (a slice value of the slot's own type: a nil slice is null — a
|
|
9048
|
+
// `??` of exec results —, so it stays nil; anything else is boxed)
|
|
9049
|
+
if (ownSlice === goType.slice(1)) {
|
|
9050
|
+
useHelper('slicePtr');
|
|
9051
|
+
return `TnSlicePtr(${boxedRead()})`;
|
|
9052
|
+
}
|
|
8746
9053
|
return `func() ${goType} { __v := ${boxedRead()}; return &__v }()`;
|
|
8747
9054
|
}
|
|
8748
9055
|
const code = visit(expr);
|
|
@@ -9132,7 +9439,7 @@ function getNarrowedNames(condition, whenTrue, seen = new Set()) {
|
|
|
9132
9439
|
if (kind === 'InstanceOfKeyword') {
|
|
9133
9440
|
const operand = unwrapParentheses(condition.left);
|
|
9134
9441
|
const className = isIdentifier(condition.right) ? condition.right.text : '';
|
|
9135
|
-
if (whenTrue && isIdentifier(operand) && classNames.has(className) && !isPolymorphicClass(className) &&
|
|
9442
|
+
if (whenTrue && isIdentifier(operand) && classNames.has(className) && !isPolymorphicClass(className) && !classHasStaticHasInstance(className) &&
|
|
9136
9443
|
untypedVariable(operand.text) && !referenceArrays.has(operand.text)) {
|
|
9137
9444
|
return [typeofNarrowingKey(operand.text, `*${getSafeName(className)}`)];
|
|
9138
9445
|
}
|
|
@@ -9678,6 +9985,54 @@ function visitConditionalNullUndefinedTest(node, op) {
|
|
|
9678
9985
|
const test = `(${held} && ${getSafeName(name.text)} == nil)`;
|
|
9679
9986
|
return op === '!=' ? `!${test}` : test;
|
|
9680
9987
|
}
|
|
9988
|
+
// rec[k] === undefined / rec.key === undefined / m.get(k) === undefined on a
|
|
9989
|
+
// Record or Map whose values are primitives: a missing key reads undefined,
|
|
9990
|
+
// and a stored value never is one — the comparison is the key's presence
|
|
9991
|
+
// (comma-ok, as JS sees a missing key)
|
|
9992
|
+
function visitMapMissingKeyComparison(node, op, otherSide, valueType) {
|
|
9993
|
+
if (op !== '==' && op !== '!=')
|
|
9994
|
+
return undefined;
|
|
9995
|
+
if (!otherSide || !valueType || isNilableGoType(valueType))
|
|
9996
|
+
return undefined;
|
|
9997
|
+
const element = unwrapParentheses(otherSide);
|
|
9998
|
+
let receiver;
|
|
9999
|
+
let mapType;
|
|
10000
|
+
let keyExpr;
|
|
10001
|
+
if (isElementAccessExpression(element) && !hasQuestionDot(element)) {
|
|
10002
|
+
receiver = element.expression;
|
|
10003
|
+
mapType = inferExpressionType(receiver) ?? '';
|
|
10004
|
+
if (mapType.startsWith('*TnMap[')) {
|
|
10005
|
+
keyExpr = toGoValueOfType(element.argumentExpression, extractMapKeyType(mapType));
|
|
10006
|
+
}
|
|
10007
|
+
else
|
|
10008
|
+
return undefined;
|
|
10009
|
+
}
|
|
10010
|
+
else if (isPropertyAccessExpression(element) && !hasQuestionDot(element) && isIdentifier(element.name)) {
|
|
10011
|
+
receiver = element.expression;
|
|
10012
|
+
mapType = inferExpressionType(receiver) ?? '';
|
|
10013
|
+
if (mapType.startsWith('*TnMap[')) {
|
|
10014
|
+
keyExpr = toGoStringLiteral(element.name.text);
|
|
10015
|
+
}
|
|
10016
|
+
else
|
|
10017
|
+
return undefined;
|
|
10018
|
+
}
|
|
10019
|
+
else if (isCallExpression(element) && !hasQuestionDot(element.expression) &&
|
|
10020
|
+
isPropertyAccessExpression(element.expression) && element.expression.name.text === 'get' &&
|
|
10021
|
+
(element.arguments ?? []).length === 1) {
|
|
10022
|
+
receiver = element.expression.expression;
|
|
10023
|
+
mapType = inferExpressionType(receiver) ?? '';
|
|
10024
|
+
if (mapType.startsWith('*TnMap[')) {
|
|
10025
|
+
keyExpr = toGoValueOfType(element.arguments[0], extractMapKeyType(mapType));
|
|
10026
|
+
}
|
|
10027
|
+
else
|
|
10028
|
+
return undefined;
|
|
10029
|
+
}
|
|
10030
|
+
if (!receiver || !keyExpr)
|
|
10031
|
+
return undefined;
|
|
10032
|
+
const mapExpr = toGoValueOfType(receiver, mapType);
|
|
10033
|
+
const missing = `!func() bool { _, ok := ${mapExpr}.Lookup(${keyExpr}); return ok }()`;
|
|
10034
|
+
return op === '==' ? missing : `!(${missing})`;
|
|
10035
|
+
}
|
|
9681
10036
|
// a?.items.length === 0 (the chain read as a plain Go value, 0 when a is
|
|
9682
10037
|
// unset): undefined equals no number / string / boolean literal, so the
|
|
9683
10038
|
// comparison holds only when a is set
|
|
@@ -9782,12 +10137,33 @@ function jsMapGoType(keyType, valueType) {
|
|
|
9782
10137
|
function isPlainArrayGoType(goType) {
|
|
9783
10138
|
return goType.startsWith('[]') && goType !== '[]byte';
|
|
9784
10139
|
}
|
|
10140
|
+
// A value typed DOMException / QuotaExceededError (a *TnError whose code is a number)
|
|
10141
|
+
function isDOMExceptionValue(expr) {
|
|
10142
|
+
if (inferExpressionType(expr) !== '*TnError')
|
|
10143
|
+
return false;
|
|
10144
|
+
const isDomName = (name) => name === 'DOMException' || name === 'QuotaExceededError';
|
|
10145
|
+
const u = unwrapParentheses(expr);
|
|
10146
|
+
if ((isAsExpression(u) || isTypeAssertionExpression(u)) && isTypeReferenceNode(u.type) && isIdentifier(u.type.typeName))
|
|
10147
|
+
return isDomName(u.type.typeName.text);
|
|
10148
|
+
if (isNewExpression(u) && isIdentifier(u.expression))
|
|
10149
|
+
return isDomName(u.expression.text);
|
|
10150
|
+
if (!isIdentifier(u))
|
|
10151
|
+
return false;
|
|
10152
|
+
const typeNode = variableTypeNodes.get(u.text);
|
|
10153
|
+
if (typeNode)
|
|
10154
|
+
return isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName) && isDomName(typeNode.typeName.text);
|
|
10155
|
+
// (const e = new DOMException(…) / x as DOMException)
|
|
10156
|
+
const declaration = constDeclarationOf(u);
|
|
10157
|
+
return !!declaration?.initializer && unwrapParentheses(declaration.initializer) !== u && isDOMExceptionValue(declaration.initializer);
|
|
10158
|
+
}
|
|
10159
|
+
// Map methods that read an entry's value (get, and the upserts returning it)
|
|
10160
|
+
const MAP_READ_METHODS = new Set(['get', 'getOrInsert', 'getOrInsertComputed']);
|
|
9785
10161
|
// m.get(k) (or m.get(k)!) on a Map holding arrays by reference
|
|
9786
10162
|
function isMapArrayGet(expr) {
|
|
9787
10163
|
let u = unwrapParentheses(expr);
|
|
9788
10164
|
while (isNonNullExpression(u))
|
|
9789
10165
|
u = unwrapParentheses(u.expression);
|
|
9790
|
-
if (!isCallExpression(u) || !isPropertyAccessExpression(u.expression) || u.expression.name.text
|
|
10166
|
+
if (!isCallExpression(u) || !isPropertyAccessExpression(u.expression) || !MAP_READ_METHODS.has(u.expression.name.text) || hasQuestionDot(u.expression))
|
|
9791
10167
|
return false;
|
|
9792
10168
|
const mapType = inferExpressionType(u.expression.expression) ?? '';
|
|
9793
10169
|
return mapType.startsWith('*TnMap[') && extractMapValueType(mapType).startsWith('*[]');
|
|
@@ -10504,9 +10880,16 @@ function constructorParameterNodes(className) {
|
|
|
10504
10880
|
// The parameters of the nearest user-class ancestor with a constructor, as a
|
|
10505
10881
|
// Go signature and the argument list forwarding them (null when none, or when
|
|
10506
10882
|
// they need destructuring)
|
|
10883
|
+
const VARIADIC_NODE_PARENTS = new Set([
|
|
10884
|
+
'events.EventEmitter', 'events.default', 'stream.Readable', 'stream.Writable', 'stream.Duplex', 'stream.Transform', 'stream.PassThrough'
|
|
10885
|
+
]);
|
|
10507
10886
|
function inheritedConstructorParameters(parentClass) {
|
|
10508
10887
|
let current = parentClass;
|
|
10509
10888
|
for (let depth = 0; depth < 50 && current; depth++) {
|
|
10889
|
+
// (EventEmitter and the stream classes: Go constructors over ...options)
|
|
10890
|
+
if (VARIADIC_NODE_PARENTS.has(nodeParentClassKeys.get(current) ?? '')) {
|
|
10891
|
+
return { signature: '__options ...interface{}', forward: ['__options...'] };
|
|
10892
|
+
}
|
|
10510
10893
|
const classNode = declaredClasses.get(current);
|
|
10511
10894
|
if (!classNode)
|
|
10512
10895
|
return null;
|
|
@@ -11551,6 +11934,11 @@ function dispatchArgument(goType, index) {
|
|
|
11551
11934
|
return `TnArg(__args, ${index})`;
|
|
11552
11935
|
return `TnAs[${goType}](TnArg(__args, ${index}))`;
|
|
11553
11936
|
}
|
|
11937
|
+
// Whether a class declares a static [Symbol.hasInstance] (lowered to __hasInstance)
|
|
11938
|
+
function classHasStaticHasInstance(className) {
|
|
11939
|
+
const declaration = declaredClasses.get(className);
|
|
11940
|
+
return !!declaration && (declaration.members ?? []).some((m) => isMethodDeclaration(m) && hasModifier(m, 'StaticKeyword') && isIdentifier(m.name) && m.name.text === '__hasInstance');
|
|
11941
|
+
}
|
|
11554
11942
|
// Whether some class declares a method of this name
|
|
11555
11943
|
function classMethodNamed(method) {
|
|
11556
11944
|
for (const declaration of declaredClasses.values()) {
|
|
@@ -11577,6 +11965,31 @@ function emitToJSONWrappers() {
|
|
|
11577
11965
|
: `return TnJSString(${call})`;
|
|
11578
11966
|
out.push(`func (self *${getSafeName(className)}) TnToString() string {\n\tvar __args []interface{}\n\t_ = __args\n\t${body}\n}`);
|
|
11579
11967
|
}
|
|
11968
|
+
// [util.inspect.custom](depth, options, inspect): what console.log / inspect print
|
|
11969
|
+
const inspectCustom = methods.get('__inspectCustom');
|
|
11970
|
+
if (inspectCustom) {
|
|
11971
|
+
const paramTypes = inspectCustom.params ? goFuncParamTypes(`func(${inspectCustom.params})`) : [];
|
|
11972
|
+
const call = `self.${inspectCustom.goName}(${paramTypes.map((t, i) => dispatchArgument(t, i)).join(', ')})`;
|
|
11973
|
+
out.push(`func (self *${getSafeName(className)}) TnInspectCustom(depth float64, options interface{}) interface{} {\n\t__args := []interface{}{depth, options, nil}\n\t_ = __args\n\t${inspectCustom.result ? `return ${call}` : `${call}\n\treturn nil`}\n}`);
|
|
11974
|
+
}
|
|
11975
|
+
// [Symbol.for('nodejs.rejection')](err, event, ...args): node:events calls it for captured rejections
|
|
11976
|
+
const rejection = methods.get('__nodejsRejection');
|
|
11977
|
+
if (rejection) {
|
|
11978
|
+
const paramTypes = rejection.params ? goFuncParamTypes(`func(${rejection.params})`) : [];
|
|
11979
|
+
const call = `self.${rejection.goName}(${paramTypes.map((t, i) => dispatchArgument(t, i)).join(', ')})`;
|
|
11980
|
+
out.push(`func (self *${getSafeName(className)}) TnNodejsRejection(err interface{}, event string, args []interface{}) {
|
|
11981
|
+
__args := append([]interface{}{err, event}, args...)
|
|
11982
|
+
_ = __args
|
|
11983
|
+
${call}
|
|
11984
|
+
}`);
|
|
11985
|
+
}
|
|
11986
|
+
// [Symbol.toPrimitive](hint): what String(x) / +x / x + '' convert through
|
|
11987
|
+
const toPrimitive = methods.get('__toPrimitive');
|
|
11988
|
+
if (toPrimitive) {
|
|
11989
|
+
const paramTypes = toPrimitive.params ? goFuncParamTypes(`func(${toPrimitive.params})`) : [];
|
|
11990
|
+
const call = `self.${toPrimitive.goName}(${paramTypes.map((t, i) => dispatchArgument(t, i)).join(', ')})`;
|
|
11991
|
+
out.push(`func (self *${getSafeName(className)}) TnToPrimitive(hint string) interface{} {\n\t__args := []interface{}{hint}\n\t_ = __args\n\treturn ${call}\n}`);
|
|
11992
|
+
}
|
|
11580
11993
|
const sig = methods.get('toJSON');
|
|
11581
11994
|
if (!sig)
|
|
11582
11995
|
continue;
|
|
@@ -11585,6 +11998,14 @@ function emitToJSONWrappers() {
|
|
|
11585
11998
|
const call = `self.${sig.goName}(${callArgs})`;
|
|
11586
11999
|
out.push(`func (self *${getSafeName(className)}) TnToJSON(key string) interface{} {\n\t__args := []interface{}{key}\n\t_ = __args\n\t${sig.result ? `return ${call}` : `${call}\n\treturn nil`}\n}`);
|
|
11587
12000
|
}
|
|
12001
|
+
// get [Symbol.toStringTag](): Object.prototype.toString's tag
|
|
12002
|
+
for (const [className, declaration] of declaredClasses) {
|
|
12003
|
+
const tag = (declaration.members ?? []).find((m) => isIdentifier(m.name) && m.name.text === '__toStringTag' && !hasModifier(m, 'StaticKeyword'));
|
|
12004
|
+
if (!tag)
|
|
12005
|
+
continue;
|
|
12006
|
+
const read = tag.kind === 'GetAccessor' ? `self.Get___toStringTag()` : `self.__toStringTag`;
|
|
12007
|
+
out.push(`func (self *${getSafeName(className)}) TnToStringTag() string {\n\treturn TnJSString(${read})\n}`);
|
|
12008
|
+
}
|
|
11588
12009
|
if (out.length > 0)
|
|
11589
12010
|
useHelper('dynamic');
|
|
11590
12011
|
return out.join('\n\n');
|
|
@@ -11950,7 +12371,7 @@ function isArrayBufferExpression(node) {
|
|
|
11950
12371
|
}
|
|
11951
12372
|
if (isPropertyAccessExpression(expr))
|
|
11952
12373
|
return expr.name.text === 'buffer';
|
|
11953
|
-
if (isCallExpression(expr) && isPropertyAccessExpression(expr.expression) && expr.expression.name.text
|
|
12374
|
+
if (isCallExpression(expr) && isPropertyAccessExpression(expr.expression) && ['slice', 'transfer', 'transferToFixedLength'].includes(expr.expression.name.text)) {
|
|
11954
12375
|
return isArrayBufferExpression(expr.expression.expression);
|
|
11955
12376
|
}
|
|
11956
12377
|
if (isIdentifier(expr)) {
|
|
@@ -11958,6 +12379,32 @@ function isArrayBufferExpression(node) {
|
|
|
11958
12379
|
}
|
|
11959
12380
|
return false;
|
|
11960
12381
|
}
|
|
12382
|
+
// ArrayBuffer properties that read its state (a resizable buffer's length,
|
|
12383
|
+
// a detached buffer's 0), and their Go types
|
|
12384
|
+
const ARRAY_BUFFER_PROPERTIES = {
|
|
12385
|
+
byteLength: ['TnABByteLength', 'float64'],
|
|
12386
|
+
maxByteLength: ['TnABMaxByteLength', 'float64'],
|
|
12387
|
+
resizable: ['TnABResizable', 'bool'],
|
|
12388
|
+
growable: ['TnABResizable', 'bool'],
|
|
12389
|
+
detached: ['TnABDetached', 'bool']
|
|
12390
|
+
};
|
|
12391
|
+
function arrayBufferPropertyType(node) {
|
|
12392
|
+
if (!isPropertyAccessExpression(node))
|
|
12393
|
+
return undefined;
|
|
12394
|
+
const prop = ARRAY_BUFFER_PROPERTIES[node.name.text];
|
|
12395
|
+
if (!prop || !isArrayBufferExpression(node.expression) || inferExpressionType(node.expression) !== '[]byte')
|
|
12396
|
+
return undefined;
|
|
12397
|
+
return prop[1];
|
|
12398
|
+
}
|
|
12399
|
+
function visitArrayBufferProperty(node) {
|
|
12400
|
+
if (!arrayBufferPropertyType(node))
|
|
12401
|
+
return undefined;
|
|
12402
|
+
useHelper('typedArrays');
|
|
12403
|
+
return `${ARRAY_BUFFER_PROPERTIES[node.name.text][0]}(${visit(node.expression)})`;
|
|
12404
|
+
}
|
|
12405
|
+
// Whether the program resizes or transfers ArrayBuffers: then buffers passed
|
|
12406
|
+
// to Node APIs are read through their state (a stale slice header otherwise)
|
|
12407
|
+
let arrayBufferStateUsed = false;
|
|
11961
12408
|
function isArrayBufferTypeNode(typeNode) {
|
|
11962
12409
|
if (!typeNode || !isTypeReferenceNode(typeNode) || !isIdentifier(typeNode.typeName))
|
|
11963
12410
|
return false;
|
|
@@ -12012,6 +12459,20 @@ function visitTypedArrayCall(node) {
|
|
|
12012
12459
|
const args = (node.arguments ?? []).map((a) => `, ${visit(a)}`).join('');
|
|
12013
12460
|
return `TnArrayBufferSlice(${visit(recvNode)}${args})`;
|
|
12014
12461
|
}
|
|
12462
|
+
// (transfer: a copy, resized; the original is detached)
|
|
12463
|
+
if ((method === 'transfer' || method === 'transferToFixedLength') && isArrayBufferExpression(recvNode)) {
|
|
12464
|
+
useHelper('typedArrays');
|
|
12465
|
+
const args = (node.arguments ?? []).map((a) => `, ${toGoValueOfType(a, 'float64')}`).join('');
|
|
12466
|
+
return `TnArrayBufferTransfer(${visit(recvNode)}, ${method === 'transferToFixedLength'}${args})`;
|
|
12467
|
+
}
|
|
12468
|
+
// resizable ArrayBuffer#resize / growable SharedArrayBuffer#grow
|
|
12469
|
+
if ((method === 'resize' || method === 'grow') && isArrayBufferExpression(recvNode) && inferExpressionType(recvNode) === '[]byte') {
|
|
12470
|
+
useHelper('typedArrays');
|
|
12471
|
+
const size = node.arguments?.[0] ? toGoValueOfType(node.arguments[0], 'float64') : 'math.NaN()';
|
|
12472
|
+
if (!node.arguments?.[0])
|
|
12473
|
+
importedPackages.add('math');
|
|
12474
|
+
return `TnAB${method === 'resize' ? 'Resize' : 'Grow'}(${visit(recvNode)}, ${size})`;
|
|
12475
|
+
}
|
|
12015
12476
|
const recvType = inferExpressionType(recvNode);
|
|
12016
12477
|
if (!isTypedArrayGoType(recvType) || !TYPED_ARRAY_CALLBACK_METHODS.includes(method))
|
|
12017
12478
|
return undefined;
|
|
@@ -13796,7 +14257,7 @@ function getContextualTypeNode(node) {
|
|
|
13796
14257
|
}
|
|
13797
14258
|
// map.set(k, v): the Map's value type
|
|
13798
14259
|
if (isCallExpression(parent) && isPropertyAccessExpression(parent.expression) &&
|
|
13799
|
-
parent.expression.name.text === 'set' && (parent.arguments ?? [])[1] === node) {
|
|
14260
|
+
(parent.expression.name.text === 'set' || parent.expression.name.text === 'getOrInsert') && (parent.arguments ?? [])[1] === node) {
|
|
13800
14261
|
const mapType = inferExpressionType(parent.expression.expression) ?? '';
|
|
13801
14262
|
const valueType = mapType.startsWith('*TnMap[') ? extractMapValueType(mapType) : '';
|
|
13802
14263
|
if (valueType.startsWith('*struct{'))
|
|
@@ -14289,8 +14750,20 @@ function visitSpreadArrayLiteral(node, elemType) {
|
|
|
14289
14750
|
if (chunk.isSpread) {
|
|
14290
14751
|
// (elements of another type spread into an any[]: boxed one by one;
|
|
14291
14752
|
// into a differently typed slice: the elements converted)
|
|
14292
|
-
|
|
14753
|
+
let source = visitSpreadSource(chunk.items[0]);
|
|
14293
14754
|
let sourceType = (inferExpressionType(chunk.items[0]) ?? '').replace(/^\*\[\]/, '[]');
|
|
14755
|
+
// (a Node class instance iterated through a method returning a slice —
|
|
14756
|
+
// Intl segments, URLSearchParams —: that slice)
|
|
14757
|
+
const nodeIterator = sourceType ? nodeRegistry.iterators[sourceType] : undefined;
|
|
14758
|
+
// (typed arrays' spread source already is the slice: visitSpreadSource)
|
|
14759
|
+
if (nodeIterator && !source.endsWith(`.${nodeIterator}()`)) {
|
|
14760
|
+
const iterClass = nodeRegistry.classes[nodeRegistry.classByGoType[sourceType]];
|
|
14761
|
+
const iterType = iterClass?.methods[nodeIterator] ?? '';
|
|
14762
|
+
if (iterType.startsWith('[]')) {
|
|
14763
|
+
source = `${source}.${nodeIterator}()`;
|
|
14764
|
+
sourceType = iterType;
|
|
14765
|
+
}
|
|
14766
|
+
}
|
|
14294
14767
|
// ([...set]: its keys' slice)
|
|
14295
14768
|
if (sourceType.startsWith('*TnMap[') && extractMapValueType(sourceType) === 'struct{}')
|
|
14296
14769
|
sourceType = `[]${extractMapKeyType(sourceType)}`;
|
|
@@ -14315,6 +14788,10 @@ function visitSpreadArrayLiteral(node, elemType) {
|
|
|
14315
14788
|
result = `append(${result}, ${chunk.items.map((e) => (arrayElementNeedsConversion(e, baseType) ? toGoValueOfType(e, baseType) : visit(e))).join(', ')})`;
|
|
14316
14789
|
}
|
|
14317
14790
|
}
|
|
14791
|
+
// (as a statement — a void arrow's body, `[...arr];` — Go rejects a bare
|
|
14792
|
+
// append: its value is discarded)
|
|
14793
|
+
if (isDiscardedValue(node))
|
|
14794
|
+
return `_ = ${result}`;
|
|
14318
14795
|
return result;
|
|
14319
14796
|
}
|
|
14320
14797
|
function visitTemplateExpression(node) {
|
|
@@ -14394,14 +14871,27 @@ function statementOfBranchingExpression(node) {
|
|
|
14394
14871
|
linkParents(result, node.parent);
|
|
14395
14872
|
return result;
|
|
14396
14873
|
}
|
|
14874
|
+
// Whether the program itself declares this name — a function, a class, a
|
|
14875
|
+
// variable, an import or an enclosing binding — shadowing the runtime builtin
|
|
14876
|
+
// of the same name (TypeNative's global assert, console…)
|
|
14877
|
+
function isUserDeclared(name, at) {
|
|
14878
|
+
return (declaredFunctions.has(name) ||
|
|
14879
|
+
classNames.has(name) ||
|
|
14880
|
+
variableGoTypes.has(name) ||
|
|
14881
|
+
topLevelGoTypes.has(name) ||
|
|
14882
|
+
importAliases.has(name) ||
|
|
14883
|
+
isLocallyBound(at));
|
|
14884
|
+
}
|
|
14397
14885
|
// An expression-bodied arrow whose callee emits Go statements (no value):
|
|
14398
|
-
// console.log(...), assert(...)
|
|
14886
|
+
// console.log(...), the global assert(...)
|
|
14399
14887
|
function isVoidStatementCall(expr) {
|
|
14400
14888
|
if (!isCallExpression(expr))
|
|
14401
14889
|
return false;
|
|
14402
14890
|
if (isIdentifier(expr.expression)) {
|
|
14403
14891
|
const name = expr.expression.text;
|
|
14404
|
-
|
|
14892
|
+
if (name === 'assert')
|
|
14893
|
+
return !isUserDeclared(name, expr);
|
|
14894
|
+
return (!!promiseResolveName && name === promiseResolveName) || (!!promiseRejectName && name === promiseRejectName);
|
|
14405
14895
|
}
|
|
14406
14896
|
return (isPropertyAccessExpression(expr.expression) &&
|
|
14407
14897
|
isIdentifier(expr.expression.expression) &&
|
|
@@ -14993,13 +15483,19 @@ function inferMemoClear() {
|
|
|
14993
15483
|
// A property read of an object type's array field (a *[]T reference): the
|
|
14994
15484
|
// array itself, []T — reads see the slice; inferRawExpressionType keeps the *
|
|
14995
15485
|
function inferExpressionType(expr) {
|
|
15486
|
+
const abType = arrayBufferPropertyType(expr);
|
|
15487
|
+
if (abType)
|
|
15488
|
+
return abType;
|
|
15489
|
+
// u8.buffer: the Uint8Array's bytes, an ArrayBuffer
|
|
15490
|
+
if (isPropertyAccessExpression(expr) && expr.name.text === 'buffer' && inferExpressionType(expr.expression) === '[]byte')
|
|
15491
|
+
return '[]byte';
|
|
14996
15492
|
const raw = inferRawExpressionType(expr);
|
|
14997
15493
|
// (an array field, or a Map's array value, read: the array)
|
|
14998
15494
|
return raw !== undefined && raw.startsWith('*[]') && (isReferenceFieldAccess(expr) || isMapArrayGetCall(expr)) ? raw.slice(1) : raw;
|
|
14999
15495
|
}
|
|
15000
15496
|
// (isMapArrayGet without the ! / parentheses: the call itself)
|
|
15001
15497
|
function isMapArrayGetCall(expr) {
|
|
15002
|
-
return isCallExpression(expr) && isPropertyAccessExpression(expr.expression) && expr.expression.name.text
|
|
15498
|
+
return isCallExpression(expr) && isPropertyAccessExpression(expr.expression) && MAP_READ_METHODS.has(expr.expression.name.text) && !hasQuestionDot(expr.expression) &&
|
|
15003
15499
|
(inferRawExpressionType(expr.expression.expression) ?? '').startsWith('*TnMap[') && extractMapValueType(inferRawExpressionType(expr.expression.expression) ?? '').startsWith('*[]');
|
|
15004
15500
|
}
|
|
15005
15501
|
// How an array field read is used: written as a whole or compared to null
|
|
@@ -15252,7 +15748,7 @@ function isBoundAsParameter(expr) {
|
|
|
15252
15748
|
// Globals of other environments a program probes for (typeof navigator !==
|
|
15253
15749
|
// 'undefined'; require, in an ES module): absent here, as under Node, unless
|
|
15254
15750
|
// the program binds the name
|
|
15255
|
-
const ABSENT_GLOBALS = new Set(['__DEV__', '
|
|
15751
|
+
const ABSENT_GLOBALS = new Set(['__DEV__', 'window', 'document', 'location', 'Deno', 'Bun', 'require', 'importScripts']);
|
|
15256
15752
|
function isAbsentGlobal(node) {
|
|
15257
15753
|
if (!isIdentifier(node) || !ABSENT_GLOBALS.has(node.text) || isFieldNameIdentifier(node))
|
|
15258
15754
|
return false;
|
|
@@ -15413,6 +15909,8 @@ function inferExpressionTypeOf(expr) {
|
|
|
15413
15909
|
return 'interface{}';
|
|
15414
15910
|
if (expr?.kind === 'TnMixinFactory')
|
|
15415
15911
|
return 'func(interface{}) interface{}';
|
|
15912
|
+
if (expr?.kind === 'TnMixinApply')
|
|
15913
|
+
return 'interface{}';
|
|
15416
15914
|
if (isPropertyAccessExpression(expr) && isIdentifier(expr.expression) && expr.expression.text === 'Object' && expr.name.text === 'prototype' && !classNames.has('Object') &&
|
|
15417
15915
|
!(isPropertyAccessExpression(expr.parent) && expr.parent.expression === expr))
|
|
15418
15916
|
return 'interface{}';
|
|
@@ -15665,6 +16163,18 @@ function inferExpressionTypeOf(expr) {
|
|
|
15665
16163
|
return mapGoType(newSetElementType(expr), 'struct{}');
|
|
15666
16164
|
}
|
|
15667
16165
|
if (isElementAccessExpression(expr)) {
|
|
16166
|
+
// (re.exec(s)?.[i] / a?.[i]: a missed match or an absent array is
|
|
16167
|
+
// undefined, so the element is nullable)
|
|
16168
|
+
const optionalBase = unwrapParentheses(expr.expression);
|
|
16169
|
+
const rawObjectType = inferExpressionType(expr.expression) ?? '';
|
|
16170
|
+
const maybeMissingBase = isCallExpression(optionalBase) &&
|
|
16171
|
+
isPropertyAccessExpression(optionalBase.expression) &&
|
|
16172
|
+
MAYBE_MISSING_METHODS.has(optionalBase.expression.name.text);
|
|
16173
|
+
if (hasQuestionDot(expr) && (maybeMissingBase || rawObjectType.startsWith('*'))) {
|
|
16174
|
+
const baseType = rawObjectType.replace(/^\*/, '');
|
|
16175
|
+
if (baseType.startsWith('[]'))
|
|
16176
|
+
return makeNullableType(baseType.slice(2));
|
|
16177
|
+
}
|
|
15668
16178
|
const tupleElement = tupleElementGoType(expr);
|
|
15669
16179
|
if (tupleElement)
|
|
15670
16180
|
return tupleElement;
|
|
@@ -15680,6 +16190,8 @@ function inferExpressionTypeOf(expr) {
|
|
|
15680
16190
|
}
|
|
15681
16191
|
if (isTypedArrayGoType(objectType))
|
|
15682
16192
|
return 'float64';
|
|
16193
|
+
if (isBigIntArrayGoType(objectType))
|
|
16194
|
+
return '*tnbig.Int';
|
|
15683
16195
|
if (objectType?.startsWith('*TnMap['))
|
|
15684
16196
|
return extractMapValueType(objectType);
|
|
15685
16197
|
// (an any object's element is read as any: TnIndex)
|
|
@@ -15777,6 +16289,13 @@ function inferExpressionTypeOf(expr) {
|
|
|
15777
16289
|
}
|
|
15778
16290
|
if (callee === 'Array.of')
|
|
15779
16291
|
return arrayOfGoType((expr.arguments ?? []).map((a) => inferExpressionType(a)));
|
|
16292
|
+
if (callee === 'Array.fromAsync')
|
|
16293
|
+
return fromAsyncGoType(expr);
|
|
16294
|
+
if (isPropertyAccessExpression(expr.expression) && ['transfer', 'transferToFixedLength'].includes(expr.expression.name.text) && isArrayBufferExpression(expr.expression.expression))
|
|
16295
|
+
return '[]byte';
|
|
16296
|
+
if (callee === 'Iterator.concat') {
|
|
16297
|
+
return `chan ${iteratorConcatElementType((expr.arguments ?? []).map((a) => inferExpressionType(a) ?? ''))}`;
|
|
16298
|
+
}
|
|
15780
16299
|
if (callee === 'Iterator.from' && expr.arguments?.[0]) {
|
|
15781
16300
|
const sourceType = (inferExpressionType(expr.arguments[0]) ?? '').replace(/^\*/, '');
|
|
15782
16301
|
if (sourceType.startsWith('chan '))
|
|
@@ -15847,6 +16366,9 @@ function inferExpressionTypeOf(expr) {
|
|
|
15847
16366
|
return ['static', 'private'].includes(expr.name.text) ? 'bool' : 'string';
|
|
15848
16367
|
}
|
|
15849
16368
|
if (isPropertyAccessExpression(expr) && expr.name.text === 'length' && hasDynamicProperties(expr.expression)) {
|
|
16369
|
+
// n?.length on an any value: undefined when n is nullish or has no length
|
|
16370
|
+
if (hasQuestionDot(expr))
|
|
16371
|
+
return 'interface{}';
|
|
15850
16372
|
return 'float64';
|
|
15851
16373
|
}
|
|
15852
16374
|
if ((isPropertyAccessExpression(expr) || isElementAccessExpression(expr)) && isDynamicValue(expr.expression)) {
|
|
@@ -15999,16 +16521,26 @@ function inferExpressionTypeOf(expr) {
|
|
|
15999
16521
|
if (expr.name.text === 'constructor')
|
|
16000
16522
|
return 'interface{}';
|
|
16001
16523
|
const leftType = inferExpressionType(expr.expression);
|
|
16002
|
-
if (expr.name.text === 'length')
|
|
16524
|
+
if (expr.name.text === 'length') {
|
|
16525
|
+
// arr?.length: undefined — not 0 — when the array is absent
|
|
16526
|
+
if (hasQuestionDot(expr) && /^\*?\[\]/.test(inferRawExpressionType(expr.expression) ?? leftType ?? ''))
|
|
16527
|
+
return '*float64';
|
|
16003
16528
|
return 'float64';
|
|
16529
|
+
}
|
|
16004
16530
|
// (m.size: the number of entries)
|
|
16005
|
-
if (expr.name.text === 'size' && (leftType ?? '').startsWith('*TnMap[') && !isCallee(expr))
|
|
16531
|
+
if (expr.name.text === 'size' && (leftType ?? '').startsWith('*TnMap[') && !isCallee(expr) && resolveExpressionType(expr.expression) !== 'Record')
|
|
16006
16532
|
return 'float64';
|
|
16007
16533
|
if (expr.name.text === 'index' && leftType === '[]string')
|
|
16008
16534
|
return 'float64';
|
|
16535
|
+
if (expr.name.text === 'indices' && leftType === '[]string')
|
|
16536
|
+
return '[][]float64';
|
|
16537
|
+
if (expr.name.text === 'code' && isDOMExceptionValue(expr.expression))
|
|
16538
|
+
return 'float64';
|
|
16009
16539
|
// record.key reads the Record's value type
|
|
16010
|
-
if (leftType?.startsWith('*TnMap[') &&
|
|
16540
|
+
if (leftType?.startsWith('*TnMap[') && !isCallee(expr)) {
|
|
16011
16541
|
const objectType = resolveExpressionType(expr.expression);
|
|
16542
|
+
if (expr.name.text === 'size' && objectType !== 'Record')
|
|
16543
|
+
return undefined;
|
|
16012
16544
|
if (objectType === 'Record' || objectType === 'Map' || objectType === undefined) {
|
|
16013
16545
|
const valueType = extractMapValueType(leftType);
|
|
16014
16546
|
if (valueType !== 'struct{}')
|
|
@@ -16156,13 +16688,17 @@ function inferExpressionTypeOf(expr) {
|
|
|
16156
16688
|
if (methodName === 'toISOString' || methodName === 'toJSON' || methodName === 'toString' ||
|
|
16157
16689
|
methodName === 'toDateString' || methodName === 'toTimeString')
|
|
16158
16690
|
return 'string';
|
|
16691
|
+
if (methodName === 'toTemporalInstant') {
|
|
16692
|
+
useNodeHelperDefining('*TnTemporalInstant');
|
|
16693
|
+
return '*TnTemporalInstant';
|
|
16694
|
+
}
|
|
16159
16695
|
}
|
|
16160
16696
|
if (ownerType && ownerType.startsWith('*TnMap[')) {
|
|
16161
16697
|
if (['has', 'isSubsetOf', 'isSupersetOf', 'isDisjointFrom'].includes(methodName))
|
|
16162
16698
|
return 'bool';
|
|
16163
16699
|
if (['union', 'intersection', 'difference', 'symmetricDifference'].includes(methodName))
|
|
16164
16700
|
return ownerType;
|
|
16165
|
-
if (methodName === 'get') {
|
|
16701
|
+
if (methodName === 'get' || methodName === 'getOrInsert' || methodName === 'getOrInsertComputed') {
|
|
16166
16702
|
const valueType = extractMapValueType(ownerType);
|
|
16167
16703
|
return isStructGoType(valueType) ? `*${valueType}` : valueType;
|
|
16168
16704
|
}
|
|
@@ -16413,6 +16949,9 @@ const BUILTIN_CALL_TYPES = {
|
|
|
16413
16949
|
'Math.acosh': 'float64',
|
|
16414
16950
|
'Math.atanh': 'float64',
|
|
16415
16951
|
'Math.fround': 'float64',
|
|
16952
|
+
'Math.f16round': 'float64',
|
|
16953
|
+
'RegExp.escape': 'string',
|
|
16954
|
+
'Error.isError': 'bool',
|
|
16416
16955
|
'Math.imul': 'float64',
|
|
16417
16956
|
'Math.clz32': 'float64',
|
|
16418
16957
|
'Math.sumPrecise': 'float64',
|
|
@@ -16518,7 +17057,7 @@ function reflectCallName(node) {
|
|
|
16518
17057
|
if (variableGoTypes.has('Reflect') || classNames.has('Reflect'))
|
|
16519
17058
|
return undefined;
|
|
16520
17059
|
const name = callee.name.text;
|
|
16521
|
-
return ['ownKeys', 'apply', 'get', 'set', 'has', 'deleteProperty', 'getOwnPropertyDescriptor', 'defineProperty', 'getPrototypeOf'].includes(name) ? name : undefined;
|
|
17060
|
+
return ['ownKeys', 'apply', 'construct', 'get', 'set', 'has', 'deleteProperty', 'getOwnPropertyDescriptor', 'defineProperty', 'getPrototypeOf'].includes(name) ? name : undefined;
|
|
16522
17061
|
}
|
|
16523
17062
|
// Reflect's methods, as the Object operations they stand for
|
|
16524
17063
|
function visitReflectCall(node) {
|
|
@@ -16535,6 +17074,9 @@ function visitReflectCall(node) {
|
|
|
16535
17074
|
case 'apply':
|
|
16536
17075
|
useHelper('decorators');
|
|
16537
17076
|
return `TnWithThis(${arg(1)}, func() interface{} { return TnCallValue(${arg(0)}, TnAs[[]interface{}](${arg(2)})...) })`;
|
|
17077
|
+
case 'construct':
|
|
17078
|
+
useHelper('classes');
|
|
17079
|
+
return `TnNew(${arg(0)}, TnAs[[]interface{}](${arg(1)})...)`;
|
|
16538
17080
|
case 'get':
|
|
16539
17081
|
return `TnGet(${arg(0)}, TnJSString(${arg(1)}))`;
|
|
16540
17082
|
case 'set':
|
|
@@ -16789,6 +17331,87 @@ function visitPromiseCall(node) {
|
|
|
16789
17331
|
return `TnPromiseCatch${returnsValue ? 'Value' : ''}(${receiver}, ${handler})`;
|
|
16790
17332
|
}
|
|
16791
17333
|
// Element type of `await Promise.all([...])` from the first promise channel
|
|
17334
|
+
// Array.fromAsync(source): the element type of the values it collects
|
|
17335
|
+
function fromAsyncSourceElementType(sourceNode) {
|
|
17336
|
+
const t = (sourceNode ? inferExpressionType(sourceNode) ?? '' : '').replace(/^\*\[\]/, '[]');
|
|
17337
|
+
if (t.startsWith('chan '))
|
|
17338
|
+
return t.slice(5) || 'interface{}';
|
|
17339
|
+
if (t.startsWith('[]chan '))
|
|
17340
|
+
return t.slice(7) || 'interface{}';
|
|
17341
|
+
if (t.startsWith('[]'))
|
|
17342
|
+
return t.slice(2) || 'interface{}';
|
|
17343
|
+
return 'interface{}';
|
|
17344
|
+
}
|
|
17345
|
+
// Array.fromAsync(source, mapFn?): its Go type (chan []T)
|
|
17346
|
+
function fromAsyncGoType(expr) {
|
|
17347
|
+
const callback = (expr.arguments ?? [])[1];
|
|
17348
|
+
if (callback) {
|
|
17349
|
+
const result = goFuncReturnType(functionValueGoType(callback) ?? '') ?? '';
|
|
17350
|
+
if (result.startsWith('chan '))
|
|
17351
|
+
return `chan []${result.slice(5)}`;
|
|
17352
|
+
return result ? `chan []${result}` : 'chan []interface{}';
|
|
17353
|
+
}
|
|
17354
|
+
return `chan []${fromAsyncSourceElementType((expr.arguments ?? [])[0])}`;
|
|
17355
|
+
}
|
|
17356
|
+
function visitArrayFromAsync(node) {
|
|
17357
|
+
useHelper('promiseAll');
|
|
17358
|
+
const sourceNode = (node.arguments ?? [])[0];
|
|
17359
|
+
const callbackNode = (node.arguments ?? [])[1];
|
|
17360
|
+
const sourceType = (sourceNode ? inferExpressionType(sourceNode) ?? '' : '').replace(/^\*\[\]/, '[]');
|
|
17361
|
+
const elem = fromAsyncSourceElementType(sourceNode);
|
|
17362
|
+
const source = sourceNode ? visit(sourceNode) : 'nil';
|
|
17363
|
+
let collected;
|
|
17364
|
+
if (sourceType.startsWith('chan '))
|
|
17365
|
+
collected = `TnFromAsyncChan(${source})`;
|
|
17366
|
+
else if (sourceType.startsWith('[]chan '))
|
|
17367
|
+
collected = `TnPromiseAll(${source})`;
|
|
17368
|
+
else if (sourceType === '[]interface{}') {
|
|
17369
|
+
useHelper('dynamic');
|
|
17370
|
+
collected = `TnPromiseAllValues(${source})`;
|
|
17371
|
+
}
|
|
17372
|
+
else if (sourceType.startsWith('[]'))
|
|
17373
|
+
collected = `TnFromAsyncValues(${source})`;
|
|
17374
|
+
else {
|
|
17375
|
+
useHelper('dynamic');
|
|
17376
|
+
collected = `TnPromiseAllValues(TnAs[[]interface{}](${source}))`;
|
|
17377
|
+
}
|
|
17378
|
+
if (!callbackNode)
|
|
17379
|
+
return collected;
|
|
17380
|
+
if (isArrowFunction(callbackNode) || isFunctionExpression(callbackNode)) {
|
|
17381
|
+
const paramTypes = [elem, 'float64'];
|
|
17382
|
+
(callbackNode.parameters ?? []).forEach((p, index) => {
|
|
17383
|
+
if (isIdentifier(p.name) && paramTypes[index] && !p.type)
|
|
17384
|
+
variableGoTypes.set(p.name.text, paramTypes[index]);
|
|
17385
|
+
});
|
|
17386
|
+
}
|
|
17387
|
+
const result = goFuncReturnType(functionValueGoType(callbackNode) ?? '') ?? 'interface{}';
|
|
17388
|
+
const out = result.startsWith('chan ') ? result.slice(5) : result;
|
|
17389
|
+
const arity = (callbackNode.parameters ?? []).length;
|
|
17390
|
+
const cb = visit(callbackNode);
|
|
17391
|
+
// (an untyped source — an async generator's values — as the callback's parameter type)
|
|
17392
|
+
const firstParam = goFuncParamTypes(functionValueGoType(callbackNode) ?? '')[0] ?? elem;
|
|
17393
|
+
let value = '__v';
|
|
17394
|
+
if (elem === 'interface{}' && firstParam !== 'interface{}') {
|
|
17395
|
+
useHelper('dynamic');
|
|
17396
|
+
value = `TnAs[${firstParam}](__v)`;
|
|
17397
|
+
}
|
|
17398
|
+
const call = arity >= 2 ? `__cb(${value}, __i)` : arity === 1 ? `__cb(${value})` : `__cb()`;
|
|
17399
|
+
const mapper = `func(__v ${elem}, __i float64) ${result} { __cb := ${cb}; return ${call} }`;
|
|
17400
|
+
return result.startsWith('chan ') ? `TnFromAsyncMapAwait(${collected}, ${mapper})` : `TnFromAsyncMap[${elem}, ${out}](${collected}, ${mapper})`;
|
|
17401
|
+
}
|
|
17402
|
+
// Iterator.concat(...): the element type its sources share (else interface{})
|
|
17403
|
+
function iteratorConcatElementType(types) {
|
|
17404
|
+
let elem = '';
|
|
17405
|
+
for (const raw of types) {
|
|
17406
|
+
const t = (raw ?? '').replace(/^\*/, '');
|
|
17407
|
+
const e = t.startsWith('chan ') ? t.slice(5) : t.startsWith('[]') ? t.slice(2) : 'interface{}';
|
|
17408
|
+
if (elem === '')
|
|
17409
|
+
elem = e;
|
|
17410
|
+
else if (elem !== e)
|
|
17411
|
+
return 'interface{}';
|
|
17412
|
+
}
|
|
17413
|
+
return elem || 'interface{}';
|
|
17414
|
+
}
|
|
16792
17415
|
function promiseAllElementType(expr) {
|
|
16793
17416
|
const arrayNode = (expr.arguments ?? [])[0];
|
|
16794
17417
|
const first = arrayNode?.elements?.[0];
|
|
@@ -17721,8 +18344,15 @@ function flattenNullishChain(node) {
|
|
|
17721
18344
|
}
|
|
17722
18345
|
// Converts a Go variable between T and *T as the target type requires
|
|
17723
18346
|
function convertGoValue(variable, fromType, toType) {
|
|
17724
|
-
if (toType === `*${fromType}`)
|
|
18347
|
+
if (toType === `*${fromType}`) {
|
|
18348
|
+
// (a slice value into a *[]T slot: a nil slice is null, not &slice —
|
|
18349
|
+
// TnSlicePtr only boxes a value, so a ?? b of exec results keeps null)
|
|
18350
|
+
if (fromType.startsWith('[]')) {
|
|
18351
|
+
useHelper('slicePtr');
|
|
18352
|
+
return `TnSlicePtr(${variable})`;
|
|
18353
|
+
}
|
|
17725
18354
|
return `&${variable}`;
|
|
18355
|
+
}
|
|
17726
18356
|
if (fromType === `*${toType}`)
|
|
17727
18357
|
return `*${variable}`;
|
|
17728
18358
|
// dynamic (any) values hold the concrete type at runtime (a primitive may
|
|
@@ -17786,6 +18416,12 @@ function visitOptionalPropertyAccess(node) {
|
|
|
17786
18416
|
return `func() *float64 { if __m := ${baseExpr}; __m != nil { __n := float64(__m.Len()); return &__n }; return nil }()`;
|
|
17787
18417
|
}
|
|
17788
18418
|
if (!baseType || !baseType.startsWith('*') || baseType.startsWith('*TnMap[')) {
|
|
18419
|
+
// arr?.length: undefined — not 0 — when the array is absent
|
|
18420
|
+
if (node.name.text === 'length' && hasQuestionDot(node) && /^\*?\[\]/.test(inferRawExpressionType(node.expression) ?? inferExpressionType(node.expression) ?? '')) {
|
|
18421
|
+
useHelper('dynamic');
|
|
18422
|
+
const arrTemp = getTempName('optarr');
|
|
18423
|
+
return `func() *float64 { ${arrTemp} := ${baseExpr}; if ${arrTemp} == nil { return nil }; __n := float64(len(${arrTemp})); return &__n }()`;
|
|
18424
|
+
}
|
|
17789
18425
|
// Record/Map members are key lookups even through optional chains
|
|
17790
18426
|
const objectType = resolveExpressionType(node.expression);
|
|
17791
18427
|
if (objectType === 'Map' || objectType === 'Record') {
|
|
@@ -17796,6 +18432,10 @@ function visitOptionalPropertyAccess(node) {
|
|
|
17796
18432
|
useHelper('regexMatch');
|
|
17797
18433
|
return `TnMatchIndex(${baseExpr})`;
|
|
17798
18434
|
}
|
|
18435
|
+
if (node.name.text === 'indices' && baseType === '[]string') {
|
|
18436
|
+
useHelper('regexMatch');
|
|
18437
|
+
return `TnMatchIndices(${baseExpr})`;
|
|
18438
|
+
}
|
|
17799
18439
|
return getAcessString(baseExpr, visit(node.name), objectType);
|
|
17800
18440
|
}
|
|
17801
18441
|
const className = baseType.replace(/^\*/, '').replace(/\[.*\]$/, '');
|
|
@@ -17809,12 +18449,19 @@ function visitOptionalPropertyAccess(node) {
|
|
|
17809
18449
|
const tmp = getTempName('opt');
|
|
17810
18450
|
// Class getters (also Node classes' accessors such as err.syscall) are calls
|
|
17811
18451
|
let propertyAccess = classGetterMethods.has(`${className}.${node.name.text}`)
|
|
17812
|
-
? `${tmp}.Get_${visit(node.name)}()`
|
|
18452
|
+
? (useNodeHelperForGetter(className, node.name.text), `${tmp}.Get_${visit(node.name)}()`)
|
|
17813
18453
|
: `${tmp}.${visit(node.name)}`;
|
|
17814
18454
|
if (arrayReference) {
|
|
17815
18455
|
useHelper('dynamic');
|
|
17816
18456
|
propertyAccess = `TnDerefSlice(${propertyAccess})`;
|
|
17817
18457
|
}
|
|
18458
|
+
// arr?.length: undefined — not 0 — when the array is absent (a nil slice
|
|
18459
|
+
// is not a zero-length array, as JS sees it)
|
|
18460
|
+
if (node.name.text === 'length' && /^\*?\[\]/.test(propertyType)) {
|
|
18461
|
+
useHelper('dynamic');
|
|
18462
|
+
const arrTemp = getTempName('optarr');
|
|
18463
|
+
return `func() *float64 { ${tmp} := ${baseExpr}; if ${tmp} == nil { return nil }; ${arrTemp} := ${propertyAccess}; if ${arrTemp} == nil { return nil }; __n := float64(len(${arrTemp})); return &__n }()`;
|
|
18464
|
+
}
|
|
17818
18465
|
if (nullableType.startsWith('*') && nullableType.slice(1) === propertyType) {
|
|
17819
18466
|
const valueTemp = getTempName('optv');
|
|
17820
18467
|
return `func() ${nullableType} { ${tmp} := ${baseExpr}; if ${tmp} == nil { var __zero ${nullableType}; return __zero }; ${valueTemp} := ${propertyAccess}; return &${valueTemp} }()`;
|
|
@@ -17825,6 +18472,23 @@ function visitOptionalElementAccess(node) {
|
|
|
17825
18472
|
const baseExpr = visit(node.expression);
|
|
17826
18473
|
const baseType = inferExpressionType(node.expression);
|
|
17827
18474
|
if (!baseType || !baseType.startsWith('*') || baseType.startsWith('*TnMap[')) {
|
|
18475
|
+
// (re.exec(s)?.[i]: a missed match is nil, and its element undefined)
|
|
18476
|
+
const missing = unwrapParentheses(node.expression);
|
|
18477
|
+
if (baseType?.startsWith('[]') &&
|
|
18478
|
+
isCallExpression(missing) &&
|
|
18479
|
+
isPropertyAccessExpression(missing.expression) &&
|
|
18480
|
+
MAYBE_MISSING_METHODS.has(missing.expression.name.text)) {
|
|
18481
|
+
useHelper('dynamic');
|
|
18482
|
+
const valueType = inferExpectedTypeFromContext(node) ?? baseType.slice(2);
|
|
18483
|
+
const nullableType = makeNullableType(valueType);
|
|
18484
|
+
const tmp = getTempName('opte');
|
|
18485
|
+
const read = `TnAt(${tmp}, ${visit(node.argumentExpression)})`;
|
|
18486
|
+
if (nullableType.startsWith('*') && nullableType.slice(1) === valueType) {
|
|
18487
|
+
const valueTemp = getTempName('optev');
|
|
18488
|
+
return `func() ${nullableType} { ${tmp} := ${baseExpr}; if ${tmp} == nil { var __zero ${nullableType}; return __zero }; ${valueTemp} := ${read}; return &${valueTemp} }()`;
|
|
18489
|
+
}
|
|
18490
|
+
return `func() ${nullableType} { ${tmp} := ${baseExpr}; if ${tmp} == nil { var __zero ${nullableType}; return __zero }; return ${read} }()`;
|
|
18491
|
+
}
|
|
17828
18492
|
const plainAccess = { ...node, questionDotToken: undefined };
|
|
17829
18493
|
return visit(plainAccess);
|
|
17830
18494
|
}
|
|
@@ -18029,8 +18693,9 @@ function visitOptionalCall(node) {
|
|
|
18029
18693
|
if (!resultType || resultType === 'interface{}') {
|
|
18030
18694
|
return `func() interface{} { ${guard} := ${baseExpr}; if TnIsNil(${guard}) { return nil }; return ${callCode} }()`;
|
|
18031
18695
|
}
|
|
18032
|
-
// (a typed result:
|
|
18033
|
-
|
|
18696
|
+
// (a typed result: undefined — not the zero value — when a is nullish, so
|
|
18697
|
+
// ?? sees it and === undefined holds)
|
|
18698
|
+
return `func() interface{} { ${guard} := ${baseExpr}; if TnIsNil(${guard}) { return nil }; return interface{}(${callCode}) }()`;
|
|
18034
18699
|
}
|
|
18035
18700
|
// m?.set(k, v) on a Map / Set that may be absent: run only when it is set
|
|
18036
18701
|
// (the receiver bound once, an undefined result when it is not)
|
|
@@ -18170,12 +18835,16 @@ function buildArrayCallbackInfo(callback, elementType, forcedReturnType, paramTy
|
|
|
18170
18835
|
function buildLiteralCallbackInfo(callback, elementType, forcedReturnType, paramTypes) {
|
|
18171
18836
|
{
|
|
18172
18837
|
const paramCount = (callback.parameters ?? []).length;
|
|
18838
|
+
// (a typed local: the AST's dynamic array dereferences once, and the
|
|
18839
|
+
// slice below is a Go slice)
|
|
18840
|
+
const allParameters = callback.parameters ?? [];
|
|
18841
|
+
const parameters = allParameters.slice(0, paramTypes.length);
|
|
18173
18842
|
// ([k, v]) => … / ({ a }) => …: a temporary parameter unpacked first
|
|
18174
18843
|
const unpack = [];
|
|
18175
18844
|
// (a parameter annotated with a type of its own where the elements are
|
|
18176
18845
|
// any values: asserted to it)
|
|
18177
18846
|
const asserted = new Set();
|
|
18178
|
-
|
|
18847
|
+
parameters.forEach((p, index) => {
|
|
18179
18848
|
const annotated = isIdentifier(p.name) && p.type && paramTypes[index] === 'interface{}' && !p.dotDotDotToken ? getType(p.type) : '';
|
|
18180
18849
|
if (annotated && annotated !== 'interface{}' && annotated !== ':' && !isUnboundGoType(annotated)) {
|
|
18181
18850
|
asserted.add(index);
|
|
@@ -18189,9 +18858,7 @@ function buildLiteralCallbackInfo(callback, elementType, forcedReturnType, param
|
|
|
18189
18858
|
unpack.push(destructureCallbackParam(p.name, `__dp${index}`, paramTypes[index]));
|
|
18190
18859
|
});
|
|
18191
18860
|
const callbackReturnType = forcedReturnType ?? inferArrayCallbackReturnType(callback, elementType, elementType);
|
|
18192
|
-
const params = (
|
|
18193
|
-
.slice(0, paramTypes.length)
|
|
18194
|
-
.map((p, index) => `${isIdentifier(p.name) && !asserted.has(index) ? getSafeName(p.name.text) : `__dp${index}`} ${paramTypes[index]}`);
|
|
18861
|
+
const params = parameters.map((p, index) => `${isIdentifier(p.name) && !asserted.has(index) ? getSafeName(p.name.text) : `__dp${index}`} ${paramTypes[index]}`);
|
|
18195
18862
|
const prefix = unpack.join('');
|
|
18196
18863
|
// (its returns convert to the result it is emitted with)
|
|
18197
18864
|
if (isBlock(callback.body) && callbackReturnType)
|
|
@@ -18338,7 +19005,7 @@ function visitArrayHigherOrderCall(node) {
|
|
|
18338
19005
|
if (!isPropertyAccessExpression(node.expression))
|
|
18339
19006
|
return undefined;
|
|
18340
19007
|
const methodName = node.expression.name.text;
|
|
18341
|
-
if (!['map', 'filter', 'some', 'find', 'findIndex', 'findLast', 'findLastIndex', 'every', 'forEach', 'reduce', 'reduceRight', 'join', 'entries', 'flatMap'].includes(methodName)) {
|
|
19008
|
+
if (!['map', 'filter', 'some', 'find', 'findIndex', 'findLast', 'findLastIndex', 'every', 'forEach', 'reduce', 'reduceRight', 'join', 'entries', 'flatMap', 'toLocaleString'].includes(methodName)) {
|
|
18342
19009
|
return undefined;
|
|
18343
19010
|
}
|
|
18344
19011
|
const arrayExprNode = node.expression.expression;
|
|
@@ -18398,6 +19065,18 @@ function visitArrayHigherOrderCall(node) {
|
|
|
18398
19065
|
useHelper('dynamic');
|
|
18399
19066
|
return `func() string { ${arrVar} := ${arrayExpr}; ${partsVar} := make([]string, len(${arrVar})); for i, v := range ${arrVar} { if !TnIsNil(v) { ${partsVar}[i] = TnJSString(v) } }; return strings.Join(${partsVar}, ${separator}) }()`;
|
|
18400
19067
|
}
|
|
19068
|
+
if (methodName === 'toLocaleString') {
|
|
19069
|
+
// arr.toLocaleString(locales, options): each element's toLocaleString
|
|
19070
|
+
if (!isArrayLikeGoType(ownerType))
|
|
19071
|
+
return undefined;
|
|
19072
|
+
importedPackages.add('strings');
|
|
19073
|
+
useHelper('intlElemString');
|
|
19074
|
+
const locales = (node.arguments ?? [])[0] ? toGoValueOfType(node.arguments[0], 'interface{}') : 'nil';
|
|
19075
|
+
const options = (node.arguments ?? [])[1] ? toGoValueOfType(node.arguments[1], 'interface{}') : 'nil';
|
|
19076
|
+
const arrVar = getTempName('arrtls');
|
|
19077
|
+
const partsVar = getTempName('parts');
|
|
19078
|
+
return `func() string { ${arrVar} := ${arrayExpr}; ${partsVar} := make([]string, len(${arrVar})); for i, v := range ${arrVar} { ${partsVar}[i] = TnIntlElemLocaleString(v, ${locales}, ${options}) }; return strings.Join(${partsVar}, ",") }()`;
|
|
19079
|
+
}
|
|
18401
19080
|
if (methodName === 'entries') {
|
|
18402
19081
|
// [[index, value], ...] pairs, destructured by for...of
|
|
18403
19082
|
if (!isArrayLikeGoType(ownerType))
|
|
@@ -19476,8 +20155,19 @@ function resolveExpressionType(expr) {
|
|
|
19476
20155
|
if (expr.kind === 'ThisKeyword') {
|
|
19477
20156
|
return 'class';
|
|
19478
20157
|
}
|
|
20158
|
+
if (isNodeRecordExpression(expr))
|
|
20159
|
+
return 'Record';
|
|
19479
20160
|
return goTypeCategory(inferExpressionType(expr));
|
|
19480
20161
|
}
|
|
20162
|
+
// A Node accessor whose *TnMap is a plain object (instance.exports): its
|
|
20163
|
+
// .size is a key, not a Map's size
|
|
20164
|
+
function isNodeRecordExpression(expr) {
|
|
20165
|
+
const e = unwrapParentheses(expr);
|
|
20166
|
+
if (!isPropertyAccessExpression(e))
|
|
20167
|
+
return false;
|
|
20168
|
+
const classKey = nodeClassKeyOfType(inferExpressionType(e.expression));
|
|
20169
|
+
return !!classKey && !!nodeRegistry.records[`${classKey}#${e.name.text}`];
|
|
20170
|
+
}
|
|
19481
20171
|
// Method-dispatch category of an inferred Go type (e.g. `const s = new Set<T>()`)
|
|
19482
20172
|
function goTypeCategory(goType) {
|
|
19483
20173
|
if (!goType)
|
|
@@ -19592,41 +20282,41 @@ function getAcessString(leftSide, rightSide, objectType) {
|
|
|
19592
20282
|
return `${leftSide}.${rightSide}`;
|
|
19593
20283
|
}
|
|
19594
20284
|
const callHandlers = {
|
|
19595
|
-
assert: (_caller, args) => {
|
|
20285
|
+
assert: (_caller, args, _typeArgs) => {
|
|
19596
20286
|
const message = args.length > 1 ? args[1] : '"Assertion failed"';
|
|
19597
20287
|
return `if !(${args[0]}) {\n\t\tpanic(${message})\n\t}`;
|
|
19598
20288
|
},
|
|
19599
|
-
'console.log': (_caller, args) => consoleOut('Stdout', args),
|
|
19600
|
-
'console.info': (_caller, args) => consoleOut('Stdout', args),
|
|
19601
|
-
'console.debug': (_caller, args) => consoleOut('Stdout', args),
|
|
19602
|
-
'console.trace': (_caller, args) => consoleOut('Stderr', args, 'Trace:'),
|
|
19603
|
-
'console.dir': (_caller, args) => {
|
|
20289
|
+
'console.log': (_caller, args, _typeArgs) => consoleOut('Stdout', args),
|
|
20290
|
+
'console.info': (_caller, args, _typeArgs) => consoleOut('Stdout', args),
|
|
20291
|
+
'console.debug': (_caller, args, _typeArgs) => consoleOut('Stdout', args),
|
|
20292
|
+
'console.trace': (_caller, args, _typeArgs) => consoleOut('Stderr', args, 'Trace:'),
|
|
20293
|
+
'console.dir': (_caller, args, _typeArgs) => {
|
|
19604
20294
|
useHelper('nodeUtil');
|
|
19605
20295
|
return consoleOut('Stdout', [`TnInspect(${args.join(', ')})`], '', true);
|
|
19606
20296
|
},
|
|
19607
|
-
'console.assert': (_caller, args) => {
|
|
20297
|
+
'console.assert': (_caller, args, _typeArgs) => {
|
|
19608
20298
|
const condition = args[0] ?? 'false';
|
|
19609
20299
|
currentCallArgTypes = currentCallArgTypes.slice(1);
|
|
19610
20300
|
const message = consoleOut('Stderr', args.slice(1), args.length > 1 ? 'Assertion failed:' : 'Assertion failed');
|
|
19611
20301
|
return `if !(${condition}) {\n\t\t${message}\n\t}`;
|
|
19612
20302
|
},
|
|
19613
|
-
'console.table': (_caller, args) => {
|
|
20303
|
+
'console.table': (_caller, args, _typeArgs) => {
|
|
19614
20304
|
useHelper('nodeUtil');
|
|
19615
20305
|
return consoleOut('Stdout', [`TnConsoleTableString(${args.join(', ')})`], '', true);
|
|
19616
20306
|
},
|
|
19617
|
-
'console.count': (_caller, args) => {
|
|
20307
|
+
'console.count': (_caller, args, _typeArgs) => {
|
|
19618
20308
|
useHelper('console');
|
|
19619
20309
|
return `TnConsoleCount(${args.join(', ')})`;
|
|
19620
20310
|
},
|
|
19621
|
-
'console.countReset': (_caller, args) => {
|
|
20311
|
+
'console.countReset': (_caller, args, _typeArgs) => {
|
|
19622
20312
|
useHelper('console');
|
|
19623
20313
|
return `TnConsoleCountReset(${args.join(', ')})`;
|
|
19624
20314
|
},
|
|
19625
|
-
'console.group': (_caller, args) => {
|
|
20315
|
+
'console.group': (_caller, args, _typeArgs) => {
|
|
19626
20316
|
useHelper('console');
|
|
19627
20317
|
return `TnConsoleGroup(${consoleArgs(args).join(', ')})`;
|
|
19628
20318
|
},
|
|
19629
|
-
'console.groupCollapsed': (_caller, args) => {
|
|
20319
|
+
'console.groupCollapsed': (_caller, args, _typeArgs) => {
|
|
19630
20320
|
useHelper('console');
|
|
19631
20321
|
return `TnConsoleGroup(${consoleArgs(args).join(', ')})`;
|
|
19632
20322
|
},
|
|
@@ -19634,15 +20324,15 @@ const callHandlers = {
|
|
|
19634
20324
|
useHelper('console');
|
|
19635
20325
|
return 'TnConsoleGroupEnd()';
|
|
19636
20326
|
},
|
|
19637
|
-
'console.time': (_caller, args) => {
|
|
20327
|
+
'console.time': (_caller, args, _typeArgs) => {
|
|
19638
20328
|
useHelper('console');
|
|
19639
20329
|
return `TnConsoleTime(${args.slice(0, 1).join(', ')})`;
|
|
19640
20330
|
},
|
|
19641
|
-
'console.timeEnd': (_caller, args) => {
|
|
20331
|
+
'console.timeEnd': (_caller, args, _typeArgs) => {
|
|
19642
20332
|
useHelper('console');
|
|
19643
20333
|
return `TnConsoleTimeEnd(${args.slice(0, 1).join(', ')})`;
|
|
19644
20334
|
},
|
|
19645
|
-
'console.timeLog': (_caller, args) => {
|
|
20335
|
+
'console.timeLog': (_caller, args, _typeArgs) => {
|
|
19646
20336
|
useHelper('console');
|
|
19647
20337
|
const label = args[0] ?? '"default"';
|
|
19648
20338
|
currentCallArgTypes = currentCallArgTypes.slice(1);
|
|
@@ -19652,36 +20342,44 @@ const callHandlers = {
|
|
|
19652
20342
|
const text = extra.length > 0 ? `strings.TrimSuffix(fmt.Sprintln(${extra.join(', ')}), "\\n")` : '""';
|
|
19653
20343
|
return `TnConsoleTimeLog(${label}, ${text})`;
|
|
19654
20344
|
},
|
|
19655
|
-
'Math.hypot': (_caller, args) => mathCall('Hypot', args),
|
|
19656
|
-
'Math.cbrt': (_caller, args) => mathCall('Cbrt', args),
|
|
19657
|
-
'Math.exp': (_caller, args) => mathCall('Exp', args),
|
|
19658
|
-
'Math.expm1': (_caller, args) => mathCall('Expm1', args),
|
|
19659
|
-
'Math.log1p': (_caller, args) => mathCall('Log1p', args),
|
|
19660
|
-
'Math.asin': (_caller, args) => mathCall('Asin', args),
|
|
19661
|
-
'Math.acos': (_caller, args) => mathCall('Acos', args),
|
|
19662
|
-
'Math.atan': (_caller, args) => mathCall('Atan', args),
|
|
19663
|
-
'Math.atan2': (_caller, args) => mathCall('Atan2', args),
|
|
19664
|
-
'Math.sinh': (_caller, args) => mathCall('Sinh', args),
|
|
19665
|
-
'Math.cosh': (_caller, args) => mathCall('Cosh', args),
|
|
19666
|
-
'Math.tanh': (_caller, args) => mathCall('Tanh', args),
|
|
19667
|
-
'Math.asinh': (_caller, args) => mathCall('Asinh', args),
|
|
19668
|
-
'Math.acosh': (_caller, args) => mathCall('Acosh', args),
|
|
19669
|
-
'Math.atanh': (_caller, args) => mathCall('Atanh', args),
|
|
19670
|
-
'Math.fround': (_caller, args) => `float64(float32(${args[0]}))`,
|
|
19671
|
-
'
|
|
20345
|
+
'Math.hypot': (_caller, args, _typeArgs) => mathCall('Hypot', args),
|
|
20346
|
+
'Math.cbrt': (_caller, args, _typeArgs) => mathCall('Cbrt', args),
|
|
20347
|
+
'Math.exp': (_caller, args, _typeArgs) => mathCall('Exp', args),
|
|
20348
|
+
'Math.expm1': (_caller, args, _typeArgs) => mathCall('Expm1', args),
|
|
20349
|
+
'Math.log1p': (_caller, args, _typeArgs) => mathCall('Log1p', args),
|
|
20350
|
+
'Math.asin': (_caller, args, _typeArgs) => mathCall('Asin', args),
|
|
20351
|
+
'Math.acos': (_caller, args, _typeArgs) => mathCall('Acos', args),
|
|
20352
|
+
'Math.atan': (_caller, args, _typeArgs) => mathCall('Atan', args),
|
|
20353
|
+
'Math.atan2': (_caller, args, _typeArgs) => mathCall('Atan2', args),
|
|
20354
|
+
'Math.sinh': (_caller, args, _typeArgs) => mathCall('Sinh', args),
|
|
20355
|
+
'Math.cosh': (_caller, args, _typeArgs) => mathCall('Cosh', args),
|
|
20356
|
+
'Math.tanh': (_caller, args, _typeArgs) => mathCall('Tanh', args),
|
|
20357
|
+
'Math.asinh': (_caller, args, _typeArgs) => mathCall('Asinh', args),
|
|
20358
|
+
'Math.acosh': (_caller, args, _typeArgs) => mathCall('Acosh', args),
|
|
20359
|
+
'Math.atanh': (_caller, args, _typeArgs) => mathCall('Atanh', args),
|
|
20360
|
+
'Math.fround': (_caller, args, _typeArgs) => `float64(float32(${args[0]}))`,
|
|
20361
|
+
'RegExp.escape': (_caller, args, _typeArgs) => {
|
|
20362
|
+
useHelper('builtins');
|
|
20363
|
+
return `TnRegExpEscape(${args[0]})`;
|
|
20364
|
+
},
|
|
20365
|
+
'Math.f16round': (_caller, args, _typeArgs) => {
|
|
20366
|
+
useHelper('builtins');
|
|
20367
|
+
return `TnF16Round(${args[0]})`;
|
|
20368
|
+
},
|
|
20369
|
+
'Math.imul': (_caller, args, _typeArgs) => {
|
|
19672
20370
|
useHelper('dynamic');
|
|
19673
20371
|
return `float64(TnInt32(${args[0]}) * TnInt32(${args[1]}))`;
|
|
19674
20372
|
},
|
|
19675
|
-
'Math.clz32': (_caller, args) => {
|
|
20373
|
+
'Math.clz32': (_caller, args, _typeArgs) => {
|
|
19676
20374
|
useHelper('dynamic');
|
|
19677
20375
|
importedPackages.add('math/bits');
|
|
19678
20376
|
return `float64(bits.LeadingZeros32(TnUint32(${args[0]})))`;
|
|
19679
20377
|
},
|
|
19680
|
-
'Math.sumPrecise': (_caller, args) => {
|
|
20378
|
+
'Math.sumPrecise': (_caller, args, _typeArgs) => {
|
|
19681
20379
|
useHelper('builtins');
|
|
19682
20380
|
return `TnSumPrecise(${args[0]})`;
|
|
19683
20381
|
},
|
|
19684
|
-
'Number.isSafeInteger': (_caller, args) => {
|
|
20382
|
+
'Number.isSafeInteger': (_caller, args, _typeArgs) => {
|
|
19685
20383
|
importedPackages.add('math');
|
|
19686
20384
|
// (no coercion: anything but a number is false)
|
|
19687
20385
|
if (currentCallArgTypes[0] !== 'float64') {
|
|
@@ -19689,78 +20387,91 @@ const callHandlers = {
|
|
|
19689
20387
|
}
|
|
19690
20388
|
return `(${args[0]} == math.Trunc(${args[0]}) && math.Abs(${args[0]}) <= 9007199254740991)`;
|
|
19691
20389
|
},
|
|
19692
|
-
'Number.parseInt': (_caller, args) => {
|
|
20390
|
+
'Number.parseInt': (_caller, args, _typeArgs) => {
|
|
19693
20391
|
useHelper('dynamic');
|
|
19694
20392
|
// (the string of a non-string value, as JS converts it)
|
|
19695
20393
|
const str = currentCallArgTypes[0] === 'string' ? args[0] : jsStringOf(args[0], currentCallArgTypes[0]);
|
|
19696
20394
|
return `TnParseInt(${str}, ${args[1] ?? '10'})`;
|
|
19697
20395
|
},
|
|
19698
|
-
'Number.parseFloat': (_caller, args) => {
|
|
20396
|
+
'Number.parseFloat': (_caller, args, _typeArgs) => {
|
|
19699
20397
|
useHelper('dynamic');
|
|
19700
20398
|
return `TnParseFloat(${args[0]})`;
|
|
19701
20399
|
},
|
|
19702
|
-
'Object.groupBy': (_caller, args) => visitGroupBy(args, false),
|
|
19703
|
-
'Map.groupBy': (_caller, args) => visitGroupBy(args, true),
|
|
19704
|
-
'Iterator.
|
|
20400
|
+
'Object.groupBy': (_caller, args, _typeArgs) => visitGroupBy(args, false),
|
|
20401
|
+
'Map.groupBy': (_caller, args, _typeArgs) => visitGroupBy(args, true),
|
|
20402
|
+
'Iterator.concat': (_caller, args, _typeArgs) => {
|
|
20403
|
+
useHelper('iterators');
|
|
20404
|
+
const elem = iteratorConcatElementType(currentCallArgTypes);
|
|
20405
|
+
return `TnIterConcat[${elem}](${args.map((a, i) => {
|
|
20406
|
+
const t = (currentCallArgTypes[i] ?? '').replace(/^\*/, '');
|
|
20407
|
+
if (t.startsWith('chan '))
|
|
20408
|
+
return a;
|
|
20409
|
+
if (t.startsWith('[]') && t.slice(2) === elem)
|
|
20410
|
+
return `TnIterFrom(${a})`;
|
|
20411
|
+
useHelper('dynamic');
|
|
20412
|
+
return `TnIterFrom(TnAs[[]${elem}](${a}))`;
|
|
20413
|
+
}).join(', ')})`;
|
|
20414
|
+
},
|
|
20415
|
+
'Iterator.from': (_caller, args, _typeArgs) => {
|
|
19705
20416
|
useHelper('iterators');
|
|
19706
20417
|
const sourceType = (currentCallArgTypes[0] ?? '').replace(/^\*/, '');
|
|
19707
20418
|
if (sourceType.startsWith('chan '))
|
|
19708
20419
|
return args[0];
|
|
19709
20420
|
return `TnIterFrom(${args[0]})`;
|
|
19710
20421
|
},
|
|
19711
|
-
'Object.is': (_caller, args) => {
|
|
20422
|
+
'Object.is': (_caller, args, _typeArgs) => {
|
|
19712
20423
|
useHelper('builtins');
|
|
19713
20424
|
return `TnObjectIs(${args[0]}, ${args[1]})`;
|
|
19714
20425
|
},
|
|
19715
|
-
'Array.of': (_caller, args) => `${arrayOfGoType(currentCallArgTypes)}{${args.join(', ')}}`,
|
|
19716
|
-
'String.fromCodePoint': (_caller, args) => `string([]rune{${args.map((a, i) => `rune(int(${numericArgument(a, i)}))`).join(', ')}})`,
|
|
19717
|
-
'Symbol.for': (_caller, args) => {
|
|
20426
|
+
'Array.of': (_caller, args, _typeArgs) => `${arrayOfGoType(currentCallArgTypes)}{${args.join(', ')}}`,
|
|
20427
|
+
'String.fromCodePoint': (_caller, args, _typeArgs) => `string([]rune{${args.map((a, i) => `rune(int(${numericArgument(a, i)}))`).join(', ')}})`,
|
|
20428
|
+
'Symbol.for': (_caller, args, _typeArgs) => {
|
|
19718
20429
|
useHelper('symbol');
|
|
19719
20430
|
return `TnSymbolFor(${args[0]})`;
|
|
19720
20431
|
},
|
|
19721
|
-
'Symbol.keyFor': (_caller, args) => {
|
|
20432
|
+
'Symbol.keyFor': (_caller, args, _typeArgs) => {
|
|
19722
20433
|
useHelper('symbol');
|
|
19723
20434
|
return `TnSymbolKeyFor(${args[0]})`;
|
|
19724
20435
|
},
|
|
19725
|
-
BigInt: (_caller, args) => {
|
|
20436
|
+
BigInt: (_caller, args, _typeArgs) => {
|
|
19726
20437
|
useHelper('builtins');
|
|
19727
20438
|
return `TnBigIntOf(${args[0]})`;
|
|
19728
20439
|
},
|
|
19729
|
-
'BigInt.asIntN': (_caller, args) => {
|
|
20440
|
+
'BigInt.asIntN': (_caller, args, _typeArgs) => {
|
|
19730
20441
|
useHelper('builtins');
|
|
19731
20442
|
useHelper('dynamic');
|
|
19732
20443
|
return `TnBigIntAsN(${args[0]}, TnAs[*tnbig.Int](${args[1]}), true)`;
|
|
19733
20444
|
},
|
|
19734
|
-
'BigInt.asUintN': (_caller, args) => {
|
|
20445
|
+
'BigInt.asUintN': (_caller, args, _typeArgs) => {
|
|
19735
20446
|
useHelper('builtins');
|
|
19736
20447
|
useHelper('dynamic');
|
|
19737
20448
|
return `TnBigIntAsN(${args[0]}, TnAs[*tnbig.Int](${args[1]}), false)`;
|
|
19738
20449
|
},
|
|
19739
|
-
isFinite: (_caller, args) => {
|
|
20450
|
+
isFinite: (_caller, args, _typeArgs) => {
|
|
19740
20451
|
importedPackages.add('math');
|
|
19741
20452
|
return `(!math.IsInf(${args[0]}, 0) && !math.IsNaN(${args[0]}))`;
|
|
19742
20453
|
},
|
|
19743
|
-
encodeURIComponent: (_caller, args) => {
|
|
20454
|
+
encodeURIComponent: (_caller, args, _typeArgs) => {
|
|
19744
20455
|
useHelper('uri');
|
|
19745
20456
|
return `TnEncodeURIComponent(${args[0]})`;
|
|
19746
20457
|
},
|
|
19747
|
-
encodeURI: (_caller, args) => {
|
|
20458
|
+
encodeURI: (_caller, args, _typeArgs) => {
|
|
19748
20459
|
useHelper('uri');
|
|
19749
20460
|
return `TnEncodeURI(${args[0]})`;
|
|
19750
20461
|
},
|
|
19751
|
-
decodeURIComponent: (_caller, args) => {
|
|
20462
|
+
decodeURIComponent: (_caller, args, _typeArgs) => {
|
|
19752
20463
|
useHelper('uri');
|
|
19753
20464
|
return `TnDecodeURIComponent(${args[0]})`;
|
|
19754
20465
|
},
|
|
19755
|
-
'Object.fromEntries': (_caller, args) => {
|
|
20466
|
+
'Object.fromEntries': (_caller, args, _typeArgs) => {
|
|
19756
20467
|
useHelper('dynamic');
|
|
19757
20468
|
return `TnFromEntries(${args[0]})`;
|
|
19758
20469
|
},
|
|
19759
|
-
'Date.parse': (_caller, args) => {
|
|
20470
|
+
'Date.parse': (_caller, args, _typeArgs) => {
|
|
19760
20471
|
useHelper('date');
|
|
19761
20472
|
return `TnDateMs(TnParseDate(${args[0]}))`;
|
|
19762
20473
|
},
|
|
19763
|
-
'Date.UTC': (_caller, args) => {
|
|
20474
|
+
'Date.UTC': (_caller, args, _typeArgs) => {
|
|
19764
20475
|
importedPackages.add('time');
|
|
19765
20476
|
const part = (i, fallback) => (args[i] ? `int(${args[i]})` : fallback);
|
|
19766
20477
|
return `float64(time.Date(${part(0, '1970')}, time.Month(${part(1, '0')}+1), ${part(2, '1')}, ${part(3, '0')}, ${part(4, '0')}, ${part(5, '0')}, ${part(6, '0')}*1000000, time.UTC).UnixMilli())`;
|
|
@@ -19773,7 +20484,7 @@ const callHandlers = {
|
|
|
19773
20484
|
},
|
|
19774
20485
|
// Promise.try(fn, ...args): fn runs now; its result (or a promise it
|
|
19775
20486
|
// returns) settles the promise, and a throw rejects it
|
|
19776
|
-
'Promise.try': (_caller, args) => {
|
|
20487
|
+
'Promise.try': (_caller, args, _typeArgs) => {
|
|
19777
20488
|
useHelper('promise');
|
|
19778
20489
|
const fnType = currentCallArgNodes[0] ? functionValueGoType(currentCallArgNodes[0]) : '';
|
|
19779
20490
|
const result = fnType ? goFuncReturnType(fnType) ?? '' : '';
|
|
@@ -19785,27 +20496,32 @@ const callHandlers = {
|
|
|
19785
20496
|
const settle = result ? `TnResolver[${t}](ch)(${call})` : `${call}; TnResolveZero(ch)`;
|
|
19786
20497
|
return `func() chan ${t} { ch := make(chan ${t}, 1); func() { defer TnRejectExecutor(ch); ${settle} }(); return ch }()`;
|
|
19787
20498
|
},
|
|
19788
|
-
'Promise.resolve': (_caller, args) => {
|
|
20499
|
+
'Promise.resolve': (_caller, args, _typeArgs) => {
|
|
19789
20500
|
const valueType = currentCallArgTypes[0] && currentCallArgTypes[0] !== 'nil' ? currentCallArgTypes[0] : 'interface{}';
|
|
19790
20501
|
return `func() chan ${valueType} { __ch := make(chan ${valueType}, 1); __ch <- ${args[0] ?? 'nil'}; return __ch }()`;
|
|
19791
20502
|
},
|
|
19792
|
-
structuredClone: (_caller, args) => {
|
|
20503
|
+
structuredClone: (_caller, args, _typeArgs) => {
|
|
19793
20504
|
useHelper('structuredClone');
|
|
20505
|
+
// (structuredClone(v, { transfer }): listed web streams move instead)
|
|
20506
|
+
if (args.length > 1) {
|
|
20507
|
+
useHelper('structuredCloneTransfer');
|
|
20508
|
+
return `TnStructuredCloneTransfer(${args[0]}, ${args[1]})`;
|
|
20509
|
+
}
|
|
19794
20510
|
return `TnStructuredClone(${args[0]})`;
|
|
19795
20511
|
},
|
|
19796
|
-
setInterval: (_caller, args) => {
|
|
20512
|
+
setInterval: (_caller, args, _typeArgs) => {
|
|
19797
20513
|
useHelper('timerWait');
|
|
19798
20514
|
return `TnSetInterval(${args[1] ?? '0'}, ${args[0]})`;
|
|
19799
20515
|
},
|
|
19800
|
-
clearInterval: (_caller, args) => {
|
|
20516
|
+
clearInterval: (_caller, args, _typeArgs) => {
|
|
19801
20517
|
useHelper('timerWait');
|
|
19802
20518
|
return `TnClearInterval(${args[0]})`;
|
|
19803
20519
|
},
|
|
19804
|
-
queueMicrotask: (_caller, args) => {
|
|
20520
|
+
queueMicrotask: (_caller, args, _typeArgs) => {
|
|
19805
20521
|
useHelper('timerWait');
|
|
19806
20522
|
return `TnQueueMicrotask(${args[0]})`;
|
|
19807
20523
|
},
|
|
19808
|
-
clearTimeout: (_caller, args) => {
|
|
20524
|
+
clearTimeout: (_caller, args, _typeArgs) => {
|
|
19809
20525
|
useHelper('timerWait');
|
|
19810
20526
|
return `TnClearTimeout(${args[0]})`;
|
|
19811
20527
|
},
|
|
@@ -19813,56 +20529,56 @@ const callHandlers = {
|
|
|
19813
20529
|
importedPackages.add('math/rand');
|
|
19814
20530
|
return 'rand.Float64()';
|
|
19815
20531
|
},
|
|
19816
|
-
'Math.floor': (_caller, args) => {
|
|
20532
|
+
'Math.floor': (_caller, args, _typeArgs) => {
|
|
19817
20533
|
importedPackages.add('math');
|
|
19818
20534
|
return `math.Floor(${args[0]})`;
|
|
19819
20535
|
},
|
|
19820
|
-
'Math.ceil': (_caller, args) => {
|
|
20536
|
+
'Math.ceil': (_caller, args, _typeArgs) => {
|
|
19821
20537
|
importedPackages.add('math');
|
|
19822
20538
|
return `math.Ceil(${args[0]})`;
|
|
19823
20539
|
},
|
|
19824
|
-
'Math.round': (_caller, args) => {
|
|
20540
|
+
'Math.round': (_caller, args, _typeArgs) => {
|
|
19825
20541
|
importedPackages.add('math');
|
|
19826
20542
|
return `math.Round(${args[0]})`;
|
|
19827
20543
|
},
|
|
19828
|
-
'Math.abs': (_caller, args) => {
|
|
20544
|
+
'Math.abs': (_caller, args, _typeArgs) => {
|
|
19829
20545
|
importedPackages.add('math');
|
|
19830
20546
|
return `math.Abs(${args[0]})`;
|
|
19831
20547
|
},
|
|
19832
20548
|
// Math.max(...arr) → slices.Max(arr); otherwise Go's variadic builtin
|
|
19833
|
-
'Math.max': (_caller, args) => {
|
|
20549
|
+
'Math.max': (_caller, args, _typeArgs) => {
|
|
19834
20550
|
if (args.length === 1 && args[0].endsWith('...')) {
|
|
19835
20551
|
importedPackages.add('slices');
|
|
19836
20552
|
return `slices.Max(${args[0].slice(0, -3)})`;
|
|
19837
20553
|
}
|
|
19838
20554
|
return `max(${args.join(', ')})`;
|
|
19839
20555
|
},
|
|
19840
|
-
'Math.min': (_caller, args) => {
|
|
20556
|
+
'Math.min': (_caller, args, _typeArgs) => {
|
|
19841
20557
|
if (args.length === 1 && args[0].endsWith('...')) {
|
|
19842
20558
|
importedPackages.add('slices');
|
|
19843
20559
|
return `slices.Min(${args[0].slice(0, -3)})`;
|
|
19844
20560
|
}
|
|
19845
20561
|
return `min(${args.join(', ')})`;
|
|
19846
20562
|
},
|
|
19847
|
-
'Math.sqrt': (_caller, args) => {
|
|
20563
|
+
'Math.sqrt': (_caller, args, _typeArgs) => {
|
|
19848
20564
|
importedPackages.add('math');
|
|
19849
20565
|
return `math.Sqrt(${args[0]})`;
|
|
19850
20566
|
},
|
|
19851
|
-
'Math.pow': (_caller, args) => {
|
|
20567
|
+
'Math.pow': (_caller, args, _typeArgs) => {
|
|
19852
20568
|
importedPackages.add('math');
|
|
19853
20569
|
return `math.Pow(${args[0]}, ${args[1]})`;
|
|
19854
20570
|
},
|
|
19855
|
-
parseInt: (_caller, args) => {
|
|
20571
|
+
parseInt: (_caller, args, _typeArgs) => {
|
|
19856
20572
|
useHelper('dynamic');
|
|
19857
20573
|
// (the string of a non-string value, as JS converts it)
|
|
19858
20574
|
const str = currentCallArgTypes[0] === 'string' ? args[0] : jsStringOf(args[0], currentCallArgTypes[0]);
|
|
19859
20575
|
return `TnParseInt(${str}, ${args[1] ?? '10'})`;
|
|
19860
20576
|
},
|
|
19861
|
-
parseFloat: (_caller, args) => {
|
|
20577
|
+
parseFloat: (_caller, args, _typeArgs) => {
|
|
19862
20578
|
useHelper('dynamic');
|
|
19863
20579
|
return `TnParseFloat(${args[0]})`;
|
|
19864
20580
|
},
|
|
19865
|
-
'process.exit': (_caller, args) => {
|
|
20581
|
+
'process.exit': (_caller, args, _typeArgs) => {
|
|
19866
20582
|
importedPackages.add('os');
|
|
19867
20583
|
return `os.Exit(int(${args[0] ?? '0'}))`;
|
|
19868
20584
|
},
|
|
@@ -19870,7 +20586,7 @@ const callHandlers = {
|
|
|
19870
20586
|
importedPackages.add('os');
|
|
19871
20587
|
return `func() string { __d, _ := os.Getwd(); return __d }()`;
|
|
19872
20588
|
},
|
|
19873
|
-
'JSON.stringify': (_caller, args) => {
|
|
20589
|
+
'JSON.stringify': (_caller, args, _typeArgs) => {
|
|
19874
20590
|
useHelper('jsonStringify');
|
|
19875
20591
|
useHelper('dynamic');
|
|
19876
20592
|
if (args.length === 1)
|
|
@@ -19879,7 +20595,7 @@ const callHandlers = {
|
|
|
19879
20595
|
const replacer = jsonCallbackAdapter(replacerNode, args[1]) || (isNilLiteral(replacerNode) ? 'nil' : args[1]);
|
|
19880
20596
|
return `TnJSONStringifyWith(${args[0]}, ${replacer}, ${args[2] ?? 'nil'})`;
|
|
19881
20597
|
},
|
|
19882
|
-
'JSON.parse': (_caller, args) => {
|
|
20598
|
+
'JSON.parse': (_caller, args, _typeArgs) => {
|
|
19883
20599
|
useHelper('jsonStringify');
|
|
19884
20600
|
// (a value not typed string — a T narrowed by typeof — is its string)
|
|
19885
20601
|
if (args[0] && currentCallArgTypes[0] !== 'string') {
|
|
@@ -19894,20 +20610,20 @@ const callHandlers = {
|
|
|
19894
20610
|
return `TnJSONParse(${args[0]})`;
|
|
19895
20611
|
},
|
|
19896
20612
|
// Maps / records have ordered keys; other objects go through reflection
|
|
19897
|
-
'Object.keys': (_caller, args) => {
|
|
20613
|
+
'Object.keys': (_caller, args, _typeArgs) => {
|
|
19898
20614
|
if (isOrderedMapArg(currentCallArgNodes[0]))
|
|
19899
20615
|
return `${args[0]}.Keys()`;
|
|
19900
20616
|
useHelper('dynamic');
|
|
19901
20617
|
return `TnKeys(${args[0]})`;
|
|
19902
20618
|
},
|
|
19903
|
-
'Object.values': (_caller, args) => {
|
|
20619
|
+
'Object.values': (_caller, args, _typeArgs) => {
|
|
19904
20620
|
if (isOrderedMapArg(currentCallArgNodes[0]))
|
|
19905
20621
|
return `${args[0]}.Values()`;
|
|
19906
20622
|
useHelper('dynamic');
|
|
19907
20623
|
return `TnValues(${args[0]})`;
|
|
19908
20624
|
},
|
|
19909
20625
|
// Outside for...of (which iterates the map directly): [key, value] pairs
|
|
19910
|
-
'Object.entries': (_caller, args) => {
|
|
20626
|
+
'Object.entries': (_caller, args, _typeArgs) => {
|
|
19911
20627
|
if (isOrderedMapArg(currentCallArgNodes[0]))
|
|
19912
20628
|
return `${args[0]}.Entries()`;
|
|
19913
20629
|
useHelper('dynamic');
|
|
@@ -19915,7 +20631,7 @@ const callHandlers = {
|
|
|
19915
20631
|
},
|
|
19916
20632
|
// Object.assign copies sources into a fresh ordered map (mutating structs is
|
|
19917
20633
|
// not observable the way it is in JS)
|
|
19918
|
-
'Object.assign': (_caller, args) => {
|
|
20634
|
+
'Object.assign': (_caller, args, _typeArgs) => {
|
|
19919
20635
|
const call = currentCallNode;
|
|
19920
20636
|
const targetType = call ? objectAssignTargetType(call) : undefined;
|
|
19921
20637
|
// (an existing object is updated in place and returned, whatever its type)
|
|
@@ -19943,7 +20659,11 @@ const callHandlers = {
|
|
|
19943
20659
|
// Promise.all: drain every promise channel, collect the results
|
|
19944
20660
|
// (V8's; there are no V8 stack frames to capture)
|
|
19945
20661
|
'Error.captureStackTrace': () => 'func() {}()',
|
|
19946
|
-
'
|
|
20662
|
+
'Error.isError': (_caller, args, _typeArgs) => {
|
|
20663
|
+
useHelper('error');
|
|
20664
|
+
return `TnIsErrorOf(interface{}(${args[0] ?? 'nil'}), "Error")`;
|
|
20665
|
+
},
|
|
20666
|
+
'Promise.all': (_caller, args, _typeArgs) => {
|
|
19947
20667
|
useHelper('promiseAll');
|
|
19948
20668
|
// (values that may or may not be promises, an any[]: each awaited when it is one)
|
|
19949
20669
|
const listNode = currentCallArgNodes[0];
|
|
@@ -19953,35 +20673,35 @@ const callHandlers = {
|
|
|
19953
20673
|
}
|
|
19954
20674
|
return `TnPromiseAll(${args[0] ?? '[]chan interface{}{}'})`;
|
|
19955
20675
|
},
|
|
19956
|
-
'Math.log': (_caller, args) => {
|
|
20676
|
+
'Math.log': (_caller, args, _typeArgs) => {
|
|
19957
20677
|
importedPackages.add('math');
|
|
19958
20678
|
return `math.Log(${args[0]})`;
|
|
19959
20679
|
},
|
|
19960
|
-
'Math.log2': (_caller, args) => {
|
|
20680
|
+
'Math.log2': (_caller, args, _typeArgs) => {
|
|
19961
20681
|
importedPackages.add('math');
|
|
19962
20682
|
return `math.Log2(${args[0]})`;
|
|
19963
20683
|
},
|
|
19964
|
-
'Math.log10': (_caller, args) => {
|
|
20684
|
+
'Math.log10': (_caller, args, _typeArgs) => {
|
|
19965
20685
|
importedPackages.add('math');
|
|
19966
20686
|
return `math.Log10(${args[0]})`;
|
|
19967
20687
|
},
|
|
19968
|
-
'Math.sin': (_caller, args) => {
|
|
20688
|
+
'Math.sin': (_caller, args, _typeArgs) => {
|
|
19969
20689
|
importedPackages.add('math');
|
|
19970
20690
|
return `math.Sin(${args[0]})`;
|
|
19971
20691
|
},
|
|
19972
|
-
'Math.cos': (_caller, args) => {
|
|
20692
|
+
'Math.cos': (_caller, args, _typeArgs) => {
|
|
19973
20693
|
importedPackages.add('math');
|
|
19974
20694
|
return `math.Cos(${args[0]})`;
|
|
19975
20695
|
},
|
|
19976
|
-
'Math.tan': (_caller, args) => {
|
|
20696
|
+
'Math.tan': (_caller, args, _typeArgs) => {
|
|
19977
20697
|
importedPackages.add('math');
|
|
19978
20698
|
return `math.Tan(${args[0]})`;
|
|
19979
20699
|
},
|
|
19980
|
-
'Math.trunc': (_caller, args) => {
|
|
20700
|
+
'Math.trunc': (_caller, args, _typeArgs) => {
|
|
19981
20701
|
importedPackages.add('math');
|
|
19982
20702
|
return `math.Trunc(${args[0]})`;
|
|
19983
20703
|
},
|
|
19984
|
-
'Math.sign': (_caller, args) => {
|
|
20704
|
+
'Math.sign': (_caller, args, _typeArgs) => {
|
|
19985
20705
|
return `func() float64 { if ${args[0]} > 0 { return 1 }; if ${args[0]} < 0 { return -1 }; return 0 }()`;
|
|
19986
20706
|
},
|
|
19987
20707
|
'Date.now': () => {
|
|
@@ -19989,9 +20709,9 @@ const callHandlers = {
|
|
|
19989
20709
|
useHelper('clock');
|
|
19990
20710
|
return 'float64(TnTimeNow().UnixMilli())';
|
|
19991
20711
|
},
|
|
19992
|
-
'console.error': (_caller, args) => consoleOut('Stderr', args),
|
|
19993
|
-
'console.warn': (_caller, args) => consoleOut('Stderr', args),
|
|
19994
|
-
'Array.isArray': (_caller, args) => {
|
|
20712
|
+
'console.error': (_caller, args, _typeArgs) => consoleOut('Stderr', args),
|
|
20713
|
+
'console.warn': (_caller, args, _typeArgs) => consoleOut('Stderr', args),
|
|
20714
|
+
'Array.isArray': (_caller, args, _typeArgs) => {
|
|
19995
20715
|
useHelper('isArray');
|
|
19996
20716
|
// (an array reference variable — possibly unset —: whether it is set)
|
|
19997
20717
|
const arg = currentCallArgNodes[0] ? unwrapParentheses(currentCallArgNodes[0]) : undefined;
|
|
@@ -20000,37 +20720,37 @@ const callHandlers = {
|
|
|
20000
20720
|
return `TnIsArray(${args[0]})`;
|
|
20001
20721
|
},
|
|
20002
20722
|
// (String(null): "null" — the literal's Go code, nil, is undefined's too)
|
|
20003
|
-
'String': (_caller, args) => currentCallArgNodes[0] && unwrapParentheses(currentCallArgNodes[0]).kind === 'NullKeyword' ? '"null"' : jsStringOf(args[0] ?? '""', currentCallArgTypes[0]),
|
|
20004
|
-
'String.fromCharCode': (_caller, args) => `string(rune(int(${args[0] ? numericArgument(args[0], 0) : '0'})))`,
|
|
20723
|
+
'String': (_caller, args, _typeArgs) => currentCallArgNodes[0] && unwrapParentheses(currentCallArgNodes[0]).kind === 'NullKeyword' ? '"null"' : jsStringOf(args[0] ?? '""', currentCallArgTypes[0]),
|
|
20724
|
+
'String.fromCharCode': (_caller, args, _typeArgs) => `string(rune(int(${args[0] ? numericArgument(args[0], 0) : '0'})))`,
|
|
20005
20725
|
// Symbol(description) — unique values for record keys
|
|
20006
|
-
Symbol: (_caller, args) => {
|
|
20726
|
+
Symbol: (_caller, args, _typeArgs) => {
|
|
20007
20727
|
useHelper('symbol');
|
|
20008
20728
|
return `TnNewSymbol(${args[0] ?? '""'})`;
|
|
20009
20729
|
},
|
|
20010
|
-
'Number': (_caller, args) => {
|
|
20730
|
+
'Number': (_caller, args, _typeArgs) => {
|
|
20011
20731
|
useHelper('dynamic');
|
|
20012
20732
|
return `TnNumber(${args[0]})`;
|
|
20013
20733
|
},
|
|
20014
|
-
'Number.isNaN': (_caller, args) => {
|
|
20734
|
+
'Number.isNaN': (_caller, args, _typeArgs) => {
|
|
20015
20735
|
importedPackages.add('math');
|
|
20016
20736
|
if (currentCallArgTypes[0] !== 'float64') {
|
|
20017
20737
|
return `func() bool { __n, __ok := interface{}(${numberCheckArgument(args[0])}).(float64); return __ok && math.IsNaN(__n) }()`;
|
|
20018
20738
|
}
|
|
20019
20739
|
return `math.IsNaN(${args[0]})`;
|
|
20020
20740
|
},
|
|
20021
|
-
isNaN: (_caller, args) => {
|
|
20741
|
+
isNaN: (_caller, args, _typeArgs) => {
|
|
20022
20742
|
importedPackages.add('math');
|
|
20023
20743
|
return `math.IsNaN(${args[0]})`;
|
|
20024
20744
|
},
|
|
20025
20745
|
// (no coercion: anything but a number is false)
|
|
20026
|
-
'Number.isFinite': (_caller, args) => {
|
|
20746
|
+
'Number.isFinite': (_caller, args, _typeArgs) => {
|
|
20027
20747
|
importedPackages.add('math');
|
|
20028
20748
|
if (currentCallArgTypes[0] !== 'float64') {
|
|
20029
20749
|
return `func() bool { __n, __ok := interface{}(${numberCheckArgument(args[0])}).(float64); return __ok && !math.IsInf(__n, 0) && !math.IsNaN(__n) }()`;
|
|
20030
20750
|
}
|
|
20031
20751
|
return `!math.IsInf(${args[0]}, 0) && !math.IsNaN(${args[0]})`;
|
|
20032
20752
|
},
|
|
20033
|
-
'Number.isInteger': (_caller, args) => {
|
|
20753
|
+
'Number.isInteger': (_caller, args, _typeArgs) => {
|
|
20034
20754
|
importedPackages.add('math');
|
|
20035
20755
|
if (currentCallArgTypes[0] !== 'float64') {
|
|
20036
20756
|
return `func() bool { __n, __ok := interface{}(${numberCheckArgument(args[0])}).(float64); return __ok && __n == math.Trunc(__n) && !math.IsInf(__n, 0) }()`;
|
|
@@ -20038,8 +20758,8 @@ const callHandlers = {
|
|
|
20038
20758
|
return `(${args[0]} == math.Trunc(${args[0]}) && !math.IsInf(${args[0]}, 0))`;
|
|
20039
20759
|
},
|
|
20040
20760
|
// Object(x) is x (primitives are not boxed)
|
|
20041
|
-
'Object': (_caller, args) => `interface{}(${args[0] ?? 'map[string]interface{}{}'})`,
|
|
20042
|
-
'Boolean': (_caller, args) => `(${truthinessCheck(args[0] ?? 'false', currentCallArgTypes[0] ?? 'interface{}')})`,
|
|
20761
|
+
'Object': (_caller, args, _typeArgs) => `interface{}(${args[0] ?? 'map[string]interface{}{}'})`,
|
|
20762
|
+
'Boolean': (_caller, args, _typeArgs) => `(${truthinessCheck(args[0] ?? 'false', currentCallArgTypes[0] ?? 'interface{}')})`,
|
|
20043
20763
|
};
|
|
20044
20764
|
// A call's argument as a number (an any or nullable value: its JS number)
|
|
20045
20765
|
function numericArgument(arg, index) {
|
|
@@ -20058,7 +20778,7 @@ function numberCheckArgument(arg) {
|
|
|
20058
20778
|
return `TnPtrValue(${arg})`;
|
|
20059
20779
|
}
|
|
20060
20780
|
// Built-in Error subclasses (TnErrors carrying their name)
|
|
20061
|
-
const BUILTIN_ERROR_NAMES = new Set(['TypeError', 'RangeError', 'SyntaxError', 'ReferenceError', 'EvalError', 'URIError', 'AggregateError']);
|
|
20781
|
+
const BUILTIN_ERROR_NAMES = new Set(['TypeError', 'RangeError', 'SyntaxError', 'ReferenceError', 'EvalError', 'URIError', 'AggregateError', 'DOMException', 'QuotaExceededError']);
|
|
20062
20782
|
// Whether the program uses console.group (then every console line is
|
|
20063
20783
|
// written through the indentation-aware helper)
|
|
20064
20784
|
let consoleGroupsUsed = false;
|
|
@@ -20165,9 +20885,17 @@ const stringMethodHandlers = {
|
|
|
20165
20885
|
useHelper('strIndex');
|
|
20166
20886
|
return `TnCharCodeAt(${obj}, ${args[0] ?? '0'})`;
|
|
20167
20887
|
},
|
|
20888
|
+
// (the root collation: letters by base letter, then accents, then case; a
|
|
20889
|
+
// locale or options argument uses the full Intl.Collator instead)
|
|
20168
20890
|
localeCompare: (obj, args) => {
|
|
20169
|
-
|
|
20170
|
-
|
|
20891
|
+
if (currentCallArgNodes[1] || currentCallArgNodes[2]) {
|
|
20892
|
+
useHelper('intlCollate');
|
|
20893
|
+
const locales = currentCallArgNodes[1] ? toGoValueOfType(currentCallArgNodes[1], 'interface{}') : 'nil';
|
|
20894
|
+
const options = currentCallArgNodes[2] ? toGoValueOfType(currentCallArgNodes[2], 'interface{}') : 'nil';
|
|
20895
|
+
return `TnIntlCompare(${obj}, ${args[0]}, ${locales}, ${options})`;
|
|
20896
|
+
}
|
|
20897
|
+
useHelper('builtins');
|
|
20898
|
+
return `TnLocaleCompare(${obj}, ${args[0]}, nil)`;
|
|
20171
20899
|
},
|
|
20172
20900
|
includes: (obj, args) => {
|
|
20173
20901
|
importedPackages.add('strings');
|
|
@@ -20336,11 +21064,20 @@ const stringMethodHandlers = {
|
|
|
20336
21064
|
useHelper('jsSpace');
|
|
20337
21065
|
return `strings.TrimRightFunc(${obj}, TnIsJSSpace)`;
|
|
20338
21066
|
},
|
|
20339
|
-
toLocaleUpperCase: (obj) => {
|
|
21067
|
+
toLocaleUpperCase: (obj, args) => {
|
|
21068
|
+
// with a locale: the locale's case mapping (tr/az/lt); else plain
|
|
21069
|
+
if (currentCallArgNodes[0]) {
|
|
21070
|
+
useHelper('intlCase');
|
|
21071
|
+
return `TnIntlToUpper(TnIntlCaseLoc(${args[0]}), ${obj})`;
|
|
21072
|
+
}
|
|
20340
21073
|
importedPackages.add('strings');
|
|
20341
21074
|
return `strings.ToUpper(${obj})`;
|
|
20342
21075
|
},
|
|
20343
|
-
toLocaleLowerCase: (obj) => {
|
|
21076
|
+
toLocaleLowerCase: (obj, args) => {
|
|
21077
|
+
if (currentCallArgNodes[0]) {
|
|
21078
|
+
useHelper('intlCase');
|
|
21079
|
+
return `TnIntlToLower(TnIntlCaseLoc(${args[0]}), ${obj})`;
|
|
21080
|
+
}
|
|
20344
21081
|
importedPackages.add('strings');
|
|
20345
21082
|
return `strings.ToLower(${obj})`;
|
|
20346
21083
|
},
|
|
@@ -20432,6 +21169,16 @@ function dateFormatter(kind) {
|
|
|
20432
21169
|
return `TnDateFormat(${obj}, ${toGoStringLiteral(kind)})`;
|
|
20433
21170
|
};
|
|
20434
21171
|
}
|
|
21172
|
+
// d.toLocaleString(locales, options) & co.: the Intl date formatting (the
|
|
21173
|
+
// default locale follows the OS, as Node's do)
|
|
21174
|
+
function dateLocaleFormatter(kind) {
|
|
21175
|
+
return (obj) => {
|
|
21176
|
+
useHelper('intlDate');
|
|
21177
|
+
const locales = currentCallArgNodes[0] ? toGoValueOfType(currentCallArgNodes[0], 'interface{}') : 'nil';
|
|
21178
|
+
const options = currentCallArgNodes[1] ? toGoValueOfType(currentCallArgNodes[1], 'interface{}') : 'nil';
|
|
21179
|
+
return `TnIntlDateFmt(${obj}, ${locales}, ${options}, ${toGoStringLiteral(kind)})`;
|
|
21180
|
+
};
|
|
21181
|
+
}
|
|
20435
21182
|
const dateMethodHandlers = {
|
|
20436
21183
|
getTime: (obj) => {
|
|
20437
21184
|
useHelper('date');
|
|
@@ -20460,9 +21207,9 @@ const dateMethodHandlers = {
|
|
|
20460
21207
|
toTimeString: dateFormatter('time'),
|
|
20461
21208
|
toUTCString: dateFormatter('utc'),
|
|
20462
21209
|
toGMTString: dateFormatter('utc'),
|
|
20463
|
-
toLocaleDateString:
|
|
20464
|
-
toLocaleTimeString:
|
|
20465
|
-
toLocaleString:
|
|
21210
|
+
toLocaleDateString: dateLocaleFormatter('localeDate'),
|
|
21211
|
+
toLocaleTimeString: dateLocaleFormatter('localeTime'),
|
|
21212
|
+
toLocaleString: dateLocaleFormatter('locale'),
|
|
20466
21213
|
getTimezoneOffset: (obj) => {
|
|
20467
21214
|
useHelper('date');
|
|
20468
21215
|
return `TnDateTimezoneOffset(${obj})`;
|
|
@@ -20485,7 +21232,11 @@ const dateMethodHandlers = {
|
|
|
20485
21232
|
setUTCHours: dateSetter('hours', true),
|
|
20486
21233
|
setUTCMinutes: dateSetter('minutes', true),
|
|
20487
21234
|
setUTCSeconds: dateSetter('seconds', true),
|
|
20488
|
-
setUTCMilliseconds: dateSetter('milliseconds', true)
|
|
21235
|
+
setUTCMilliseconds: dateSetter('milliseconds', true),
|
|
21236
|
+
toTemporalInstant: (obj) => {
|
|
21237
|
+
useHelper('date');
|
|
21238
|
+
return `TnDateToTemporalInstant(${obj})`;
|
|
21239
|
+
}
|
|
20489
21240
|
};
|
|
20490
21241
|
// append(base, args…) where some arguments are spreads (`x...`): one
|
|
20491
21242
|
// append per run, as Go allows a spread only as the last argument
|
|
@@ -20512,35 +21263,70 @@ function appendArguments(base, args, elementType) {
|
|
|
20512
21263
|
}
|
|
20513
21264
|
return run.length > 0 ? `append(${[out, ...run].join(', ')})` : out;
|
|
20514
21265
|
}
|
|
21266
|
+
// target = append(target, args…) as a statement. One value pushed onto a
|
|
21267
|
+
// variable or field (target a plain path, (*p) or *p) is TnPushTo(&target, v),
|
|
21268
|
+
// which stores the slice only when it grows; anything else (a map's value
|
|
21269
|
+
// m[k], spreads, several values) assigns the appended slice back.
|
|
21270
|
+
function pushStatement(target, args, elementType) {
|
|
21271
|
+
if (args.length === 1 && !args[0].endsWith('...') && elementType) {
|
|
21272
|
+
const deref = /^\(\*([\w.]+)\)$/.exec(target) ?? /^\*([\w.]+)$/.exec(target);
|
|
21273
|
+
if (deref || /^[\w.]+$/.test(target)) {
|
|
21274
|
+
useHelper('arrayPush');
|
|
21275
|
+
return `TnPushTo[${elementType}](${deref ? deref[1] : `&${target}`}, ${args[0]})`;
|
|
21276
|
+
}
|
|
21277
|
+
}
|
|
21278
|
+
return `${target} = ${appendArguments(target, args, elementType)}`;
|
|
21279
|
+
}
|
|
20515
21280
|
const arrayMethodHandlers = {
|
|
20516
21281
|
// push / unshift return the new length when their value is used
|
|
20517
21282
|
push: (obj, args) => {
|
|
20518
21283
|
const element = currentReceiverGoType?.startsWith('[]') ? currentReceiverGoType.slice(2) : undefined;
|
|
21284
|
+
// (an Array subclass's elements (seq.push(…), list.push(…) on T[] & {…}):
|
|
21285
|
+
// the embedded TnArray's reference, so the push reaches the instance)
|
|
21286
|
+
const itemsNode = currentCallNode && isPropertyAccessExpression(currentCallNode.expression) && currentCallNode.expression.expression.kind === 'TnArrayItems'
|
|
21287
|
+
? currentCallNode.expression.expression
|
|
21288
|
+
: undefined;
|
|
21289
|
+
if (itemsNode) {
|
|
21290
|
+
return `func() float64 { __p := ${visit(itemsNode.expression)}.TnItems(); ${pushStatement('*__p', args, element)}; return float64(len(*__p)) }()`;
|
|
21291
|
+
}
|
|
20519
21292
|
// (an array a call returns — a getter's — is no Go variable: appended to a copy)
|
|
20520
21293
|
// (a field through a call's pointer result — getter().items — is addressable)
|
|
20521
21294
|
const receiver = currentCallNode && isPropertyAccessExpression(currentCallNode.expression) ? currentCallNode.expression.expression : undefined;
|
|
20522
|
-
if (obj.endsWith(')') && !isAddressable(obj)
|
|
21295
|
+
if (obj.endsWith(')') && !isAddressable(obj)) {
|
|
20523
21296
|
// (a call returning an array reference — a Map of arrays' value through
|
|
20524
|
-
// getOrInsertWith — appends to the array it refers to)
|
|
20525
|
-
|
|
20526
|
-
|
|
21297
|
+
// getOrInsertWith, or m.get(k)! — appends to the array it refers to)
|
|
21298
|
+
const receiverType = receiver ? (inferRawExpressionType(receiver) ?? '') : '';
|
|
21299
|
+
const pointer = /^\(\*(.+)\)$/.exec(obj)?.[1];
|
|
21300
|
+
const receiverCall = receiver ? unwrapParentheses(receiver) : undefined;
|
|
21301
|
+
if (receiver &&
|
|
21302
|
+
!isElementAccessExpression(receiver) &&
|
|
21303
|
+
(receiverType.startsWith('*[]') ||
|
|
21304
|
+
(inferExpressionType(receiver) ?? '').startsWith('*[]') ||
|
|
21305
|
+
isMapArrayGet(receiver) ||
|
|
21306
|
+
// (a call's result: the reference, as `return n.sep ?? n.items`
|
|
21307
|
+
// or a generic V bound to an array does)
|
|
21308
|
+
(receiverCall !== undefined && isCallExpression(receiverCall) && !isOptionalChain(receiver)) ||
|
|
21309
|
+
// (obj is a dereference of the receiver: an array reference)
|
|
21310
|
+
(pointer !== undefined && !(isPropertyAccessExpression(receiver) && hasDynamicProperties(receiver.expression))))) {
|
|
21311
|
+
// (the receiver is the reference: obj is it, or its dereference)
|
|
21312
|
+
return `func() float64 { __p := ${pointer ?? obj}; ${pushStatement('*__p', args, element)}; return float64(len(*__p)) }()`;
|
|
20527
21313
|
}
|
|
20528
21314
|
// (a read out of a container — FLIPPED_ALIAS_KEYS[alias], a Map's value
|
|
20529
21315
|
// —: the array lives in it, so the appended one is stored back, as push
|
|
20530
21316
|
// mutates it in JS)
|
|
20531
21317
|
if (receiver && isElementAccessExpression(receiver) && (hasDynamicProperties(receiver.expression) || (inferExpressionType(receiver.expression) ?? '').startsWith('*TnMap['))) {
|
|
20532
|
-
return (`func() float64 { __s := ${obj};
|
|
21318
|
+
return (`func() float64 { __s := ${obj}; ${pushStatement('__s', args, element)}; ` +
|
|
20533
21319
|
`TnSetIndex(${visit(receiver.expression)}, ${visit(receiver.argumentExpression)}, __s); return float64(len(__s)) }()`);
|
|
20534
21320
|
}
|
|
20535
21321
|
if (receiver && isPropertyAccessExpression(receiver) && hasDynamicProperties(receiver.expression) && !hasQuestionDot(receiver)) {
|
|
20536
|
-
return (`func() float64 { __s := ${obj};
|
|
21322
|
+
return (`func() float64 { __s := ${obj}; ${pushStatement('__s', args, element)}; ` +
|
|
20537
21323
|
`TnSet(${visit(receiver.expression)}, ${toGoStringLiteral(receiver.name.text)}, __s); return float64(len(__s)) }()`);
|
|
20538
21324
|
}
|
|
20539
|
-
return `func() float64 { __s := ${obj};
|
|
21325
|
+
return `func() float64 { __s := ${obj}; ${pushStatement('__s', args, element)}; return float64(len(__s)) }()`;
|
|
20540
21326
|
}
|
|
20541
21327
|
return currentCallNode && !isDiscardedValue(currentCallNode)
|
|
20542
|
-
? `func() float64 { ${
|
|
20543
|
-
:
|
|
21328
|
+
? `func() float64 { ${pushStatement(obj, args, element)}; return float64(len(${obj})) }()`
|
|
21329
|
+
: pushStatement(obj, args, element);
|
|
20544
21330
|
},
|
|
20545
21331
|
pop: (obj) => {
|
|
20546
21332
|
const elementType = receiverElementType();
|
|
@@ -20787,6 +21573,27 @@ function elementEquals(a, b) {
|
|
|
20787
21573
|
const mapMethodHandlers = {
|
|
20788
21574
|
set: (obj, args) => `${obj}.Set(${args[0]}, ${args[1]})`,
|
|
20789
21575
|
get: (obj, args) => `${obj}.Get(${args[0]})`,
|
|
21576
|
+
getOrInsert: (obj, args) => `${obj}.GetOrInsert(${args[0]}, ${args[1]})`,
|
|
21577
|
+
// (the callback as a func(K) V, whatever arity it was written with)
|
|
21578
|
+
getOrInsertComputed: (obj, args) => {
|
|
21579
|
+
const keyType = currentReceiverGoType ? extractMapKeyType(currentReceiverGoType) : 'interface{}';
|
|
21580
|
+
const valueType = currentReceiverGoType ? extractMapValueType(currentReceiverGoType) : 'interface{}';
|
|
21581
|
+
const cbNode = currentCallArgNodes[1];
|
|
21582
|
+
const arity = cbNode && (isArrowFunction(cbNode) || isFunctionExpression(cbNode)) ? (cbNode.parameters ?? []).length : 1;
|
|
21583
|
+
const call = `(${args[1]})(${arity === 0 ? '' : '__k'})`;
|
|
21584
|
+
// (the callback's value as the map's: an array stored by reference, a literal converted)
|
|
21585
|
+
const cbResult = cbNode ? goFuncReturnType(functionValueGoType(cbNode) ?? '') ?? '' : '';
|
|
21586
|
+
let value = call;
|
|
21587
|
+
if (valueType.startsWith('*[]') && cbResult !== valueType) {
|
|
21588
|
+
useHelper('dynamic');
|
|
21589
|
+
value = `func() ${valueType} { __r := TnSliceAs[${valueType.slice(3)}](${call}); return &__r }()`;
|
|
21590
|
+
}
|
|
21591
|
+
else if (cbResult !== valueType && valueType !== 'interface{}') {
|
|
21592
|
+
useHelper('dynamic');
|
|
21593
|
+
value = `TnAs[${valueType}](${call})`;
|
|
21594
|
+
}
|
|
21595
|
+
return `${obj}.GetOrInsertComputed(${args[0]}, func(__k ${keyType}) ${valueType} { return ${value} })`;
|
|
21596
|
+
},
|
|
20790
21597
|
has: (obj, args) => `${obj}.Has(${args[0]})`,
|
|
20791
21598
|
delete: (obj, args) => `${obj}.Delete(${args[0]})`,
|
|
20792
21599
|
clear: (obj) => `${obj}.Clear()`,
|
|
@@ -20822,7 +21629,7 @@ function ownMethodHandler(table, key) {
|
|
|
20822
21629
|
function getDynamicCallHandler(caller, objectType) {
|
|
20823
21630
|
if (promiseResolveName && caller === promiseResolveName) {
|
|
20824
21631
|
// The first resolution wins; later ones are ignored (as in JS)
|
|
20825
|
-
return (_caller, args) => {
|
|
21632
|
+
return (_caller, args, _typeArgs) => {
|
|
20826
21633
|
// resolve() without a value: the channel type's zero value
|
|
20827
21634
|
if (args.length === 0 || args[0] === 'nil') {
|
|
20828
21635
|
useHelper('promise');
|
|
@@ -20832,7 +21639,7 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20832
21639
|
};
|
|
20833
21640
|
}
|
|
20834
21641
|
if (promiseRejectName && caller === promiseRejectName) {
|
|
20835
|
-
return (_caller, args) => {
|
|
21642
|
+
return (_caller, args, _typeArgs) => {
|
|
20836
21643
|
useHelper('promise');
|
|
20837
21644
|
return `TnReject(ch, ${args[0] ?? 'nil'})`;
|
|
20838
21645
|
};
|
|
@@ -20848,7 +21655,7 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20848
21655
|
if (receiverClassName && findClassMethod(receiverClassName, methodName))
|
|
20849
21656
|
return null;
|
|
20850
21657
|
if (methodName === 'toString') {
|
|
20851
|
-
return (c, args) => {
|
|
21658
|
+
return (c, args, _typeArgs) => {
|
|
20852
21659
|
const obj = c.substring(0, dotIndex);
|
|
20853
21660
|
if (currentReceiverGoType === 'time.Time') {
|
|
20854
21661
|
useHelper('date');
|
|
@@ -20871,20 +21678,39 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20871
21678
|
};
|
|
20872
21679
|
}
|
|
20873
21680
|
if (methodName === 'toExponential') {
|
|
20874
|
-
return (c, args) => {
|
|
21681
|
+
return (c, args, _typeArgs) => {
|
|
20875
21682
|
useHelper('builtins');
|
|
20876
21683
|
return `TnToExponential(${c.substring(0, dotIndex)}, ${args[0] ?? '0'}, ${args.length > 0})`;
|
|
20877
21684
|
};
|
|
20878
21685
|
}
|
|
20879
21686
|
if (methodName === 'toPrecision') {
|
|
20880
|
-
return (c, args) => {
|
|
21687
|
+
return (c, args, _typeArgs) => {
|
|
20881
21688
|
importedPackages.add('strconv');
|
|
20882
21689
|
return `strconv.FormatFloat(${c.substring(0, dotIndex)}, 'g', int(${args[0] ?? '-1'}), 64)`;
|
|
20883
21690
|
};
|
|
20884
21691
|
}
|
|
21692
|
+
// number.toLocaleString(locales, options): the Intl number formatting
|
|
21693
|
+
// (the default locale follows the OS, as Node's do)
|
|
21694
|
+
if (methodName === 'toLocaleString' && (currentReceiverGoType === 'float64' || ((objectType === 'number' || objectType === 'float64') && currentReceiverGoType !== 'time.Time'))) {
|
|
21695
|
+
return (c, _args, _typeArgs) => {
|
|
21696
|
+
useHelper('intlNumber');
|
|
21697
|
+
const locales = currentCallArgNodes[0] ? toGoValueOfType(currentCallArgNodes[0], 'interface{}') : 'nil';
|
|
21698
|
+
const options = currentCallArgNodes[1] ? toGoValueOfType(currentCallArgNodes[1], 'interface{}') : 'nil';
|
|
21699
|
+
return `TnIntlNumLocale(${c.substring(0, dotIndex)}, ${locales}, ${options})`;
|
|
21700
|
+
};
|
|
21701
|
+
}
|
|
21702
|
+
// bigint.toLocaleString(locales, options)
|
|
21703
|
+
if (methodName === 'toLocaleString' && currentReceiverGoType === '*tnbig.Int') {
|
|
21704
|
+
return (c, _args, _typeArgs) => {
|
|
21705
|
+
useHelper('intlNumber');
|
|
21706
|
+
const locales = currentCallArgNodes[0] ? toGoValueOfType(currentCallArgNodes[0], 'interface{}') : 'nil';
|
|
21707
|
+
const options = currentCallArgNodes[1] ? toGoValueOfType(currentCallArgNodes[1], 'interface{}') : 'nil';
|
|
21708
|
+
return `TnIntlNumLocale(${c.substring(0, dotIndex)}, ${locales}, ${options})`;
|
|
21709
|
+
};
|
|
21710
|
+
}
|
|
20885
21711
|
// number.toFixed(digits)
|
|
20886
21712
|
if (methodName === 'toFixed') {
|
|
20887
|
-
return (c, args) => {
|
|
21713
|
+
return (c, args, _typeArgs) => {
|
|
20888
21714
|
useHelper('toFixed');
|
|
20889
21715
|
return `TnToFixed(${c.substring(0, dotIndex)}, ${args[0] ?? '0'})`;
|
|
20890
21716
|
};
|
|
@@ -20903,13 +21729,13 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20903
21729
|
const elementType = currentReceiverGoType.slice(5);
|
|
20904
21730
|
const callbackNode = currentCallArgNodes[0];
|
|
20905
21731
|
const extraArgs = currentCallArgNodes.slice(1);
|
|
20906
|
-
return (c, args) => visitIteratorHelper(c.substring(0, dotIndex), helperName, elementType, args, callbackNode, extraArgs);
|
|
21732
|
+
return (c, args, _typeArgs) => visitIteratorHelper(c.substring(0, dotIndex), helperName, elementType, args, callbackNode, extraArgs);
|
|
20907
21733
|
}
|
|
20908
21734
|
if (currentReceiverGoType?.startsWith('*TnWeakRef[') && methodName === 'deref') {
|
|
20909
|
-
return (c) => `${c.substring(0, dotIndex)}.deref()`;
|
|
21735
|
+
return (c, _args, _typeArgs) => `${c.substring(0, dotIndex)}.deref()`;
|
|
20910
21736
|
}
|
|
20911
21737
|
if (currentReceiverGoType === '*TnFinalizationRegistry' && (methodName === 'register' || methodName === 'unregister')) {
|
|
20912
|
-
return (c, args) => {
|
|
21738
|
+
return (c, args, _typeArgs) => {
|
|
20913
21739
|
const obj = c.substring(0, dotIndex);
|
|
20914
21740
|
if (methodName === 'unregister')
|
|
20915
21741
|
return `${obj}.unregister(${args[0]})`;
|
|
@@ -20924,7 +21750,7 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20924
21750
|
const isSet = extractMapValueType(currentReceiverGoType) === 'struct{}';
|
|
20925
21751
|
handler = ownMethodHandler(isSet ? setMethodHandlers : mapMethodHandlers, methodName);
|
|
20926
21752
|
if (handler) {
|
|
20927
|
-
return (c, args) => {
|
|
21753
|
+
return (c, args, _typeArgs) => {
|
|
20928
21754
|
const obj = c.substring(0, dotIndex);
|
|
20929
21755
|
return handler(obj, args);
|
|
20930
21756
|
};
|
|
@@ -20956,7 +21782,7 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20956
21782
|
ownMethodHandler(regexpMethodHandlers, methodName);
|
|
20957
21783
|
}
|
|
20958
21784
|
if (handler) {
|
|
20959
|
-
return (c, args) => {
|
|
21785
|
+
return (c, args, _typeArgs) => {
|
|
20960
21786
|
const obj = c.substring(0, dotIndex);
|
|
20961
21787
|
return handler(obj, args);
|
|
20962
21788
|
};
|
|
@@ -20964,13 +21790,18 @@ function getDynamicCallHandler(caller, objectType) {
|
|
|
20964
21790
|
}
|
|
20965
21791
|
return null;
|
|
20966
21792
|
}
|
|
20967
|
-
function getCallString(caller, args, typeArgs = '', objectType) {
|
|
21793
|
+
function getCallString(caller, args, typeArgs = '', objectType, at) {
|
|
20968
21794
|
// Parentheses from casts like `(mod as any).fn(...)` are stripped for lookup
|
|
20969
21795
|
// (own entries only: a plain-object lookup would also find Object.prototype members)
|
|
20970
21796
|
const bare = caller.replace(/[()]/g, '');
|
|
20971
|
-
|
|
20972
|
-
|
|
20973
|
-
|
|
21797
|
+
// A program's own `assert` (function, variable, parameter…) is a plain call;
|
|
21798
|
+
// only the global assertion lowers to the panic statement
|
|
21799
|
+
const ownAssert = bare === 'assert' && !!at && isUserDeclared('assert', at);
|
|
21800
|
+
const handler = ownAssert
|
|
21801
|
+
? undefined
|
|
21802
|
+
: (Object.hasOwn(callHandlers, caller) ? callHandlers[caller] : undefined) ??
|
|
21803
|
+
(Object.hasOwn(callHandlers, bare) ? callHandlers[bare] : undefined) ??
|
|
21804
|
+
getDynamicCallHandler(caller, objectType);
|
|
20974
21805
|
if (handler) {
|
|
20975
21806
|
return handler(caller, args, typeArgs);
|
|
20976
21807
|
}
|
|
@@ -21023,7 +21854,8 @@ const GLOBAL_TYPEOF = {
|
|
|
21023
21854
|
Buffer: 'function', Uint8Array: 'function', btoa: 'function', atob: 'function', String: 'function',
|
|
21024
21855
|
Number: 'function', Boolean: 'function', Symbol: 'function', Array: 'function', Object: 'function',
|
|
21025
21856
|
Map: 'function', Set: 'function', Date: 'function', RegExp: 'function', Promise: 'function', Error: 'function',
|
|
21026
|
-
BigInt: 'function'
|
|
21857
|
+
BigInt: 'function', navigator: 'object', sessionStorage: 'object', Storage: 'function', CustomEvent: 'function',
|
|
21858
|
+
ErrorEvent: 'function', DOMException: 'function', Temporal: 'object'
|
|
21027
21859
|
};
|
|
21028
21860
|
const CONSOLE_METHODS = new Set(['log', 'info', 'warn', 'error', 'debug', 'trace', 'dir', 'table', 'time', 'timeEnd', 'timeLog', 'group', 'groupEnd', 'groupCollapsed', 'count', 'countReset', 'assert', 'clear']);
|
|
21029
21861
|
function visitTypeOf(node) {
|
|
@@ -21500,6 +22332,31 @@ function visitRegexReplace(node) {
|
|
|
21500
22332
|
// (an expression read twice must be pure: a name, fields, a Record lookup)
|
|
21501
22333
|
else if (reIsWrapper && /^[\w.]+(\.Get\("[^"\\]*"\))?[\w.]*$/.test(re))
|
|
21502
22334
|
isGlobal = `${re}.global`;
|
|
22335
|
+
else if (reIsWrapper) {
|
|
22336
|
+
// new RegExp(p, 'g…') written out: its flags are known here
|
|
22337
|
+
const flags = newRegExpLiteralFlags(pattern);
|
|
22338
|
+
if (flags !== undefined)
|
|
22339
|
+
isGlobal = flags.includes('g') ? 'true' : 'false';
|
|
22340
|
+
// any other RegExp (a call's result, new RegExp(p, flags)): evaluated
|
|
22341
|
+
// once, its g flag tested at run time
|
|
22342
|
+
else
|
|
22343
|
+
return `func() string { __rx := ${re}; return ${emitRegexReplace(pattern, replacement, target, reIsWrapper, '__rx', '__rx.global')} }()`;
|
|
22344
|
+
}
|
|
22345
|
+
return emitRegexReplace(pattern, replacement, target, reIsWrapper, re, isGlobal);
|
|
22346
|
+
}
|
|
22347
|
+
// The flags of new RegExp(p) / new RegExp(p, 'literal flags'); undefined for
|
|
22348
|
+
// any other expression or flags computed at run time
|
|
22349
|
+
function newRegExpLiteralFlags(node) {
|
|
22350
|
+
const expr = unwrapParentheses(node);
|
|
22351
|
+
if (!isNewExpression(expr) || !isIdentifier(expr.expression) || expr.expression.text !== 'RegExp')
|
|
22352
|
+
return undefined;
|
|
22353
|
+
const args = expr.arguments ?? [];
|
|
22354
|
+
if (args.length < 2)
|
|
22355
|
+
return args.length === 1 && isRegularExpressionLiteral(unwrapParentheses(args[0])) ? undefined : '';
|
|
22356
|
+
const flags = unwrapParentheses(args[1]);
|
|
22357
|
+
return isStringLiteral(flags) || isNoSubstitutionTemplateLiteral(flags) ? flags.text : undefined;
|
|
22358
|
+
}
|
|
22359
|
+
function emitRegexReplace(pattern, replacement, target, reIsWrapper, re, isGlobal) {
|
|
21503
22360
|
importedPackages.add('regexp');
|
|
21504
22361
|
if (isArrowFunction(replacement) || isFunctionExpression(replacement)) {
|
|
21505
22362
|
useHelper('regexReplaceFunc');
|
|
@@ -21648,7 +22505,8 @@ function translateJsRegexPattern(pattern) {
|
|
|
21648
22505
|
// before testing for lookarounds (?= (?! (?<= (?<!
|
|
21649
22506
|
function needsStatefulRegex(pattern, flags) {
|
|
21650
22507
|
// /g and /y keep lastIndex state; /u keeps its flag for .flags
|
|
21651
|
-
|
|
22508
|
+
// (/d: its matches carry .indices, which only TnRegex records)
|
|
22509
|
+
if (flags.includes('g') || flags.includes('y') || flags.includes('u') || flags.includes('d'))
|
|
21652
22510
|
return true;
|
|
21653
22511
|
const stripped = pattern.replace(/\(\?<[A-Za-z_][A-Za-z0-9_]*>/g, '');
|
|
21654
22512
|
// (?= (?! and any remaining (?< (lookbehind) need the backtracker, as do
|
|
@@ -21656,7 +22514,7 @@ function needsStatefulRegex(pattern, flags) {
|
|
|
21656
22514
|
return /\\[1-9]|\\k<|\(\?[=!<]/.test(stripped);
|
|
21657
22515
|
}
|
|
21658
22516
|
const REGEX_FLAG_PROPERTIES = {
|
|
21659
|
-
global: 'g', ignoreCase: 'i', multiline: 'm', dotAll: 's', unicode: 'u', unicodeSets: 'v', sticky: 'y'
|
|
22517
|
+
global: 'g', ignoreCase: 'i', multiline: 'm', dotAll: 's', unicode: 'u', unicodeSets: 'v', sticky: 'y', hasIndices: 'd'
|
|
21660
22518
|
};
|
|
21661
22519
|
function inferRegexPropertyType(expr) {
|
|
21662
22520
|
if (!isPropertyAccessExpression(expr))
|
|
@@ -23543,8 +24401,10 @@ function getCollectionArgumentTypes(node) {
|
|
|
23543
24401
|
return [keyType];
|
|
23544
24402
|
if (['get', 'has', 'delete'].includes(method))
|
|
23545
24403
|
return [keyType];
|
|
23546
|
-
if (method === 'set')
|
|
24404
|
+
if (method === 'set' || method === 'getOrInsert')
|
|
23547
24405
|
return [keyType, valueType];
|
|
24406
|
+
if (method === 'getOrInsertComputed')
|
|
24407
|
+
return [keyType];
|
|
23548
24408
|
}
|
|
23549
24409
|
if (receiverType === '*regexp.Regexp' && (method === 'test' || method === 'exec'))
|
|
23550
24410
|
return ['string'];
|
|
@@ -24386,6 +25246,16 @@ function useNodeHelperDefining(goType) {
|
|
|
24386
25246
|
}
|
|
24387
25247
|
}
|
|
24388
25248
|
}
|
|
25249
|
+
// A Node class getter whose Go type another helper declares (stats.atimeInstant:
|
|
25250
|
+
// *TnTemporalInstant → the Temporal helper): pull it in, so fs alone doesn't
|
|
25251
|
+
function useNodeHelperForGetter(className, accessor) {
|
|
25252
|
+
if (!className.startsWith('Tn'))
|
|
25253
|
+
return;
|
|
25254
|
+
const clsKey = nodeRegistry.classByGoType[`*${className}`];
|
|
25255
|
+
const getterType = clsKey ? nodeRegistry.classes[clsKey]?.getters[accessor] : undefined;
|
|
25256
|
+
if (getterType)
|
|
25257
|
+
useNodeHelperDefining(getterType);
|
|
25258
|
+
}
|
|
24389
25259
|
// Go packages the generated code may import: a user identifier with one of
|
|
24390
25260
|
// these names would shadow the package, so it is renamed (unless the name is
|
|
24391
25261
|
// itself a `go:` package import)
|
|
@@ -24583,13 +25453,13 @@ const generatorYieldsInferring = new Set();
|
|
|
24583
25453
|
function getGeneratorYieldType(fn) {
|
|
24584
25454
|
// (a function expression's slot type — let tokenize: (text) => Generator<T> — names it too)
|
|
24585
25455
|
const contextualReturn = !fn.type && isFunctionExpression(fn) ? resolveTypeNode(getContextualFunctionType(fn)?.type) : undefined;
|
|
24586
|
-
if (contextualReturn && isTypeReferenceNode(contextualReturn) && isIdentifier(contextualReturn.typeName) && ['Generator', 'IterableIterator', 'Iterable', 'Iterator'].includes(contextualReturn.typeName.text) && (contextualReturn.typeArguments ?? []).length > 0) {
|
|
25456
|
+
if (contextualReturn && isTypeReferenceNode(contextualReturn) && isIdentifier(contextualReturn.typeName) && ['Generator', 'IterableIterator', 'Iterable', 'Iterator', 'AsyncGenerator', 'AsyncIterableIterator', 'AsyncIterable'].includes(contextualReturn.typeName.text) && (contextualReturn.typeArguments ?? []).length > 0) {
|
|
24587
25457
|
const annotated = getType(contextualReturn.typeArguments[0]);
|
|
24588
25458
|
if (annotated && annotated !== ':')
|
|
24589
25459
|
return annotated;
|
|
24590
25460
|
}
|
|
24591
25461
|
// (an annotation Generator<T> / Iterable<T> / Iterator<T> names it)
|
|
24592
|
-
if (fn.type && isTypeReferenceNode(fn.type) && isIdentifier(fn.type.typeName) && ['Generator', 'IterableIterator', 'Iterable', 'Iterator'].includes(fn.type.typeName.text) && (fn.type.typeArguments ?? []).length > 0) {
|
|
25462
|
+
if (fn.type && isTypeReferenceNode(fn.type) && isIdentifier(fn.type.typeName) && ['Generator', 'IterableIterator', 'Iterable', 'Iterator', 'AsyncGenerator', 'AsyncIterableIterator', 'AsyncIterable'].includes(fn.type.typeName.text) && (fn.type.typeArguments ?? []).length > 0) {
|
|
24593
25463
|
const annotated = getType(fn.type.typeArguments[0]);
|
|
24594
25464
|
if (annotated && annotated !== ':')
|
|
24595
25465
|
return annotated;
|
|
@@ -24998,6 +25868,9 @@ function instanceMethodNames(cls) {
|
|
|
24998
25868
|
.filter((n) => !!n);
|
|
24999
25869
|
}
|
|
25000
25870
|
function collectMixins() {
|
|
25871
|
+
mixinBaseOf.clear();
|
|
25872
|
+
mixinVirtualMethods.clear();
|
|
25873
|
+
mixinBaseCtorSignatures.clear();
|
|
25001
25874
|
for (const [name, declaration] of declaredClasses) {
|
|
25002
25875
|
if (!declaration.tnMixin)
|
|
25003
25876
|
continue;
|
|
@@ -26376,15 +27249,18 @@ const helperRequires = {
|
|
|
26376
27249
|
functionThis: [],
|
|
26377
27250
|
jsx: [],
|
|
26378
27251
|
objectIntegrity: [],
|
|
26379
|
-
structuredClone: [],
|
|
27252
|
+
structuredClone: ['domException'],
|
|
27253
|
+
structuredCloneTransfer: ['structuredClone', 'dynamic'],
|
|
26380
27254
|
globalThis: ['dynamic'],
|
|
26381
27255
|
namedGroups: ['orderedMap', 'regexMatch'],
|
|
26382
27256
|
fancyRegex: ['orderedMap', 'regexMatch', 'regexEngine'],
|
|
26383
27257
|
dynamic: ['error', 'strIndex', 'toFixed', 'functionThis'],
|
|
27258
|
+
orderedMap: ['dynamic'],
|
|
26384
27259
|
mapAssign: ['dynamic', 'orderedMap'],
|
|
26385
27260
|
regexMatch: ['strIndex'],
|
|
26386
27261
|
stringSearch: ['strIndex'],
|
|
26387
27262
|
classes: ['dynamic', 'error', 'orderedMap', 'decorators'],
|
|
27263
|
+
domException: ['error', 'dynamic'],
|
|
26388
27264
|
arraySubclass: ['dynamic', 'classes'],
|
|
26389
27265
|
moduleUrl: ['pathToFileURL'],
|
|
26390
27266
|
timerWait: ['eventLoop'],
|
|
@@ -26416,6 +27292,10 @@ function useHelper(id) {
|
|
|
26416
27292
|
importedPackages.add(pkg);
|
|
26417
27293
|
helperProvidedPackages.add(pkg);
|
|
26418
27294
|
}
|
|
27295
|
+
// Blank side-effect imports a helper needs (time/tzdata for Temporal's
|
|
27296
|
+
// named zones): kept even when no code names the package
|
|
27297
|
+
for (const pkg of nodeRegistry.helperSideEffects[id] ?? [])
|
|
27298
|
+
goSideEffectImports.add(pkg);
|
|
26419
27299
|
// (dynamic values and promises both used: promises held as any get their methods)
|
|
26420
27300
|
if ((id === 'dynamic' || id === 'promise') && usedHelpers.has('dynamic') && usedHelpers.has('promise'))
|
|
26421
27301
|
useHelper('dynamicPromise');
|
|
@@ -27097,6 +27977,11 @@ registerTls(nodeRegistry);
|
|
|
27097
27977
|
registerHttp(nodeRegistry);
|
|
27098
27978
|
registerDgram(nodeRegistry);
|
|
27099
27979
|
registerSqlite(nodeRegistry);
|
|
27980
|
+
registerWebAssembly(nodeRegistry);
|
|
27981
|
+
registerWasi(nodeRegistry);
|
|
27982
|
+
registerFfi(nodeRegistry);
|
|
27983
|
+
registerTemporal(nodeRegistry);
|
|
27984
|
+
registerIntl(nodeRegistry);
|
|
27100
27985
|
registerWebview(nodeRegistry);
|
|
27101
27986
|
registerFetch(nodeRegistry);
|
|
27102
27987
|
registerStreamWeb(nodeRegistry);
|
|
@@ -27105,6 +27990,7 @@ registerTest(nodeRegistry);
|
|
|
27105
27990
|
registerWorkerThreads(nodeRegistry);
|
|
27106
27991
|
registerCluster(nodeRegistry);
|
|
27107
27992
|
registerHttp2(nodeRegistry);
|
|
27993
|
+
registerWebSocket(nodeRegistry);
|
|
27108
27994
|
registerSystemExtra(nodeRegistry);
|
|
27109
27995
|
registerModuleV8(nodeRegistry);
|
|
27110
27996
|
// Go packages required by each helper, registered when the helper is used.
|
|
@@ -27122,9 +28008,9 @@ const helperPackages = {
|
|
|
27122
28008
|
isArray: ['reflect'],
|
|
27123
28009
|
iterators: [],
|
|
27124
28010
|
weakRefs: ['weak', 'runtime', 'sync'],
|
|
27125
|
-
builtins: ['math', 'strconv', 'strings', 'math/big'],
|
|
28011
|
+
builtins: ['math', 'strconv', 'strings', 'math/big', 'unicode'],
|
|
27126
28012
|
date: ['time', 'math', 'regexp', 'strings', 'strconv', 'fmt'],
|
|
27127
|
-
dynamic: ['math', 'strings', 'fmt', 'sort', 'reflect', 'strconv', 'regexp', 'unsafe', 'time', 'sync', 'sync/atomic', 'weak', 'runtime'],
|
|
28013
|
+
dynamic: ['math', 'math/big', 'strings', 'fmt', 'sort', 'reflect', 'strconv', 'regexp', 'unsafe', 'time', 'sync', 'sync/atomic', 'weak', 'runtime'],
|
|
27128
28014
|
classes: ['reflect'],
|
|
27129
28015
|
generatorStep: ['sync'],
|
|
27130
28016
|
generatorSeq: [],
|
|
@@ -27144,7 +28030,7 @@ const helperPackages = {
|
|
|
27144
28030
|
fancyRegex: ['regexp', 'strings', 'strconv', 'unicode/utf8', 'sync/atomic'],
|
|
27145
28031
|
regexEngine: ['strings', 'fmt', 'strconv', 'sync', 'sync/atomic', 'unicode', 'unicode/utf8'],
|
|
27146
28032
|
namedGroups: ['regexp', 'unicode/utf8'],
|
|
27147
|
-
regexMatch: ['regexp', 'math', 'strconv', 'unsafe', 'unicode/utf8'],
|
|
28033
|
+
regexMatch: ['regexp', 'math', 'strconv', 'strings', 'unsafe', 'unicode/utf8'],
|
|
27148
28034
|
strIndex: ['unicode/utf8', 'sync', 'sync/atomic', 'unsafe', 'math', 'strings', 'sort'],
|
|
27149
28035
|
jsReplacement: ['strings'],
|
|
27150
28036
|
moduleUrl: ['os'],
|
|
@@ -27166,6 +28052,7 @@ const helperPackages = {
|
|
|
27166
28052
|
jsx: ['strings', 'html', 'reflect', 'strconv', 'fmt'],
|
|
27167
28053
|
objectIntegrity: ['sync', 'reflect'],
|
|
27168
28054
|
structuredClone: ['reflect', 'unsafe'],
|
|
28055
|
+
structuredCloneTransfer: ['reflect'],
|
|
27169
28056
|
globalThis: [],
|
|
27170
28057
|
getenv: ['os'],
|
|
27171
28058
|
strAppend: ['sync', 'unsafe'],
|
|
@@ -27179,15 +28066,31 @@ const goHelpers = {
|
|
|
27179
28066
|
// its final memory
|
|
27180
28067
|
func TnPush[T any](s []T, v T) []T {
|
|
27181
28068
|
if len(s) == cap(s) {
|
|
27182
|
-
|
|
27183
|
-
if n < 16 {
|
|
27184
|
-
n = 16
|
|
27185
|
-
}
|
|
27186
|
-
ns := make([]T, len(s), n)
|
|
27187
|
-
copy(ns, s)
|
|
27188
|
-
s = ns
|
|
28069
|
+
s = tnPushGrow(s)
|
|
27189
28070
|
}
|
|
27190
28071
|
return append(s, v)
|
|
28072
|
+
}
|
|
28073
|
+
|
|
28074
|
+
// arr.push(v) on an array variable or field, in place: the slice is stored
|
|
28075
|
+
// only when it grows, so a push into spare capacity writes just its length,
|
|
28076
|
+
// as x = append(x, v) does (x = TnPush(x, v) stores the whole slice, with a
|
|
28077
|
+
// GC write barrier, on every push)
|
|
28078
|
+
func TnPushTo[T any](s *[]T, v T) {
|
|
28079
|
+
if len(*s) == cap(*s) {
|
|
28080
|
+
*s = tnPushGrow(*s)
|
|
28081
|
+
}
|
|
28082
|
+
*s = append(*s, v)
|
|
28083
|
+
}
|
|
28084
|
+
|
|
28085
|
+
// A full slice's copy with twice its capacity (at least 16)
|
|
28086
|
+
func tnPushGrow[T any](s []T) []T {
|
|
28087
|
+
n := len(s) * 2
|
|
28088
|
+
if n < 16 {
|
|
28089
|
+
n = 16
|
|
28090
|
+
}
|
|
28091
|
+
ns := make([]T, len(s), n)
|
|
28092
|
+
copy(ns, s)
|
|
28093
|
+
return ns
|
|
27191
28094
|
}`,
|
|
27192
28095
|
slicePtr: `// A *[]T slot from a slice: nil stays nil (no match, undefined), and the box
|
|
27193
28096
|
// is allocated only for a value, not for every call a local &v would cost
|
|
@@ -27306,6 +28209,20 @@ func TnIterNext[T any](ch chan T) *TnIterResult[T] {
|
|
|
27306
28209
|
return &TnIterResult[T]{value: v, done: !ok}
|
|
27307
28210
|
}
|
|
27308
28211
|
|
|
28212
|
+
// Iterator.concat(a, b, …): each iterable's values in turn
|
|
28213
|
+
func TnIterConcat[T any](chs ...chan T) chan T {
|
|
28214
|
+
ch := make(chan T)
|
|
28215
|
+
go func() {
|
|
28216
|
+
defer close(ch)
|
|
28217
|
+
for _, src := range chs {
|
|
28218
|
+
for v := range src {
|
|
28219
|
+
ch <- v
|
|
28220
|
+
}
|
|
28221
|
+
}
|
|
28222
|
+
}()
|
|
28223
|
+
return ch
|
|
28224
|
+
}
|
|
28225
|
+
|
|
27309
28226
|
// Iterator.from(array)
|
|
27310
28227
|
func TnIterFrom[T any](values []T) chan T {
|
|
27311
28228
|
ch := make(chan T)
|
|
@@ -27521,6 +28438,310 @@ func TnToExponential(x float64, digits float64, hasDigits bool) string {
|
|
|
27521
28438
|
return mantissa + "e" + sign + exponent
|
|
27522
28439
|
}
|
|
27523
28440
|
|
|
28441
|
+
// localeCompare / toLocaleString without locale data: the root collation
|
|
28442
|
+
// (CLDR) approximated — spaces and punctuation, then digits, then letters;
|
|
28443
|
+
// accents and case only break ties — and en-US number formatting
|
|
28444
|
+
|
|
28445
|
+
// Latin-1 and Latin Extended-A letters (U+00C0–U+017F) as their base letter ('.': none)
|
|
28446
|
+
const tnLatinBase = "AAAAAA.CEEEEIIIIDNOOOOO.OUUUUY..aaaaaa.ceeeeiiiidnooooo.ouuuuy.yAaAaAaCcCcCcCcDdDdEeEeEeEeEeGgGgGgGgHhHhIiIiIiIiIi..JjKkkLlLlLlLlLlNnNnNnn..OoOoOo..RrRrRrSsSsSsSsTtTtTtUuUuUuUuUuUuWwYyYZzZzZzs"
|
|
28447
|
+
|
|
28448
|
+
type tnCollationUnit struct {
|
|
28449
|
+
class int // 1 space / punctuation, 2 digits, 3 letters and the rest
|
|
28450
|
+
primary rune // the base letter, lowercased
|
|
28451
|
+
digits string // a run of digits (numeric collation)
|
|
28452
|
+
secondary rune // the accented letter (0: none)
|
|
28453
|
+
upper bool
|
|
28454
|
+
}
|
|
28455
|
+
|
|
28456
|
+
func tnCollationUnits(s string, numeric bool, ignorePunctuation bool) []tnCollationUnit {
|
|
28457
|
+
units := make([]tnCollationUnit, 0, len(s))
|
|
28458
|
+
runes := []rune(s)
|
|
28459
|
+
for i := 0; i < len(runes); i++ {
|
|
28460
|
+
r := runes[i]
|
|
28461
|
+
if numeric && r >= '0' && r <= '9' {
|
|
28462
|
+
j := i
|
|
28463
|
+
for j < len(runes) && runes[j] >= '0' && runes[j] <= '9' {
|
|
28464
|
+
j++
|
|
28465
|
+
}
|
|
28466
|
+
digits := strings.TrimLeft(string(runes[i:j]), "0")
|
|
28467
|
+
units = append(units, tnCollationUnit{class: 2, digits: digits})
|
|
28468
|
+
i = j - 1
|
|
28469
|
+
continue
|
|
28470
|
+
}
|
|
28471
|
+
base, accent := r, rune(0)
|
|
28472
|
+
if r >= 0xc0 && r <= 0x17f {
|
|
28473
|
+
if b := tnLatinBase[r-0xc0]; b != '.' {
|
|
28474
|
+
base, accent = rune(b), r
|
|
28475
|
+
}
|
|
28476
|
+
}
|
|
28477
|
+
unit := tnCollationUnit{class: 3, primary: unicode.ToLower(base), secondary: accent, upper: unicode.IsUpper(base)}
|
|
28478
|
+
switch {
|
|
28479
|
+
case unicode.IsSpace(r) || unicode.IsPunct(r) || unicode.IsSymbol(r):
|
|
28480
|
+
if ignorePunctuation {
|
|
28481
|
+
continue
|
|
28482
|
+
}
|
|
28483
|
+
unit.class = 1
|
|
28484
|
+
case unicode.IsDigit(r):
|
|
28485
|
+
unit.class = 2
|
|
28486
|
+
unit.digits = string(r)
|
|
28487
|
+
}
|
|
28488
|
+
units = append(units, unit)
|
|
28489
|
+
}
|
|
28490
|
+
return units
|
|
28491
|
+
}
|
|
28492
|
+
|
|
28493
|
+
func tnCollationSign(n int) float64 {
|
|
28494
|
+
if n < 0 {
|
|
28495
|
+
return -1
|
|
28496
|
+
}
|
|
28497
|
+
if n > 0 {
|
|
28498
|
+
return 1
|
|
28499
|
+
}
|
|
28500
|
+
return 0
|
|
28501
|
+
}
|
|
28502
|
+
|
|
28503
|
+
// a.localeCompare(b, locales, { sensitivity, numeric, caseFirst, ignorePunctuation })
|
|
28504
|
+
func TnLocaleCompare(a string, b string, options interface{}) float64 {
|
|
28505
|
+
sensitivity, caseFirst := "variant", "false"
|
|
28506
|
+
numeric, ignorePunctuation := false, false
|
|
28507
|
+
if options != nil {
|
|
28508
|
+
if v, ok := TnGetValue(options, "sensitivity").(string); ok {
|
|
28509
|
+
sensitivity = v
|
|
28510
|
+
}
|
|
28511
|
+
if v, ok := TnGetValue(options, "caseFirst").(string); ok {
|
|
28512
|
+
caseFirst = v
|
|
28513
|
+
}
|
|
28514
|
+
numeric = TnTruthy(TnGetValue(options, "numeric"))
|
|
28515
|
+
ignorePunctuation = TnTruthy(TnGetValue(options, "ignorePunctuation"))
|
|
28516
|
+
}
|
|
28517
|
+
ua := tnCollationUnits(a, numeric, ignorePunctuation)
|
|
28518
|
+
ub := tnCollationUnits(b, numeric, ignorePunctuation)
|
|
28519
|
+
// primary: base letters, digits, punctuation
|
|
28520
|
+
for i := 0; i < len(ua) && i < len(ub); i++ {
|
|
28521
|
+
x, y := ua[i], ub[i]
|
|
28522
|
+
if x.class != y.class {
|
|
28523
|
+
return tnCollationSign(x.class - y.class)
|
|
28524
|
+
}
|
|
28525
|
+
if x.class == 2 {
|
|
28526
|
+
if len(x.digits) != len(y.digits) && numeric {
|
|
28527
|
+
return tnCollationSign(len(x.digits) - len(y.digits))
|
|
28528
|
+
}
|
|
28529
|
+
if c := strings.Compare(x.digits, y.digits); c != 0 {
|
|
28530
|
+
return float64(c)
|
|
28531
|
+
}
|
|
28532
|
+
continue
|
|
28533
|
+
}
|
|
28534
|
+
if x.primary != y.primary {
|
|
28535
|
+
return tnCollationSign(int(x.primary) - int(y.primary))
|
|
28536
|
+
}
|
|
28537
|
+
}
|
|
28538
|
+
if len(ua) != len(ub) {
|
|
28539
|
+
return tnCollationSign(len(ua) - len(ub))
|
|
28540
|
+
}
|
|
28541
|
+
// secondary: accents (an unaccented letter first)
|
|
28542
|
+
if sensitivity == "accent" || sensitivity == "variant" {
|
|
28543
|
+
for i := range ua {
|
|
28544
|
+
if ua[i].secondary != ub[i].secondary {
|
|
28545
|
+
return tnCollationSign(int(ua[i].secondary) - int(ub[i].secondary))
|
|
28546
|
+
}
|
|
28547
|
+
}
|
|
28548
|
+
}
|
|
28549
|
+
// tertiary: case (lowercase first unless caseFirst is "upper")
|
|
28550
|
+
if sensitivity == "case" || sensitivity == "variant" {
|
|
28551
|
+
for i := range ua {
|
|
28552
|
+
if ua[i].upper != ub[i].upper {
|
|
28553
|
+
if ua[i].upper == (caseFirst == "upper") {
|
|
28554
|
+
return -1
|
|
28555
|
+
}
|
|
28556
|
+
return 1
|
|
28557
|
+
}
|
|
28558
|
+
}
|
|
28559
|
+
}
|
|
28560
|
+
return 0
|
|
28561
|
+
}
|
|
28562
|
+
|
|
28563
|
+
// n.toLocaleString(locales, options): en-US grouping and digits
|
|
28564
|
+
func TnNumberLocale(x float64, options interface{}) string {
|
|
28565
|
+
if math.IsNaN(x) {
|
|
28566
|
+
return "NaN"
|
|
28567
|
+
}
|
|
28568
|
+
if math.IsInf(x, 0) {
|
|
28569
|
+
if x < 0 {
|
|
28570
|
+
return "-∞"
|
|
28571
|
+
}
|
|
28572
|
+
return "∞"
|
|
28573
|
+
}
|
|
28574
|
+
minFD, maxFD := -1, -1
|
|
28575
|
+
grouping := true
|
|
28576
|
+
prefix, suffix := "", ""
|
|
28577
|
+
style := "decimal"
|
|
28578
|
+
if options != nil {
|
|
28579
|
+
if v, ok := TnGetValue(options, "style").(string); ok {
|
|
28580
|
+
style = v
|
|
28581
|
+
}
|
|
28582
|
+
if v, ok := TnGetValue(options, "minimumFractionDigits").(float64); ok {
|
|
28583
|
+
minFD = int(v)
|
|
28584
|
+
}
|
|
28585
|
+
if v, ok := TnGetValue(options, "maximumFractionDigits").(float64); ok {
|
|
28586
|
+
maxFD = int(v)
|
|
28587
|
+
}
|
|
28588
|
+
if v := TnGetValue(options, "useGrouping"); v != nil && !TnTruthy(v) {
|
|
28589
|
+
grouping = false
|
|
28590
|
+
}
|
|
28591
|
+
}
|
|
28592
|
+
defaultMin, defaultMax := 0, 3
|
|
28593
|
+
switch style {
|
|
28594
|
+
case "percent":
|
|
28595
|
+
x *= 100
|
|
28596
|
+
defaultMax = 0
|
|
28597
|
+
suffix = "%"
|
|
28598
|
+
case "currency":
|
|
28599
|
+
code, _ := TnGetValue(options, "currency").(string)
|
|
28600
|
+
code = strings.ToUpper(code)
|
|
28601
|
+
symbols := map[string]string{"USD": "$", "EUR": "€", "GBP": "£", "JPY": "¥", "INR": "₹", "CNY": "CN¥", "CAD": "CA$", "AUD": "A$"}
|
|
28602
|
+
if sym, ok := symbols[code]; ok {
|
|
28603
|
+
prefix = sym
|
|
28604
|
+
} else {
|
|
28605
|
+
prefix = code + " "
|
|
28606
|
+
}
|
|
28607
|
+
defaultMin, defaultMax = 2, 2
|
|
28608
|
+
if code == "JPY" {
|
|
28609
|
+
defaultMin, defaultMax = 0, 0
|
|
28610
|
+
}
|
|
28611
|
+
}
|
|
28612
|
+
if minFD < 0 {
|
|
28613
|
+
minFD = defaultMin
|
|
28614
|
+
}
|
|
28615
|
+
if maxFD < 0 {
|
|
28616
|
+
maxFD = max(defaultMax, minFD)
|
|
28617
|
+
}
|
|
28618
|
+
negative := x < 0 || (x == 0 && math.Signbit(x))
|
|
28619
|
+
digits := TnToFixed(math.Abs(x), float64(maxFD))
|
|
28620
|
+
intPart, frac, _ := strings.Cut(digits, ".")
|
|
28621
|
+
frac = strings.TrimRight(frac, "0")
|
|
28622
|
+
for len(frac) < minFD {
|
|
28623
|
+
frac += "0"
|
|
28624
|
+
}
|
|
28625
|
+
if grouping && len(intPart) > 3 {
|
|
28626
|
+
var b strings.Builder
|
|
28627
|
+
lead := len(intPart) % 3
|
|
28628
|
+
if lead > 0 {
|
|
28629
|
+
b.WriteString(intPart[:lead])
|
|
28630
|
+
}
|
|
28631
|
+
for i := lead; i < len(intPart); i += 3 {
|
|
28632
|
+
if b.Len() > 0 {
|
|
28633
|
+
b.WriteByte(',')
|
|
28634
|
+
}
|
|
28635
|
+
b.WriteString(intPart[i : i+3])
|
|
28636
|
+
}
|
|
28637
|
+
intPart = b.String()
|
|
28638
|
+
}
|
|
28639
|
+
out := prefix + intPart
|
|
28640
|
+
if frac != "" {
|
|
28641
|
+
out += "." + frac
|
|
28642
|
+
}
|
|
28643
|
+
out += suffix
|
|
28644
|
+
if negative {
|
|
28645
|
+
out = "-" + out
|
|
28646
|
+
}
|
|
28647
|
+
return out
|
|
28648
|
+
}
|
|
28649
|
+
|
|
28650
|
+
// RegExp.escape(s): s as a pattern matching itself literally
|
|
28651
|
+
func TnRegExpEscape(s string) string {
|
|
28652
|
+
var b strings.Builder
|
|
28653
|
+
hex := func(c rune) {
|
|
28654
|
+
h := strconv.FormatInt(int64(c), 16)
|
|
28655
|
+
if c <= 0xff {
|
|
28656
|
+
b.WriteString("\\\\x")
|
|
28657
|
+
if len(h) < 2 {
|
|
28658
|
+
b.WriteByte('0')
|
|
28659
|
+
}
|
|
28660
|
+
} else {
|
|
28661
|
+
b.WriteString("\\\\u")
|
|
28662
|
+
b.WriteString(strings.Repeat("0", max(0, 4-len(h))))
|
|
28663
|
+
}
|
|
28664
|
+
b.WriteString(h)
|
|
28665
|
+
}
|
|
28666
|
+
for i, c := range s {
|
|
28667
|
+
switch {
|
|
28668
|
+
case i == 0 && (c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'):
|
|
28669
|
+
hex(c)
|
|
28670
|
+
case strings.ContainsRune("^$\\\\.*+?()[]{}|/", c):
|
|
28671
|
+
b.WriteByte('\\\\')
|
|
28672
|
+
b.WriteRune(c)
|
|
28673
|
+
case strings.ContainsRune(",-=<>#&!%:;@~'\\x60\\"", c):
|
|
28674
|
+
hex(c)
|
|
28675
|
+
case c == '\\t':
|
|
28676
|
+
b.WriteString("\\\\t")
|
|
28677
|
+
case c == '\\n':
|
|
28678
|
+
b.WriteString("\\\\n")
|
|
28679
|
+
case c == '\\v':
|
|
28680
|
+
b.WriteString("\\\\v")
|
|
28681
|
+
case c == '\\f':
|
|
28682
|
+
b.WriteString("\\\\f")
|
|
28683
|
+
case c == '\\r':
|
|
28684
|
+
b.WriteString("\\\\r")
|
|
28685
|
+
case c == ' ' || c == 0xa0 || c == 0x1680 || (c >= 0x2000 && c <= 0x200a) || c == 0x2028 || c == 0x2029 || c == 0x202f || c == 0x205f || c == 0x3000 || c == 0xfeff:
|
|
28686
|
+
hex(c)
|
|
28687
|
+
default:
|
|
28688
|
+
b.WriteRune(c)
|
|
28689
|
+
}
|
|
28690
|
+
}
|
|
28691
|
+
return b.String()
|
|
28692
|
+
}
|
|
28693
|
+
|
|
28694
|
+
// Math.f16round / Float16Array: a float64 rounded (to nearest, ties to even)
|
|
28695
|
+
// to an IEEE 754 binary16, as its bits
|
|
28696
|
+
func TnF64ToF16(x float64) uint16 {
|
|
28697
|
+
sign := uint16(math.Float64bits(x)>>48) & 0x8000
|
|
28698
|
+
if math.IsNaN(x) {
|
|
28699
|
+
return 0x7e00
|
|
28700
|
+
}
|
|
28701
|
+
a := math.Abs(x)
|
|
28702
|
+
if a >= 65520 {
|
|
28703
|
+
return sign | 0x7c00
|
|
28704
|
+
}
|
|
28705
|
+
if a < 1.0/16384 {
|
|
28706
|
+
return sign | uint16(math.RoundToEven(a*16777216))
|
|
28707
|
+
}
|
|
28708
|
+
frac, exp := math.Frexp(a)
|
|
28709
|
+
e := exp - 1
|
|
28710
|
+
m := math.RoundToEven((frac*2 - 1) * 1024)
|
|
28711
|
+
if m == 1024 {
|
|
28712
|
+
m = 0
|
|
28713
|
+
e++
|
|
28714
|
+
}
|
|
28715
|
+
if e > 15 {
|
|
28716
|
+
return sign | 0x7c00
|
|
28717
|
+
}
|
|
28718
|
+
return sign | uint16(e+15)<<10 | uint16(m)
|
|
28719
|
+
}
|
|
28720
|
+
|
|
28721
|
+
// The float64 value of binary16 bits
|
|
28722
|
+
func TnF16ToF64(h uint16) float64 {
|
|
28723
|
+
sign := 1.0
|
|
28724
|
+
if h&0x8000 != 0 {
|
|
28725
|
+
sign = -1
|
|
28726
|
+
}
|
|
28727
|
+
exp := int(h>>10) & 0x1f
|
|
28728
|
+
m := float64(h & 0x3ff)
|
|
28729
|
+
switch exp {
|
|
28730
|
+
case 0:
|
|
28731
|
+
return sign * math.Ldexp(m, -24)
|
|
28732
|
+
case 31:
|
|
28733
|
+
if m == 0 {
|
|
28734
|
+
return math.Inf(int(sign))
|
|
28735
|
+
}
|
|
28736
|
+
return math.NaN()
|
|
28737
|
+
}
|
|
28738
|
+
return sign * math.Ldexp(1024+m, exp-25)
|
|
28739
|
+
}
|
|
28740
|
+
|
|
28741
|
+
func TnF16Round(x float64) float64 {
|
|
28742
|
+
return TnF16ToF64(TnF64ToF16(x))
|
|
28743
|
+
}
|
|
28744
|
+
|
|
27524
28745
|
// Math.sumPrecise: Neumaier-compensated sum
|
|
27525
28746
|
func TnSumPrecise(values []float64) float64 {
|
|
27526
28747
|
sum, compensation := 0.0, 0.0
|
|
@@ -27893,7 +29114,17 @@ func tnPlainValue(v interface{}) interface{} {
|
|
|
27893
29114
|
func TnGetRef(obj interface{}, key string) interface{} {
|
|
27894
29115
|
// (a JSON-like object: no views, accessors or fields, a missing key is undefined)
|
|
27895
29116
|
if o, ok := obj.(map[string]interface{}); ok {
|
|
27896
|
-
|
|
29117
|
+
v, present := o[key]
|
|
29118
|
+
if !present {
|
|
29119
|
+
return nil
|
|
29120
|
+
}
|
|
29121
|
+
// (an array entry read as a reference: boxed, and the box stored back
|
|
29122
|
+
// — every binding of the value shares the array, as JS arrays do)
|
|
29123
|
+
if box, boxed := tnBoxSliceRef(v); boxed {
|
|
29124
|
+
o[key] = box
|
|
29125
|
+
return box
|
|
29126
|
+
}
|
|
29127
|
+
return v
|
|
27897
29128
|
}
|
|
27898
29129
|
// (a view copy reads stale fields once the origin was written directly;
|
|
27899
29130
|
// resolve to the origin so reads and writes agree — JS object identity)
|
|
@@ -27985,9 +29216,42 @@ func tnGetRefSlow(obj interface{}, key string) interface{} {
|
|
|
27985
29216
|
}
|
|
27986
29217
|
}
|
|
27987
29218
|
}
|
|
29219
|
+
// (a dynamic record — a TnMap: an array entry read as a reference is
|
|
29220
|
+
// boxed and stored back, so pushes through any binding of the value
|
|
29221
|
+
// reach the object, as JS arrays are shared)
|
|
29222
|
+
if m, ok := obj.(interface {
|
|
29223
|
+
TnProp(string) (interface{}, bool)
|
|
29224
|
+
TnSetProp(string, interface{}) bool
|
|
29225
|
+
}); ok {
|
|
29226
|
+
if v, present := m.TnProp(key); present {
|
|
29227
|
+
if box, boxed := tnBoxSliceRef(v); boxed {
|
|
29228
|
+
m.TnSetProp(key, box)
|
|
29229
|
+
return box
|
|
29230
|
+
}
|
|
29231
|
+
return v
|
|
29232
|
+
}
|
|
29233
|
+
// (a missing data key is undefined — except the collection
|
|
29234
|
+
// pseudo-properties, which TnGet answers; a Set's .size read as a
|
|
29235
|
+
// reference, as in an interpolated set.size, must not read as undefined)
|
|
29236
|
+
if key != "length" && key != "size" {
|
|
29237
|
+
return nil
|
|
29238
|
+
}
|
|
29239
|
+
}
|
|
27988
29240
|
return TnGet(obj, key)
|
|
27989
29241
|
}
|
|
27990
29242
|
|
|
29243
|
+
// A slice entry read as a reference: a fresh box when the value isn't one
|
|
29244
|
+
// already (the caller stores it back, so every binding shares the array)
|
|
29245
|
+
func tnBoxSliceRef(v interface{}) (interface{}, bool) {
|
|
29246
|
+
if _, ok := v.(*[]interface{}); ok {
|
|
29247
|
+
return v, false
|
|
29248
|
+
}
|
|
29249
|
+
if box, ok := tnBoxArray(v).(*[]interface{}); ok {
|
|
29250
|
+
return box, true
|
|
29251
|
+
}
|
|
29252
|
+
return v, false
|
|
29253
|
+
}
|
|
29254
|
+
|
|
27991
29255
|
// Values whose properties TnGet reads through their own lookup
|
|
27992
29256
|
func tnHasOwnGet(obj interface{}) bool {
|
|
27993
29257
|
switch obj.(type) {
|
|
@@ -28460,6 +29724,8 @@ func TnSwitchString(v interface{}) string {
|
|
|
28460
29724
|
return s
|
|
28461
29725
|
}
|
|
28462
29726
|
|
|
29727
|
+
var tnFuncPropHooks []func(interface{}, string) (interface{}, bool)
|
|
29728
|
+
|
|
28463
29729
|
func TnGet(obj interface{}, key string) interface{} {
|
|
28464
29730
|
if obj != nil && key != "length" && key != "size" {
|
|
28465
29731
|
if origin, ok := tnViewOrigin(obj); ok {
|
|
@@ -28499,6 +29765,14 @@ func TnGet(obj interface{}, key string) interface{} {
|
|
|
28499
29765
|
}
|
|
28500
29766
|
return o.prop(key)
|
|
28501
29767
|
}
|
|
29768
|
+
// (properties a module hangs on Go funcs: node:ffi wrappers' .pointer)
|
|
29769
|
+
if len(tnFuncPropHooks) > 0 && obj != nil && reflect.ValueOf(obj).Kind() == reflect.Func {
|
|
29770
|
+
for _, hook := range tnFuncPropHooks {
|
|
29771
|
+
if v, ok := hook(obj, key); ok {
|
|
29772
|
+
return v
|
|
29773
|
+
}
|
|
29774
|
+
}
|
|
29775
|
+
}
|
|
28502
29776
|
// (an accessor shadows the property: its getter runs on reads — Babel's
|
|
28503
29777
|
// ParseError defines a 'message' getter that computes and self-assigns)
|
|
28504
29778
|
if obj != nil && key != "length" {
|
|
@@ -29059,6 +30333,13 @@ var tnDynamicPromiseMethod func(p reflect.Value, name string, args []interface{}
|
|
|
29059
30333
|
func TnCallMember(obj interface{}, name string, args ...interface{}) interface{} {
|
|
29060
30334
|
// a Map / Set's methods (Get, Set, Has … on the ordered map)
|
|
29061
30335
|
if kind, ok := obj.(interface{ TnJSKind() uint8 }); ok {
|
|
30336
|
+
// (a plain object's own function property named add / get / set …:
|
|
30337
|
+
// a WebAssembly instance's exports, a record of callbacks)
|
|
30338
|
+
if kind.TnJSKind() == 0 {
|
|
30339
|
+
if fn := TnGet(obj, name); fn != nil && reflect.ValueOf(fn).Kind() == reflect.Func {
|
|
30340
|
+
return TnCallValue(fn, args...)
|
|
30341
|
+
}
|
|
30342
|
+
}
|
|
29062
30343
|
if v, handled := tnCallCollection(obj, kind.TnJSKind() == 2, name, args); handled {
|
|
29063
30344
|
return v
|
|
29064
30345
|
}
|
|
@@ -29275,6 +30556,18 @@ func tnCallCollection(obj interface{}, isSet bool, name string, args []interface
|
|
|
29275
30556
|
return call("Get", arg(0)), true
|
|
29276
30557
|
case "has":
|
|
29277
30558
|
return call("Has", arg(0)), true
|
|
30559
|
+
case "getOrInsert":
|
|
30560
|
+
if call("Has", arg(0)).(bool) {
|
|
30561
|
+
return call("Get", arg(0)), true
|
|
30562
|
+
}
|
|
30563
|
+
call("Set", arg(0), arg(1))
|
|
30564
|
+
return call("Get", arg(0)), true
|
|
30565
|
+
case "getOrInsertComputed":
|
|
30566
|
+
if call("Has", arg(0)).(bool) {
|
|
30567
|
+
return call("Get", arg(0)), true
|
|
30568
|
+
}
|
|
30569
|
+
call("Set", arg(0), TnCallValue(arg(1), arg(0)))
|
|
30570
|
+
return call("Get", arg(0)), true
|
|
29278
30571
|
case "delete":
|
|
29279
30572
|
return call("Delete", arg(0)), true
|
|
29280
30573
|
case "clear":
|
|
@@ -29722,7 +31015,14 @@ func TnIndex(obj interface{}, key interface{}) interface{} {
|
|
|
29722
31015
|
}
|
|
29723
31016
|
case map[string]interface{}:
|
|
29724
31017
|
if k, ok := key.(string); ok {
|
|
29725
|
-
|
|
31018
|
+
// (an array entry read as a reference: boxed, and the box stored
|
|
31019
|
+
// back — every binding of the value shares the array, as JS does)
|
|
31020
|
+
v := o[k]
|
|
31021
|
+
if box, boxed := tnBoxSliceRef(v); boxed {
|
|
31022
|
+
o[k] = box
|
|
31023
|
+
return box
|
|
31024
|
+
}
|
|
31025
|
+
return v
|
|
29726
31026
|
}
|
|
29727
31027
|
case []interface{}:
|
|
29728
31028
|
if i, ok := key.(float64); ok && i >= 0 && int(i) < len(o) {
|
|
@@ -29739,6 +31039,15 @@ func TnIndex(obj interface{}, key interface{}) interface{} {
|
|
|
29739
31039
|
case interface{ TnProp(string) (interface{}, bool) }:
|
|
29740
31040
|
if k, ok := key.(string); ok {
|
|
29741
31041
|
v, _ := o.TnProp(k)
|
|
31042
|
+
// (a record's array entry read as a reference: boxed and stored
|
|
31043
|
+
// back, as JS arrays are shared; without a working setter the raw
|
|
31044
|
+
// value stays, so bindings agree)
|
|
31045
|
+
if box, boxed := tnBoxSliceRef(v); boxed {
|
|
31046
|
+
if setter, canSet := any(obj).(interface{ TnSetProp(string, interface{}) bool }); canSet && setter.TnSetProp(k, box) {
|
|
31047
|
+
return box
|
|
31048
|
+
}
|
|
31049
|
+
return v
|
|
31050
|
+
}
|
|
29742
31051
|
return v
|
|
29743
31052
|
}
|
|
29744
31053
|
case interface{ TnItems() *[]interface{} }:
|
|
@@ -29770,9 +31079,14 @@ func TnIndex(obj interface{}, key interface{}) interface{} {
|
|
|
29770
31079
|
return nil
|
|
29771
31080
|
}
|
|
29772
31081
|
|
|
29773
|
-
// JS ===: objects and arrays compare by identity, other values by value
|
|
31082
|
+
// JS ===: objects and arrays compare by identity, other values by value.
|
|
31083
|
+
// Bigints are primitives: two of them compare by value; one never strictly
|
|
31084
|
+
// equals a number's, a string's or a boolean's value
|
|
29774
31085
|
func TnSame(a interface{}, b interface{}) bool {
|
|
29775
31086
|
switch x := a.(type) {
|
|
31087
|
+
case *tnbig.Int:
|
|
31088
|
+
y, ok := b.(*tnbig.Int)
|
|
31089
|
+
return ok && y != nil && x != nil && x.Cmp(y) == 0
|
|
29776
31090
|
case nil:
|
|
29777
31091
|
return b == nil
|
|
29778
31092
|
case string:
|
|
@@ -29854,11 +31168,22 @@ func tnConcat(a string, b string) string {
|
|
|
29854
31168
|
}
|
|
29855
31169
|
|
|
29856
31170
|
// a == b (JS loose equality): null == undefined; a number, string or boolean
|
|
29857
|
-
// compares with another primitive by ToNumber; two strings compare as strings
|
|
31171
|
+
// compares with another primitive by ToNumber; two strings compare as strings;
|
|
31172
|
+
// a bigint compares by value with a number's, an integer string's or a
|
|
31173
|
+
// boolean's value
|
|
29858
31174
|
func TnLooseEqual(a interface{}, b interface{}) bool {
|
|
29859
31175
|
if TnSame(a, b) || TnIsNil(a) && TnIsNil(b) {
|
|
29860
31176
|
return true
|
|
29861
31177
|
}
|
|
31178
|
+
if ab, ok := a.(*tnbig.Int); ok && ab != nil {
|
|
31179
|
+
if bb, ok2 := b.(*tnbig.Int); ok2 && bb != nil {
|
|
31180
|
+
return ab.Cmp(bb) == 0
|
|
31181
|
+
}
|
|
31182
|
+
return tnBigLooseNumber(ab, b)
|
|
31183
|
+
}
|
|
31184
|
+
if bb, ok := b.(*tnbig.Int); ok && bb != nil {
|
|
31185
|
+
return tnBigLooseNumber(bb, a)
|
|
31186
|
+
}
|
|
29862
31187
|
if a == nil || b == nil {
|
|
29863
31188
|
return false
|
|
29864
31189
|
}
|
|
@@ -29881,6 +31206,73 @@ func tnIsPrimitive(v interface{}) bool {
|
|
|
29881
31206
|
return false
|
|
29882
31207
|
}
|
|
29883
31208
|
|
|
31209
|
+
// 5n == 5 / 5n == '5' / 5n == true: the other side by its number or bigint value
|
|
31210
|
+
func tnBigLooseNumber(b *tnbig.Int, v interface{}) bool {
|
|
31211
|
+
switch t := v.(type) {
|
|
31212
|
+
case float64, bool:
|
|
31213
|
+
return TnBigCmpNumber(b, TnNumber(t)) == 0
|
|
31214
|
+
case string:
|
|
31215
|
+
other, ok := new(tnbig.Int).SetString(strings.TrimSpace(t), 10)
|
|
31216
|
+
return ok && other.Cmp(b) == 0
|
|
31217
|
+
}
|
|
31218
|
+
return false
|
|
31219
|
+
}
|
|
31220
|
+
|
|
31221
|
+
// 5n == 5: loose equality of a value against a static number — a bigint
|
|
31222
|
+
// compares exactly, anything else by ToNumber
|
|
31223
|
+
func TnBigLooseEqual(a interface{}, f float64) bool {
|
|
31224
|
+
if b, ok := a.(*tnbig.Int); ok && b != nil {
|
|
31225
|
+
return TnBigCmpNumber(b, f) == 0
|
|
31226
|
+
}
|
|
31227
|
+
x := TnNumber(a)
|
|
31228
|
+
if math.IsNaN(x) {
|
|
31229
|
+
return false
|
|
31230
|
+
}
|
|
31231
|
+
return x == f
|
|
31232
|
+
}
|
|
31233
|
+
|
|
31234
|
+
// 5n == '5': a static string that parses as an integer compares with the
|
|
31235
|
+
// bigint's value (a fraction or other text is unequal, as JS reads it)
|
|
31236
|
+
func TnBigLooseEqualStr(b *tnbig.Int, s string) bool {
|
|
31237
|
+
if b == nil {
|
|
31238
|
+
return false
|
|
31239
|
+
}
|
|
31240
|
+
other, ok := new(tnbig.Int).SetString(strings.TrimSpace(s), 10)
|
|
31241
|
+
return ok && other.Cmp(b) == 0
|
|
31242
|
+
}
|
|
31243
|
+
|
|
31244
|
+
// An exact comparison of a bigint with a number (5n > 5): -1 / 0 / 1; 2 when
|
|
31245
|
+
// the number is NaN (every JS comparison with NaN is false; big.Float panics
|
|
31246
|
+
// on NaN, and ±Infinity compares exactly)
|
|
31247
|
+
func TnBigCmpNumber(b *tnbig.Int, f float64) int {
|
|
31248
|
+
if math.IsNaN(f) {
|
|
31249
|
+
return 2
|
|
31250
|
+
}
|
|
31251
|
+
return new(tnbig.Float).SetInt(b).Cmp(new(tnbig.Float).SetFloat64(f))
|
|
31252
|
+
}
|
|
31253
|
+
|
|
31254
|
+
// The order of a dynamic value and a static number when one is a bigint:
|
|
31255
|
+
// -1 / 0 / 1, 2 when either side is NaN. A value that isn't a bigint at run
|
|
31256
|
+
// time (an any variable may hold anything) compares by ToNumber, as JS's
|
|
31257
|
+
// relational operators do
|
|
31258
|
+
func TnBigOrder(a interface{}, f float64) int {
|
|
31259
|
+
b, ok := a.(*tnbig.Int)
|
|
31260
|
+
if !ok || b == nil {
|
|
31261
|
+
x := TnNumber(a)
|
|
31262
|
+
if math.IsNaN(x) || math.IsNaN(f) {
|
|
31263
|
+
return 2
|
|
31264
|
+
}
|
|
31265
|
+
if x < f {
|
|
31266
|
+
return -1
|
|
31267
|
+
}
|
|
31268
|
+
if x > f {
|
|
31269
|
+
return 1
|
|
31270
|
+
}
|
|
31271
|
+
return 0
|
|
31272
|
+
}
|
|
31273
|
+
return TnBigCmpNumber(b, f)
|
|
31274
|
+
}
|
|
31275
|
+
|
|
29884
31276
|
// Whether a dynamic value is a plain array (a slice or a reference to one)
|
|
29885
31277
|
func TnIsSlice(v interface{}) bool {
|
|
29886
31278
|
rv := reflect.ValueOf(v)
|
|
@@ -30071,6 +31463,8 @@ func TnJSString(v interface{}) string {
|
|
|
30071
31463
|
return "null"
|
|
30072
31464
|
}
|
|
30073
31465
|
switch x := v.(type) {
|
|
31466
|
+
case interface{ TnToPrimitive(string) interface{} }:
|
|
31467
|
+
return TnJSString(x.TnToPrimitive("string"))
|
|
30074
31468
|
case interface{ TnToString() string }:
|
|
30075
31469
|
return x.TnToString()
|
|
30076
31470
|
case time.Time:
|
|
@@ -30205,6 +31599,9 @@ func TnObjectTypeTag(v interface{}) string {
|
|
|
30205
31599
|
if v == nil {
|
|
30206
31600
|
return "[object Undefined]"
|
|
30207
31601
|
}
|
|
31602
|
+
if t, ok := v.(interface{ TnToStringTag() string }); ok {
|
|
31603
|
+
return "[object " + t.TnToStringTag() + "]"
|
|
31604
|
+
}
|
|
30208
31605
|
if v == TnNull {
|
|
30209
31606
|
return "[object Null]"
|
|
30210
31607
|
}
|
|
@@ -30251,6 +31648,14 @@ func TnNumber(v interface{}) float64 {
|
|
|
30251
31648
|
switch t := v.(type) {
|
|
30252
31649
|
case float64:
|
|
30253
31650
|
return t
|
|
31651
|
+
case *tnbig.Int:
|
|
31652
|
+
if t != nil {
|
|
31653
|
+
f, _ := new(tnbig.Float).SetInt(t).Float64()
|
|
31654
|
+
return f
|
|
31655
|
+
}
|
|
31656
|
+
return 0
|
|
31657
|
+
case interface{ TnToPrimitive(string) interface{} }:
|
|
31658
|
+
return TnNumber(t.TnToPrimitive("number"))
|
|
30254
31659
|
case *tnNullValue:
|
|
30255
31660
|
return 0
|
|
30256
31661
|
case bool:
|
|
@@ -30657,6 +32062,13 @@ func TnIncludes(v interface{}, x interface{}, from ...float64) bool {
|
|
|
30657
32062
|
|
|
30658
32063
|
// x.indexOf(y, from?) of an any value (a string or an array)
|
|
30659
32064
|
func TnIndexOf(v interface{}, x interface{}, from ...float64) float64 {
|
|
32065
|
+
// (a dynamic array from a parsed AST or JSON: stored as a reference)
|
|
32066
|
+
if p, ok := v.(*[]interface{}); ok {
|
|
32067
|
+
if p == nil {
|
|
32068
|
+
return -1
|
|
32069
|
+
}
|
|
32070
|
+
v = *p
|
|
32071
|
+
}
|
|
30660
32072
|
start := 0
|
|
30661
32073
|
if len(from) > 0 && from[0] > 0 {
|
|
30662
32074
|
start = int(from[0])
|
|
@@ -30694,6 +32106,13 @@ var tnCharBoxes = func() (t [128]interface{}) {
|
|
|
30694
32106
|
}()
|
|
30695
32107
|
|
|
30696
32108
|
func TnSlice(v interface{}, bounds ...float64) interface{} {
|
|
32109
|
+
// (a dynamic array from a parsed AST or JSON: stored as a reference)
|
|
32110
|
+
if p, ok := v.(*[]interface{}); ok {
|
|
32111
|
+
if p == nil {
|
|
32112
|
+
return nil
|
|
32113
|
+
}
|
|
32114
|
+
v = *p
|
|
32115
|
+
}
|
|
30697
32116
|
length := 0
|
|
30698
32117
|
switch t := v.(type) {
|
|
30699
32118
|
case string:
|
|
@@ -30741,6 +32160,16 @@ func TnConcat(v interface{}, others ...interface{}) interface{} {
|
|
|
30741
32160
|
for _, o := range others {
|
|
30742
32161
|
if items, ok := o.([]interface{}); ok {
|
|
30743
32162
|
result = append(result, items...)
|
|
32163
|
+
} else if p, ok := o.(*[]interface{}); ok && p != nil {
|
|
32164
|
+
result = append(result, (*p)...)
|
|
32165
|
+
} else if rv := reflect.ValueOf(o); o != nil && (rv.Kind() == reflect.Slice || (rv.Kind() == reflect.Pointer && !rv.IsNil() && rv.Elem().Kind() == reflect.Slice)) && rv.Type() != reflect.TypeOf([]byte(nil)) {
|
|
32166
|
+
// (a typed array argument — string[], number[] — is spread too)
|
|
32167
|
+
if rv.Kind() == reflect.Pointer {
|
|
32168
|
+
rv = rv.Elem()
|
|
32169
|
+
}
|
|
32170
|
+
for i := 0; i < rv.Len(); i++ {
|
|
32171
|
+
result = append(result, rv.Index(i).Interface())
|
|
32172
|
+
}
|
|
30744
32173
|
} else {
|
|
30745
32174
|
result = append(result, o)
|
|
30746
32175
|
}
|
|
@@ -33768,6 +35197,10 @@ func (w *tnJSONWriter) property(key string, v interface{}, depth int) bool {
|
|
|
33768
35197
|
w.buf = append(w.buf, "{}"...)
|
|
33769
35198
|
return true
|
|
33770
35199
|
}
|
|
35200
|
+
// (the entry walk recurses into the values: the record itself
|
|
35201
|
+
// is on the cycle stack, as JS's stringify has it)
|
|
35202
|
+
w.enter(rv.Pointer())
|
|
35203
|
+
defer w.leave()
|
|
33771
35204
|
return w.object(depth, func(emit func(string, interface{})) {
|
|
33772
35205
|
for _, e := range m.Entries() {
|
|
33773
35206
|
emit(fmt.Sprint(e[0]), e[1])
|
|
@@ -34545,6 +35978,32 @@ type TnMap[K comparable, V any] struct {
|
|
|
34545
35978
|
dead []bool
|
|
34546
35979
|
deadN int
|
|
34547
35980
|
keyMode uint8 // hk: 0 not known yet, 1 keys are stored as they are, 2 K is an interface
|
|
35981
|
+
// keys not listed yet: values is an any object's map, viewed as a record
|
|
35982
|
+
// (TnRecordOf), and listKeys lists them when something first needs keys
|
|
35983
|
+
view bool
|
|
35984
|
+
}
|
|
35985
|
+
|
|
35986
|
+
// A record view's keys, listed the first time they're needed: sorted (a Go
|
|
35987
|
+
// map keeps no order), as converting the object would list them
|
|
35988
|
+
func (m *TnMap[K, V]) listKeys() {
|
|
35989
|
+
if !m.view {
|
|
35990
|
+
return
|
|
35991
|
+
}
|
|
35992
|
+
m.view = false
|
|
35993
|
+
keys := make([]K, 0, len(m.values))
|
|
35994
|
+
for k := range m.values {
|
|
35995
|
+
keys = append(keys, k)
|
|
35996
|
+
}
|
|
35997
|
+
if ks, ok := any(keys).([]string); ok {
|
|
35998
|
+
sort.Strings(ks)
|
|
35999
|
+
}
|
|
36000
|
+
m.keys = keys
|
|
36001
|
+
for _, k := range keys {
|
|
36002
|
+
if _, isIndex := tnIndexKey(any(k)); isIndex {
|
|
36003
|
+
m.indexKeys = true
|
|
36004
|
+
break
|
|
36005
|
+
}
|
|
36006
|
+
}
|
|
34548
36007
|
}
|
|
34549
36008
|
|
|
34550
36009
|
// An accessor property of a dynamic object: reading it calls Get, writing it
|
|
@@ -34574,6 +36033,7 @@ func (m *TnMap[K, V]) read(k K) (V, bool) {
|
|
|
34574
36033
|
|
|
34575
36034
|
// Appends a new key (keeping pos / dead in step when a delete made them)
|
|
34576
36035
|
func (m *TnMap[K, V]) pushKey(k K) {
|
|
36036
|
+
m.listKeys()
|
|
34577
36037
|
m.keys = append(m.keys, k)
|
|
34578
36038
|
if m.pos != nil {
|
|
34579
36039
|
m.pos[m.hk(k)] = len(m.keys) - 1
|
|
@@ -34583,6 +36043,7 @@ func (m *TnMap[K, V]) pushKey(k K) {
|
|
|
34583
36043
|
|
|
34584
36044
|
// Drops deleted keys from keys: every reader of keys calls it first
|
|
34585
36045
|
func (m *TnMap[K, V]) compact() {
|
|
36046
|
+
m.listKeys()
|
|
34586
36047
|
if m.deadN == 0 {
|
|
34587
36048
|
return
|
|
34588
36049
|
}
|
|
@@ -34851,14 +36312,41 @@ func (m *TnMap[K, V]) TnSetProp(key string, value interface{}) bool {
|
|
|
34851
36312
|
}
|
|
34852
36313
|
var v V
|
|
34853
36314
|
if value != nil {
|
|
34854
|
-
|
|
34855
|
-
|
|
36315
|
+
// (an array is stored as a reference when the map's values are any:
|
|
36316
|
+
// JS arrays are shared, so a push through a binding reaches the entry)
|
|
36317
|
+
candidate := value
|
|
36318
|
+
if box, boxed := tnBoxSliceRef(value); boxed {
|
|
36319
|
+
candidate = box
|
|
36320
|
+
}
|
|
36321
|
+
if v, ok = candidate.(V); !ok {
|
|
36322
|
+
if v, ok = value.(V); !ok {
|
|
36323
|
+
return false
|
|
36324
|
+
}
|
|
34856
36325
|
}
|
|
34857
36326
|
}
|
|
34858
36327
|
m.Set(k, v)
|
|
34859
36328
|
return true
|
|
34860
36329
|
}
|
|
34861
36330
|
|
|
36331
|
+
// m.getOrInsert(k, v): the entry's value, v stored first when k is missing
|
|
36332
|
+
func (m *TnMap[K, V]) GetOrInsert(k K, v V) V {
|
|
36333
|
+
if old, ok := m.read(k); ok {
|
|
36334
|
+
return old
|
|
36335
|
+
}
|
|
36336
|
+
m.Set(k, v)
|
|
36337
|
+
return v
|
|
36338
|
+
}
|
|
36339
|
+
|
|
36340
|
+
// m.getOrInsertComputed(k, fn): fn(k) runs (and is stored) only when k is missing
|
|
36341
|
+
func (m *TnMap[K, V]) GetOrInsertComputed(k K, fn func(K) V) V {
|
|
36342
|
+
if old, ok := m.read(k); ok {
|
|
36343
|
+
return old
|
|
36344
|
+
}
|
|
36345
|
+
v := fn(k)
|
|
36346
|
+
m.Set(k, v)
|
|
36347
|
+
return v
|
|
36348
|
+
}
|
|
36349
|
+
|
|
34862
36350
|
func (m *TnMap[K, V]) Lookup(k K) (V, bool) {
|
|
34863
36351
|
if m == nil {
|
|
34864
36352
|
var zero V
|
|
@@ -34887,6 +36375,11 @@ func (m *TnMap[K, V]) Delete(k K) bool {
|
|
|
34887
36375
|
if m.hidden != nil {
|
|
34888
36376
|
delete(m.hidden, h)
|
|
34889
36377
|
}
|
|
36378
|
+
if m.view {
|
|
36379
|
+
// (a view's keys are listed now, without the deleted one)
|
|
36380
|
+
m.listKeys()
|
|
36381
|
+
return true
|
|
36382
|
+
}
|
|
34890
36383
|
n := len(m.keys)
|
|
34891
36384
|
// the newest key (a stack), or a small map: removed from keys right away
|
|
34892
36385
|
if m.deadN == 0 && n > 0 && m.hk(m.keys[n-1]) == h {
|
|
@@ -34977,7 +36470,7 @@ func (m *TnMap[K, V]) IsSubsetOf(o *TnMap[K, V]) bool {
|
|
|
34977
36470
|
}
|
|
34978
36471
|
|
|
34979
36472
|
func (m *TnMap[K, V]) Clear() {
|
|
34980
|
-
m.keys, m.pos, m.dead, m.deadN = nil, nil, nil, 0
|
|
36473
|
+
m.keys, m.pos, m.dead, m.deadN, m.view = nil, nil, nil, 0, false
|
|
34981
36474
|
m.values = map[K]V{}
|
|
34982
36475
|
m.accessors = nil
|
|
34983
36476
|
m.hidden = nil
|
|
@@ -34987,6 +36480,7 @@ func (m *TnMap[K, V]) Len() int {
|
|
|
34987
36480
|
if m == nil {
|
|
34988
36481
|
return 0
|
|
34989
36482
|
}
|
|
36483
|
+
m.listKeys()
|
|
34990
36484
|
return len(m.keys) - m.deadN - len(m.hidden)
|
|
34991
36485
|
}
|
|
34992
36486
|
|
|
@@ -35038,7 +36532,7 @@ func (m *TnMap[K, V]) UnmarshalJSON(data []byte) error {
|
|
|
35038
36532
|
if delim, ok := tok.(json.Delim); !ok || delim != '{' {
|
|
35039
36533
|
return fmt.Errorf("json: cannot unmarshal %v into an object", tok)
|
|
35040
36534
|
}
|
|
35041
|
-
m.keys, m.pos, m.dead, m.deadN = nil, nil, nil, 0
|
|
36535
|
+
m.keys, m.pos, m.dead, m.deadN, m.view = nil, nil, nil, 0, false
|
|
35042
36536
|
m.values = map[K]V{}
|
|
35043
36537
|
for dec.More() {
|
|
35044
36538
|
tok, err := dec.Token()
|
|
@@ -35157,6 +36651,59 @@ func tnMatchTag(groups []string, s string, lo int) {
|
|
|
35157
36651
|
hidden[n], hidden[n+1] = tnMatchMark, s[:lo]
|
|
35158
36652
|
}
|
|
35159
36653
|
|
|
36654
|
+
// A /d match: its groups copied with two more hidden slots, a mark and each
|
|
36655
|
+
// group's code point [start, end] ("-1:-1" for a group that did not take part)
|
|
36656
|
+
var tnIndicesMark = "\\x00indices:"
|
|
36657
|
+
|
|
36658
|
+
func tnMatchWithIndices(groups []string, s string, caps []int) []string {
|
|
36659
|
+
n := len(groups)
|
|
36660
|
+
out := make([]string, n, n+4)
|
|
36661
|
+
copy(out, groups)
|
|
36662
|
+
var b strings.Builder
|
|
36663
|
+
for i := 0; i < n; i++ {
|
|
36664
|
+
a, z := -1, -1
|
|
36665
|
+
if 2*i+1 < len(caps) && caps[2*i] >= 0 && caps[2*i+1] >= caps[2*i] {
|
|
36666
|
+
a, z = tnStrRune(s, caps[2*i]), tnStrRune(s, caps[2*i+1])
|
|
36667
|
+
}
|
|
36668
|
+
if i > 0 {
|
|
36669
|
+
b.WriteByte(',')
|
|
36670
|
+
}
|
|
36671
|
+
b.WriteString(strconv.Itoa(a))
|
|
36672
|
+
b.WriteByte(':')
|
|
36673
|
+
b.WriteString(strconv.Itoa(z))
|
|
36674
|
+
}
|
|
36675
|
+
hidden := out[:n+4]
|
|
36676
|
+
hidden[n], hidden[n+1] = tnMatchMark, s[:caps[0]]
|
|
36677
|
+
hidden[n+2], hidden[n+3] = tnIndicesMark, b.String()
|
|
36678
|
+
return out
|
|
36679
|
+
}
|
|
36680
|
+
|
|
36681
|
+
// m.indices: each group's [start, end] (nil for one that did not take part);
|
|
36682
|
+
// nil when m is not a /d match
|
|
36683
|
+
func TnMatchIndices(m []string) [][]float64 {
|
|
36684
|
+
n := len(m)
|
|
36685
|
+
if cap(m) < n+4 {
|
|
36686
|
+
return nil
|
|
36687
|
+
}
|
|
36688
|
+
hidden := m[:n+4]
|
|
36689
|
+
if unsafe.StringData(hidden[n+2]) != unsafe.StringData(tnIndicesMark) {
|
|
36690
|
+
return nil
|
|
36691
|
+
}
|
|
36692
|
+
out := make([][]float64, n)
|
|
36693
|
+
for i, pair := range strings.Split(hidden[n+3], ",") {
|
|
36694
|
+
if i >= n {
|
|
36695
|
+
break
|
|
36696
|
+
}
|
|
36697
|
+
a, z, _ := strings.Cut(pair, ":")
|
|
36698
|
+
start, _ := strconv.Atoi(a)
|
|
36699
|
+
end, _ := strconv.Atoi(z)
|
|
36700
|
+
if start >= 0 {
|
|
36701
|
+
out[i] = []float64{float64(start), float64(end)}
|
|
36702
|
+
}
|
|
36703
|
+
}
|
|
36704
|
+
return out
|
|
36705
|
+
}
|
|
36706
|
+
|
|
35160
36707
|
// The groups of the match at loc, with their hidden slots
|
|
35161
36708
|
func tnMatchGroups(s string, loc []int) []string {
|
|
35162
36709
|
n := len(loc) / 2
|
|
@@ -35337,13 +36884,15 @@ type TnRegex struct {
|
|
|
35337
36884
|
lastIndex float64
|
|
35338
36885
|
global bool
|
|
35339
36886
|
sticky bool
|
|
35340
|
-
|
|
35341
|
-
|
|
35342
|
-
|
|
36887
|
+
// /d: matches record their groups' [start, end] (m.indices)
|
|
36888
|
+
indices bool
|
|
36889
|
+
source string
|
|
36890
|
+
flags string
|
|
36891
|
+
site *TnRegexSite
|
|
35343
36892
|
}
|
|
35344
36893
|
|
|
35345
36894
|
func TnRegexCompile(pattern string, flags string, source string) *TnRegex {
|
|
35346
|
-
return &TnRegex{vm: true, global: strings.Contains(flags, "g"), sticky: strings.Contains(flags, "y"), source: source, flags: flags, pattern: pattern}
|
|
36895
|
+
return &TnRegex{vm: true, global: strings.Contains(flags, "g"), sticky: strings.Contains(flags, "y"), indices: strings.Contains(flags, "d"), source: source, flags: flags, pattern: pattern}
|
|
35347
36896
|
}
|
|
35348
36897
|
|
|
35349
36898
|
// A regex literal's site. Each evaluation of the literal is a new RegExp
|
|
@@ -35752,6 +37301,11 @@ func (r *TnRegex) matchAt(s string, start int, sticky bool, want bool) ([]string
|
|
|
35752
37301
|
var groups []string
|
|
35753
37302
|
if want && lo >= 0 {
|
|
35754
37303
|
groups = m.groups(p.ncaps/2, lo, hi)
|
|
37304
|
+
if r.indices {
|
|
37305
|
+
caps := append([]int{}, m.caps[:p.ncaps]...)
|
|
37306
|
+
caps[0], caps[1] = lo, hi
|
|
37307
|
+
groups = tnMatchWithIndices(groups, s, caps)
|
|
37308
|
+
}
|
|
35755
37309
|
}
|
|
35756
37310
|
tnRxRelease(m)
|
|
35757
37311
|
return groups, lo, hi
|
|
@@ -35780,6 +37334,9 @@ func (r *TnRegex) matchAt(s string, start int, sticky bool, want bool) ([]string
|
|
|
35780
37334
|
if !want {
|
|
35781
37335
|
return nil, loc[0], loc[1]
|
|
35782
37336
|
}
|
|
37337
|
+
if r.indices {
|
|
37338
|
+
return tnMatchWithIndices(tnMatchGroups(s, loc), s, loc), loc[0], loc[1]
|
|
37339
|
+
}
|
|
35783
37340
|
return tnMatchGroups(s, loc), loc[0], loc[1]
|
|
35784
37341
|
}
|
|
35785
37342
|
|
|
@@ -35824,6 +37381,46 @@ func (r *TnRegex) find(s string, want bool) ([]string, int, int) {
|
|
|
35824
37381
|
return groups, lo, hi
|
|
35825
37382
|
}`,
|
|
35826
37383
|
regexEngine: REGEX_ENGINE_HELPER,
|
|
37384
|
+
domException: `// new DOMException(message, name | { name, cause })
|
|
37385
|
+
func TnNewDOMException(message string, options interface{}) *TnError {
|
|
37386
|
+
name := "Error"
|
|
37387
|
+
var cause interface{}
|
|
37388
|
+
hasCause := false
|
|
37389
|
+
switch o := options.(type) {
|
|
37390
|
+
case nil:
|
|
37391
|
+
case string:
|
|
37392
|
+
name = o
|
|
37393
|
+
default:
|
|
37394
|
+
if n, ok := TnGetValue(o, "name").(string); ok {
|
|
37395
|
+
name = n
|
|
37396
|
+
}
|
|
37397
|
+
if TnHas(o, "cause") {
|
|
37398
|
+
cause, hasCause = TnGetValue(o, "cause"), true
|
|
37399
|
+
}
|
|
37400
|
+
}
|
|
37401
|
+
e := TnNodeError(name, "", message)
|
|
37402
|
+
e.dom = true
|
|
37403
|
+
e.props["code"] = tnDOMExceptionCodes[name]
|
|
37404
|
+
if hasCause {
|
|
37405
|
+
e.props["cause"] = cause
|
|
37406
|
+
}
|
|
37407
|
+
return e
|
|
37408
|
+
}
|
|
37409
|
+
|
|
37410
|
+
// new QuotaExceededError(message, { quota, requested })
|
|
37411
|
+
func TnNewQuotaExceededError(message string, options interface{}) *TnError {
|
|
37412
|
+
e := TnNewDOMException(message, "QuotaExceededError")
|
|
37413
|
+
e.props["quota"], e.props["requested"] = nil, nil
|
|
37414
|
+
if options != nil {
|
|
37415
|
+
if q, ok := TnGetValue(options, "quota").(float64); ok {
|
|
37416
|
+
e.props["quota"] = q
|
|
37417
|
+
}
|
|
37418
|
+
if r, ok := TnGetValue(options, "requested").(float64); ok {
|
|
37419
|
+
e.props["requested"] = r
|
|
37420
|
+
}
|
|
37421
|
+
}
|
|
37422
|
+
return e
|
|
37423
|
+
}`,
|
|
35827
37424
|
objectAssignTo: `// Object.assign(target, ...sources) on a typed target (a struct or a Map):
|
|
35828
37425
|
// each source's properties are set on the target's fields / entries, and the
|
|
35829
37426
|
// target is the result. Unset (nil) fields of a struct source count as absent;
|
|
@@ -36421,6 +38018,8 @@ type TnError struct {
|
|
|
36421
38018
|
props map[string]interface{}
|
|
36422
38019
|
goErr error
|
|
36423
38020
|
pcs []uintptr // where the error was created (err.stack)
|
|
38021
|
+
// a DOMException (instanceof DOMException; its code is the legacy number)
|
|
38022
|
+
dom bool
|
|
36424
38023
|
}
|
|
36425
38024
|
|
|
36426
38025
|
func (e *TnError) Error() string { return e.message }
|
|
@@ -36475,9 +38074,21 @@ func TnIsErrorOf(v interface{}, name string) bool {
|
|
|
36475
38074
|
return ok
|
|
36476
38075
|
}
|
|
36477
38076
|
e, ok := v.(*TnError)
|
|
38077
|
+
if name == "DOMException" {
|
|
38078
|
+
return ok && e.dom
|
|
38079
|
+
}
|
|
36478
38080
|
return ok && e.Get_name() == name
|
|
36479
38081
|
}
|
|
36480
38082
|
|
|
38083
|
+
// DOMException's legacy numeric codes, by name
|
|
38084
|
+
var tnDOMExceptionCodes = map[string]float64{
|
|
38085
|
+
"IndexSizeError": 1, "HierarchyRequestError": 3, "WrongDocumentError": 4, "InvalidCharacterError": 5,
|
|
38086
|
+
"NoModificationAllowedError": 7, "NotFoundError": 8, "NotSupportedError": 9, "InvalidStateError": 11,
|
|
38087
|
+
"SyntaxError": 12, "InvalidModificationError": 13, "NamespaceError": 14, "InvalidAccessError": 15,
|
|
38088
|
+
"TypeMismatchError": 17, "SecurityError": 18, "NetworkError": 19, "AbortError": 20, "URLMismatchError": 21,
|
|
38089
|
+
"QuotaExceededError": 22, "TimeoutError": 23, "InvalidNodeTypeError": 24, "DataCloneError": 25,
|
|
38090
|
+
}
|
|
38091
|
+
|
|
36481
38092
|
// A Node error: name ('TypeError', 'AssertionError'), code and message
|
|
36482
38093
|
// A recovered panic as the value a JS catch receives: a Go runtime failure
|
|
36483
38094
|
// (nil dereference, failed assertion …) is a TypeError
|
|
@@ -36582,6 +38193,12 @@ func (e *TnError) Get_errno() float64 {
|
|
|
36582
38193
|
|
|
36583
38194
|
func (e *TnError) Get_cause() interface{} { return e.prop("cause") }
|
|
36584
38195
|
|
|
38196
|
+
// A DOMException's legacy numeric code (0 for a name without one)
|
|
38197
|
+
func (e *TnError) Get_domCode() float64 {
|
|
38198
|
+
n, _ := e.prop("code").(float64)
|
|
38199
|
+
return n
|
|
38200
|
+
}
|
|
38201
|
+
|
|
36585
38202
|
func (e *TnError) Get_hostname() string {
|
|
36586
38203
|
s, _ := e.prop("hostname").(string)
|
|
36587
38204
|
return s
|
|
@@ -37117,18 +38734,67 @@ type TnAsyncContext map[interface{}]interface{}
|
|
|
37117
38734
|
|
|
37118
38735
|
var tnAsyncCtx TnAsyncContext
|
|
37119
38736
|
|
|
37120
|
-
|
|
38737
|
+
// Async ids (node:async_hooks executionAsyncId / createHook): tracked only
|
|
38738
|
+
// when a program asks for them; each snapshot is then a new async resource
|
|
38739
|
+
// whose id the context carries to the callback that runs in it
|
|
38740
|
+
type tnAsyncIDKey struct{}
|
|
38741
|
+
|
|
38742
|
+
var tnAsyncHooksOn bool
|
|
38743
|
+
var tnAsyncNextID float64 = 1
|
|
38744
|
+
var tnAsyncCurID, tnAsyncCurTrigger float64 = 1, 0
|
|
38745
|
+
var tnAsyncHookInit func(id float64, trigger float64)
|
|
38746
|
+
var tnAsyncHookBefore, tnAsyncHookAfter func(id float64)
|
|
38747
|
+
|
|
38748
|
+
func TnAsyncSnapshot() TnAsyncContext {
|
|
38749
|
+
if !tnAsyncHooksOn {
|
|
38750
|
+
return tnAsyncCtx
|
|
38751
|
+
}
|
|
38752
|
+
return tnAsyncSnapshotIDs()
|
|
38753
|
+
}
|
|
38754
|
+
|
|
38755
|
+
func tnAsyncSnapshotIDs() TnAsyncContext {
|
|
38756
|
+
tnAsyncNextID++
|
|
38757
|
+
id := tnAsyncNextID
|
|
38758
|
+
ctx := TnAsyncContext{}
|
|
38759
|
+
for k, v := range tnAsyncCtx {
|
|
38760
|
+
ctx[k] = v
|
|
38761
|
+
}
|
|
38762
|
+
ctx[tnAsyncIDKey{}] = [2]float64{id, tnAsyncCurID}
|
|
38763
|
+
if tnAsyncHookInit != nil {
|
|
38764
|
+
tnAsyncHookInit(id, tnAsyncCurID)
|
|
38765
|
+
}
|
|
38766
|
+
return ctx
|
|
38767
|
+
}
|
|
37121
38768
|
|
|
37122
38769
|
// Runs fn with ctx as the current context, restoring the previous one afterwards
|
|
37123
38770
|
func TnAsyncRun(ctx TnAsyncContext, fn func()) {
|
|
37124
38771
|
saved := tnAsyncCtx
|
|
37125
38772
|
tnAsyncCtx = ctx
|
|
37126
38773
|
defer func() { tnAsyncCtx = saved }()
|
|
38774
|
+
if tnAsyncHooksOn {
|
|
38775
|
+
if ids, ok := ctx[tnAsyncIDKey{}].([2]float64); ok {
|
|
38776
|
+
prevID, prevTrigger := tnAsyncCurID, tnAsyncCurTrigger
|
|
38777
|
+
tnAsyncCurID, tnAsyncCurTrigger = ids[0], ids[1]
|
|
38778
|
+
if tnAsyncHookBefore != nil {
|
|
38779
|
+
tnAsyncHookBefore(ids[0])
|
|
38780
|
+
}
|
|
38781
|
+
defer func() {
|
|
38782
|
+
if tnAsyncHookAfter != nil {
|
|
38783
|
+
tnAsyncHookAfter(ids[0])
|
|
38784
|
+
}
|
|
38785
|
+
tnAsyncCurID, tnAsyncCurTrigger = prevID, prevTrigger
|
|
38786
|
+
}()
|
|
38787
|
+
}
|
|
38788
|
+
}
|
|
37127
38789
|
fn()
|
|
37128
38790
|
}
|
|
37129
38791
|
|
|
37130
38792
|
// fn bound to the current context (no-op when there is none to keep)
|
|
37131
38793
|
func TnAsyncWrap(fn func()) func() {
|
|
38794
|
+
if tnAsyncHooksOn {
|
|
38795
|
+
ctx := tnAsyncSnapshotIDs()
|
|
38796
|
+
return func() { TnAsyncRun(ctx, fn) }
|
|
38797
|
+
}
|
|
37132
38798
|
ctx := tnAsyncCtx
|
|
37133
38799
|
if ctx == nil {
|
|
37134
38800
|
return fn
|
|
@@ -37623,12 +39289,37 @@ func TnStructuredClone[T any](v T) T {
|
|
|
37623
39289
|
return tnCloneValue(reflect.ValueOf(&v).Elem()).Interface().(T)
|
|
37624
39290
|
}
|
|
37625
39291
|
|
|
39292
|
+
// Transferable objects (web streams) are never copied: structuredClone(v, {
|
|
39293
|
+
// transfer }) moves the listed ones (tnCloneTransfers), others throw
|
|
39294
|
+
type tnTransferable interface {
|
|
39295
|
+
tnTransfer() interface{}
|
|
39296
|
+
}
|
|
39297
|
+
|
|
39298
|
+
var tnCloneTransfers map[interface{}]interface{}
|
|
39299
|
+
|
|
39300
|
+
func tnCloneTransferable(t tnTransferable) interface{} {
|
|
39301
|
+
moved, listed := tnCloneTransfers[t]
|
|
39302
|
+
if !listed {
|
|
39303
|
+
panic(TnNewDOMException("Object that needs transfer was found in message but not listed in transferList", "DataCloneError"))
|
|
39304
|
+
}
|
|
39305
|
+
if moved == nil {
|
|
39306
|
+
moved = t.tnTransfer()
|
|
39307
|
+
tnCloneTransfers[t] = moved
|
|
39308
|
+
}
|
|
39309
|
+
return moved
|
|
39310
|
+
}
|
|
39311
|
+
|
|
37626
39312
|
func tnCloneValue(v reflect.Value) reflect.Value {
|
|
37627
39313
|
switch v.Kind() {
|
|
37628
39314
|
case reflect.Pointer:
|
|
37629
39315
|
if v.IsNil() {
|
|
37630
39316
|
return v
|
|
37631
39317
|
}
|
|
39318
|
+
if v.CanInterface() {
|
|
39319
|
+
if t, ok := v.Interface().(tnTransferable); ok {
|
|
39320
|
+
return reflect.ValueOf(tnCloneTransferable(t))
|
|
39321
|
+
}
|
|
39322
|
+
}
|
|
37632
39323
|
c := reflect.New(v.Elem().Type())
|
|
37633
39324
|
c.Elem().Set(tnCloneValue(v.Elem()))
|
|
37634
39325
|
return c
|
|
@@ -37674,6 +39365,26 @@ func tnCloneValue(v reflect.Value) reflect.Value {
|
|
|
37674
39365
|
return c
|
|
37675
39366
|
}
|
|
37676
39367
|
return v
|
|
39368
|
+
}`,
|
|
39369
|
+
structuredCloneTransfer: `// structuredClone(value, { transfer }): the listed transferables move
|
|
39370
|
+
func TnStructuredCloneTransfer[T any](v T, options interface{}) T {
|
|
39371
|
+
saved := tnCloneTransfers
|
|
39372
|
+
tnCloneTransfers = map[interface{}]interface{}{}
|
|
39373
|
+
defer func() { tnCloneTransfers = saved }()
|
|
39374
|
+
if options != nil && !TnIsNil(options) {
|
|
39375
|
+
list := reflect.ValueOf(TnGetValue(options, "transfer"))
|
|
39376
|
+
if list.IsValid() && list.Kind() == reflect.Pointer && !list.IsNil() {
|
|
39377
|
+
list = list.Elem()
|
|
39378
|
+
}
|
|
39379
|
+
if list.IsValid() && (list.Kind() == reflect.Slice || list.Kind() == reflect.Array) {
|
|
39380
|
+
for i := 0; i < list.Len(); i++ {
|
|
39381
|
+
if t, ok := list.Index(i).Interface().(tnTransferable); ok {
|
|
39382
|
+
tnCloneTransfers[t] = nil
|
|
39383
|
+
}
|
|
39384
|
+
}
|
|
39385
|
+
}
|
|
39386
|
+
}
|
|
39387
|
+
return TnStructuredClone(v)
|
|
37677
39388
|
}`,
|
|
37678
39389
|
globalThis: `// (globalThis as any).x: properties set on the global object at runtime
|
|
37679
39390
|
var TnGlobalThis = map[string]interface{}{}`,
|
|
@@ -38011,10 +39722,16 @@ func TnReject[T any](ch chan T, reason interface{}) {
|
|
|
38011
39722
|
// unless process.on('unhandledRejection') takes it
|
|
38012
39723
|
var tnUnhandledHook func(reason interface{}) bool
|
|
38013
39724
|
|
|
39725
|
+
// Promises util.markPromiseAsHandled marked: their rejection is not reported
|
|
39726
|
+
var tnHandledPromises sync.Map
|
|
39727
|
+
|
|
38014
39728
|
func TnDetach[T any](ch chan T) {
|
|
38015
39729
|
go func() {
|
|
38016
39730
|
defer __tnWaitGroup.Done()
|
|
38017
39731
|
_, reason, rejected := tnSettle(ch)
|
|
39732
|
+
if _, handled := tnHandledPromises.Load(any(ch)); handled {
|
|
39733
|
+
return
|
|
39734
|
+
}
|
|
38018
39735
|
if rejected {
|
|
38019
39736
|
TnLoopCall(func() {
|
|
38020
39737
|
if tnUnhandledHook != nil && tnUnhandledHook(reason) {
|
|
@@ -38067,8 +39784,27 @@ func TnAwaitValue(v interface{}, inline bool) interface{} {
|
|
|
38067
39784
|
return TnAwait(ch)
|
|
38068
39785
|
}
|
|
38069
39786
|
if rv := reflect.ValueOf(v); rv.Kind() == reflect.Chan {
|
|
38070
|
-
|
|
38071
|
-
|
|
39787
|
+
// (a typed promise: forwarded onto an interface{} channel, whose await
|
|
39788
|
+
// keeps the loop running while this goroutine waits)
|
|
39789
|
+
untyped := make(chan interface{}, 1)
|
|
39790
|
+
go func() {
|
|
39791
|
+
received, ok := rv.Recv()
|
|
39792
|
+
if !ok {
|
|
39793
|
+
// (a rejected promise: a closed channel with its reason recorded)
|
|
39794
|
+
if r, rejected := tnRejections.Load(rv.Interface()); rejected {
|
|
39795
|
+
TnReject(untyped, r)
|
|
39796
|
+
return
|
|
39797
|
+
}
|
|
39798
|
+
close(untyped)
|
|
39799
|
+
return
|
|
39800
|
+
}
|
|
39801
|
+
untyped <- received.Interface()
|
|
39802
|
+
close(untyped)
|
|
39803
|
+
}()
|
|
39804
|
+
if inline {
|
|
39805
|
+
return TnAwaitInline(untyped)
|
|
39806
|
+
}
|
|
39807
|
+
return TnAwait(untyped)
|
|
38072
39808
|
}
|
|
38073
39809
|
return v
|
|
38074
39810
|
}
|
|
@@ -38240,8 +39976,17 @@ func TnPromiseAllValues(values []interface{}) chan []interface{} {
|
|
|
38240
39976
|
}
|
|
38241
39977
|
results[i] = r
|
|
38242
39978
|
} else if rv := reflect.ValueOf(v); rv.IsValid() && rv.Kind() == reflect.Chan {
|
|
38243
|
-
r,
|
|
38244
|
-
|
|
39979
|
+
r, ok := rv.Recv()
|
|
39980
|
+
if !ok {
|
|
39981
|
+
// (a rejected promise: a closed channel with its reason recorded)
|
|
39982
|
+
if reason, rejected := tnRejections.Load(rv.Interface()); rejected {
|
|
39983
|
+
TnReject(out, reason)
|
|
39984
|
+
return
|
|
39985
|
+
}
|
|
39986
|
+
results[i] = nil
|
|
39987
|
+
} else {
|
|
39988
|
+
results[i] = r.Interface()
|
|
39989
|
+
}
|
|
38245
39990
|
} else {
|
|
38246
39991
|
results[i] = v
|
|
38247
39992
|
}
|
|
@@ -38252,6 +39997,70 @@ func TnPromiseAllValues(values []interface{}) chan []interface{} {
|
|
|
38252
39997
|
return out
|
|
38253
39998
|
}
|
|
38254
39999
|
|
|
40000
|
+
// Array.fromAsync over an async iterable (a channel): its values, in order.
|
|
40001
|
+
// It runs as an async function does (TnStartAsync): generator channels are
|
|
40002
|
+
// fed by raw sends, received with the baton like for await's
|
|
40003
|
+
func TnFromAsyncChan[T any](ch chan T) chan []T {
|
|
40004
|
+
out := make(chan []T, 1)
|
|
40005
|
+
TnStartAsync(func() {
|
|
40006
|
+
defer TnAsyncClose(out)
|
|
40007
|
+
defer TnRejectOnPanic(out)
|
|
40008
|
+
results := []T{}
|
|
40009
|
+
for {
|
|
40010
|
+
v, ok := tnRawReceive(ch)
|
|
40011
|
+
if !ok {
|
|
40012
|
+
if reason, rejected := tnRejections.Load(ch); rejected {
|
|
40013
|
+
panic(reason)
|
|
40014
|
+
}
|
|
40015
|
+
break
|
|
40016
|
+
}
|
|
40017
|
+
results = append(results, v)
|
|
40018
|
+
}
|
|
40019
|
+
TnAsyncSend(out, results)
|
|
40020
|
+
})
|
|
40021
|
+
return out
|
|
40022
|
+
}
|
|
40023
|
+
|
|
40024
|
+
// Array.fromAsync over plain values: resolved with a copy of them
|
|
40025
|
+
func TnFromAsyncValues[T any](values []T) chan []T {
|
|
40026
|
+
out := make(chan []T, 1)
|
|
40027
|
+
out <- append([]T{}, values...)
|
|
40028
|
+
close(out)
|
|
40029
|
+
return out
|
|
40030
|
+
}
|
|
40031
|
+
|
|
40032
|
+
// Array.fromAsync(source, mapFn): the collected values mapped in turn
|
|
40033
|
+
func TnFromAsyncMap[T, U any](src chan []T, fn func(T, float64) U) chan []U {
|
|
40034
|
+
out := make(chan []U, 1)
|
|
40035
|
+
TnStartAsync(func() {
|
|
40036
|
+
defer TnAsyncClose(out)
|
|
40037
|
+
defer TnRejectOnPanic(out)
|
|
40038
|
+
values := TnAwait(src)
|
|
40039
|
+
results := make([]U, len(values))
|
|
40040
|
+
for i, v := range values {
|
|
40041
|
+
results[i] = fn(v, float64(i))
|
|
40042
|
+
}
|
|
40043
|
+
TnAsyncSend(out, results)
|
|
40044
|
+
})
|
|
40045
|
+
return out
|
|
40046
|
+
}
|
|
40047
|
+
|
|
40048
|
+
// Array.fromAsync(source, async mapFn): each mapped promise awaited in turn
|
|
40049
|
+
func TnFromAsyncMapAwait[T, U any](src chan []T, fn func(T, float64) chan U) chan []U {
|
|
40050
|
+
out := make(chan []U, 1)
|
|
40051
|
+
TnStartAsync(func() {
|
|
40052
|
+
defer TnAsyncClose(out)
|
|
40053
|
+
defer TnRejectOnPanic(out)
|
|
40054
|
+
values := TnAwait(src)
|
|
40055
|
+
results := make([]U, len(values))
|
|
40056
|
+
for i, v := range values {
|
|
40057
|
+
results[i] = TnAwait(fn(v, float64(i)))
|
|
40058
|
+
}
|
|
40059
|
+
TnAsyncSend(out, results)
|
|
40060
|
+
})
|
|
40061
|
+
return out
|
|
40062
|
+
}
|
|
40063
|
+
|
|
38255
40064
|
// Promise.all: every channel drained in order, results collected
|
|
38256
40065
|
func TnPromiseAll[T any](chs []chan T) chan []T {
|
|
38257
40066
|
out := make(chan []T, 1)
|
|
@@ -38276,22 +40085,11 @@ func TnPromiseAll[T any](chs []chan T) chan []T {
|
|
|
38276
40085
|
recordView: `// An any value as a Record<string, any>. A JSON-like object (a Go map) is
|
|
38277
40086
|
// viewed in place, sharing its map, so writes through the record reach the
|
|
38278
40087
|
// object as in JS; its keys list in the order a conversion gives them
|
|
38279
|
-
// (sorted: a Go map keeps none)
|
|
40088
|
+
// (sorted: a Go map keeps none), listed only when something first needs them
|
|
40089
|
+
// (a record read by key never does). Anything else converts as TnAsPtr does.
|
|
38280
40090
|
func TnRecordOf(v interface{}) *TnMap[string, interface{}] {
|
|
38281
40091
|
if m, ok := v.(map[string]interface{}); ok && m != nil {
|
|
38282
|
-
|
|
38283
|
-
for k := range m {
|
|
38284
|
-
keys = append(keys, k)
|
|
38285
|
-
}
|
|
38286
|
-
sort.Strings(keys)
|
|
38287
|
-
r := &TnMap[string, interface{}]{keys: keys, values: m, keyMode: 1}
|
|
38288
|
-
for _, k := range keys {
|
|
38289
|
-
if _, isIndex := tnIndexKey(k); isIndex {
|
|
38290
|
-
r.indexKeys = true
|
|
38291
|
-
break
|
|
38292
|
-
}
|
|
38293
|
-
}
|
|
38294
|
-
return r
|
|
40092
|
+
return &TnMap[string, interface{}]{values: m, keyMode: 1, view: true}
|
|
38295
40093
|
}
|
|
38296
40094
|
return TnAsPtr[TnMap[string, interface{}]](v)
|
|
38297
40095
|
}`,
|
|
@@ -38481,6 +40279,17 @@ function resolveNodeKey(expr) {
|
|
|
38481
40279
|
}
|
|
38482
40280
|
return '';
|
|
38483
40281
|
}
|
|
40282
|
+
// x instanceof <Node class>: its Go type; error classes sharing *TnError
|
|
40283
|
+
// (AssertionError, WebAssembly.RuntimeError …) by name
|
|
40284
|
+
function nodeClassInstanceOf(left, key) {
|
|
40285
|
+
const nodeClass = nodeRegistry.classes[key];
|
|
40286
|
+
if (nodeClass.goType === '*TnError') {
|
|
40287
|
+
useHelper('error');
|
|
40288
|
+
return `TnIsErrorOf(${visit(left)}, ${toGoStringLiteral(key.slice(key.lastIndexOf('.') + 1))})`;
|
|
40289
|
+
}
|
|
40290
|
+
useNodeHelperDefining(nodeClass.goType);
|
|
40291
|
+
return `func() bool { _, ok := interface{}(${visit(left)}).(${nodeClass.goType}); return ok }()`;
|
|
40292
|
+
}
|
|
38484
40293
|
// The promise variant of a Node function, '' when it has none
|
|
38485
40294
|
function nodePromisifiedKey(fnExpr) {
|
|
38486
40295
|
let key = resolveNodeKey(fnExpr);
|
|
@@ -38610,11 +40419,31 @@ function applyNodeParamTypes(key, args) {
|
|
|
38610
40419
|
}
|
|
38611
40420
|
}
|
|
38612
40421
|
}
|
|
40422
|
+
// new Int32Array(buffer) / new DataView(buffer) / new Uint8Array(buffer) &
|
|
40423
|
+
// co. and ArrayBuffer.isView: they take the buffer itself
|
|
40424
|
+
function isArrayBufferViewConstructor(node) {
|
|
40425
|
+
if (isNewExpression(node) && isIdentifier(node.expression)) {
|
|
40426
|
+
const name = node.expression.text;
|
|
40427
|
+
return name in TYPED_ARRAY_KINDS || BIGINT_ARRAY_KINDS.includes(name) || name === 'DataView' || name === 'Uint8Array';
|
|
40428
|
+
}
|
|
40429
|
+
return isCallExpression(node) && isPropertyAccessExpression(node.expression) && isIdentifier(node.expression.expression) &&
|
|
40430
|
+
node.expression.expression.text === 'ArrayBuffer' && node.expression.name.text === 'isView';
|
|
40431
|
+
}
|
|
38613
40432
|
function makeNodeCall(node, recv) {
|
|
38614
40433
|
const nodes = node.arguments ?? [];
|
|
38615
40434
|
const hasSpread = nodes.some((a) => isSpreadElement(a));
|
|
38616
40435
|
const args = hasSpread ? visitSpreadCallArguments(node) : nodes.map((a) => visit(a));
|
|
38617
40436
|
const types = nodes.map((a) => inferExpressionType(a) ?? '');
|
|
40437
|
+
// (a resized or detached ArrayBuffer passed to a Node API: its bytes now;
|
|
40438
|
+
// views keep the buffer itself)
|
|
40439
|
+
if (arrayBufferStateUsed && !hasSpread && !isArrayBufferViewConstructor(node)) {
|
|
40440
|
+
nodes.forEach((a, i) => {
|
|
40441
|
+
if (types[i] === '[]byte' && isArrayBufferExpression(a)) {
|
|
40442
|
+
useHelper('typedArrays');
|
|
40443
|
+
args[i] = `TnABBytes(${args[i]})`;
|
|
40444
|
+
}
|
|
40445
|
+
});
|
|
40446
|
+
}
|
|
38618
40447
|
return { args: args, nodes: nodes, types: types, recv: recv, site: node };
|
|
38619
40448
|
}
|
|
38620
40449
|
// Calls of Node APIs: imported functions, statics (Buffer.from) and methods of
|