goscript 0.1.2 → 0.1.4
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/cmd/goscript/cmd_compile.go +28 -8
- package/cmd/goscript/cmd_compile_test.go +105 -6
- package/compiler/build-flags.go +9 -10
- package/compiler/gotest/runner_test.go +127 -0
- package/compiler/lowered-program.go +1 -0
- package/compiler/lowering.go +1325 -194
- package/compiler/lowering_bench_test.go +350 -0
- package/compiler/override-registry_test.go +43 -0
- package/compiler/package-graph.go +61 -4
- package/compiler/package-graph_test.go +30 -0
- package/compiler/semantic-model-types.go +8 -0
- package/compiler/semantic-model.go +447 -22
- package/compiler/semantic-model_test.go +138 -0
- package/compiler/skeleton_test.go +1436 -50
- package/compiler/typescript-emitter.go +47 -4
- package/dist/gs/builtin/builtin.d.ts +2 -2
- package/dist/gs/builtin/builtin.js +20 -0
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.js +36 -9
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/slice.js +5 -0
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +1 -1
- package/dist/gs/builtin/type.js +80 -8
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.d.ts +7 -5
- package/dist/gs/bytes/bytes.gs.js +10 -4
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/compress/zlib/index.d.ts +3 -3
- package/dist/gs/compress/zlib/index.js +88 -26
- package/dist/gs/compress/zlib/index.js.map +1 -1
- package/dist/gs/crypto/sha1/index.d.ts +5 -0
- package/dist/gs/crypto/sha1/index.js +103 -0
- package/dist/gs/crypto/sha1/index.js.map +1 -0
- package/dist/gs/crypto/sha256/index.js +2 -5
- package/dist/gs/crypto/sha256/index.js.map +1 -1
- package/dist/gs/crypto/sha512/index.js +2 -5
- package/dist/gs/crypto/sha512/index.js.map +1 -1
- package/dist/gs/embed/index.d.ts +6 -0
- package/dist/gs/embed/index.js +210 -5
- package/dist/gs/embed/index.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +4 -4
- package/dist/gs/fmt/fmt.js +93 -19
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +118 -6
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -1
- package/dist/gs/github.com/go-git/go-billy/v6/osfs/index.d.ts +45 -0
- package/dist/gs/github.com/go-git/go-billy/v6/osfs/index.js +229 -0
- package/dist/gs/github.com/go-git/go-billy/v6/osfs/index.js.map +1 -0
- package/dist/gs/io/fs/readdir.js +5 -3
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/io.d.ts +18 -11
- package/dist/gs/io/io.js +107 -44
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +26 -5
- package/dist/gs/math/bits/index.js +13 -24
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/net/http/httptest/index.js +7 -5
- package/dist/gs/net/http/httptest/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +11 -1
- package/dist/gs/net/http/index.js +157 -11
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +6 -2
- package/dist/gs/os/types_js.gs.js +169 -8
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +1 -0
- package/dist/gs/reflect/type.js +80 -51
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/strings/reader.d.ts +1 -1
- package/dist/gs/strings/reader.js +2 -2
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +2 -1
- package/dist/gs/sync/sync.js +37 -16
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/js/index.js +9 -0
- package/dist/gs/syscall/js/index.js.map +1 -1
- package/dist/gs/testing/testing.js +8 -6
- package/dist/gs/testing/testing.js.map +1 -1
- package/gs/builtin/builtin.ts +25 -2
- package/gs/builtin/channel.ts +47 -9
- package/gs/builtin/runtime-contract.test.ts +78 -0
- package/gs/builtin/slice.ts +7 -0
- package/gs/builtin/type.ts +97 -8
- package/gs/bytes/bytes.gs.ts +19 -10
- package/gs/bytes/bytes.test.ts +17 -0
- package/gs/compress/zlib/index.test.ts +97 -0
- package/gs/compress/zlib/index.ts +117 -27
- package/gs/compress/zlib/meta.json +4 -1
- package/gs/context/context.test.ts +5 -1
- package/gs/crypto/sha1/index.test.ts +45 -0
- package/gs/crypto/sha1/index.ts +127 -0
- package/gs/crypto/sha1/meta.json +8 -0
- package/gs/crypto/sha256/index.test.ts +14 -2
- package/gs/crypto/sha256/index.ts +3 -6
- package/gs/crypto/sha512/index.test.ts +17 -2
- package/gs/crypto/sha512/index.ts +3 -6
- package/gs/embed/index.test.ts +87 -0
- package/gs/embed/index.ts +229 -5
- package/gs/fmt/fmt.test.ts +61 -3
- package/gs/fmt/fmt.ts +115 -22
- package/gs/fmt/meta.json +6 -1
- package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +8 -1
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +139 -11
- package/gs/github.com/aperturerobotics/util/conc/index.test.ts +1 -1
- package/gs/github.com/go-git/go-billy/v6/osfs/index.test.ts +110 -0
- package/gs/github.com/go-git/go-billy/v6/osfs/index.ts +280 -0
- package/gs/github.com/go-git/go-billy/v6/osfs/meta.json +8 -0
- package/gs/io/fs/readdir.test.ts +38 -0
- package/gs/io/fs/readdir.ts +7 -3
- package/gs/io/io.test.ts +135 -0
- package/gs/io/io.ts +143 -63
- package/gs/io/meta.json +7 -1
- package/gs/math/bits/index.ts +52 -28
- package/gs/net/http/httptest/index.test.ts +34 -2
- package/gs/net/http/httptest/index.ts +23 -8
- package/gs/net/http/index.test.ts +46 -0
- package/gs/net/http/index.ts +178 -12
- package/gs/os/file_unix_js.test.ts +52 -0
- package/gs/os/meta.json +4 -0
- package/gs/os/readdir.test.ts +56 -0
- package/gs/os/types_js.gs.ts +169 -8
- package/gs/os/zero_copy_posix.gs.ts +1 -2
- package/gs/reflect/deepequal.test.ts +10 -1
- package/gs/reflect/type.ts +91 -56
- package/gs/reflect/typefor.test.ts +31 -1
- package/gs/strings/meta.json +5 -2
- package/gs/strings/reader.test.ts +2 -2
- package/gs/strings/reader.ts +2 -2
- package/gs/sync/meta.json +2 -0
- package/gs/sync/sync.test.ts +41 -1
- package/gs/sync/sync.ts +41 -16
- package/gs/syscall/js/index.test.ts +18 -0
- package/gs/syscall/js/index.ts +12 -0
- package/gs/testing/testing.test.ts +32 -3
- package/gs/testing/testing.ts +13 -10
- package/package.json +1 -1
|
@@ -314,6 +314,144 @@ func TestSemanticModelPropagatesCascadedAsyncInterfaceMethods(t *testing.T) {
|
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
func TestSemanticModelPropagatesAsyncToOverrideInterfaceMethods(t *testing.T) {
|
|
318
|
+
moduleDir := writePackageGraphFixture(t, map[string]string{
|
|
319
|
+
"go.mod": "module example.test/overrideiface\n\ngo 1.25.3\n",
|
|
320
|
+
"main.go": strings.Join([]string{
|
|
321
|
+
"package overrideiface",
|
|
322
|
+
"import (",
|
|
323
|
+
" \"io\"",
|
|
324
|
+
" \"sync\"",
|
|
325
|
+
")",
|
|
326
|
+
"type asyncWriter struct { mu sync.Mutex }",
|
|
327
|
+
"func (w *asyncWriter) Write(p []byte) (int, error) {",
|
|
328
|
+
" w.mu.Lock()",
|
|
329
|
+
" defer w.mu.Unlock()",
|
|
330
|
+
" return len(p), nil",
|
|
331
|
+
"}",
|
|
332
|
+
"func Use(w io.Writer) {",
|
|
333
|
+
" _, _ = w.Write(nil)",
|
|
334
|
+
"}",
|
|
335
|
+
"func main() { Use(&asyncWriter{}) }",
|
|
336
|
+
"",
|
|
337
|
+
}, "\n"),
|
|
338
|
+
})
|
|
339
|
+
graph := loadPackageGraph(t, &CompileRequest{
|
|
340
|
+
Patterns: []string{"."},
|
|
341
|
+
Dir: moduleDir,
|
|
342
|
+
OutputPath: filepath.Join(t.TempDir(), "out"),
|
|
343
|
+
DependencyMode: DependencyModeAll,
|
|
344
|
+
RuntimeEmissionMode: RuntimeEmissionModeEmit,
|
|
345
|
+
})
|
|
346
|
+
model := buildSemanticModel(t, graph)
|
|
347
|
+
|
|
348
|
+
for _, name := range []string{"Write", "Use", "main"} {
|
|
349
|
+
fn := requireDefinedFunc(t, graph, "example.test/overrideiface", name)
|
|
350
|
+
if !model.functions[fn].async {
|
|
351
|
+
t.Fatalf("expected %s to be async, got %#v", name, model.functions[fn])
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
found := false
|
|
355
|
+
for _, implementation := range model.interfaceImplementations {
|
|
356
|
+
if implementation.typ != nil && implementation.typ.Obj().Name() == "asyncWriter" &&
|
|
357
|
+
implementation.iface != nil && implementation.iface.Obj().Pkg().Path() == "io" &&
|
|
358
|
+
implementation.iface.Obj().Name() == "Writer" &&
|
|
359
|
+
implementation.pointer && implementation.asyncMethods["Write"] {
|
|
360
|
+
found = true
|
|
361
|
+
break
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if !found {
|
|
365
|
+
t.Fatalf("missing async *asyncWriter -> io.Writer implementation: %#v", model.interfaceImplementations)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
func TestSemanticModelPropagatesAsyncToAnonymousInterfaceMethods(t *testing.T) {
|
|
370
|
+
moduleDir := writePackageGraphFixture(t, map[string]string{
|
|
371
|
+
"go.mod": "module example.test/anonymousiface\n\ngo 1.25.3\n",
|
|
372
|
+
"main.go": strings.Join([]string{
|
|
373
|
+
"package anonymousiface",
|
|
374
|
+
"import \"context\"",
|
|
375
|
+
"type Snapshot int",
|
|
376
|
+
"type Watcher struct { ch chan Snapshot }",
|
|
377
|
+
"func (w *Watcher) WaitValueChange(ctx context.Context, old Snapshot, errCh <-chan error) (Snapshot, error) {",
|
|
378
|
+
" select {",
|
|
379
|
+
" case v := <-w.ch:",
|
|
380
|
+
" return v, nil",
|
|
381
|
+
" case err := <-errCh:",
|
|
382
|
+
" return old, err",
|
|
383
|
+
" case <-ctx.Done():",
|
|
384
|
+
" return old, ctx.Err()",
|
|
385
|
+
" }",
|
|
386
|
+
"}",
|
|
387
|
+
"func Use(ctx context.Context, w interface {",
|
|
388
|
+
" WaitValueChange(context.Context, Snapshot, <-chan error) (Snapshot, error)",
|
|
389
|
+
"}, old Snapshot) (Snapshot, error) {",
|
|
390
|
+
" return w.WaitValueChange(ctx, old, nil)",
|
|
391
|
+
"}",
|
|
392
|
+
"",
|
|
393
|
+
}, "\n"),
|
|
394
|
+
})
|
|
395
|
+
graph := loadPackageGraph(t, &CompileRequest{
|
|
396
|
+
Patterns: []string{"."},
|
|
397
|
+
Dir: moduleDir,
|
|
398
|
+
OutputPath: filepath.Join(t.TempDir(), "out"),
|
|
399
|
+
DependencyMode: DependencyModeAll,
|
|
400
|
+
RuntimeEmissionMode: RuntimeEmissionModeEmit,
|
|
401
|
+
})
|
|
402
|
+
model := buildSemanticModel(t, graph)
|
|
403
|
+
|
|
404
|
+
fn := requireDefinedFunc(t, graph, "example.test/anonymousiface", "Use")
|
|
405
|
+
if !model.functions[fn].async {
|
|
406
|
+
t.Fatalf("expected Use to be async, got %#v", model.functions[fn])
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
func TestSemanticModelPropagatesAsyncThroughInstantiatedNamedInterface(t *testing.T) {
|
|
411
|
+
moduleDir := writePackageGraphFixture(t, map[string]string{
|
|
412
|
+
"go.mod": "module example.test/instantiatediface\n\ngo 1.25.3\n",
|
|
413
|
+
"main.go": strings.Join([]string{
|
|
414
|
+
"package instantiatediface",
|
|
415
|
+
"import \"context\"",
|
|
416
|
+
"type Snapshot int",
|
|
417
|
+
"type Watchable[T any] interface {",
|
|
418
|
+
" WaitValueChange(context.Context, T, <-chan error) (T, error)",
|
|
419
|
+
"}",
|
|
420
|
+
"type Container[T any] struct { ch chan T }",
|
|
421
|
+
"func (c *Container[T]) WaitValueChange(ctx context.Context, old T, errCh <-chan error) (T, error) {",
|
|
422
|
+
" select {",
|
|
423
|
+
" case v := <-c.ch:",
|
|
424
|
+
" return v, nil",
|
|
425
|
+
" case err := <-errCh:",
|
|
426
|
+
" return old, err",
|
|
427
|
+
" case <-ctx.Done():",
|
|
428
|
+
" return old, ctx.Err()",
|
|
429
|
+
" }",
|
|
430
|
+
"}",
|
|
431
|
+
"func Bind(w Watchable[Snapshot]) {}",
|
|
432
|
+
"func Use(ctx context.Context, w interface {",
|
|
433
|
+
" WaitValueChange(context.Context, Snapshot, <-chan error) (Snapshot, error)",
|
|
434
|
+
"}, old Snapshot) (Snapshot, error) {",
|
|
435
|
+
" return w.WaitValueChange(ctx, old, nil)",
|
|
436
|
+
"}",
|
|
437
|
+
"",
|
|
438
|
+
}, "\n"),
|
|
439
|
+
})
|
|
440
|
+
graph := loadPackageGraph(t, &CompileRequest{
|
|
441
|
+
Patterns: []string{"."},
|
|
442
|
+
Dir: moduleDir,
|
|
443
|
+
OutputPath: filepath.Join(t.TempDir(), "out"),
|
|
444
|
+
DependencyMode: DependencyModeAll,
|
|
445
|
+
RuntimeEmissionMode: RuntimeEmissionModeEmit,
|
|
446
|
+
})
|
|
447
|
+
model := buildSemanticModel(t, graph)
|
|
448
|
+
|
|
449
|
+
fn := requireDefinedFunc(t, graph, "example.test/instantiatediface", "Use")
|
|
450
|
+
if !model.functions[fn].async {
|
|
451
|
+
t.Fatalf("expected Use to be async, got %#v", model.functions[fn])
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
317
455
|
func TestSemanticModelIndexesFunctionsByFullName(t *testing.T) {
|
|
318
456
|
model := newSemanticModel()
|
|
319
457
|
semPkg := &semanticPackage{}
|