goscript 0.0.53 → 0.0.54

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 CHANGED
@@ -1,13 +1,11 @@
1
1
  # GoScript
2
2
 
3
- [![GoDoc Widget]][GoDoc] [![Go Report Card Widget]][Go Report Card] [![DeepWiki Widget]][DeepWiki]
3
+ [![GoDoc Widget]][GoDoc] [![Go Report Card Widget]][Go Report Card] [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/aperturerobotics/goscript)
4
4
 
5
5
  [GoDoc]: https://godoc.org/github.com/aperturerobotics/goscript
6
6
  [GoDoc Widget]: https://godoc.org/github.com/aperturerobotics/goscript?status.svg
7
7
  [Go Report Card Widget]: https://goreportcard.com/badge/github.com/aperturerobotics/goscript
8
8
  [Go Report Card]: https://goreportcard.com/report/github.com/aperturerobotics/goscript
9
- [DeepWiki Widget]: https://img.shields.io/badge/DeepWiki-aperturerobotics%2Fgoscript-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==
10
- [DeepWiki]: https://deepwiki.com/aperturerobotics/goscript
11
9
 
12
10
  ## What is GoScript?
13
11
 
@@ -595,10 +595,15 @@ func (c *FileCompiler) Compile(ctx context.Context) error {
595
595
  for _, sourceFile := range sourceFiles {
596
596
  functions := imports[sourceFile]
597
597
  if len(functions) > 0 {
598
+ // Apply sanitization to function names
599
+ var sanitizedFunctions []string
600
+ for _, fn := range functions {
601
+ sanitizedFunctions = append(sanitizedFunctions, sanitizeIdentifier(fn))
602
+ }
598
603
  // Sort functions for consistent output
599
- sort.Strings(functions)
604
+ sort.Strings(sanitizedFunctions)
600
605
  c.codeWriter.WriteLinef("import { %s } from \"./%s.gs.js\";",
601
- strings.Join(functions, ", "), sourceFile)
606
+ strings.Join(sanitizedFunctions, ", "), sourceFile)
602
607
  }
603
608
  }
604
609
  }
@@ -649,10 +654,15 @@ func (c *FileCompiler) Compile(ctx context.Context) error {
649
654
  }
650
655
 
651
656
  if len(nonProtobufTypes) > 0 {
657
+ // Apply sanitization to type names
658
+ var sanitizedTypes []string
659
+ for _, typeName := range nonProtobufTypes {
660
+ sanitizedTypes = append(sanitizedTypes, sanitizeIdentifier(typeName))
661
+ }
652
662
  // Sort types for consistent output
653
- sort.Strings(nonProtobufTypes)
663
+ sort.Strings(sanitizedTypes)
654
664
  c.codeWriter.WriteLinef("import { %s } from \"./%s.gs.js\";",
655
- strings.Join(nonProtobufTypes, ", "), sourceFile)
665
+ strings.Join(sanitizedTypes, ", "), sourceFile)
656
666
  }
657
667
  }
658
668
  }
package/compiler/spec.go CHANGED
@@ -623,6 +623,9 @@ func (c *GoToTSCompiler) WriteImportSpec(a *ast.ImportSpec) {
623
623
  }
624
624
  }
625
625
 
626
+ // Apply sanitization to handle known names like "Promise" -> "PromiseType"
627
+ impName = c.sanitizeIdentifier(impName)
628
+
626
629
  // All Go package imports are mapped to the @goscript/ scope.
627
630
  // The TypeScript compiler will resolve these using tsconfig paths to either
628
631
  // handwritten versions (in .goscript-assets) or transpiled versions (in goscript).
@@ -4,6 +4,9 @@ import (
4
4
  "fmt"
5
5
  "go/ast"
6
6
  "go/types"
7
+ "strings"
8
+
9
+ "go/token"
7
10
 
8
11
  "github.com/pkg/errors"
9
12
  )
@@ -85,6 +88,10 @@ func (c *GoToTSCompiler) WriteStmtRange(exp *ast.RangeStmt) error {
85
88
  return c.writeInterfaceIteratorRange(exp)
86
89
  }
87
90
 
91
+ if _, ok := underlying.(*types.Chan); ok {
92
+ return c.writeChannelRange(exp)
93
+ }
94
+
88
95
  return errors.Errorf("unsupported range loop type: %T for expression %v", underlying, exp)
89
96
  }
90
97
 
