goscript 0.0.84 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -243
- package/cmd/goscript/cmd-test.go +193 -0
- package/cmd/goscript/cmd-test_test.go +76 -0
- package/cmd/goscript/cmd_compile.go +70 -69
- package/cmd/goscript/cmd_compile_test.go +79 -0
- package/cmd/goscript/main.go +11 -5
- package/compiler/build-flags.go +38 -0
- package/compiler/compile-request.go +220 -0
- package/compiler/compiler.go +16 -1336
- package/compiler/compliance_test.go +188 -0
- package/compiler/config.go +6 -13
- package/compiler/diagnostic.go +70 -0
- package/compiler/gotest/owner.go +24 -0
- package/compiler/gotest/package-result.go +67 -0
- package/compiler/gotest/request.go +145 -0
- package/compiler/gotest/result.go +28 -0
- package/compiler/gotest/runner.go +588 -0
- package/compiler/gotest/runner_test.go +627 -0
- package/compiler/gotest/test.go +9 -0
- package/compiler/index.test.ts +28 -28
- package/compiler/index.ts +40 -72
- package/compiler/lowered-program.go +184 -0
- package/compiler/lowering.go +8072 -0
- package/compiler/override-facts.go +307 -0
- package/compiler/override-registry.go +283 -0
- package/compiler/override-registry_test.go +254 -0
- package/compiler/package-graph.go +254 -0
- package/compiler/package-graph_test.go +316 -0
- package/compiler/package-test-function.go +9 -0
- package/compiler/package-test-graph-package.go +40 -0
- package/compiler/package-test-graph-variant.go +105 -0
- package/compiler/package-test-graph.go +117 -0
- package/compiler/package-test-graph_test.go +144 -0
- package/compiler/result.go +13 -0
- package/compiler/runtime-contract.go +439 -0
- package/compiler/runtime-contract_test.go +104 -0
- package/compiler/semantic-model-types.go +113 -0
- package/compiler/semantic-model.go +1422 -0
- package/compiler/semantic-model_test.go +471 -0
- package/compiler/service.go +133 -0
- package/compiler/skeleton_test.go +1775 -0
- package/compiler/tsworkspace/owner.go +334 -0
- package/compiler/tsworkspace/owner_test.go +93 -0
- package/compiler/tsworkspace/result.go +17 -0
- package/compiler/typescript-emitter.go +1040 -0
- package/compiler/wasm/compile.go +2 -3
- package/compiler/wasm/compile_test.go +79 -0
- package/compiler/wasm_api.go +140 -124
- package/dist/compiler/index.d.ts +1 -3
- package/dist/compiler/index.js +31 -55
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/builtin/builtin.d.ts +33 -2
- package/dist/gs/builtin/builtin.js +217 -6
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +11 -3
- package/dist/gs/builtin/channel.js +12 -0
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/hostio.d.ts +15 -1
- package/dist/gs/builtin/hostio.js +134 -49
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/index.d.ts +1 -0
- package/dist/gs/builtin/index.js +1 -0
- package/dist/gs/builtin/index.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +23 -3
- package/dist/gs/builtin/slice.js +216 -44
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +16 -2
- package/dist/gs/builtin/type.js +134 -21
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +5 -0
- package/dist/gs/builtin/varRef.js +23 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +48 -44
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.js +20 -18
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/context/context.d.ts +5 -4
- package/dist/gs/context/context.js +10 -10
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js.map +1 -0
- package/dist/gs/crypto/rand/index.d.ts +5 -0
- package/dist/gs/crypto/rand/index.js +77 -0
- package/dist/gs/crypto/rand/index.js.map +1 -0
- package/dist/gs/embed/index.d.ts +7 -0
- package/dist/gs/embed/index.js +16 -0
- package/dist/gs/embed/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +4 -0
- package/dist/gs/encoding/json/index.js +178 -0
- package/dist/gs/encoding/json/index.js.map +1 -0
- package/dist/gs/errors/errors.d.ts +4 -0
- package/dist/gs/errors/errors.js +81 -0
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +4 -4
- package/dist/gs/fmt/fmt.js +42 -11
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +36 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +212 -2
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.d.ts +189 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +825 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +163 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +449 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
- package/dist/gs/github.com/klauspost/compress/internal/le/index.d.ts +9 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +71 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/go/internal/scannerhooks/index.d.ts +3 -0
- package/dist/gs/go/internal/scannerhooks/index.js +5 -0
- package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
- package/dist/gs/go/scanner/index.d.ts +42 -0
- package/dist/gs/go/scanner/index.js +155 -0
- package/dist/gs/go/scanner/index.js.map +1 -0
- package/dist/gs/go/token/index.d.ts +187 -0
- package/dist/gs/go/token/index.js +578 -0
- package/dist/gs/go/token/index.js.map +1 -0
- package/dist/gs/internal/abi/index.d.ts +4 -0
- package/dist/gs/internal/abi/index.js +10 -0
- package/dist/gs/internal/abi/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +14 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +8 -2
- package/dist/gs/internal/byteorder/index.js +56 -25
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/godebug/index.d.ts +12 -0
- package/dist/gs/internal/godebug/index.js +30 -0
- package/dist/gs/internal/godebug/index.js.map +1 -0
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/fs/index.d.ts +1 -0
- package/dist/gs/io/fs/index.js +1 -0
- package/dist/gs/io/fs/index.js.map +1 -1
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readfile.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +8 -0
- package/dist/gs/io/fs/readlink.js +64 -0
- package/dist/gs/io/fs/readlink.js.map +1 -0
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.d.ts +3 -3
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +40 -6
- package/dist/gs/io/io.js +151 -26
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +3 -3
- package/dist/gs/maps/iter.js +3 -3
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +2 -2
- package/dist/gs/maps/maps.js +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +13 -4
- package/dist/gs/math/bits/index.js +66 -34
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/const.gs.d.ts +5 -5
- package/dist/gs/math/const.gs.js +4 -4
- package/dist/gs/math/const.gs.js.map +1 -1
- package/dist/gs/mime/index.d.ts +1 -0
- package/dist/gs/mime/index.js +50 -0
- package/dist/gs/mime/index.js.map +1 -0
- package/dist/gs/net/http/httptest/index.d.ts +11 -0
- package/dist/gs/net/http/httptest/index.js +21 -0
- package/dist/gs/net/http/httptest/index.js.map +1 -0
- package/dist/gs/net/http/index.d.ts +27 -0
- package/dist/gs/net/http/index.js +61 -0
- package/dist/gs/net/http/index.js.map +1 -0
- package/dist/gs/os/dir_unix.gs.js +2 -2
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- package/dist/gs/os/error.gs.js +2 -4
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/exec.gs.js.map +1 -1
- package/dist/gs/os/exec_posix.gs.js.map +1 -1
- package/dist/gs/os/rawconn_js.gs.js.map +1 -1
- package/dist/gs/os/root_js.gs.js.map +1 -1
- package/dist/gs/os/tempfile.gs.js +66 -9
- package/dist/gs/os/tempfile.gs.js.map +1 -1
- package/dist/gs/os/types.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js +9 -9
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js +165 -3
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +3 -1
- package/dist/gs/path/filepath/path.js +133 -4
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/path/path.d.ts +4 -1
- package/dist/gs/path/path.js +16 -4
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +3 -3
- package/dist/gs/reflect/index.js +2 -2
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +3 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +9 -5
- package/dist/gs/reflect/type.js +233 -21
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +2 -0
- package/dist/gs/runtime/debug/index.js +8 -0
- package/dist/gs/runtime/debug/index.js.map +1 -0
- package/dist/gs/runtime/runtime.d.ts +35 -3
- package/dist/gs/runtime/runtime.js +72 -0
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/slices/slices.d.ts +24 -5
- package/dist/gs/slices/slices.js +214 -5
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +3 -3
- package/dist/gs/sort/slice.gs.js +6 -6
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/sort/sort.gs.d.ts +4 -4
- package/dist/gs/sort/sort.gs.js +11 -8
- package/dist/gs/sort/sort.gs.js.map +1 -1
- package/dist/gs/strconv/atoi.gs.js.map +1 -1
- package/dist/gs/strconv/quote.gs.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +3 -2
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +9 -8
- package/dist/gs/sync/atomic/type.gs.js +0 -2
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/atomic/value.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +3 -0
- package/dist/gs/sync/sync.js +39 -0
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/constants.d.ts +36 -24
- package/dist/gs/syscall/constants.js +12 -0
- package/dist/gs/syscall/constants.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +2 -0
- package/dist/gs/syscall/errors.js +8 -0
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +43 -0
- package/dist/gs/syscall/fs.js +102 -0
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.d.ts +90 -0
- package/dist/gs/syscall/js/index.js +375 -0
- package/dist/gs/syscall/js/index.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +22 -0
- package/dist/gs/syscall/types.js +45 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/index.d.ts +1 -0
- package/dist/gs/testing/index.js +2 -0
- package/dist/gs/testing/index.js.map +1 -0
- package/dist/gs/testing/testing.d.ts +77 -0
- package/dist/gs/testing/testing.js +301 -0
- package/dist/gs/testing/testing.js.map +1 -0
- package/dist/gs/time/time.d.ts +41 -4
- package/dist/gs/time/time.js +205 -36
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.d.ts +23 -1
- package/dist/gs/unicode/unicode.js +79 -10
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
- package/dist/gs/unicode/utf8/utf8.js +24 -11
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unique/index.d.ts +11 -0
- package/dist/gs/unique/index.js +71 -0
- package/dist/gs/unique/index.js.map +1 -0
- package/go.mod +2 -2
- package/go.sum +9 -0
- package/gs/builtin/builtin.ts +266 -8
- package/gs/builtin/channel.ts +22 -0
- package/gs/builtin/hostio.test.ts +177 -0
- package/gs/builtin/hostio.ts +171 -56
- package/gs/builtin/index.ts +1 -0
- package/gs/builtin/runtime-contract.test.ts +356 -0
- package/gs/builtin/slice.ts +259 -50
- package/gs/builtin/type.ts +188 -30
- package/gs/builtin/varRef.ts +38 -1
- package/gs/bytes/buffer.gs.ts +48 -44
- package/gs/bytes/meta.json +8 -3
- package/gs/bytes/reader.gs.ts +20 -19
- package/gs/context/context.test.ts +41 -0
- package/gs/context/context.ts +22 -26
- package/gs/crypto/internal/fips140deps/byteorder/index.ts +1 -0
- package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -0
- package/gs/crypto/rand/index.test.ts +32 -0
- package/gs/crypto/rand/index.ts +90 -0
- package/gs/crypto/rand/meta.json +5 -0
- package/gs/embed/index.ts +20 -0
- package/gs/embed/meta.json +5 -0
- package/gs/encoding/json/index.test.ts +79 -0
- package/gs/encoding/json/index.ts +210 -0
- package/gs/errors/errors.test.ts +82 -0
- package/gs/errors/errors.ts +104 -0
- package/gs/fmt/fmt.ts +56 -16
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +95 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +300 -2
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +159 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1005 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +719 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +40 -0
- package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/meta.json +3 -1
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +36 -0
- package/gs/github.com/klauspost/compress/internal/le/index.ts +114 -0
- package/gs/go/internal/scannerhooks/index.test.ts +14 -0
- package/gs/go/internal/scannerhooks/index.ts +9 -0
- package/gs/go/scanner/index.test.ts +72 -0
- package/gs/go/scanner/index.ts +204 -0
- package/gs/go/token/index.test.ts +67 -0
- package/gs/go/token/index.ts +686 -0
- package/gs/internal/abi/index.test.ts +18 -0
- package/gs/internal/abi/index.ts +14 -0
- package/gs/internal/bytealg/index.test.ts +18 -0
- package/gs/internal/bytealg/index.ts +16 -0
- package/gs/internal/byteorder/index.test.ts +39 -0
- package/gs/internal/byteorder/index.ts +100 -27
- package/gs/internal/godebug/index.test.ts +16 -0
- package/gs/internal/godebug/index.ts +35 -0
- package/gs/io/fs/index.ts +1 -0
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readlink.test.ts +43 -0
- package/gs/io/fs/readlink.ts +77 -0
- package/gs/io/fs/walk.test.ts +61 -0
- package/gs/io/fs/walk.ts +9 -9
- package/gs/io/io.ts +174 -31
- package/gs/io/meta.json +10 -2
- package/gs/maps/iter.ts +12 -6
- package/gs/maps/maps.ts +8 -6
- package/gs/math/bits/index.ts +103 -47
- package/gs/math/const.gs.test.ts +11 -5
- package/gs/math/const.gs.ts +5 -6
- package/gs/mime/index.ts +54 -0
- package/gs/net/http/httptest/index.ts +25 -0
- package/gs/net/http/index.test.ts +20 -0
- package/gs/net/http/index.ts +81 -0
- package/gs/os/dir_unix.gs.ts +2 -3
- package/gs/os/file_unix_js.test.ts +50 -0
- package/gs/os/meta.json +1 -2
- package/gs/os/tempfile.gs.test.ts +85 -0
- package/gs/os/tempfile.gs.ts +71 -11
- package/gs/os/types_js.gs.ts +11 -11
- package/gs/path/filepath/match.test.ts +31 -12
- package/gs/path/filepath/match.ts +178 -3
- package/gs/path/filepath/path.test.ts +25 -0
- package/gs/path/filepath/path.ts +159 -5
- package/gs/path/path.ts +20 -5
- package/gs/reflect/index.ts +2 -1
- package/gs/reflect/map.test.ts +19 -0
- package/gs/reflect/map.ts +4 -0
- package/gs/reflect/type.ts +298 -29
- package/gs/reflect/typefor.test.ts +75 -0
- package/gs/runtime/debug/index.test.ts +24 -0
- package/gs/runtime/debug/index.ts +8 -0
- package/gs/runtime/runtime.test.ts +19 -0
- package/gs/runtime/runtime.ts +98 -3
- package/gs/slices/slices.test.ts +94 -0
- package/gs/slices/slices.ts +245 -5
- package/gs/sort/meta.json +7 -0
- package/gs/sort/slice.gs.ts +16 -7
- package/gs/sort/sort.gs.ts +16 -13
- package/gs/strings/builder.ts +4 -3
- package/gs/sync/atomic/type.gs.ts +13 -14
- package/gs/sync/meta.json +3 -1
- package/gs/sync/sync.test.ts +36 -0
- package/gs/sync/sync.ts +39 -0
- package/gs/syscall/constants.ts +39 -24
- package/gs/syscall/errors.ts +10 -0
- package/gs/syscall/fs.ts +195 -0
- package/gs/syscall/js/index.ts +458 -0
- package/gs/syscall/js/meta.json +4 -0
- package/gs/syscall/net.test.ts +85 -0
- package/gs/syscall/types.ts +56 -0
- package/gs/testing/index.ts +1 -0
- package/gs/testing/meta.json +5 -0
- package/gs/testing/testing.test.ts +90 -0
- package/gs/testing/testing.ts +382 -0
- package/gs/time/time.test.ts +106 -0
- package/gs/time/time.ts +278 -57
- package/gs/unicode/unicode.test.ts +25 -0
- package/gs/unicode/unicode.ts +119 -9
- package/gs/unicode/utf8/utf8.test.ts +13 -0
- package/gs/unicode/utf8/utf8.ts +28 -16
- package/gs/unique/index.ts +91 -0
- package/package.json +14 -13
- package/compiler/analysis.go +0 -3475
- package/compiler/analysis_test.go +0 -338
- package/compiler/assignment.go +0 -580
- package/compiler/builtin_test.go +0 -92
- package/compiler/code-writer.go +0 -115
- package/compiler/compiler_test.go +0 -149
- package/compiler/composite-lit.go +0 -779
- package/compiler/config_test.go +0 -62
- package/compiler/constraint.go +0 -86
- package/compiler/decl.go +0 -801
- package/compiler/expr-call-async.go +0 -188
- package/compiler/expr-call-builtins.go +0 -208
- package/compiler/expr-call-helpers.go +0 -382
- package/compiler/expr-call-make.go +0 -318
- package/compiler/expr-call-type-conversion.go +0 -520
- package/compiler/expr-call.go +0 -413
- package/compiler/expr-selector.go +0 -343
- package/compiler/expr-star.go +0 -82
- package/compiler/expr-type.go +0 -442
- package/compiler/expr-value.go +0 -89
- package/compiler/expr.go +0 -773
- package/compiler/field.go +0 -183
- package/compiler/gs_dependencies_test.go +0 -298
- package/compiler/lit.go +0 -322
- package/compiler/output.go +0 -72
- package/compiler/primitive.go +0 -149
- package/compiler/protobuf.go +0 -697
- package/compiler/sanitize.go +0 -100
- package/compiler/spec-struct.go +0 -995
- package/compiler/spec-value.go +0 -540
- package/compiler/spec.go +0 -725
- package/compiler/stmt-assign.go +0 -664
- package/compiler/stmt-for.go +0 -266
- package/compiler/stmt-range.go +0 -475
- package/compiler/stmt-select.go +0 -262
- package/compiler/stmt-type-switch.go +0 -147
- package/compiler/stmt.go +0 -1308
- package/compiler/type-assert.go +0 -386
- package/compiler/type-info.go +0 -156
- package/compiler/type-utils.go +0 -207
- package/compiler/type.go +0 -892
package/gs/math/const.gs.ts
CHANGED
|
@@ -47,10 +47,10 @@ export let SmallestNonzeroFloat64: number = Number.MIN_VALUE
|
|
|
47
47
|
let intSize: number = (32 << ((~(0 as number) >> 63)))
|
|
48
48
|
|
|
49
49
|
// MaxInt32 or MaxInt64 depending on intSize.
|
|
50
|
-
export let MaxInt:
|
|
50
|
+
export let MaxInt: number = 9223372036854775807
|
|
51
51
|
|
|
52
52
|
// MinInt32 or MinInt64 depending on intSize.
|
|
53
|
-
export let MinInt:
|
|
53
|
+
export let MinInt: number = -9223372036854775808
|
|
54
54
|
|
|
55
55
|
// 127
|
|
56
56
|
export let MaxInt8: number = 127
|
|
@@ -71,10 +71,10 @@ export let MaxInt32: number = 2147483647
|
|
|
71
71
|
export let MinInt32: number = -2147483648
|
|
72
72
|
|
|
73
73
|
// 9223372036854775807
|
|
74
|
-
export let MaxInt64:
|
|
74
|
+
export let MaxInt64: number = 9223372036854775807
|
|
75
75
|
|
|
76
76
|
// -9223372036854775808
|
|
77
|
-
export let MinInt64:
|
|
77
|
+
export let MinInt64: number = -9223372036854775808
|
|
78
78
|
|
|
79
79
|
// MaxUint32 or MaxUint64 depending on intSize.
|
|
80
80
|
export let MaxUint: bigint = 0xFFFFFFFFFFFFFFFFn
|
|
@@ -89,5 +89,4 @@ export let MaxUint16: number = 65535
|
|
|
89
89
|
export let MaxUint32: number = 4294967295
|
|
90
90
|
|
|
91
91
|
// 18446744073709551615
|
|
92
|
-
export let MaxUint64: bigint = 0xFFFFFFFFFFFFFFFFn
|
|
93
|
-
|
|
92
|
+
export let MaxUint64: number | bigint = 0xFFFFFFFFFFFFFFFFn
|
package/gs/mime/index.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export function FormatMediaType(t: string, param: Map<string, string> | Record<string, string> | null): string {
|
|
2
|
+
if (!isToken(t)) {
|
|
3
|
+
return ''
|
|
4
|
+
}
|
|
5
|
+
let out = t
|
|
6
|
+
const entries = param instanceof Map ? Array.from(param.entries()) : Object.entries(param ?? {})
|
|
7
|
+
entries.sort(([a], [b]) => a.localeCompare(b))
|
|
8
|
+
for (const [key, value] of entries) {
|
|
9
|
+
if (!isToken(key)) {
|
|
10
|
+
return ''
|
|
11
|
+
}
|
|
12
|
+
out += formatParam(key, String(value))
|
|
13
|
+
}
|
|
14
|
+
return out
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function formatParam(key: string, value: string): string {
|
|
18
|
+
if (isToken(value)) {
|
|
19
|
+
return `; ${key}=${value}`
|
|
20
|
+
}
|
|
21
|
+
return `; ${key}*=utf-8''${percentEncode(value)}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isToken(value: string): boolean {
|
|
25
|
+
return /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function percentEncode(value: string): string {
|
|
29
|
+
let out = ''
|
|
30
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
31
|
+
if (
|
|
32
|
+
(byte >= 0x30 && byte <= 0x39) ||
|
|
33
|
+
(byte >= 0x41 && byte <= 0x5a) ||
|
|
34
|
+
(byte >= 0x61 && byte <= 0x7a) ||
|
|
35
|
+
byte === 0x21 ||
|
|
36
|
+
byte === 0x23 ||
|
|
37
|
+
byte === 0x24 ||
|
|
38
|
+
byte === 0x26 ||
|
|
39
|
+
byte === 0x2b ||
|
|
40
|
+
byte === 0x2d ||
|
|
41
|
+
byte === 0x2e ||
|
|
42
|
+
byte === 0x5e ||
|
|
43
|
+
byte === 0x5f ||
|
|
44
|
+
byte === 0x60 ||
|
|
45
|
+
byte === 0x7c ||
|
|
46
|
+
byte === 0x7e
|
|
47
|
+
) {
|
|
48
|
+
out += String.fromCharCode(byte)
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
out += `%${byte.toString(16).toUpperCase().padStart(2, '0')}`
|
|
52
|
+
}
|
|
53
|
+
return out
|
|
54
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
import * as http from '@goscript/net/http/index.js'
|
|
3
|
+
|
|
4
|
+
export class ResponseRecorder implements http.ResponseWriter {
|
|
5
|
+
public Code = 200
|
|
6
|
+
public Body: $.Slice<number> = null
|
|
7
|
+
private headerMap = new http.Header()
|
|
8
|
+
|
|
9
|
+
public Header(): http.Header {
|
|
10
|
+
return this.headerMap
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public Write(p: $.Slice<number>): [number, $.GoError] {
|
|
14
|
+
this.Body = $.append(this.Body, p)
|
|
15
|
+
return [$.len(p), null]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public WriteHeader(statusCode: number): void {
|
|
19
|
+
this.Code = statusCode
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function NewRecorder(): ResponseRecorder {
|
|
24
|
+
return new ResponseRecorder()
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Get, Response, StatusOK, StatusText } from './index.js'
|
|
4
|
+
|
|
5
|
+
describe('net/http override', () => {
|
|
6
|
+
it('exports response status helpers', () => {
|
|
7
|
+
const resp = new Response({ StatusCode: StatusOK })
|
|
8
|
+
|
|
9
|
+
expect(resp.StatusCode).toBe(200)
|
|
10
|
+
expect(StatusText(resp.StatusCode)).toBe('OK')
|
|
11
|
+
expect(StatusText(599)).toBe('')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('returns an explicit unsupported error for Get', () => {
|
|
15
|
+
const [resp, err] = Get('https://example.invalid')
|
|
16
|
+
|
|
17
|
+
expect(resp).toBeNull()
|
|
18
|
+
expect(err?.Error()).toBe('net/http: Get is not implemented in GoScript')
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
import * as errors from '@goscript/errors/index.js'
|
|
3
|
+
import * as io from '@goscript/io/index.js'
|
|
4
|
+
|
|
5
|
+
export const StatusOK = 200
|
|
6
|
+
|
|
7
|
+
export function StatusText(code: number): string {
|
|
8
|
+
switch (code) {
|
|
9
|
+
case StatusOK:
|
|
10
|
+
return 'OK'
|
|
11
|
+
default:
|
|
12
|
+
return ''
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Header extends Map<string, $.Slice<string>> {
|
|
17
|
+
public Add(key: string, value: string): void {
|
|
18
|
+
const values = Array.from(this.get(key) ?? [])
|
|
19
|
+
values.push(value)
|
|
20
|
+
this.set(key, $.arrayToSlice(values))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public Del(key: string): void {
|
|
24
|
+
this.delete(key)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public Get(key: string): string {
|
|
28
|
+
const values = this.get(key)
|
|
29
|
+
return values == null || values.length === 0 ? '' : String(values[0])
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public Set(key: string, value: string): void {
|
|
33
|
+
this.set(key, $.arrayToSlice([value]))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function Header_Add(h: Header, key: string, value: string): void {
|
|
38
|
+
h.Add(key, value)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function Header_Del(h: Header, key: string): void {
|
|
42
|
+
h.Del(key)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function Header_Get(h: Header, key: string): string {
|
|
46
|
+
return h.Get(key)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function Header_Set(h: Header, key: string, value: string): void {
|
|
50
|
+
h.Set(key, value)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ResponseWriter {
|
|
54
|
+
Header(): Header
|
|
55
|
+
Write(p: $.Slice<number>): [number, $.GoError]
|
|
56
|
+
WriteHeader(statusCode: number): void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class Response {
|
|
60
|
+
public StatusCode: number
|
|
61
|
+
public Body: io.ReadCloser | null
|
|
62
|
+
public Header: Header
|
|
63
|
+
|
|
64
|
+
constructor(init?: Partial<Response>) {
|
|
65
|
+
this.StatusCode = init?.StatusCode ?? 0
|
|
66
|
+
this.Body = init?.Body ?? null
|
|
67
|
+
this.Header = init?.Header ?? new Header()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public clone(): Response {
|
|
71
|
+
return new Response({
|
|
72
|
+
Body: this.Body,
|
|
73
|
+
Header: this.Header,
|
|
74
|
+
StatusCode: this.StatusCode,
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function Get(_url: string): [Response | null, $.GoError] {
|
|
80
|
+
return [null, errors.New('net/http: Get is not implemented in GoScript')]
|
|
81
|
+
}
|
package/gs/os/dir_unix.gs.ts
CHANGED
|
@@ -130,7 +130,7 @@ export function readIntBE(b: $.Bytes, size: uintptr): number {
|
|
|
130
130
|
case 4:
|
|
131
131
|
return (byteorder.BEUint32(b) as number)
|
|
132
132
|
case 8:
|
|
133
|
-
return (byteorder.BEUint64(b)
|
|
133
|
+
return Number(byteorder.BEUint64(b))
|
|
134
134
|
default:
|
|
135
135
|
$.panic("syscall: readInt with unsupported size")
|
|
136
136
|
return 0 // This line will never be reached due to panic, but satisfies TypeScript
|
|
@@ -146,10 +146,9 @@ export function readIntLE(b: $.Bytes, size: uintptr): number {
|
|
|
146
146
|
case 4:
|
|
147
147
|
return (byteorder.LEUint32(b) as number)
|
|
148
148
|
case 8:
|
|
149
|
-
return (byteorder.LEUint64(b)
|
|
149
|
+
return Number(byteorder.LEUint64(b))
|
|
150
150
|
default:
|
|
151
151
|
$.panic("syscall: readInt with unsupported size")
|
|
152
152
|
return 0 // This line will never be reached due to panic, but satisfies TypeScript
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
|
|
@@ -115,6 +115,56 @@ describe('os stdio', () => {
|
|
|
115
115
|
expect(writeSync).toHaveBeenCalledTimes(1)
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
+
it('falls back to process builtin fs when Deno lacks sync stdio', () => {
|
|
119
|
+
const readSync = vi.fn(
|
|
120
|
+
(
|
|
121
|
+
_fd: number,
|
|
122
|
+
buffer: Uint8Array,
|
|
123
|
+
_offset?: number,
|
|
124
|
+
_length?: number,
|
|
125
|
+
_position?: number | null,
|
|
126
|
+
) => {
|
|
127
|
+
buffer.set([5, 6], 0)
|
|
128
|
+
return 2
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
const writeSync = vi.fn(
|
|
132
|
+
(
|
|
133
|
+
_fd: number,
|
|
134
|
+
_buffer: Uint8Array,
|
|
135
|
+
_offset?: number,
|
|
136
|
+
length?: number,
|
|
137
|
+
_position?: number | null,
|
|
138
|
+
) => length ?? 0,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
;(globalThis as any).Deno = {
|
|
142
|
+
stdin: {},
|
|
143
|
+
stdout: {},
|
|
144
|
+
}
|
|
145
|
+
;(globalThis as any).process = {
|
|
146
|
+
getBuiltinModule: vi.fn(() => ({
|
|
147
|
+
readSync,
|
|
148
|
+
writeSync,
|
|
149
|
+
})),
|
|
150
|
+
}
|
|
151
|
+
resetHostRuntimeForTests()
|
|
152
|
+
|
|
153
|
+
const input = NewFile(0, 'stdin')
|
|
154
|
+
const output = NewFile(1, 'stdout')
|
|
155
|
+
const readBuf = new Uint8Array(2)
|
|
156
|
+
|
|
157
|
+
const [readN, readErr] = input!.Read(readBuf)
|
|
158
|
+
expect(readN).toBe(2)
|
|
159
|
+
expect(readErr).toBeNull()
|
|
160
|
+
expect(Array.from(readBuf)).toEqual([5, 6])
|
|
161
|
+
|
|
162
|
+
const [writeN, writeErr] = output!.Write(new Uint8Array([7, 8, 9]))
|
|
163
|
+
expect(writeN).toBe(3)
|
|
164
|
+
expect(writeErr).toBeNull()
|
|
165
|
+
expect(writeSync).toHaveBeenCalledTimes(1)
|
|
166
|
+
})
|
|
167
|
+
|
|
118
168
|
it('returns EOF on zero-byte reads and ErrClosed after Close', () => {
|
|
119
169
|
const stdinReadSync = vi.fn(() => 0)
|
|
120
170
|
|
package/gs/os/meta.json
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { basename, join } from 'node:path'
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import { ErrUnimplemented } from './error.gs.js'
|
|
7
|
+
import { CreateTemp, MkdirTemp } from './tempfile.gs.js'
|
|
8
|
+
|
|
9
|
+
const tempRoots: string[] = []
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.restoreAllMocks()
|
|
13
|
+
vi.unstubAllGlobals()
|
|
14
|
+
for (const root of tempRoots.splice(0)) {
|
|
15
|
+
rmSync(root, { force: true, recursive: true })
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
function makeTempRoot(): string {
|
|
20
|
+
const root = mkdtempSync(join(tmpdir(), 'goscript-os-temp-'))
|
|
21
|
+
tempRoots.push(root)
|
|
22
|
+
return root
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function stubRandomBytes(bytes: number[]): void {
|
|
26
|
+
vi.stubGlobal('crypto', {
|
|
27
|
+
getRandomValues: vi.fn((dst: Uint8Array) => {
|
|
28
|
+
for (let i = 0; i < dst.length; i++) {
|
|
29
|
+
dst[i] = bytes[i] ?? 0
|
|
30
|
+
}
|
|
31
|
+
return dst
|
|
32
|
+
}),
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function forbidMathRandom(): void {
|
|
37
|
+
vi.spyOn(Math, 'random').mockImplementation(() => {
|
|
38
|
+
throw new Error('os temp names must not use Math.random')
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('os temp files', () => {
|
|
43
|
+
it('uses Web Crypto bytes for temp names', () => {
|
|
44
|
+
const root = makeTempRoot()
|
|
45
|
+
stubRandomBytes([0x78, 0x56, 0x34, 0x12])
|
|
46
|
+
forbidMathRandom()
|
|
47
|
+
|
|
48
|
+
const [dir, dirErr] = MkdirTemp(root, 'dir-*.tmp')
|
|
49
|
+
expect(dirErr).toBeNull()
|
|
50
|
+
expect(basename(dir)).toBe('dir-305419896.tmp')
|
|
51
|
+
expect(existsSync(dir)).toBe(true)
|
|
52
|
+
|
|
53
|
+
const [file, fileErr] = CreateTemp(root, 'file-*.tmp')
|
|
54
|
+
expect(fileErr).toBeNull()
|
|
55
|
+
expect(file).not.toBeNull()
|
|
56
|
+
expect(basename(file!.Name())).toBe('file-305419896.tmp')
|
|
57
|
+
expect(existsSync(file!.Name())).toBe(true)
|
|
58
|
+
file!.Close()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('does not truncate an existing path after a random collision', () => {
|
|
62
|
+
const root = makeTempRoot()
|
|
63
|
+
const existing = join(root, 'file-305419896.tmp')
|
|
64
|
+
writeFileSync(existing, 'keep')
|
|
65
|
+
stubRandomBytes([0x78, 0x56, 0x34, 0x12])
|
|
66
|
+
forbidMathRandom()
|
|
67
|
+
|
|
68
|
+
const [file, err] = CreateTemp(root, 'file-*.tmp')
|
|
69
|
+
|
|
70
|
+
expect(file).toBeNull()
|
|
71
|
+
expect(err).not.toBeNull()
|
|
72
|
+
expect(readFileSync(existing, 'utf8')).toBe('keep')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('reports ErrUnimplemented without a secure random source', () => {
|
|
76
|
+
const root = makeTempRoot()
|
|
77
|
+
vi.stubGlobal('crypto', {})
|
|
78
|
+
forbidMathRandom()
|
|
79
|
+
|
|
80
|
+
const [dir, err] = MkdirTemp(root, 'dir-*')
|
|
81
|
+
|
|
82
|
+
expect(dir).toBe('')
|
|
83
|
+
expect(err).toBe(ErrUnimplemented)
|
|
84
|
+
})
|
|
85
|
+
})
|
package/gs/os/tempfile.gs.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as $ from "@goscript/builtin/index.js";
|
|
2
2
|
import { ErrUnimplemented } from "./error.gs.js";
|
|
3
3
|
import { TempDir } from "./file_constants_js.gs.js";
|
|
4
|
-
import {
|
|
5
|
-
import { File } from "./types_js.gs.js";
|
|
4
|
+
import { Mkdir } from "./file_js.gs.js";
|
|
5
|
+
import { createHostFile, File, getDeno, getNodeFS, newHostError } from "./types_js.gs.js";
|
|
6
6
|
|
|
7
7
|
export function joinPath(dir: string, file: string): string {
|
|
8
8
|
if (dir === "" || dir === ".") {
|
|
@@ -20,33 +20,93 @@ export function joinPath(dir: string, file: string): string {
|
|
|
20
20
|
return dir + "/" + file
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function nextTempPath(dir: string, pattern: string): string {
|
|
23
|
+
function nextTempPath(dir: string, pattern: string): [string, $.GoError] {
|
|
24
24
|
const baseDir = dir === "" ? TempDir() : dir
|
|
25
|
-
const suffix
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const [suffix, err] = nextRandom()
|
|
26
|
+
if (err !== null) {
|
|
27
|
+
return ["", err]
|
|
28
|
+
}
|
|
29
|
+
const star = pattern.lastIndexOf("*")
|
|
30
|
+
const name =
|
|
31
|
+
star >= 0
|
|
32
|
+
? pattern.slice(0, star) + suffix + pattern.slice(star + 1)
|
|
33
|
+
: pattern + suffix
|
|
34
|
+
return [joinPath(baseDir, name), null]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function nextRandom(): [string, $.GoError] {
|
|
38
|
+
const crypto = globalThis.crypto
|
|
39
|
+
if (!crypto || typeof crypto.getRandomValues !== "function") {
|
|
40
|
+
return ["", ErrUnimplemented]
|
|
41
|
+
}
|
|
42
|
+
const bytes = new Uint8Array(4)
|
|
43
|
+
crypto.getRandomValues(bytes)
|
|
44
|
+
const value =
|
|
45
|
+
bytes[0] |
|
|
46
|
+
(bytes[1] << 8) |
|
|
47
|
+
(bytes[2] << 16) |
|
|
48
|
+
(bytes[3] << 24)
|
|
49
|
+
return [(value >>> 0).toString(10), null]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createTempFile(path: string): [File | null, $.GoError] {
|
|
53
|
+
const denoObj = getDeno()
|
|
54
|
+
if (denoObj?.openSync) {
|
|
55
|
+
try {
|
|
56
|
+
const handle = denoObj.openSync(path, {
|
|
57
|
+
createNew: true,
|
|
58
|
+
mode: 0o600,
|
|
59
|
+
read: true,
|
|
60
|
+
write: true,
|
|
61
|
+
})
|
|
62
|
+
return [createHostFile(path, handle?.rid ?? -1, handle), null]
|
|
63
|
+
} catch (err) {
|
|
64
|
+
return [null, newHostError(err)]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const nodeFS = getNodeFS()
|
|
69
|
+
if (nodeFS?.openSync) {
|
|
70
|
+
try {
|
|
71
|
+
return [createHostFile(path, nodeFS.openSync(path, "wx+", 0o600)), null]
|
|
72
|
+
} catch (err) {
|
|
73
|
+
return [null, newHostError(err)]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return [null, ErrUnimplemented]
|
|
28
78
|
}
|
|
29
79
|
|
|
30
80
|
export function CreateTemp(dir: string, pattern: string): [File | null, $.GoError] {
|
|
31
81
|
const template = pattern === "" ? "tmp-*" : pattern
|
|
82
|
+
let lastErr: $.GoError = ErrUnimplemented
|
|
32
83
|
for (let i = 0; i < 16; i++) {
|
|
33
|
-
const path = nextTempPath(dir, template)
|
|
34
|
-
|
|
84
|
+
const [path, randErr] = nextTempPath(dir, template)
|
|
85
|
+
if (randErr !== null) {
|
|
86
|
+
return [null, randErr]
|
|
87
|
+
}
|
|
88
|
+
const [file, err] = createTempFile(path)
|
|
35
89
|
if (err === null) {
|
|
36
90
|
return [file, null]
|
|
37
91
|
}
|
|
92
|
+
lastErr = err
|
|
38
93
|
}
|
|
39
|
-
return [null,
|
|
94
|
+
return [null, lastErr]
|
|
40
95
|
}
|
|
41
96
|
|
|
42
97
|
export function MkdirTemp(dir: string, pattern: string): [string, $.GoError] {
|
|
43
98
|
const template = pattern === "" ? "tmp-*" : pattern
|
|
99
|
+
let lastErr: $.GoError = ErrUnimplemented
|
|
44
100
|
for (let i = 0; i < 16; i++) {
|
|
45
|
-
const path = nextTempPath(dir, template)
|
|
101
|
+
const [path, randErr] = nextTempPath(dir, template)
|
|
102
|
+
if (randErr !== null) {
|
|
103
|
+
return ["", randErr]
|
|
104
|
+
}
|
|
46
105
|
const err = Mkdir(path, 0o700)
|
|
47
106
|
if (err === null) {
|
|
48
107
|
return [path, null]
|
|
49
108
|
}
|
|
109
|
+
lastErr = err
|
|
50
110
|
}
|
|
51
|
-
return ["",
|
|
111
|
+
return ["", lastErr]
|
|
52
112
|
}
|
package/gs/os/types_js.gs.ts
CHANGED
|
@@ -8,8 +8,8 @@ import * as syscall from "@goscript/syscall/index.js"
|
|
|
8
8
|
import {
|
|
9
9
|
DenoFileLike,
|
|
10
10
|
DenoStream,
|
|
11
|
+
getHostRuntime,
|
|
11
12
|
HostUnsupportedError,
|
|
12
|
-
hostRuntime,
|
|
13
13
|
NodeFSModule,
|
|
14
14
|
resetHostRuntimeForTests,
|
|
15
15
|
} from "@goscript/builtin/hostio.js"
|
|
@@ -33,23 +33,23 @@ export function newHostError(err: unknown): $.GoError {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function getNodeFS(): NodeFSModule | null {
|
|
36
|
-
return
|
|
36
|
+
return getHostRuntime().nodeFS
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function getDeno(): any | null {
|
|
40
|
-
return
|
|
40
|
+
return getHostRuntime().deno
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function getPlatform(): string {
|
|
44
|
-
return
|
|
44
|
+
return getHostRuntime().platform
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function getEnv(name: string): string {
|
|
48
|
-
return
|
|
48
|
+
return getHostRuntime().getEnv(name)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export function getDenoStream(fd: number): DenoStream | null {
|
|
52
|
-
return
|
|
52
|
+
return getHostRuntime().getStdioHandle(fd)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function readFD(fd: number, b: Uint8Array): [number, $.GoError] {
|
|
@@ -58,7 +58,7 @@ function readFD(fd: number, b: Uint8Array): [number, $.GoError] {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
try {
|
|
61
|
-
const n =
|
|
61
|
+
const n = getHostRuntime().readFD(fd, b)
|
|
62
62
|
if (n === null || n === 0) {
|
|
63
63
|
return [0, io.EOF]
|
|
64
64
|
}
|
|
@@ -77,7 +77,7 @@ function writeFD(fd: number, b: Uint8Array): [number, $.GoError] {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
|
-
return [
|
|
80
|
+
return [getHostRuntime().writeFD(fd, b), null]
|
|
81
81
|
} catch (err) {
|
|
82
82
|
if (err instanceof HostUnsupportedError) {
|
|
83
83
|
return [0, ErrUnimplemented]
|
|
@@ -192,7 +192,7 @@ export function createFileInfo(name: string, stat: HostStatLike): fs.FileInfo {
|
|
|
192
192
|
export function createHostFile(name: string, fd: number = -1, handle: DenoFileLike | null = null): File {
|
|
193
193
|
return new File({
|
|
194
194
|
fd,
|
|
195
|
-
file: new file({ handle: handle ??
|
|
195
|
+
file: new file({ handle: handle ?? getHostRuntime().getStdioHandle(fd), path: name }),
|
|
196
196
|
name,
|
|
197
197
|
})
|
|
198
198
|
}
|
|
@@ -312,7 +312,7 @@ export class File {
|
|
|
312
312
|
if (this.closed) {
|
|
313
313
|
return [0, ErrClosed]
|
|
314
314
|
}
|
|
315
|
-
return io.Copy(this, r)
|
|
315
|
+
return io.Copy(this, r) as any
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
public Write(b: $.Bytes): [number, $.GoError] {
|
|
@@ -349,7 +349,7 @@ export class File {
|
|
|
349
349
|
if (this.closed) {
|
|
350
350
|
return [0, ErrClosed]
|
|
351
351
|
}
|
|
352
|
-
return io.Copy(w, this)
|
|
352
|
+
return io.Copy(w, this) as any
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
public Seek(offset: number, whence: number): [number, $.GoError] {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
2
5
|
import { Match, Glob, ErrBadPattern } from './match.js'
|
|
3
6
|
|
|
4
7
|
describe('path/filepath - Pattern matching functions', () => {
|
|
@@ -216,20 +219,36 @@ describe('path/filepath - Pattern matching functions', () => {
|
|
|
216
219
|
})
|
|
217
220
|
|
|
218
221
|
describe('Glob', () => {
|
|
219
|
-
it('should
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
it('should read host filesystem matches', () => {
|
|
223
|
+
const root = mkdtempSync(join(tmpdir(), 'goscript-filepath-glob-'))
|
|
224
|
+
const oldwd = process.cwd()
|
|
225
|
+
try {
|
|
226
|
+
mkdirSync(join(root, 'a', 'b', 'c.d', 'e.f'), { recursive: true })
|
|
227
|
+
process.chdir(root)
|
|
228
|
+
|
|
229
|
+
const [files1, err1] = Glob('./*/*/*.d')
|
|
230
|
+
expect(err1).toBeNull()
|
|
231
|
+
expect(files1).toEqual(['a/b/c.d'])
|
|
224
232
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
233
|
+
const [files2, err2] = Glob('a/b/c.d/e.*')
|
|
234
|
+
expect(err2).toBeNull()
|
|
235
|
+
expect(files2).toEqual(['a/b/c.d/e.f'])
|
|
236
|
+
} finally {
|
|
237
|
+
process.chdir(oldwd)
|
|
238
|
+
rmSync(root, { force: true, recursive: true })
|
|
239
|
+
}
|
|
240
|
+
})
|
|
228
241
|
|
|
229
|
-
|
|
230
|
-
const [
|
|
231
|
-
expect(
|
|
232
|
-
expect(
|
|
242
|
+
it('should validate bad patterns', () => {
|
|
243
|
+
const [files1, err1] = Glob('[unclosed')
|
|
244
|
+
expect(err1).toBe(ErrBadPattern)
|
|
245
|
+
expect(files1).toEqual([])
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('should return empty results for unmatched valid patterns', () => {
|
|
249
|
+
const [files1, err1] = Glob('missing-*.txt')
|
|
250
|
+
expect(err1).toBeNull()
|
|
251
|
+
expect(files1).toEqual([])
|
|
233
252
|
})
|
|
234
253
|
})
|
|
235
254
|
|