goscript 0.0.36 → 0.0.38
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/compiler/analysis.go +129 -8
- package/compiler/compiler.go +4 -1
- package/compiler/composite-lit.go +2 -4
- package/compiler/expr-call.go +26 -0
- package/compiler/lit.go +83 -0
- package/compiler/protobuf.go +2 -2
- package/compiler/spec-value.go +3 -3
- package/compiler/spec.go +7 -4
- package/compiler/stmt-assign.go +1 -1
- package/compiler/stmt.go +26 -8
- package/dist/gs/builtin/slice.js +2 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/errors.js +182 -23
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
- package/dist/gs/github.com/pkg/errors/index.js +3 -3
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js +8 -5
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/internal/abi/index.d.ts +20 -0
- package/dist/gs/internal/abi/index.js +20 -0
- package/dist/gs/internal/abi/index.js.map +1 -0
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +33 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -0
- package/dist/gs/internal/byteorder/index.d.ts +8 -0
- package/dist/gs/internal/byteorder/index.js +34 -0
- package/dist/gs/internal/byteorder/index.js.map +1 -0
- package/dist/gs/internal/testlog/index.d.ts +1 -0
- package/dist/gs/internal/testlog/index.js +5 -0
- package/dist/gs/internal/testlog/index.js.map +1 -0
- package/dist/gs/math/index.d.ts +44 -44
- package/dist/gs/math/index.js +44 -44
- package/dist/gs/math/index.js.map +1 -1
- package/dist/gs/os/dir.gs.d.ts +6 -0
- package/dist/gs/os/dir.gs.js +35 -0
- package/dist/gs/os/dir.gs.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.d.ts +7 -0
- package/dist/gs/os/dir_unix.gs.js +113 -0
- package/dist/gs/os/dir_unix.gs.js.map +1 -0
- package/dist/gs/os/dirent_js.gs.d.ts +5 -0
- package/dist/gs/os/dirent_js.gs.js +20 -0
- package/dist/gs/os/dirent_js.gs.js.map +1 -0
- package/dist/gs/os/env.gs.d.ts +12 -0
- package/dist/gs/os/env.gs.js +157 -0
- package/dist/gs/os/env.gs.js.map +1 -0
- package/dist/gs/os/error.gs.d.ts +40 -0
- package/dist/gs/os/error.gs.js +158 -0
- package/dist/gs/os/error.gs.js.map +1 -0
- package/dist/gs/os/error_errno.gs.d.ts +1 -0
- package/dist/gs/os/error_errno.gs.js +5 -0
- package/dist/gs/os/error_errno.gs.js.map +1 -0
- package/dist/gs/os/exec.gs.d.ts +60 -0
- package/dist/gs/os/exec.gs.js +136 -0
- package/dist/gs/os/exec.gs.js.map +1 -0
- package/dist/gs/os/exec_nohandle.gs.d.ts +1 -0
- package/dist/gs/os/exec_nohandle.gs.js +2 -0
- package/dist/gs/os/exec_nohandle.gs.js.map +1 -0
- package/dist/gs/os/exec_posix.gs.d.ts +25 -0
- package/dist/gs/os/exec_posix.gs.js +67 -0
- package/dist/gs/os/exec_posix.gs.js.map +1 -0
- package/dist/gs/os/exec_unix.gs.d.ts +4 -0
- package/dist/gs/os/exec_unix.gs.js +46 -0
- package/dist/gs/os/exec_unix.gs.js.map +1 -0
- package/dist/gs/os/executable.gs.d.ts +2 -0
- package/dist/gs/os/executable.gs.js +16 -0
- package/dist/gs/os/executable.gs.js.map +1 -0
- package/dist/gs/os/executable_js.gs.d.ts +2 -0
- package/dist/gs/os/executable_js.gs.js +5 -0
- package/dist/gs/os/executable_js.gs.js.map +1 -0
- package/dist/gs/os/executable_wasm.gs.d.ts +2 -0
- package/dist/gs/os/executable_wasm.gs.js +6 -0
- package/dist/gs/os/executable_wasm.gs.js.map +1 -0
- package/dist/gs/os/file_constants_js.gs.d.ts +41 -0
- package/dist/gs/os/file_constants_js.gs.js +78 -0
- package/dist/gs/os/file_constants_js.gs.js.map +1 -0
- package/dist/gs/os/file_js.gs.d.ts +22 -0
- package/dist/gs/os/file_js.gs.js +73 -0
- package/dist/gs/os/file_js.gs.js.map +1 -0
- package/dist/gs/os/file_open_unix.gs.d.ts +6 -0
- package/dist/gs/os/file_open_unix.gs.js +10 -0
- package/dist/gs/os/file_open_unix.gs.js.map +1 -0
- package/dist/gs/os/file_posix_js.gs.d.ts +8 -0
- package/dist/gs/os/file_posix_js.gs.js +32 -0
- package/dist/gs/os/file_posix_js.gs.js.map +1 -0
- package/dist/gs/os/file_unix_js.gs.d.ts +27 -0
- package/dist/gs/os/file_unix_js.gs.js +64 -0
- package/dist/gs/os/file_unix_js.gs.js.map +1 -0
- package/dist/gs/os/getwd_js.gs.d.ts +6 -0
- package/dist/gs/os/getwd_js.gs.js +21 -0
- package/dist/gs/os/getwd_js.gs.js.map +1 -0
- package/dist/gs/os/index.d.ts +19 -0
- package/dist/gs/os/index.js +20 -0
- package/dist/gs/os/index.js.map +1 -0
- package/dist/gs/os/path.gs.d.ts +4 -0
- package/dist/gs/os/path.gs.js +32 -0
- package/dist/gs/os/path.gs.js.map +1 -0
- package/dist/gs/os/path_unix.gs.d.ts +4 -0
- package/dist/gs/os/path_unix.gs.js +40 -0
- package/dist/gs/os/path_unix.gs.js.map +1 -0
- package/dist/gs/os/pidfd_js.gs.d.ts +6 -0
- package/dist/gs/os/pidfd_js.gs.js +14 -0
- package/dist/gs/os/pidfd_js.gs.js.map +1 -0
- package/dist/gs/os/pipe_wasm.gs.d.ts +2 -0
- package/dist/gs/os/pipe_wasm.gs.js +14 -0
- package/dist/gs/os/pipe_wasm.gs.js.map +1 -0
- package/dist/gs/os/proc.gs.d.ts +11 -0
- package/dist/gs/os/proc.gs.js +68 -0
- package/dist/gs/os/proc.gs.js.map +1 -0
- package/dist/gs/os/proc_js.gs.d.ts +3 -0
- package/dist/gs/os/proc_js.gs.js +12 -0
- package/dist/gs/os/proc_js.gs.js.map +1 -0
- package/dist/gs/os/rawconn_js.gs.d.ts +10 -0
- package/dist/gs/os/rawconn_js.gs.js +26 -0
- package/dist/gs/os/rawconn_js.gs.js.map +1 -0
- package/dist/gs/os/removeall_js.gs.d.ts +2 -0
- package/dist/gs/os/removeall_js.gs.js +7 -0
- package/dist/gs/os/removeall_js.gs.js.map +1 -0
- package/dist/gs/os/root_js.gs.d.ts +23 -0
- package/dist/gs/os/root_js.gs.js +80 -0
- package/dist/gs/os/root_js.gs.js.map +1 -0
- package/dist/gs/os/root_nonwindows.gs.d.ts +2 -0
- package/dist/gs/os/root_nonwindows.gs.js +4 -0
- package/dist/gs/os/root_nonwindows.gs.js.map +1 -0
- package/dist/gs/os/root_noopenat.gs.d.ts +11 -0
- package/dist/gs/os/root_noopenat.gs.js +31 -0
- package/dist/gs/os/root_noopenat.gs.js.map +1 -0
- package/dist/gs/os/stat.gs.d.ts +24 -0
- package/dist/gs/os/stat.gs.js +20 -0
- package/dist/gs/os/stat.gs.js.map +1 -0
- package/dist/gs/os/stat_js.gs.d.ts +6 -0
- package/dist/gs/os/stat_js.gs.js +23 -0
- package/dist/gs/os/stat_js.gs.js.map +1 -0
- package/dist/gs/os/stat_unix_js.gs.d.ts +8 -0
- package/dist/gs/os/stat_unix_js.gs.js +16 -0
- package/dist/gs/os/stat_unix_js.gs.js.map +1 -0
- package/dist/gs/os/sticky_bsd.gs.d.ts +1 -0
- package/dist/gs/os/sticky_bsd.gs.js +3 -0
- package/dist/gs/os/sticky_bsd.gs.js.map +1 -0
- package/dist/gs/os/sys.gs.d.ts +2 -0
- package/dist/gs/os/sys.gs.js +10 -0
- package/dist/gs/os/sys.gs.js.map +1 -0
- package/dist/gs/os/sys_bsd.gs.d.ts +2 -0
- package/dist/gs/os/sys_bsd.gs.js +15 -0
- package/dist/gs/os/sys_bsd.gs.js.map +1 -0
- package/dist/gs/os/sys_js.gs.d.ts +2 -0
- package/dist/gs/os/sys_js.gs.js +6 -0
- package/dist/gs/os/sys_js.gs.js.map +1 -0
- package/dist/gs/os/tempfile.gs.d.ts +5 -0
- package/dist/gs/os/tempfile.gs.js +30 -0
- package/dist/gs/os/tempfile.gs.js.map +1 -0
- package/dist/gs/os/types.gs.d.ts +59 -0
- package/dist/gs/os/types.gs.js +123 -0
- package/dist/gs/os/types.gs.js.map +1 -0
- package/dist/gs/os/types_js.gs.d.ts +74 -0
- package/dist/gs/os/types_js.gs.js +147 -0
- package/dist/gs/os/types_js.gs.js.map +1 -0
- package/dist/gs/os/types_unix.gs.d.ts +40 -0
- package/dist/gs/os/types_unix.gs.js +87 -0
- package/dist/gs/os/types_unix.gs.js.map +1 -0
- package/dist/gs/os/wait_unimp.gs.d.ts +1 -0
- package/dist/gs/os/wait_unimp.gs.js +2 -0
- package/dist/gs/os/wait_unimp.gs.js.map +1 -0
- package/dist/gs/os/zero_copy_posix.gs.d.ts +4 -0
- package/dist/gs/os/zero_copy_posix.gs.js +27 -0
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -0
- package/dist/gs/os/zero_copy_stub.gs.d.ts +1 -0
- package/dist/gs/os/zero_copy_stub.gs.js +2 -0
- package/dist/gs/os/zero_copy_stub.gs.js.map +1 -0
- package/dist/gs/reflect/abi.d.ts +59 -0
- package/dist/gs/reflect/abi.gs.d.ts +59 -0
- package/dist/gs/reflect/abi.gs.js +79 -0
- package/dist/gs/reflect/abi.gs.js.map +1 -0
- package/dist/gs/reflect/abi.js +79 -0
- package/dist/gs/reflect/abi.js.map +1 -0
- package/dist/gs/reflect/badlinkname.d.ts +52 -0
- package/dist/gs/reflect/badlinkname.gs.d.ts +52 -0
- package/dist/gs/reflect/badlinkname.gs.js +72 -0
- package/dist/gs/reflect/badlinkname.gs.js.map +1 -0
- package/dist/gs/reflect/badlinkname.js +72 -0
- package/dist/gs/reflect/badlinkname.js.map +1 -0
- package/dist/gs/reflect/deepequal.d.ts +1 -0
- package/dist/gs/reflect/deepequal.gs.d.ts +25 -0
- package/dist/gs/reflect/deepequal.gs.js +308 -0
- package/dist/gs/reflect/deepequal.gs.js.map +1 -0
- package/dist/gs/reflect/deepequal.js +139 -0
- package/dist/gs/reflect/deepequal.js.map +1 -0
- package/dist/gs/reflect/float32reg_generic.gs.d.ts +2 -0
- package/dist/gs/reflect/float32reg_generic.gs.js +10 -0
- package/dist/gs/reflect/float32reg_generic.gs.js.map +1 -0
- package/dist/gs/reflect/index.d.ts +8 -0
- package/dist/gs/reflect/index.gs.d.ts +1 -0
- package/dist/gs/reflect/index.gs.js +3 -0
- package/dist/gs/reflect/index.gs.js.map +1 -0
- package/dist/gs/reflect/index.js +10 -0
- package/dist/gs/reflect/index.js.map +1 -0
- package/dist/gs/reflect/iter.d.ts +4 -0
- package/dist/gs/reflect/iter.gs.d.ts +3 -0
- package/dist/gs/reflect/iter.gs.js +24 -0
- package/dist/gs/reflect/iter.gs.js.map +1 -0
- package/dist/gs/reflect/iter.js +24 -0
- package/dist/gs/reflect/iter.js.map +1 -0
- package/dist/gs/reflect/makefunc.gs.d.ts +34 -0
- package/dist/gs/reflect/makefunc.gs.js +288 -0
- package/dist/gs/reflect/makefunc.gs.js.map +1 -0
- package/dist/gs/reflect/map.d.ts +14 -0
- package/dist/gs/reflect/map.js +70 -0
- package/dist/gs/reflect/map.js.map +1 -0
- package/dist/gs/reflect/map_swiss.gs.d.ts +14 -0
- package/dist/gs/reflect/map_swiss.gs.js +70 -0
- package/dist/gs/reflect/map_swiss.gs.js.map +1 -0
- package/dist/gs/reflect/reflect.gs.d.ts +132 -0
- package/dist/gs/reflect/reflect.gs.js +437 -0
- package/dist/gs/reflect/reflect.gs.js.map +1 -0
- package/dist/gs/reflect/swapper.d.ts +2 -0
- package/dist/gs/reflect/swapper.gs.d.ts +1 -0
- package/dist/gs/reflect/swapper.gs.js +32 -0
- package/dist/gs/reflect/swapper.gs.js.map +1 -0
- package/dist/gs/reflect/swapper.js +46 -0
- package/dist/gs/reflect/swapper.js.map +1 -0
- package/dist/gs/reflect/type.d.ts +126 -0
- package/dist/gs/reflect/type.gs.d.ts +4 -0
- package/dist/gs/reflect/type.gs.js +21 -0
- package/dist/gs/reflect/type.gs.js.map +1 -0
- package/dist/gs/reflect/type.js +825 -0
- package/dist/gs/reflect/type.js.map +1 -0
- package/dist/gs/reflect/types.d.ts +90 -0
- package/dist/gs/reflect/types.js +119 -0
- package/dist/gs/reflect/types.js.map +1 -0
- package/dist/gs/reflect/value.d.ts +13 -0
- package/dist/gs/reflect/value.gs.d.ts +4 -0
- package/dist/gs/reflect/value.gs.js +12 -0
- package/dist/gs/reflect/value.gs.js.map +1 -0
- package/dist/gs/reflect/value.js +201 -0
- package/dist/gs/reflect/value.js.map +1 -0
- package/dist/gs/reflect/visiblefields.d.ts +4 -0
- package/dist/gs/reflect/visiblefields.gs.d.ts +3 -0
- package/dist/gs/reflect/visiblefields.gs.js +123 -0
- package/dist/gs/reflect/visiblefields.gs.js.map +1 -0
- package/dist/gs/reflect/visiblefields.js +143 -0
- package/dist/gs/reflect/visiblefields.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -6
- package/dist/gs/strconv/index.js +6 -6
- package/dist/gs/strconv/index.js.map +1 -1
- package/dist/gs/strings/index.d.ts +1 -1
- package/dist/gs/strings/index.js +1 -1
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/sync/atomic/index.d.ts +4 -4
- package/dist/gs/sync/atomic/index.js +4 -4
- package/dist/gs/sync/atomic/index.js.map +1 -1
- package/dist/gs/syscall/index.d.ts +80 -0
- package/dist/gs/syscall/index.js +169 -0
- package/dist/gs/syscall/index.js.map +1 -0
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/slice.ts +2 -1
- package/gs/github.com/pkg/errors/errors.ts +408 -238
- package/gs/github.com/pkg/errors/go113.ts +5 -6
- package/gs/github.com/pkg/errors/index.ts +12 -3
- package/gs/github.com/pkg/errors/stack.ts +107 -105
- package/gs/internal/abi/index.ts +37 -0
- package/gs/internal/bytealg/index.ts +34 -0
- package/gs/internal/byteorder/index.ts +40 -0
- package/gs/math/abs.gs.test.ts +1 -1
- package/gs/math/acosh.gs.test.ts +4 -2
- package/gs/math/asin.gs.test.ts +1 -1
- package/gs/math/asinh.gs.test.ts +7 -3
- package/gs/math/atan.gs.test.ts +1 -1
- package/gs/math/atan2.gs.test.ts +17 -9
- package/gs/math/atanh.gs.test.ts +1 -1
- package/gs/math/bits.gs.test.ts +1 -1
- package/gs/math/cbrt.gs.test.ts +1 -1
- package/gs/math/const.gs.test.ts +34 -8
- package/gs/math/copysign.gs.test.ts +7 -3
- package/gs/math/dim.gs.test.ts +19 -7
- package/gs/math/erf.gs.test.ts +1 -1
- package/gs/math/erfinv.gs.test.ts +4 -2
- package/gs/math/exp.gs.test.ts +1 -1
- package/gs/math/expm1.gs.test.ts +6 -4
- package/gs/math/floor.gs.test.ts +17 -4
- package/gs/math/fma.gs.test.ts +53 -53
- package/gs/math/frexp.gs.test.ts +112 -117
- package/gs/math/gamma.gs.test.ts +1 -1
- package/gs/math/hypot.gs.test.ts +53 -53
- package/gs/math/index.ts +80 -44
- package/gs/math/j0.gs.test.ts +6 -2
- package/gs/math/j1.gs.test.ts +6 -2
- package/gs/math/jn.gs.test.ts +9 -5
- package/gs/math/ldexp.gs.test.ts +103 -86
- package/gs/math/lgamma.gs.test.ts +10 -10
- package/gs/math/log.gs.test.ts +1 -1
- package/gs/math/log10.gs.test.ts +1 -1
- package/gs/math/log1p.gs.test.ts +2 -2
- package/gs/math/logb.gs.test.ts +1 -1
- package/gs/math/mod.gs.test.ts +2 -2
- package/gs/math/modf.gs.test.ts +7 -7
- package/gs/math/nextafter.gs.test.ts +9 -7
- package/gs/math/pow.gs.test.ts +6 -4
- package/gs/math/pow10.gs.test.ts +1 -1
- package/gs/math/remainder.gs.test.ts +1 -1
- package/gs/math/signbit.gs.test.ts +1 -1
- package/gs/math/sin.gs.test.ts +1 -1
- package/gs/math/sincos.gs.test.ts +33 -14
- package/gs/math/sinh.gs.test.ts +1 -1
- package/gs/math/sqrt.gs.test.ts +1 -1
- package/gs/math/tan.gs.test.ts +3 -3
- package/gs/math/tanh.gs.test.ts +1 -1
- package/gs/os/dir.gs.ts +42 -0
- package/gs/os/dir_unix.gs.ts +155 -0
- package/gs/os/dirent_js.gs.ts +27 -0
- package/gs/os/env.gs.ts +179 -0
- package/gs/os/error.gs.ts +205 -0
- package/gs/os/error_errno.gs.ts +12 -0
- package/gs/os/exec.gs.ts +198 -0
- package/gs/os/exec_nohandle.gs.ts +2 -0
- package/gs/os/exec_posix.gs.ts +95 -0
- package/gs/os/exec_unix.gs.ts +64 -0
- package/gs/os/executable.gs.ts +18 -0
- package/gs/os/executable_js.gs.ts +6 -0
- package/gs/os/executable_wasm.gs.ts +10 -0
- package/gs/os/file_constants_js.gs.ts +98 -0
- package/gs/os/file_js.gs.ts +99 -0
- package/gs/os/file_open_unix.gs.ts +15 -0
- package/gs/os/file_posix_js.gs.ts +40 -0
- package/gs/os/file_unix_js.gs.ts +94 -0
- package/gs/os/getwd_js.gs.ts +28 -0
- package/gs/os/index.ts +128 -0
- package/gs/os/path.gs.ts +35 -0
- package/gs/os/path_unix.gs.ts +49 -0
- package/gs/os/pidfd_js.gs.ts +25 -0
- package/gs/os/pipe_wasm.gs.ts +17 -0
- package/gs/os/proc.gs.ts +84 -0
- package/gs/os/proc_js.gs.ts +15 -0
- package/gs/os/rawconn_js.gs.ts +30 -0
- package/gs/os/removeall_js.gs.ts +9 -0
- package/gs/os/root_js.gs.ts +111 -0
- package/gs/os/root_nonwindows.gs.ts +6 -0
- package/gs/os/root_noopenat.gs.ts +45 -0
- package/gs/os/stat.gs.ts +38 -0
- package/gs/os/stat_js.gs.ts +30 -0
- package/gs/os/stat_unix_js.gs.ts +27 -0
- package/gs/os/sticky_bsd.gs.ts +4 -0
- package/gs/os/sys.gs.ts +12 -0
- package/gs/os/sys_bsd.gs.ts +17 -0
- package/gs/os/sys_js.gs.ts +9 -0
- package/gs/os/tempfile.gs.ts +34 -0
- package/gs/os/types.gs.ts +170 -0
- package/gs/os/types_js.gs.ts +205 -0
- package/gs/os/types_unix.gs.ts +118 -0
- package/gs/os/wait_unimp.gs.ts +2 -0
- package/gs/os/zero_copy_posix.gs.ts +35 -0
- package/gs/os/zero_copy_stub.gs.ts +4 -0
- package/gs/reflect/ANALYSIS.md +278 -0
- package/gs/reflect/deepequal.ts +154 -0
- package/gs/reflect/function-types.test.ts +146 -0
- package/gs/reflect/godoc.txt +67 -0
- package/gs/reflect/index.ts +83 -0
- package/gs/reflect/iter.ts +44 -0
- package/gs/reflect/map.ts +81 -0
- package/gs/reflect/swapper.ts +52 -0
- package/gs/reflect/type.ts +1012 -0
- package/gs/reflect/types.ts +214 -0
- package/gs/reflect/value.ts +264 -0
- package/gs/reflect/visiblefields.ts +173 -0
- package/gs/strconv/index.ts +39 -6
- package/gs/strings/index.ts +7 -1
- package/gs/strings/replace.ts +1 -9
- package/gs/sync/atomic/index.ts +53 -4
- package/gs/syscall/index.ts +212 -0
- package/gs/unsafe/unsafe.ts +1 -1
- package/package.json +2 -1
package/compiler/analysis.go
CHANGED
|
@@ -43,12 +43,25 @@ type VariableUsageInfo struct {
|
|
|
43
43
|
Destinations []AssignmentInfo
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// FunctionTypeInfo represents Go function type information for reflection
|
|
47
|
+
type FunctionTypeInfo struct {
|
|
48
|
+
Params []types.Type // Parameter types
|
|
49
|
+
Results []types.Type // Return types
|
|
50
|
+
Variadic bool // Whether the function is variadic
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
// FunctionInfo consolidates function-related tracking data.
|
|
47
54
|
type FunctionInfo struct {
|
|
48
55
|
IsAsync bool
|
|
49
56
|
NamedReturns []string
|
|
50
57
|
}
|
|
51
58
|
|
|
59
|
+
// ReflectedFunctionInfo tracks functions that need reflection support
|
|
60
|
+
type ReflectedFunctionInfo struct {
|
|
61
|
+
FuncType *types.Signature // The function's type signature
|
|
62
|
+
NeedsReflect bool // Whether this function is used with reflection
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
// NodeInfo consolidates node-related tracking data.
|
|
53
66
|
type NodeInfo struct {
|
|
54
67
|
NeedsDefer bool
|
|
@@ -84,6 +97,12 @@ type Analysis struct {
|
|
|
84
97
|
// FuncLitData tracks function literal specific data since they don't have types.Object
|
|
85
98
|
FuncLitData map[*ast.FuncLit]*FunctionInfo
|
|
86
99
|
|
|
100
|
+
// ReflectedFunctions tracks functions that need reflection type metadata
|
|
101
|
+
ReflectedFunctions map[ast.Node]*ReflectedFunctionInfo
|
|
102
|
+
|
|
103
|
+
// FunctionAssignments tracks which function literals are assigned to which variables
|
|
104
|
+
FunctionAssignments map[types.Object]ast.Node
|
|
105
|
+
|
|
87
106
|
// PackageMetadata holds package-level metadata
|
|
88
107
|
PackageMetadata map[string]interface{}
|
|
89
108
|
}
|
|
@@ -102,12 +121,14 @@ type PackageAnalysis struct {
|
|
|
102
121
|
// NewAnalysis creates a new Analysis instance.
|
|
103
122
|
func NewAnalysis() *Analysis {
|
|
104
123
|
return &Analysis{
|
|
105
|
-
VariableUsage:
|
|
106
|
-
Imports:
|
|
107
|
-
FunctionData:
|
|
108
|
-
NodeData:
|
|
109
|
-
FuncLitData:
|
|
110
|
-
|
|
124
|
+
VariableUsage: make(map[types.Object]*VariableUsageInfo),
|
|
125
|
+
Imports: make(map[string]*fileImport),
|
|
126
|
+
FunctionData: make(map[types.Object]*FunctionInfo),
|
|
127
|
+
NodeData: make(map[ast.Node]*NodeInfo),
|
|
128
|
+
FuncLitData: make(map[*ast.FuncLit]*FunctionInfo),
|
|
129
|
+
ReflectedFunctions: make(map[ast.Node]*ReflectedFunctionInfo),
|
|
130
|
+
FunctionAssignments: make(map[types.Object]ast.Node),
|
|
131
|
+
PackageMetadata: make(map[string]interface{}),
|
|
111
132
|
}
|
|
112
133
|
}
|
|
113
134
|
|
|
@@ -341,6 +362,10 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
|
|
|
341
362
|
// Case: var lhs = rhs_ident
|
|
342
363
|
assignmentType = DirectAssignment
|
|
343
364
|
sourceObj = v.pkg.TypesInfo.ObjectOf(rhsIdent)
|
|
365
|
+
} else if funcLit, ok := rhsExpr.(*ast.FuncLit); ok {
|
|
366
|
+
// Case: var lhs = func(...) { ... }
|
|
367
|
+
// Track function literal assignment
|
|
368
|
+
v.analysis.FunctionAssignments[lhsObj] = funcLit
|
|
344
369
|
}
|
|
345
370
|
|
|
346
371
|
// --- Record Usage ---
|
|
@@ -578,6 +603,9 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
|
|
|
578
603
|
}
|
|
579
604
|
}
|
|
580
605
|
|
|
606
|
+
// Check for reflect function calls that operate on functions
|
|
607
|
+
v.checkReflectUsage(n)
|
|
608
|
+
|
|
581
609
|
// Store async state for this call expression
|
|
582
610
|
if v.analysis.NodeData[n] == nil {
|
|
583
611
|
v.analysis.NodeData[n] = &NodeInfo{}
|
|
@@ -637,16 +665,21 @@ func (v *analysisVisitor) Visit(node ast.Node) ast.Visitor {
|
|
|
637
665
|
continue // Skip blank identifier assignments
|
|
638
666
|
}
|
|
639
667
|
lhsTrackedObj = v.pkg.TypesInfo.ObjectOf(lhsIdent)
|
|
668
|
+
|
|
669
|
+
// Check if RHS is a function literal and track the assignment
|
|
670
|
+
if funcLit, ok := currentRHSExpr.(*ast.FuncLit); ok {
|
|
671
|
+
v.analysis.FunctionAssignments[lhsTrackedObj] = funcLit
|
|
672
|
+
}
|
|
640
673
|
} else if selExpr, ok := currentLHSExpr.(*ast.SelectorExpr); ok {
|
|
641
674
|
// LHS is struct.field or package.Var
|
|
642
675
|
if selection := v.pkg.TypesInfo.Selections[selExpr]; selection != nil {
|
|
643
676
|
lhsTrackedObj = selection.Obj() // This is the field or selected var object
|
|
644
677
|
}
|
|
645
|
-
} else if _, ok := currentLHSExpr.(*ast.StarExpr); ok {
|
|
678
|
+
} /* else if _, ok := currentLHSExpr.(*ast.StarExpr); ok {
|
|
646
679
|
// LHS is *pointer.
|
|
647
680
|
// We don't try to get a types.Object for the dereferenced entity itself to store in VariableUsage.
|
|
648
681
|
// lhsTrackedObj remains nil. The effect on rhsSourceObj (if its address is taken) is handled below.
|
|
649
|
-
}
|
|
682
|
+
} */
|
|
650
683
|
// For other complex LHS (e.g., map_expr[key_expr]), lhsTrackedObj remains nil.
|
|
651
684
|
|
|
652
685
|
// --- Record Usage Information ---
|
|
@@ -1095,3 +1128,91 @@ func (a *Analysis) IsMethodAsync(pkgName, typeName, methodName string) bool {
|
|
|
1095
1128
|
|
|
1096
1129
|
return false
|
|
1097
1130
|
}
|
|
1131
|
+
|
|
1132
|
+
// NeedsReflectionMetadata returns whether the given function node needs reflection type metadata
|
|
1133
|
+
func (a *Analysis) NeedsReflectionMetadata(node ast.Node) bool {
|
|
1134
|
+
if node == nil {
|
|
1135
|
+
return false
|
|
1136
|
+
}
|
|
1137
|
+
reflectInfo := a.ReflectedFunctions[node]
|
|
1138
|
+
return reflectInfo != nil && reflectInfo.NeedsReflect
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// GetFunctionTypeInfo returns the function type information for reflection
|
|
1142
|
+
func (a *Analysis) GetFunctionTypeInfo(node ast.Node) *ReflectedFunctionInfo {
|
|
1143
|
+
if node == nil {
|
|
1144
|
+
return nil
|
|
1145
|
+
}
|
|
1146
|
+
return a.ReflectedFunctions[node]
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// MarkFunctionForReflection marks a function node as needing reflection support
|
|
1150
|
+
func (a *Analysis) MarkFunctionForReflection(node ast.Node, funcType *types.Signature) {
|
|
1151
|
+
if node == nil || funcType == nil {
|
|
1152
|
+
return
|
|
1153
|
+
}
|
|
1154
|
+
a.ReflectedFunctions[node] = &ReflectedFunctionInfo{
|
|
1155
|
+
FuncType: funcType,
|
|
1156
|
+
NeedsReflect: true,
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// checkReflectUsage checks for reflect function calls that operate on functions
|
|
1161
|
+
func (v *analysisVisitor) checkReflectUsage(callExpr *ast.CallExpr) {
|
|
1162
|
+
// Check if this is a reflect package function call
|
|
1163
|
+
if selExpr, ok := callExpr.Fun.(*ast.SelectorExpr); ok {
|
|
1164
|
+
// Check if the selector is from reflect package
|
|
1165
|
+
if ident, ok := selExpr.X.(*ast.Ident); ok {
|
|
1166
|
+
// Check if this is a reflect package call (reflect.TypeOf, reflect.ValueOf, etc.)
|
|
1167
|
+
if obj := v.pkg.TypesInfo.Uses[ident]; obj != nil {
|
|
1168
|
+
if pkgName, ok := obj.(*types.PkgName); ok && pkgName.Imported().Path() == "reflect" {
|
|
1169
|
+
methodName := selExpr.Sel.Name
|
|
1170
|
+
|
|
1171
|
+
// Check for reflect.TypeOf and reflect.ValueOf calls
|
|
1172
|
+
if methodName == "TypeOf" || methodName == "ValueOf" {
|
|
1173
|
+
// Check if any argument is a function
|
|
1174
|
+
for _, arg := range callExpr.Args {
|
|
1175
|
+
v.checkReflectArgument(arg)
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// checkReflectArgument checks if an argument to a reflect function is a function that needs metadata
|
|
1185
|
+
func (v *analysisVisitor) checkReflectArgument(arg ast.Expr) {
|
|
1186
|
+
// Check if the argument is an identifier (variable)
|
|
1187
|
+
if ident, ok := arg.(*ast.Ident); ok {
|
|
1188
|
+
// Get the object this identifier refers to
|
|
1189
|
+
if obj := v.pkg.TypesInfo.Uses[ident]; obj != nil {
|
|
1190
|
+
// Check if this object has a function type
|
|
1191
|
+
if funcType, ok := obj.Type().(*types.Signature); ok {
|
|
1192
|
+
// This is a function variable being passed to reflect
|
|
1193
|
+
// We need to find the original function definition/assignment
|
|
1194
|
+
v.markFunctionVariable(ident, funcType)
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
} else if funcLit, ok := arg.(*ast.FuncLit); ok {
|
|
1198
|
+
// This is a function literal being passed directly to reflect
|
|
1199
|
+
if funcType := v.pkg.TypesInfo.Types[funcLit].Type.(*types.Signature); funcType != nil {
|
|
1200
|
+
v.analysis.MarkFunctionForReflection(funcLit, funcType)
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// markFunctionVariable finds the function definition/assignment for a variable and marks it for reflection
|
|
1206
|
+
func (v *analysisVisitor) markFunctionVariable(ident *ast.Ident, funcType *types.Signature) {
|
|
1207
|
+
// Get the object for this identifier
|
|
1208
|
+
obj := v.pkg.TypesInfo.Uses[ident]
|
|
1209
|
+
if obj == nil {
|
|
1210
|
+
return
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
// Check if we have a tracked function assignment for this variable
|
|
1214
|
+
if funcNode := v.analysis.FunctionAssignments[obj]; funcNode != nil {
|
|
1215
|
+
// Mark the function node for reflection
|
|
1216
|
+
v.analysis.MarkFunctionForReflection(funcNode, funcType)
|
|
1217
|
+
}
|
|
1218
|
+
}
|
package/compiler/compiler.go
CHANGED
|
@@ -453,7 +453,10 @@ func (c *PackageCompiler) generateIndexFile(compiledFiles []string) error {
|
|
|
453
453
|
if strings.HasSuffix(fileName, ".pb") {
|
|
454
454
|
// For protobuf files, add a simple re-export
|
|
455
455
|
pbTsFileName := fileName + ".ts"
|
|
456
|
-
if err :=
|
|
456
|
+
if err := func() error {
|
|
457
|
+
var _ string = pbTsFileName
|
|
458
|
+
return c.writeProtobufExports(indexFile, fileName)
|
|
459
|
+
}(); err != nil {
|
|
457
460
|
return err
|
|
458
461
|
}
|
|
459
462
|
continue
|
|
@@ -503,14 +503,12 @@ func (c *GoToTSCompiler) WriteCompositeLit(exp *ast.CompositeLit) error {
|
|
|
503
503
|
case *types.Pointer:
|
|
504
504
|
// Handle pointer to composite literal
|
|
505
505
|
ptrType := underlying.(*types.Pointer)
|
|
506
|
-
elemType := ptrType.Elem().Underlying()
|
|
507
|
-
switch elemType.(type) {
|
|
506
|
+
switch elemType := ptrType.Elem().Underlying().(type) {
|
|
508
507
|
case *types.Struct:
|
|
509
508
|
// This is an anonymous struct literal with inferred pointer type
|
|
510
509
|
// Just create the struct object directly - no var-refing needed
|
|
511
510
|
// Anonymous literals are not variables, so they don't get var-refed
|
|
512
|
-
|
|
513
|
-
return c.writeUntypedStructLiteral(exp, structType) // true = anonymous
|
|
511
|
+
return c.writeUntypedStructLiteral(exp, elemType) // true = anonymous
|
|
514
512
|
default:
|
|
515
513
|
return fmt.Errorf("unhandled pointer composite literal element type: %T", elemType)
|
|
516
514
|
}
|
package/compiler/expr-call.go
CHANGED
|
@@ -1120,9 +1120,22 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
|
|
|
1120
1120
|
if i != 0 {
|
|
1121
1121
|
c.tsw.WriteLiterally(", ")
|
|
1122
1122
|
}
|
|
1123
|
+
// Check if this is the last argument and we have ellipsis (variadic call)
|
|
1124
|
+
if exp.Ellipsis != token.NoPos && i == len(exp.Args)-1 {
|
|
1125
|
+
c.tsw.WriteLiterally("...")
|
|
1126
|
+
}
|
|
1123
1127
|
if err := c.WriteValueExpr(arg); err != nil {
|
|
1124
1128
|
return fmt.Errorf("failed to write argument %d in call: %w", i, err)
|
|
1125
1129
|
}
|
|
1130
|
+
// Add non-null assertion for spread arguments that might be null
|
|
1131
|
+
if exp.Ellipsis != token.NoPos && i == len(exp.Args)-1 {
|
|
1132
|
+
// Check if the argument type is potentially nullable (slice)
|
|
1133
|
+
if argType := c.pkg.TypesInfo.TypeOf(arg); argType != nil {
|
|
1134
|
+
if _, isSlice := argType.Underlying().(*types.Slice); isSlice {
|
|
1135
|
+
c.tsw.WriteLiterally("!")
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1126
1139
|
}
|
|
1127
1140
|
c.tsw.WriteLiterally(")")
|
|
1128
1141
|
return nil // Handled regular function call
|
|
@@ -1206,9 +1219,22 @@ func (c *GoToTSCompiler) WriteCallExpr(exp *ast.CallExpr) error {
|
|
|
1206
1219
|
if i != 0 {
|
|
1207
1220
|
c.tsw.WriteLiterally(", ")
|
|
1208
1221
|
}
|
|
1222
|
+
// Check if this is the last argument and we have ellipsis (variadic call)
|
|
1223
|
+
if exp.Ellipsis != token.NoPos && i == len(exp.Args)-1 {
|
|
1224
|
+
c.tsw.WriteLiterally("...")
|
|
1225
|
+
}
|
|
1209
1226
|
if err := c.WriteValueExpr(arg); err != nil {
|
|
1210
1227
|
return fmt.Errorf("failed to write argument %d in call: %w", i, err)
|
|
1211
1228
|
}
|
|
1229
|
+
// Add non-null assertion for spread arguments that might be null
|
|
1230
|
+
if exp.Ellipsis != token.NoPos && i == len(exp.Args)-1 {
|
|
1231
|
+
// Check if the argument type is potentially nullable (slice)
|
|
1232
|
+
if argType := c.pkg.TypesInfo.TypeOf(arg); argType != nil {
|
|
1233
|
+
if _, isSlice := argType.Underlying().(*types.Slice); isSlice {
|
|
1234
|
+
c.tsw.WriteLiterally("!")
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1212
1238
|
}
|
|
1213
1239
|
c.tsw.WriteLiterally(")")
|
|
1214
1240
|
return nil
|
package/compiler/lit.go
CHANGED
|
@@ -101,6 +101,17 @@ func (c *GoToTSCompiler) WriteBasicLit(exp *ast.BasicLit) {
|
|
|
101
101
|
// - Wrapped in `Promise<>` if `async`.
|
|
102
102
|
// - The function body (`exp.Body`) is translated using `WriteStmt`.
|
|
103
103
|
func (c *GoToTSCompiler) WriteFuncLitValue(exp *ast.FuncLit) error {
|
|
104
|
+
// Check if this function needs reflection metadata
|
|
105
|
+
needsReflection := c.analysis.NeedsReflectionMetadata(exp)
|
|
106
|
+
|
|
107
|
+
if needsReflection {
|
|
108
|
+
// Start IIFE to attach metadata
|
|
109
|
+
c.tsw.WriteLiterally("(() => {")
|
|
110
|
+
c.tsw.Indent(1)
|
|
111
|
+
c.tsw.WriteLine("")
|
|
112
|
+
c.tsw.WriteLiterally("const fn = ")
|
|
113
|
+
}
|
|
114
|
+
|
|
104
115
|
// Determine if the function literal should be async
|
|
105
116
|
isAsync := c.analysis.IsFuncLitAsync(exp)
|
|
106
117
|
|
|
@@ -183,6 +194,78 @@ func (c *GoToTSCompiler) WriteFuncLitValue(exp *ast.FuncLit) error {
|
|
|
183
194
|
c.tsw.WriteLiterally("}")
|
|
184
195
|
}
|
|
185
196
|
|
|
197
|
+
// Add reflection metadata if needed
|
|
198
|
+
if needsReflection {
|
|
199
|
+
c.tsw.WriteLine("")
|
|
200
|
+
|
|
201
|
+
// Attach type metadata to the function
|
|
202
|
+
if err := c.writeReflectionMetadata(exp); err != nil {
|
|
203
|
+
return fmt.Errorf("failed to write reflection metadata: %w", err)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
c.tsw.WriteLine("return fn")
|
|
207
|
+
c.tsw.Indent(-1)
|
|
208
|
+
c.tsw.WriteLiterally("})()")
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return nil
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// writeReflectionMetadata attaches function type information to a function for reflection support
|
|
215
|
+
func (c *GoToTSCompiler) writeReflectionMetadata(exp *ast.FuncLit) error {
|
|
216
|
+
// Get the reflection info for this function
|
|
217
|
+
reflectInfo := c.analysis.GetFunctionTypeInfo(exp)
|
|
218
|
+
if reflectInfo == nil || reflectInfo.FuncType == nil {
|
|
219
|
+
return nil // No reflection info available
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
funcType := reflectInfo.FuncType
|
|
223
|
+
|
|
224
|
+
// Build FunctionTypeInfo metadata
|
|
225
|
+
c.tsw.WriteLiterally("fn.__typeInfo = {")
|
|
226
|
+
c.tsw.Indent(1)
|
|
227
|
+
c.tsw.WriteLine("")
|
|
228
|
+
c.tsw.WriteLiterally("kind: $.TypeKind.Function,")
|
|
229
|
+
c.tsw.WriteLine("")
|
|
230
|
+
|
|
231
|
+
// Add parameters
|
|
232
|
+
if funcType.Params() != nil && funcType.Params().Len() > 0 {
|
|
233
|
+
c.tsw.WriteLiterally("params: [")
|
|
234
|
+
for i := 0; i < funcType.Params().Len(); i++ {
|
|
235
|
+
if i > 0 {
|
|
236
|
+
c.tsw.WriteLiterally(", ")
|
|
237
|
+
}
|
|
238
|
+
param := funcType.Params().At(i)
|
|
239
|
+
c.tsw.WriteLiterallyf("'%s'", param.Type().String())
|
|
240
|
+
}
|
|
241
|
+
c.tsw.WriteLiterally("],")
|
|
242
|
+
c.tsw.WriteLine("")
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Add results
|
|
246
|
+
if funcType.Results() != nil && funcType.Results().Len() > 0 {
|
|
247
|
+
c.tsw.WriteLiterally("results: [")
|
|
248
|
+
for i := 0; i < funcType.Results().Len(); i++ {
|
|
249
|
+
if i > 0 {
|
|
250
|
+
c.tsw.WriteLiterally(", ")
|
|
251
|
+
}
|
|
252
|
+
result := funcType.Results().At(i)
|
|
253
|
+
c.tsw.WriteLiterallyf("'%s'", result.Type().String())
|
|
254
|
+
}
|
|
255
|
+
c.tsw.WriteLiterally("],")
|
|
256
|
+
c.tsw.WriteLine("")
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Add variadic flag
|
|
260
|
+
if funcType.Variadic() {
|
|
261
|
+
c.tsw.WriteLiterally("isVariadic: true,")
|
|
262
|
+
c.tsw.WriteLine("")
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
c.tsw.Indent(-1)
|
|
266
|
+
c.tsw.WriteLiterally("}")
|
|
267
|
+
c.tsw.WriteLine("")
|
|
268
|
+
|
|
186
269
|
return nil
|
|
187
270
|
}
|
|
188
271
|
|
package/compiler/protobuf.go
CHANGED
|
@@ -118,7 +118,7 @@ func (c *PackageCompiler) copyProtobufTSFile(sourcePath, fileName string) error
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// writeProtobufExports writes exports for a protobuf file to the index.ts file
|
|
121
|
-
func (c *PackageCompiler) writeProtobufExports(indexFile *os.File, fileName
|
|
121
|
+
func (c *PackageCompiler) writeProtobufExports(indexFile *os.File, fileName string) error {
|
|
122
122
|
// For protobuf files, we know they typically export message types
|
|
123
123
|
// For now, we'll use a simple heuristic: export all types that end with "Msg"
|
|
124
124
|
// In a full implementation, we would parse the .pb.ts file to extract actual exports
|
|
@@ -230,7 +230,7 @@ func (c *GoToTSCompiler) writeProtobufMarshalAssignment(lhs []ast.Expr, callExpr
|
|
|
230
230
|
|
|
231
231
|
// writeProtobufUnmarshalAssignment handles: err = out.UnmarshalVT(data)
|
|
232
232
|
// Generates: out = ExampleMsg.fromBinary(data); err = null;
|
|
233
|
-
func (c *GoToTSCompiler) writeProtobufUnmarshalAssignment(lhs []ast.Expr, callExpr *ast.CallExpr
|
|
233
|
+
func (c *GoToTSCompiler) writeProtobufUnmarshalAssignment(lhs []ast.Expr, callExpr *ast.CallExpr) error {
|
|
234
234
|
if len(lhs) != 1 {
|
|
235
235
|
return fmt.Errorf("protobuf unmarshal assignment requires exactly 1 LHS variable, got %d", len(lhs))
|
|
236
236
|
}
|
package/compiler/spec-value.go
CHANGED
|
@@ -233,14 +233,14 @@ func (c *GoToTSCompiler) WriteValueSpec(a *ast.ValueSpec) error {
|
|
|
233
233
|
if c.hasReceiverMethods(typeName) {
|
|
234
234
|
// Check if the initializer is a basic literal or simple value that needs wrapping
|
|
235
235
|
needsConstructor := false
|
|
236
|
-
switch initializerExpr.(type) {
|
|
236
|
+
switch expr := initializerExpr.(type) {
|
|
237
237
|
case *ast.BasicLit:
|
|
238
238
|
needsConstructor = true
|
|
239
239
|
case *ast.Ident:
|
|
240
240
|
// Check if it's a simple identifier (not a function call or complex expression)
|
|
241
|
-
if
|
|
241
|
+
if expr.Name != "nil" {
|
|
242
242
|
// Check if this identifier refers to a value of the underlying type
|
|
243
|
-
if obj := c.pkg.TypesInfo.Uses[
|
|
243
|
+
if obj := c.pkg.TypesInfo.Uses[expr]; obj != nil {
|
|
244
244
|
if objType := obj.Type(); objType != nil {
|
|
245
245
|
// If the identifier's type matches the underlying type, wrap it
|
|
246
246
|
if types.Identical(objType, namedType.Underlying()) {
|
package/compiler/spec.go
CHANGED
|
@@ -45,7 +45,10 @@ func (c *GoToTSCompiler) getEmbeddedFieldKeyName(fieldType types.Type) string {
|
|
|
45
45
|
return named.Obj().Name()
|
|
46
46
|
} else {
|
|
47
47
|
// Fallback for unnamed embedded types, though less common for structs
|
|
48
|
-
fieldKeyName :=
|
|
48
|
+
fieldKeyName := trueType.String()
|
|
49
|
+
if len(fieldKeyName) > 0 {
|
|
50
|
+
fieldKeyName = strings.ToUpper(fieldKeyName[:1]) + fieldKeyName[1:]
|
|
51
|
+
}
|
|
49
52
|
if dotIndex := strings.LastIndex(fieldKeyName, "."); dotIndex != -1 {
|
|
50
53
|
fieldKeyName = fieldKeyName[dotIndex+1:]
|
|
51
54
|
}
|
|
@@ -95,7 +98,7 @@ func (c *GoToTSCompiler) writeVarRefedFieldInitializer(fieldName string, fieldTy
|
|
|
95
98
|
if named, ok := fieldType.(*types.Named); ok {
|
|
96
99
|
if _, isStruct := named.Underlying().(*types.Struct); isStruct {
|
|
97
100
|
isStructValueType = true
|
|
98
|
-
structTypeNameForClone =
|
|
101
|
+
structTypeNameForClone = c.getTypeString(fieldType)
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
|
|
@@ -261,7 +264,7 @@ func (c *GoToTSCompiler) WriteNamedTypeWithMethods(a *ast.TypeSpec) error {
|
|
|
261
264
|
|
|
262
265
|
if recvTypeName == className {
|
|
263
266
|
c.tsw.WriteLine("")
|
|
264
|
-
if err := c.writeNamedTypeMethod(funcDecl
|
|
267
|
+
if err := c.writeNamedTypeMethod(funcDecl); err != nil {
|
|
265
268
|
return err
|
|
266
269
|
}
|
|
267
270
|
}
|
|
@@ -275,7 +278,7 @@ func (c *GoToTSCompiler) WriteNamedTypeWithMethods(a *ast.TypeSpec) error {
|
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
// writeNamedTypeMethod writes a method for a named type, handling receiver binding properly
|
|
278
|
-
func (c *GoToTSCompiler) writeNamedTypeMethod(decl *ast.FuncDecl
|
|
281
|
+
func (c *GoToTSCompiler) writeNamedTypeMethod(decl *ast.FuncDecl) error {
|
|
279
282
|
if decl.Doc != nil {
|
|
280
283
|
c.WriteDoc(decl.Doc)
|
|
281
284
|
}
|
package/compiler/stmt-assign.go
CHANGED
|
@@ -469,7 +469,7 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
469
469
|
if callExpr, ok := exp.Rhs[0].(*ast.CallExpr); ok {
|
|
470
470
|
// Handle protobuf UnmarshalVT: err = out.UnmarshalVT(data)
|
|
471
471
|
if c.isProtobufMethodCall(callExpr, "UnmarshalVT") {
|
|
472
|
-
return c.writeProtobufUnmarshalAssignment(exp.Lhs, callExpr
|
|
472
|
+
return c.writeProtobufUnmarshalAssignment(exp.Lhs, callExpr)
|
|
473
473
|
}
|
|
474
474
|
// Handle protobuf UnmarshalJSON: err = out.UnmarshalJSON(data)
|
|
475
475
|
if c.isProtobufMethodCall(callExpr, "UnmarshalJSON") {
|
package/compiler/stmt.go
CHANGED
|
@@ -170,10 +170,16 @@ func (c *GoToTSCompiler) WriteStmtBranch(stmt *ast.BranchStmt) error {
|
|
|
170
170
|
c.tsw.WriteLine("break") // No semicolon needed
|
|
171
171
|
case token.CONTINUE:
|
|
172
172
|
c.tsw.WriteLine("continue") // No semicolon needed
|
|
173
|
+
case token.GOTO:
|
|
174
|
+
// TypeScript doesn't support goto, but we can handle it by skipping it
|
|
175
|
+
// since the labeled statement restructuring should handle the control flow
|
|
176
|
+
c.tsw.WriteCommentLinef("goto %s // goto statement skipped", stmt.Label.Name)
|
|
177
|
+
case token.FALLTHROUGH:
|
|
178
|
+
// Fallthrough is handled in switch statements, should not appear elsewhere
|
|
179
|
+
c.tsw.WriteCommentLinef("fallthrough // fallthrough statement skipped")
|
|
173
180
|
default:
|
|
174
181
|
// This case should ideally not be reached if the Go parser is correct,
|
|
175
182
|
// as ast.BranchStmt only covers break, continue, goto, fallthrough.
|
|
176
|
-
// 'goto' and 'fallthrough' are handled elsewhere or not supported.
|
|
177
183
|
c.tsw.WriteCommentLinef("unhandled branch statement token: %s", stmt.Tok.String())
|
|
178
184
|
}
|
|
179
185
|
return nil
|
|
@@ -855,17 +861,29 @@ func (c *GoToTSCompiler) WriteStmtDefer(exp *ast.DeferStmt) error {
|
|
|
855
861
|
// WriteStmtLabeled handles labeled statements (ast.LabeledStmt), such as "label: statement".
|
|
856
862
|
// In TypeScript, labels cannot be used with variable declarations, so we need to handle this case specially.
|
|
857
863
|
func (c *GoToTSCompiler) WriteStmtLabeled(stmt *ast.LabeledStmt) error {
|
|
858
|
-
// Check if the labeled statement is a declaration statement
|
|
859
|
-
|
|
860
|
-
|
|
864
|
+
// Check if the labeled statement is a declaration statement or assignment with :=
|
|
865
|
+
needsBlock := false
|
|
866
|
+
if _, ok := stmt.Stmt.(*ast.DeclStmt); ok {
|
|
867
|
+
needsBlock = true
|
|
868
|
+
} else if assignStmt, ok := stmt.Stmt.(*ast.AssignStmt); ok && assignStmt.Tok == token.DEFINE {
|
|
869
|
+
// Assignment with := is also a declaration and needs special handling
|
|
870
|
+
needsBlock = true
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
if needsBlock {
|
|
874
|
+
// For declaration statements and := assignments, we need to put the label on a separate line
|
|
861
875
|
// because TypeScript doesn't allow labels with declarations
|
|
862
876
|
c.tsw.WriteLiterally(stmt.Label.Name)
|
|
863
|
-
c.tsw.WriteLine(": {
|
|
877
|
+
c.tsw.WriteLine(": {")
|
|
878
|
+
c.tsw.Indent(1)
|
|
864
879
|
|
|
865
|
-
// Write the
|
|
866
|
-
if err := c.WriteStmt(
|
|
867
|
-
return fmt.Errorf("failed to write labeled declaration statement: %w", err)
|
|
880
|
+
// Write the statement without the label
|
|
881
|
+
if err := c.WriteStmt(stmt.Stmt); err != nil {
|
|
882
|
+
return fmt.Errorf("failed to write labeled declaration/assignment statement: %w", err)
|
|
868
883
|
}
|
|
884
|
+
|
|
885
|
+
c.tsw.Indent(-1)
|
|
886
|
+
c.tsw.WriteLine("}")
|
|
869
887
|
} else {
|
|
870
888
|
// For non-declaration statements, write the label normally
|
|
871
889
|
c.tsw.WriteLiterally(stmt.Label.Name)
|
package/dist/gs/builtin/slice.js
CHANGED
|
@@ -819,8 +819,9 @@ export const sliceString = (str, low, high) => {
|
|
|
819
819
|
// Attempt to decode with strict UTF-8 validation
|
|
820
820
|
const result = new TextDecoder('utf-8', { fatal: true }).decode(slicedBytes);
|
|
821
821
|
return result;
|
|
822
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
822
823
|
}
|
|
823
|
-
catch (_e) {
|
|
824
|
+
catch (_e) {
|
|
824
825
|
// If we get here, the slice would create invalid UTF-8
|
|
825
826
|
// This is a fundamental limitation of JavaScript string handling
|
|
826
827
|
throw new Error(`Cannot slice string at byte indices [${actualLow}:${actualHigh}] because it would create invalid UTF-8. ` +
|