@@ -418,3 +425,72 @@ func (c *GoToTSCompiler) writeInterfaceIteratorRange(exp *ast.RangeStmt) error {
418
425
  c.tsw.WriteLine("})()")
419
426
  return nil
420
427
  }
428
+
429
+ func (c *GoToTSCompiler) writeChannelRange(exp *ast.RangeStmt) error {
430
+ if exp.Value != nil {
431
+ return fmt.Errorf("channel range does not support two iteration variables")
432
+ }
433
+
434
+ c.tsw.WriteLiterally("for (;;) {")
435
+ c.tsw.Indent(1)
436
+ c.tsw.WriteLine("")
437
+
438
+ valueIsBlank := exp.Key == nil
439
+ valueName := "_"
440
+ if !valueIsBlank {
441
+ if valIdent, ok := exp.Key.(*ast.Ident); ok {
442
+ if valIdent.Name != "_" {
443
+ valueName = valIdent.Name
444
+ } else {
445
+ valueIsBlank = true
446
+ }
447
+ } else {
448
+ return fmt.Errorf("unsupported iteration variable in channel range: %T", exp.Key)
449
+ }
450
+ }
451
+
452
+ keyword := "const "
453
+ okVarName := "_ok"
454
+ if exp.Tok != token.DEFINE {
455
+ keyword = ""
456
+ c.tsw.WriteLiterally("let ")
457
+ c.tsw.WriteLiterally(okVarName)
458
+ c.tsw.WriteLine("")
459
+ }
460
+
461
+ patternParts := []string{}
462
+ if !valueIsBlank {
463
+ patternParts = append(patternParts, fmt.Sprintf("value: %s", valueName))
464
+ }
465
+ patternParts = append(patternParts, fmt.Sprintf("ok: %s", okVarName))
466
+ destructuringPattern := fmt.Sprintf("{ %s }", strings.Join(patternParts, ", "))
467
+
468
+ c.tsw.WriteLiterally(keyword)
469
+ if keyword == "" {
470
+ c.tsw.WriteLiterally(";(")
471
+ }
472
+ c.tsw.WriteLiterally(destructuringPattern)
473
+ c.tsw.WriteLiterally(" = await $.chanRecvWithOk(")
474
+ if err := c.WriteValueExpr(exp.X); err != nil {
475
+ return err
476
+ }
477
+ c.tsw.WriteLiterally(")")
478
+ if keyword == "" {
479
+ c.tsw.WriteLiterally(")")
480
+ }
481
+ c.tsw.WriteLine("")
482
+
483
+ c.tsw.WriteLiterally("if (!")
484
+ c.tsw.WriteLiterally(okVarName)
485
+ c.tsw.WriteLiterally(") break")
486
+ c.tsw.WriteLine("")
487
+
488
+ if err := c.WriteStmtBlock(exp.Body, false); err != nil {
489
+ return err
490
+ }
491
+
492
+ c.tsw.Indent(-1)
493
+ c.tsw.WriteLine("}")
494
+
495
+ return nil
496
+ }
package/go.mod CHANGED
@@ -5,17 +5,17 @@ go 1.24.4
5
5
  require (
6
6
  github.com/aperturerobotics/cli v1.0.0
7
7
  github.com/aperturerobotics/protobuf-go-lite v0.9.1
8
- github.com/aperturerobotics/util v1.30.0
8
+ github.com/aperturerobotics/util v1.30.1
9
9
  github.com/pkg/errors v0.9.1
10
10
  github.com/sirupsen/logrus v1.9.3
11
- golang.org/x/tools v0.34.0
11
+ golang.org/x/tools v0.35.0
12
12
  )
13
13
 
14
14
  require (
15
- github.com/aperturerobotics/common v0.22.1 // indirect
15
+ github.com/aperturerobotics/common v0.22.5 // indirect
16
16
  github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008 // indirect
17
17
  github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
18
- golang.org/x/mod v0.25.0 // indirect
19
- golang.org/x/sync v0.15.0 // indirect
20
- golang.org/x/sys v0.33.0 // indirect
18
+ golang.org/x/mod v0.26.0 // indirect
19
+ golang.org/x/sync v0.16.0 // indirect
20
+ golang.org/x/sys v0.34.0 // indirect
21
21
  )
package/go.sum CHANGED
@@ -1,13 +1,13 @@
1
1
  github.com/aperturerobotics/cli v1.0.0 h1:s3xT2h7eBih4/4yZKTn/HQ6P+qpk6ygWZl2416xAI1M=
2
2
  github.com/aperturerobotics/cli v1.0.0/go.mod h1:wtlINjMcKuwyV1x4ftReuA6hHZcPB8kPMXHyQqGFCSc=
