goscript 0.0.73 → 0.0.75

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
@@ -36,14 +36,18 @@ Go has powerful concurrency support and an excellent standard library. GoScript
36
36
  - Control flow (if, for, switch, select, range, defer, etc.)
37
37
  - Type assertions and interface implementations
38
38
  - Closures and anonymous functions
39
+ - Generics
40
+ - Reflection
41
+ - Encoding: encoding/json
42
+ - Most of the standard library
39
43
 
40
44
  **🚧 In progress:**
41
45
 
42
- - Reflection support
43
- - Standard library coverage
44
- - Generics
46
+ - Reflection edge cases
47
+ - Full standard library coverage
48
+ - Various other edge cases (see GitHub issues)
45
49
 
46
- **Known limitations:**
50
+ **Important Notes**
47
51
 
48
52
  - Uses JavaScript `number` type (64-bit float, not Go's int types)
49
53
  - No pointer arithmetic (`uintptr`) or `unsafe` package
@@ -1003,8 +1003,12 @@ func (c *GoToTSCompiler) WriteCaseClause(exp *ast.CaseClause) error {
1003
1003
  return fmt.Errorf("failed to write statement in case clause body: %w", err)
1004
1004
  }
1005
1005
  }
1006
- // Add break statement (Go's switch has implicit breaks, TS needs explicit break)
1007
- c.tsw.WriteLine("break")
1006
+ // Add break statement only if the case body doesn't end with a terminating statement
1007
+ // (return, panic, continue, break, goto, fallthrough). Go's switch has implicit breaks,
1008
+ // but TS needs explicit break - however, adding break after return is unreachable code.
1009
+ if !endsWithTerminatingStmt(exp.Body) {
1010
+ c.tsw.WriteLine("break")
1011
+ }
1008
1012
  c.tsw.Indent(-1)
1009
1013
  c.tsw.WriteLine("}")
1010
1014
  return nil
package/compiler/decl.go CHANGED
@@ -216,12 +216,10 @@ func (c *GoToTSCompiler) extractTypeDependencies(typeExpr ast.Expr, typeSpecMap
216
216
  }
217
217
 
218
218
  case *ast.ArrayType:
219
- // Array/slice type - only depends on element type if element is a struct (not pointer)
220
- if !c.isPointerType(t.Elt) {
221
- elemDeps := c.extractTypeDependencies(t.Elt, typeSpecMap)
222
- deps = append(deps, elemDeps...)
223
- }
224
- // Arrays of pointers don't create initialization dependencies
219
+ // Array/slice types don't create initialization dependencies
220
+ // Slices are reference types (initialized to null/empty), and arrays of structs
221
+ // don't require the element type constructor at declaration time.
222
+ // This allows circular references like: type A struct { BB []B }; type B struct { AA []A }
225
223
 
226
224
  case *ast.StarExpr:
227
225
  // Pointer types don't create initialization dependencies
@@ -264,12 +262,10 @@ func (c *GoToTSCompiler) extractStructFieldDependencies(fieldType ast.Expr, type
264
262
  // Pointers are just references, no constructor call needed
265
263
 
266
264
  case *ast.ArrayType:
267
- // Array field: struct { b []B } or struct { b [5]B }
268
- // Only create dependency if element type is not a pointer
269
- if !c.isPointerType(t.Elt) {
270
- elemDeps := c.extractTypeDependencies(t.Elt, typeSpecMap)
271
- deps = append(deps, elemDeps...)
272
- }
265
+ // Array/slice fields don't create initialization dependencies
266
+ // Slices are reference types (initialized to null/empty), and arrays of structs
267
+ // don't require the element type constructor at declaration time.
268
+ // This allows circular references like: type A struct { BB []B }; type B struct { AA []A }
273
269
 
274
270
  case *ast.MapType:
275
271
  // Map field: struct { b map[K]V } - maps don't require initialization dependencies
package/compiler/stmt.go CHANGED
@@ -1275,3 +1275,34 @@ func (c *GoToTSCompiler) needsDefensiveSemicolon(expr ast.Expr) bool {
1275
1275
  }
1276
1276
  return false
1277
1277
  }
1278
+
1279
+ // isTerminatingStmt checks if a statement terminates control flow, meaning
1280
+ // code after it would be unreachable. This includes return, panic, continue,
1281
+ // break, goto, and fallthrough statements.
1282
+ func isTerminatingStmt(stmt ast.Stmt) bool {
1283
+ switch s := stmt.(type) {
1284
+ case *ast.ReturnStmt:
1285
+ return true
1286
+ case *ast.BranchStmt:
1287
+ // break, continue, goto, fallthrough all terminate the current block
1288
+ return true
1289
+ case *ast.ExprStmt:
1290
+ // Check for panic() calls
1291
+ if call, ok := s.X.(*ast.CallExpr); ok {
1292
+ if ident, ok := call.Fun.(*ast.Ident); ok {
1293
+ if ident.Name == "panic" {
1294
+ return true
1295
+ }
1296
+ }
1297
+ }
1298
+ }
1299
+ return false
1300
+ }
1301
+
1302
+ // endsWithTerminatingStmt checks if a statement list ends with a terminating statement.
1303
+ func endsWithTerminatingStmt(stmts []ast.Stmt) bool {
1304
+ if len(stmts) == 0 {
1305
+ return false
1306
+ }
1307
+ return isTerminatingStmt(stmts[len(stmts)-1])
1308
+ }
package/go.mod CHANGED
@@ -7,7 +7,7 @@ require (
7
7
  github.com/aperturerobotics/protobuf-go-lite v0.11.0
8
8
  github.com/aperturerobotics/util v1.32.0
9
9
  github.com/pkg/errors v0.9.1
10
- github.com/sirupsen/logrus v1.9.3
10
+ github.com/sirupsen/logrus v1.9.4
11
11
  golang.org/x/mod v0.32.0
12
12
  golang.org/x/tools v0.41.0
13
13
  )
package/go.sum CHANGED
@@ -8,7 +8,6 @@ github.com/aperturerobotics/protobuf-go-lite v0.11.0 h1:IAaZISqrEpodqECYxk0yKWgR
8
8
  github.com/aperturerobotics/protobuf-go-lite v0.11.0/go.mod h1:c4kGy7Dkfz6B1m0t4QBIMQoNeQ7m+nYj3Qxxnlwhygo=
9
9
  github.com/aperturerobotics/util v1.32.0 h1:6gIx5zt1/cOpyH5Wq+im3yNLnRncsfw9PupHNQsy8c0=
10
10
  github.com/aperturerobotics/util v1.32.0/go.mod h1:Aufy+WeKncuhc1L2yEg+QxRhb8uVnGBprPyTubaDxLw=
11
- github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12
11
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
13
12
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14
13
  github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
@@ -17,10 +16,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
17
16
  github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
18
17
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
19
18
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
20
- github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
21
- github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
22
- github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
23
- github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19
+ github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
20
+ github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
24
21
  github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
25
22
  github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
26
23
  github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
@@ -29,12 +26,9 @@ golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
29
26
  golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
30
27
  golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
31
28
  golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
32
- golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
33
29
  golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
34
30
  golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
35
31
  golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
36
32
  golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
37
- gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
38
- gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
39
33
  gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
40
34
  gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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.73",
4
+ "version": "0.0.75",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",