3
- github.com/aperturerobotics/common v0.22.1 h1:wxTV9wSgfAM9jYUuSzNFzUeC28DQMBgDO3iGahlHeaY=
4
- github.com/aperturerobotics/common v0.22.1/go.mod h1:wsPfDVCTNpGHddg/MSfm84rKoO4GAvb+TQtATXz+pKY=
3
+ github.com/aperturerobotics/common v0.22.5 h1:VhweXK3CVWfPdNXI2311EOMq9SUpdZAnWuinNYH7020=
4
+ github.com/aperturerobotics/common v0.22.5/go.mod h1:wsPfDVCTNpGHddg/MSfm84rKoO4GAvb+TQtATXz+pKY=
5
5
  github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008 h1:So9JeziaWKx2Fw8sK4AUN/szqKtJ0jEMhS6bU4sHbxs=
6
6
  github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008/go.mod h1:snaApCEDtrHHP6UWSLKiYNOZU9A5NyzccKenx9oZEzg=
7
7
  github.com/aperturerobotics/protobuf-go-lite v0.9.1 h1:P1knXKnwLJpVE8fmeXYGckKu79IhqUvKRdCfJNR0MwQ=
8
8
  github.com/aperturerobotics/protobuf-go-lite v0.9.1/go.mod h1:fULrxQxEBWKQm7vvju9AfjTp9yfHoLgwMQWTiZQ2tg0=
9
- github.com/aperturerobotics/util v1.30.0 h1:OKhFVPnAfR8/dfVNV27EtMr27C0kzwPiStoCwKiint0=
10
- github.com/aperturerobotics/util v1.30.0/go.mod h1:T97YTP+FVLegYo5rylOVaPuTLyZyiDqYxD5zVLI9YAc=
9
+ github.com/aperturerobotics/util v1.30.1 h1:4ssKO1TlfoBBcLXZwISAw8Yf8H9Mg9D0jnn+klMXAKY=
10
+ github.com/aperturerobotics/util v1.30.1/go.mod h1:OLTwZiBfCVh9kirNhA1quJfnLuy4OW7CyIkvoFX62+A=
11
11
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12
12
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
13
13
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -25,15 +25,15 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
25
25
  github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
26
26
  github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
27
27
  github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
28
- golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
29
- golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
30
- golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
31
- golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
28
+ golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
29
+ golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
30
+ golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
31
+ golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
32
32
  golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33
- golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
34
- golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
35
- golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
36
- golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
33
+ golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
34
+ golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
35
+ golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
36
+ golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
37
37
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
38
38
  gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
39
39
  gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goscript",
3
3
  "description": "Go to TypeScript transpiler",
4
- "version": "0.0.53",
4
+ "version": "0.0.54",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",
@@ -84,20 +84,20 @@
84
84
  "./{src,builtin,example}/**/(*.ts|*.tsx|*.html|*.css|*.scss)": "prettier --config .prettierrc.yaml --write"
85
85
  },
86
86
  "devDependencies": {
87
- "@aptre/protobuf-es-lite": "^0.4.9",
88
- "@eslint/js": "^9.25.1",
89
- "@types/node": "^22.15.18",
90
- "@typescript-eslint/eslint-plugin": "^8.31.0",
91
- "@typescript-eslint/parser": "^8.31.0",
92
- "@typescript/native-preview": "^7.0.0-dev.20250523.1",
93
- "eslint": "^9.25.1",
87
+ "@aptre/protobuf-es-lite": "^0.5.2",
88
+ "@eslint/js": "^9.31.0",
89
+ "@types/node": "^24.0.13",
90
+ "@typescript-eslint/eslint-plugin": "^8.36.0",
91
+ "@typescript-eslint/parser": "^8.36.0",
92
+ "@typescript/native-preview": "^7.0.0-dev.20250711.1",
93
+ "eslint": "^9.31.0",
94
94
  "eslint-config-prettier": "^10.0.2",
95
95
  "husky": "^9.1.7",
96
96
  "lint-staged": "^16.0.0",
97
- "prettier": "^3.5.3",
97
+ "prettier": "^3.6.2",
98
98
  "tsx": "^4.0.0",
99
99
  "typescript": "^5.8.3",
100
- "typescript-eslint": "^8.31.0",
100
+ "typescript-eslint": "^8.36.0",
101
101
  "vitest": "^3.1.2"
102
102
  }
103
103
  }