goscript 0.0.50 → 0.0.52
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 +513 -325
- package/compiler/compiler.go +39 -6
- package/compiler/expr-call-async.go +90 -23
- package/compiler/expr.go +0 -44
- package/compiler/sanitize.go +1 -2
- package/compiler/spec-struct.go +3 -3
- package/compiler/spec.go +0 -21
- package/compiler/stmt-assign.go +0 -6
- package/compiler/stmt-select.go +52 -1
- package/compiler/type-assert.go +6 -6
- package/compiler/type.go +3 -3
- package/dist/gs/builtin/builtin.d.ts +0 -1
- package/dist/gs/builtin/builtin.js +0 -9
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +5 -3
- package/dist/gs/builtin/channel.js +14 -17
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/context/context.js +2 -2
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/runtime/runtime.d.ts +1 -1
- package/dist/gs/runtime/runtime.js +1 -1
- package/dist/gs/syscall/constants.d.ts +24 -0
- package/dist/gs/syscall/constants.js +27 -0
- package/dist/gs/syscall/constants.js.map +1 -0
- package/dist/gs/syscall/env.d.ts +6 -0
- package/dist/gs/syscall/env.js +43 -0
- package/dist/gs/syscall/env.js.map +1 -0
- package/dist/gs/syscall/errors.d.ts +111 -0
- package/dist/gs/syscall/errors.js +547 -0
- package/dist/gs/syscall/errors.js.map +1 -0
- package/dist/gs/syscall/fs.d.ts +29 -0
- package/dist/gs/syscall/fs.js +53 -0
- package/dist/gs/syscall/fs.js.map +1 -0
- package/dist/gs/syscall/index.d.ts +6 -80
- package/dist/gs/syscall/index.js +12 -168
- package/dist/gs/syscall/index.js.map +1 -1
- package/dist/gs/syscall/rawconn.d.ts +7 -0
- package/dist/gs/syscall/rawconn.js +19 -0
- package/dist/gs/syscall/rawconn.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +12 -0
- package/dist/gs/syscall/types.js +2 -0
- package/dist/gs/syscall/types.js.map +1 -0
- package/dist/gs/time/time.d.ts +2 -2
- package/dist/gs/time/time.js +12 -9
- package/dist/gs/time/time.js.map +1 -1
- package/go.mod +1 -1
- package/gs/builtin/builtin.ts +0 -11
- package/gs/builtin/channel.ts +39 -17
- package/gs/context/context.ts +6 -2
- package/gs/context/meta.json +16 -0
- package/gs/runtime/runtime.ts +1 -1
- package/gs/syscall/constants.ts +29 -0
- package/gs/syscall/env.ts +47 -0
- package/gs/syscall/errors.ts +658 -0
- package/gs/syscall/fs.ts +62 -0
- package/gs/syscall/index.ts +12 -207
- package/gs/syscall/rawconn.ts +23 -0
- package/gs/syscall/types.ts +18 -0
- package/gs/time/meta.json +6 -0
- package/gs/time/time.ts +16 -13
- package/gs/unicode/meta.json +24 -0
- package/package.json +1 -1
- package/gs/unicode/unicode.go +0 -38
package/compiler/compiler.go
CHANGED
|
@@ -2,6 +2,8 @@ package compiler
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"context"
|
|
5
|
+
"crypto/sha256"
|
|
6
|
+
"encoding/hex"
|
|
5
7
|
"encoding/json"
|
|
6
8
|
"fmt"
|
|
7
9
|
"go/ast"
|
|
@@ -184,8 +186,6 @@ func (c *Compiler) CompilePackages(ctx context.Context, patterns ...string) (*Co
|
|
|
184
186
|
|
|
185
187
|
// Reload all collected packages with complete type information
|
|
186
188
|
if len(pkgPaths) > 0 {
|
|
187
|
-
c.le.Debugf("Reloading %d packages with complete type information", len(pkgPaths))
|
|
188
|
-
|
|
189
189
|
fullOpts := c.opts
|
|
190
190
|
fullOpts.Context = ctx
|
|
191
191
|
// Use LoadAllSyntax to get complete type information, syntax trees, and type checking
|
|
@@ -433,7 +433,7 @@ func (c *PackageCompiler) generateIndexFile(compiledFiles []string) error {
|
|
|
433
433
|
switch d := decl.(type) {
|
|
434
434
|
case *ast.FuncDecl:
|
|
435
435
|
if d.Recv == nil && d.Name.IsExported() {
|
|
436
|
-
valueSymbols = append(valueSymbols, d.Name.Name)
|
|
436
|
+
valueSymbols = append(valueSymbols, sanitizeIdentifier(d.Name.Name))
|
|
437
437
|
}
|
|
438
438
|
case *ast.GenDecl:
|
|
439
439
|
for _, spec := range d.Specs {
|
|
@@ -443,17 +443,17 @@ func (c *PackageCompiler) generateIndexFile(compiledFiles []string) error {
|
|
|
443
443
|
// Check if this is a struct type
|
|
444
444
|
if _, isStruct := s.Type.(*ast.StructType); isStruct {
|
|
445
445
|
// Structs become TypeScript classes and need both type and value exports
|
|
446
|
-
structSymbols = append(structSymbols, s.Name.Name)
|
|
446
|
+
structSymbols = append(structSymbols, sanitizeIdentifier(s.Name.Name))
|
|
447
447
|
} else {
|
|
448
448
|
// Other type declarations (interfaces, type definitions, type aliases)
|
|
449
449
|
// become TypeScript types and must be exported with "export type"
|
|
450
|
-
typeSymbols = append(typeSymbols, s.Name.Name)
|
|
450
|
+
typeSymbols = append(typeSymbols, sanitizeIdentifier(s.Name.Name))
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
case *ast.ValueSpec:
|
|
454
454
|
for _, name := range s.Names {
|
|
455
455
|
if name.IsExported() {
|
|
456
|
-
valueSymbols = append(valueSymbols, name.Name)
|
|
456
|
+
valueSymbols = append(valueSymbols, sanitizeIdentifier(name.Name))
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
}
|
|
@@ -689,6 +689,39 @@ func NewGoToTSCompiler(tsw *TSCodeWriter, pkg *packages.Package, analysis *Analy
|
|
|
689
689
|
}
|
|
690
690
|
}
|
|
691
691
|
|
|
692
|
+
// getDeterministicID generates a deterministic unique ID based on file position
|
|
693
|
+
// This replaces the non-deterministic Pos() values to ensure reproducible builds
|
|
694
|
+
func (c *GoToTSCompiler) getDeterministicID(pos token.Pos) string {
|
|
695
|
+
if !pos.IsValid() {
|
|
696
|
+
return "0000"
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// Get file position information
|
|
700
|
+
position := c.pkg.Fset.Position(pos)
|
|
701
|
+
|
|
702
|
+
// Use package path + base filename + line + column for deterministic hashing
|
|
703
|
+
// This avoids absolute path differences between build environments
|
|
704
|
+
baseFilename := filepath.Base(position.Filename)
|
|
705
|
+
if baseFilename == "" {
|
|
706
|
+
baseFilename = "unknown"
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
packagePath := c.pkg.PkgPath
|
|
710
|
+
if packagePath == "" {
|
|
711
|
+
packagePath = "main"
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// Create a string that uniquely identifies this position using only relative/stable info
|
|
715
|
+
positionStr := fmt.Sprintf("%s:%s:%d:%d", packagePath, baseFilename, position.Line, position.Column)
|
|
716
|
+
|
|
717
|
+
// Hash the position string with SHA256
|
|
718
|
+
hash := sha256.Sum256([]byte(positionStr))
|
|
719
|
+
|
|
720
|
+
// Convert to hex and take the last 4 characters (lowercase)
|
|
721
|
+
hexStr := hex.EncodeToString(hash[:])
|
|
722
|
+
return hexStr[len(hexStr)-4:]
|
|
723
|
+
}
|
|
724
|
+
|
|
692
725
|
// --- Exported Node-Specific Writers ---
|
|
693
726
|
|
|
694
727
|
// WriteIdent translates a Go identifier (`ast.Ident`) used as a value (e.g.,
|
|
@@ -12,49 +12,116 @@ func (c *GoToTSCompiler) writeAsyncCallIfNeeded(exp *ast.CallExpr) bool {
|
|
|
12
12
|
switch fun := exp.Fun.(type) {
|
|
13
13
|
case *ast.Ident:
|
|
14
14
|
// Function call (e.g., func())
|
|
15
|
-
if obj := c.pkg.TypesInfo.Uses[fun]; obj != nil
|
|
16
|
-
c.
|
|
17
|
-
|
|
15
|
+
if obj := c.pkg.TypesInfo.Uses[fun]; obj != nil {
|
|
16
|
+
if c.analysis.IsAsyncFunc(obj) {
|
|
17
|
+
c.tsw.WriteLiterally("await ")
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
return false
|
|
20
22
|
|
|
21
23
|
case *ast.SelectorExpr:
|
|
22
|
-
// Method call (e.g., obj.method())
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// Method call (e.g., obj.method() or obj.field.method())
|
|
25
|
+
var obj types.Object
|
|
26
|
+
var objOk bool
|
|
27
|
+
|
|
28
|
+
// Handle different patterns of method receiver
|
|
29
|
+
switch x := fun.X.(type) {
|
|
30
|
+
case *ast.Ident:
|
|
31
|
+
// Direct identifier: obj.method()
|
|
32
|
+
obj = c.pkg.TypesInfo.Uses[x]
|
|
33
|
+
objOk = obj != nil
|
|
34
|
+
|
|
35
|
+
case *ast.StarExpr:
|
|
36
|
+
// Pointer dereference: (*p).method() or p.method() where p is a pointer
|
|
37
|
+
if id, isIdent := x.X.(*ast.Ident); isIdent {
|
|
38
|
+
obj = c.pkg.TypesInfo.Uses[id]
|
|
39
|
+
objOk = obj != nil
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case *ast.SelectorExpr:
|
|
43
|
+
// Field access: obj.field.method()
|
|
44
|
+
// Get the type of the field access expression
|
|
45
|
+
if fieldType := c.pkg.TypesInfo.TypeOf(x); fieldType != nil {
|
|
46
|
+
// For field access, we create a synthetic object representing the field type
|
|
47
|
+
// We'll handle this case below when we determine the method's type
|
|
48
|
+
objOk = true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
default:
|
|
52
|
+
objOk = false
|
|
26
53
|
}
|
|
27
54
|
|
|
28
|
-
|
|
29
|
-
obj := c.pkg.TypesInfo.Uses[ident]
|
|
30
|
-
if obj == nil {
|
|
55
|
+
if !objOk {
|
|
31
56
|
return false
|
|
32
57
|
}
|
|
33
58
|
|
|
34
|
-
|
|
35
|
-
if
|
|
36
|
-
|
|
59
|
+
// Handle package-level function calls (e.g., time.Sleep)
|
|
60
|
+
if obj != nil {
|
|
61
|
+
if pkgName, isPkg := obj.(*types.PkgName); isPkg {
|
|
62
|
+
methodName := fun.Sel.Name
|
|
63
|
+
pkgPath := pkgName.Imported().Path()
|
|
64
|
+
|
|
65
|
+
// Check if this package-level function is async (empty TypeName)
|
|
66
|
+
if c.analysis.IsMethodAsync(pkgPath, "", methodName) {
|
|
67
|
+
c.tsw.WriteLiterally("await ")
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
37
72
|
}
|
|
38
73
|
|
|
39
|
-
// Get the type
|
|
40
|
-
|
|
41
|
-
|
|
74
|
+
// Get the type for method calls on objects
|
|
75
|
+
var targetType types.Type
|
|
76
|
+
|
|
77
|
+
if obj != nil {
|
|
78
|
+
// Direct variable case: obj.method()
|
|
79
|
+
if varObj, ok := obj.(*types.Var); ok {
|
|
80
|
+
targetType = varObj.Type()
|
|
81
|
+
} else {
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
// Field access case: obj.field.method()
|
|
86
|
+
// Get the type of the field access expression
|
|
87
|
+
targetType = c.pkg.TypesInfo.TypeOf(fun.X)
|
|
88
|
+
if targetType == nil {
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Get the named type from the target type
|
|
94
|
+
var namedType *types.Named
|
|
95
|
+
var namedTypeOk bool
|
|
96
|
+
|
|
97
|
+
// Handle both direct named types and pointer to named types
|
|
98
|
+
switch t := targetType.(type) {
|
|
99
|
+
case *types.Named:
|
|
100
|
+
namedType, namedTypeOk = t, true
|
|
101
|
+
case *types.Pointer:
|
|
102
|
+
if nt, isNamed := t.Elem().(*types.Named); isNamed {
|
|
103
|
+
namedType, namedTypeOk = nt, true
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if !namedTypeOk {
|
|
42
108
|
return false
|
|
43
109
|
}
|
|
44
110
|
|
|
45
111
|
typeName := namedType.Obj().Name()
|
|
46
112
|
methodName := fun.Sel.Name
|
|
47
113
|
|
|
48
|
-
//
|
|
114
|
+
// Determine the package path for the method
|
|
115
|
+
var pkgPath string
|
|
49
116
|
typePkg := namedType.Obj().Pkg()
|
|
50
|
-
if typePkg
|
|
51
|
-
|
|
117
|
+
if typePkg != nil {
|
|
118
|
+
pkgPath = typePkg.Path()
|
|
119
|
+
} else {
|
|
120
|
+
// Fallback to current package
|
|
121
|
+
pkgPath = c.pkg.Types.Path()
|
|
52
122
|
}
|
|
53
123
|
|
|
54
|
-
//
|
|
55
|
-
pkgPath := typePkg.Path()
|
|
56
|
-
|
|
57
|
-
// Check if this method is async based on metadata
|
|
124
|
+
// Check if this method is async using unified analysis
|
|
58
125
|
if c.analysis.IsMethodAsync(pkgPath, typeName, methodName) {
|
|
59
126
|
c.tsw.WriteLiterally("await ")
|
|
60
127
|
return true
|
package/compiler/expr.go
CHANGED
|
@@ -405,50 +405,6 @@ func (c *GoToTSCompiler) WriteBinaryExpr(exp *ast.BinaryExpr) error {
|
|
|
405
405
|
return nil
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
// Check for Duration arithmetic operations (multiplication)
|
|
409
|
-
if exp.Op == token.MUL && c.pkg != nil && c.pkg.TypesInfo != nil {
|
|
410
|
-
leftType := c.pkg.TypesInfo.TypeOf(exp.X)
|
|
411
|
-
rightType := c.pkg.TypesInfo.TypeOf(exp.Y)
|
|
412
|
-
|
|
413
|
-
// Check if left operand is a Duration type (from time package)
|
|
414
|
-
if leftType != nil {
|
|
415
|
-
if namedType, ok := leftType.(*types.Named); ok {
|
|
416
|
-
if namedType.Obj().Pkg() != nil && namedType.Obj().Pkg().Path() == "time" && namedType.Obj().Name() == "Duration" {
|
|
417
|
-
// Duration * number -> Duration.multiply(duration, number)
|
|
418
|
-
c.tsw.WriteLiterally("$.multiplyDuration(")
|
|
419
|
-
if err := c.WriteValueExpr(exp.X); err != nil {
|
|
420
|
-
return fmt.Errorf("failed to write Duration in multiplication: %w", err)
|
|
421
|
-
}
|
|
422
|
-
c.tsw.WriteLiterally(", ")
|
|
423
|
-
if err := c.WriteValueExpr(exp.Y); err != nil {
|
|
424
|
-
return fmt.Errorf("failed to write multiplier in Duration multiplication: %w", err)
|
|
425
|
-
}
|
|
426
|
-
c.tsw.WriteLiterally(")")
|
|
427
|
-
return nil
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// Check if right operand is a Duration type (number * Duration)
|
|
433
|
-
if rightType != nil {
|
|
434
|
-
if namedType, ok := rightType.(*types.Named); ok {
|
|
435
|
-
if namedType.Obj().Pkg() != nil && namedType.Obj().Pkg().Path() == "time" && namedType.Obj().Name() == "Duration" {
|
|
436
|
-
// number * Duration -> Duration.multiply(duration, number)
|
|
437
|
-
c.tsw.WriteLiterally("$.multiplyDuration(")
|
|
438
|
-
if err := c.WriteValueExpr(exp.Y); err != nil {
|
|
439
|
-
return fmt.Errorf("failed to write Duration in multiplication: %w", err)
|
|
440
|
-
}
|
|
441
|
-
c.tsw.WriteLiterally(", ")
|
|
442
|
-
if err := c.WriteValueExpr(exp.X); err != nil {
|
|
443
|
-
return fmt.Errorf("failed to write multiplier in Duration multiplication: %w", err)
|
|
444
|
-
}
|
|
445
|
-
c.tsw.WriteLiterally(")")
|
|
446
|
-
return nil
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
408
|
// Check if the operator is a bitwise operator
|
|
453
409
|
isBitwise := false
|
|
454
410
|
switch exp.Op {
|
package/compiler/sanitize.go
CHANGED
|
@@ -11,8 +11,7 @@ func sanitizeIdentifier(name string) string {
|
|
|
11
11
|
|
|
12
12
|
// Handle TypeScript built-in types that conflict with Go type parameter names
|
|
13
13
|
builtinTypes := map[string]string{
|
|
14
|
-
"
|
|
15
|
-
// Add other built-in types as needed
|
|
14
|
+
"Promise": "PromiseType",
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
if replacement, exists := builtinTypes[name]; exists {
|
package/compiler/spec-struct.go
CHANGED
|
@@ -37,7 +37,7 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
37
37
|
c.tsw.WriteLine("{")
|
|
38
38
|
c.tsw.Indent(1)
|
|
39
39
|
|
|
40
|
-
className := a.Name.Name
|
|
40
|
+
className := sanitizeIdentifier(a.Name.Name)
|
|
41
41
|
|
|
42
42
|
goStructType, ok := c.pkg.TypesInfo.Defs[a.Name].Type().(*types.Named)
|
|
43
43
|
if !ok {
|
|
@@ -231,10 +231,10 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
231
231
|
// Check for both simple identifiers (Pair) and generic types (Pair[T])
|
|
232
232
|
var recvTypeName string
|
|
233
233
|
if ident, ok := recvType.(*ast.Ident); ok {
|
|
234
|
-
recvTypeName = ident.Name
|
|
234
|
+
recvTypeName = sanitizeIdentifier(ident.Name)
|
|
235
235
|
} else if indexExpr, ok := recvType.(*ast.IndexExpr); ok {
|
|
236
236
|
if ident, ok := indexExpr.X.(*ast.Ident); ok {
|
|
237
|
-
recvTypeName = ident.Name
|
|
237
|
+
recvTypeName = sanitizeIdentifier(ident.Name)
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
package/compiler/spec.go
CHANGED
|
@@ -136,11 +136,6 @@ func (c *GoToTSCompiler) writeRegularFieldInitializer(fieldName string, fieldTyp
|
|
|
136
136
|
|
|
137
137
|
c.tsw.WriteLiterallyf("init?.%s ?? ", fieldName)
|
|
138
138
|
|
|
139
|
-
// Debug for Mode field specifically
|
|
140
|
-
if fieldName == "Mode" {
|
|
141
|
-
fmt.Printf("DEBUG Mode field: Type=%T, String=%s\n", fieldType, fieldType.String())
|
|
142
|
-
}
|
|
143
|
-
|
|
144
139
|
// Priority 1: Check if this is a wrapper type
|
|
145
140
|
if c.analysis.IsNamedBasicType(fieldType) {
|
|
146
141
|
// For wrapper types, use the zero value of the underlying type with type casting
|
|
@@ -161,35 +156,22 @@ func (c *GoToTSCompiler) writeRegularFieldInitializer(fieldName string, fieldTyp
|
|
|
161
156
|
|
|
162
157
|
// Priority 2: Handle imported types with basic underlying types (like os.FileMode)
|
|
163
158
|
if c.isImportedBasicType(fieldType) {
|
|
164
|
-
if fieldName == "Mode" {
|
|
165
|
-
fmt.Printf("DEBUG Mode field: Using imported basic type zero value\n")
|
|
166
|
-
}
|
|
167
159
|
c.writeImportedBasicTypeZeroValue(fieldType)
|
|
168
160
|
return
|
|
169
161
|
}
|
|
170
162
|
|
|
171
163
|
// Priority 3: Handle named types
|
|
172
164
|
if named, isNamed := fieldType.(*types.Named); isNamed {
|
|
173
|
-
if fieldName == "Mode" {
|
|
174
|
-
fmt.Printf("DEBUG Mode field: Using named type zero value\n")
|
|
175
|
-
}
|
|
176
165
|
c.writeNamedTypeZeroValue(named)
|
|
177
166
|
return
|
|
178
167
|
}
|
|
179
168
|
|
|
180
169
|
// Priority 4: Handle type aliases
|
|
181
170
|
if alias, isAlias := fieldType.(*types.Alias); isAlias {
|
|
182
|
-
if fieldName == "Mode" {
|
|
183
|
-
fmt.Printf("DEBUG Mode field: Using type alias zero value\n")
|
|
184
|
-
}
|
|
185
171
|
c.writeTypeAliasZeroValue(alias, astType)
|
|
186
172
|
return
|
|
187
173
|
}
|
|
188
174
|
|
|
189
|
-
// Default: use WriteZeroValueForType
|
|
190
|
-
if fieldName == "Mode" {
|
|
191
|
-
fmt.Printf("DEBUG Mode field: Using default WriteZeroValueForType\n")
|
|
192
|
-
}
|
|
193
175
|
c.WriteZeroValueForType(fieldType)
|
|
194
176
|
}
|
|
195
177
|
|
|
@@ -241,7 +223,6 @@ func (c *GoToTSCompiler) isImportedBasicType(fieldType types.Type) bool {
|
|
|
241
223
|
func (c *GoToTSCompiler) writeImportedBasicTypeZeroValue(fieldType types.Type) {
|
|
242
224
|
if named, ok := fieldType.(*types.Named); ok {
|
|
243
225
|
underlying := named.Underlying()
|
|
244
|
-
fmt.Printf("DEBUG writeImportedBasicTypeZeroValue: Named type, underlying=%T\n", underlying)
|
|
245
226
|
// Write zero value of underlying type with type casting
|
|
246
227
|
c.WriteZeroValueForType(underlying)
|
|
247
228
|
c.tsw.WriteLiterally(" as ")
|
|
@@ -251,7 +232,6 @@ func (c *GoToTSCompiler) writeImportedBasicTypeZeroValue(fieldType types.Type) {
|
|
|
251
232
|
|
|
252
233
|
if alias, ok := fieldType.(*types.Alias); ok {
|
|
253
234
|
underlying := alias.Underlying()
|
|
254
|
-
fmt.Printf("DEBUG writeImportedBasicTypeZeroValue: Alias type, underlying=%T\n", underlying)
|
|
255
235
|
// Write zero value of underlying type with type casting
|
|
256
236
|
c.WriteZeroValueForType(underlying)
|
|
257
237
|
c.tsw.WriteLiterally(" as ")
|
|
@@ -260,7 +240,6 @@ func (c *GoToTSCompiler) writeImportedBasicTypeZeroValue(fieldType types.Type) {
|
|
|
260
240
|
}
|
|
261
241
|
|
|
262
242
|
// Fallback (should not happen if isImportedBasicType was correct)
|
|
263
|
-
fmt.Printf("DEBUG writeImportedBasicTypeZeroValue: Fallback path\n")
|
|
264
243
|
c.WriteZeroValueForType(fieldType)
|
|
265
244
|
}
|
|
266
245
|
|
package/compiler/stmt-assign.go
CHANGED
|
@@ -117,8 +117,6 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
c.tsw.WriteLiterally("] = ")
|
|
120
|
-
// Add await if the call is async
|
|
121
|
-
c.writeAsyncCallIfNeeded(callExpr)
|
|
122
120
|
c.WriteValueExpr(callExpr)
|
|
123
121
|
c.tsw.WriteLine("")
|
|
124
122
|
return nil
|
|
@@ -167,8 +165,6 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
167
165
|
|
|
168
166
|
// Write a temporary variable to hold the function call result
|
|
169
167
|
c.tsw.WriteLiterally(" const _tmp = ")
|
|
170
|
-
// Add await if the call is async
|
|
171
|
-
c.writeAsyncCallIfNeeded(callExpr)
|
|
172
168
|
if err := c.WriteValueExpr(callExpr); err != nil {
|
|
173
169
|
return fmt.Errorf("failed to write RHS call expression in assignment: %w", err)
|
|
174
170
|
}
|
|
@@ -291,8 +287,6 @@ func (c *GoToTSCompiler) WriteStmtAssign(exp *ast.AssignStmt) error {
|
|
|
291
287
|
}
|
|
292
288
|
c.tsw.WriteLiterally("] = ")
|
|
293
289
|
|
|
294
|
-
// Add await if the call is async
|
|
295
|
-
c.writeAsyncCallIfNeeded(callExpr)
|
|
296
290
|
c.WriteValueExpr(callExpr)
|
|
297
291
|
|
|
298
292
|
c.tsw.WriteLine("")
|
package/compiler/stmt-select.go
CHANGED
|
@@ -8,6 +8,18 @@ import (
|
|
|
8
8
|
"github.com/pkg/errors"
|
|
9
9
|
)
|
|
10
10
|
|
|
11
|
+
// caseEndsWithReturn checks if a case body ends with a return statement
|
|
12
|
+
func (c *GoToTSCompiler) caseEndsWithReturn(body []ast.Stmt) bool {
|
|
13
|
+
if len(body) == 0 {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Check if the last statement is a return statement
|
|
18
|
+
lastStmt := body[len(body)-1]
|
|
19
|
+
_, isReturn := lastStmt.(*ast.ReturnStmt)
|
|
20
|
+
return isReturn
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
// WriteStmtSelect translates a Go `select` statement into an asynchronous
|
|
12
24
|
// TypeScript operation using the `$.selectStatement` runtime helper.
|
|
13
25
|
// Go's `select` provides non-deterministic choice over channel operations.
|
|
@@ -38,8 +50,29 @@ func (c *GoToTSCompiler) WriteStmtSelect(exp *ast.SelectStmt) error {
|
|
|
38
50
|
// Variable to track whether we have a default case
|
|
39
51
|
hasDefault := false
|
|
40
52
|
|
|
53
|
+
// Analyze if all cases end with return statements
|
|
54
|
+
allCasesReturn := true
|
|
55
|
+
for _, stmt := range exp.Body.List {
|
|
56
|
+
if commClause, ok := stmt.(*ast.CommClause); ok {
|
|
57
|
+
if commClause.Comm == nil {
|
|
58
|
+
// Default case - check if it ends with return
|
|
59
|
+
if !c.caseEndsWithReturn(commClause.Body) {
|
|
60
|
+
allCasesReturn = false
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
// Regular case - check if it ends with return
|
|
64
|
+
if !c.caseEndsWithReturn(commClause.Body) {
|
|
65
|
+
allCasesReturn = false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Generate unique variable names for this select statement
|
|
72
|
+
selectID := c.getDeterministicID(exp.Pos()) // Use deterministic position-based ID
|
|
73
|
+
|
|
41
74
|
// Start the selectStatement call and the array literal
|
|
42
|
-
c.tsw.
|
|
75
|
+
c.tsw.WriteLiterallyf("const [_select_has_return_%s, _select_value_%s] = await $.selectStatement(", selectID, selectID)
|
|
43
76
|
c.tsw.WriteLine("[") // Put bracket on new line
|
|
44
77
|
c.tsw.Indent(1)
|
|
45
78
|
|
|
@@ -207,5 +240,23 @@ func (c *GoToTSCompiler) WriteStmtSelect(exp *ast.SelectStmt) error {
|
|
|
207
240
|
c.tsw.WriteLiterally(")")
|
|
208
241
|
c.tsw.WriteLine("")
|
|
209
242
|
|
|
243
|
+
// Add code to handle the return value from selectStatement
|
|
244
|
+
c.tsw.WriteLiterallyf("if (_select_has_return_%s) {", selectID)
|
|
245
|
+
c.tsw.WriteLine("")
|
|
246
|
+
c.tsw.Indent(1)
|
|
247
|
+
c.tsw.WriteLiterallyf("return _select_value_%s!", selectID)
|
|
248
|
+
c.tsw.WriteLine("")
|
|
249
|
+
c.tsw.Indent(-1)
|
|
250
|
+
c.tsw.WriteLine("}")
|
|
251
|
+
|
|
252
|
+
// If all cases return, add a TypeScript-satisfying fallback return
|
|
253
|
+
if allCasesReturn {
|
|
254
|
+
c.tsw.WriteLine("// All cases should return, this fallback should never execute")
|
|
255
|
+
c.tsw.WriteLine("throw new Error('Unexpected: select statement did not return when all cases should return')")
|
|
256
|
+
} else {
|
|
257
|
+
c.tsw.WriteLiterallyf("// If _select_has_return_%s is false, continue execution", selectID)
|
|
258
|
+
c.tsw.WriteLine("")
|
|
259
|
+
}
|
|
260
|
+
|
|
210
261
|
return nil
|
|
211
262
|
}
|
package/compiler/type-assert.go
CHANGED
|
@@ -96,8 +96,8 @@ func (c *GoToTSCompiler) writeTypeAssert(lhs []ast.Expr, typeAssertExpr *ast.Typ
|
|
|
96
96
|
// For selector expressions as ok, we need to use temporary variables approach
|
|
97
97
|
if okIsSelectorExpr {
|
|
98
98
|
// Use temporary variables approach similar to SelectorExpr case
|
|
99
|
-
tempValName := fmt.Sprintf("_gs_ta_val_%
|
|
100
|
-
tempOkName := fmt.Sprintf("_gs_ta_ok_%
|
|
99
|
+
tempValName := fmt.Sprintf("_gs_ta_val_%s", c.getDeterministicID(typeAssertExpr.Pos())) // Unique name based on deterministic position
|
|
100
|
+
tempOkName := fmt.Sprintf("_gs_ta_ok_%s", c.getDeterministicID(typeAssertExpr.Pos())) // Unique name based on deterministic position
|
|
101
101
|
|
|
102
102
|
// Declare temporary variables:
|
|
103
103
|
// let _gs_ta_val_: AssertedTypeTS;
|
|
@@ -217,8 +217,8 @@ func (c *GoToTSCompiler) writeTypeAssert(lhs []ast.Expr, typeAssertExpr *ast.Typ
|
|
|
217
217
|
|
|
218
218
|
case *ast.SelectorExpr:
|
|
219
219
|
// Handle s.field, ok := expr.(Type)
|
|
220
|
-
tempValName := fmt.Sprintf("_gs_ta_val_%
|
|
221
|
-
tempOkName := fmt.Sprintf("_gs_ta_ok_%
|
|
220
|
+
tempValName := fmt.Sprintf("_gs_ta_val_%s", c.getDeterministicID(typeAssertExpr.Pos())) // Unique name based on deterministic position
|
|
221
|
+
tempOkName := fmt.Sprintf("_gs_ta_ok_%s", c.getDeterministicID(typeAssertExpr.Pos())) // Unique name based on deterministic position
|
|
222
222
|
|
|
223
223
|
// Declare temporary variables:
|
|
224
224
|
// let _gs_ta_val_: AssertedTypeTS;
|
|
@@ -284,8 +284,8 @@ func (c *GoToTSCompiler) writeTypeAssert(lhs []ast.Expr, typeAssertExpr *ast.Typ
|
|
|
284
284
|
case *ast.IndexExpr:
|
|
285
285
|
// Handle slice[index], ok := expr.(Type) or map[key], ok := expr.(Type)
|
|
286
286
|
// Use unique temporary variable names to avoid redeclaration
|
|
287
|
-
tempValName := fmt.Sprintf("_gs_ta_val_%
|
|
288
|
-
tempOkName := fmt.Sprintf("_gs_ta_ok_%
|
|
287
|
+
tempValName := fmt.Sprintf("_gs_ta_val_%s", c.getDeterministicID(vLHS.Pos())) // Unique name based on deterministic position
|
|
288
|
+
tempOkName := fmt.Sprintf("_gs_ta_ok_%s", c.getDeterministicID(vLHS.Pos())) // Unique name based on deterministic position
|
|
289
289
|
|
|
290
290
|
// Declare temporary variables:
|
|
291
291
|
// let _gs_ta_val_N_: AssertedTypeTS;
|
package/compiler/type.go
CHANGED
|
@@ -278,7 +278,7 @@ func (c *GoToTSCompiler) WriteNamedType(t *types.Named) {
|
|
|
278
278
|
// Write the qualified name: importAlias.TypeName
|
|
279
279
|
c.tsw.WriteLiterally(importAlias)
|
|
280
280
|
c.tsw.WriteLiterally(".")
|
|
281
|
-
c.tsw.WriteLiterally(t.Obj().Name())
|
|
281
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(t.Obj().Name()))
|
|
282
282
|
|
|
283
283
|
// For generic types, include type arguments
|
|
284
284
|
if t.TypeArgs() != nil && t.TypeArgs().Len() > 0 {
|
|
@@ -306,7 +306,7 @@ func (c *GoToTSCompiler) WriteNamedType(t *types.Named) {
|
|
|
306
306
|
// Write the qualified name: importAlias.TypeName
|
|
307
307
|
c.tsw.WriteLiterally(importAlias)
|
|
308
308
|
c.tsw.WriteLiterally(".")
|
|
309
|
-
c.tsw.WriteLiterally(t.Obj().Name())
|
|
309
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(t.Obj().Name()))
|
|
310
310
|
|
|
311
311
|
// For generic types, include type arguments
|
|
312
312
|
if t.TypeArgs() != nil && t.TypeArgs().Len() > 0 {
|
|
@@ -330,7 +330,7 @@ func (c *GoToTSCompiler) WriteNamedType(t *types.Named) {
|
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
// Use Obj().Name() for the original defined name (local types or unmatched imports)
|
|
333
|
-
c.tsw.WriteLiterally(t.Obj().Name())
|
|
333
|
+
c.tsw.WriteLiterally(c.sanitizeIdentifier(t.Obj().Name()))
|
|
334
334
|
|
|
335
335
|
// For generic types, include type arguments
|
|
336
336
|
if t.TypeArgs() != nil && t.TypeArgs().Len() > 0 {
|
|
@@ -11,7 +11,6 @@ export declare function println(...args: any[]): void;
|
|
|
11
11
|
export declare function panic(...args: any[]): void;
|
|
12
12
|
export type Bytes = Uint8Array | Slice<number>;
|
|
13
13
|
export declare function int(value: number): number;
|
|
14
|
-
export declare function multiplyDuration(duration: any, multiplier: number): any;
|
|
15
14
|
/**
|
|
16
15
|
* Normalizes various byte representations into a `Uint8Array` for protobuf compatibility.
|
|
17
16
|
*
|
|
@@ -27,15 +27,6 @@ export function int(value) {
|
|
|
27
27
|
// For this we use Math.trunc.
|
|
28
28
|
return Math.trunc(value);
|
|
29
29
|
}
|
|
30
|
-
// Duration multiplication helper for time package operations
|
|
31
|
-
// Handles expressions like time.Hour * 24
|
|
32
|
-
export function multiplyDuration(duration, multiplier) {
|
|
33
|
-
// Duration is now a number type alias, so just multiply directly
|
|
34
|
-
if (typeof duration === 'number') {
|
|
35
|
-
return duration * multiplier;
|
|
36
|
-
}
|
|
37
|
-
throw new Error(`Cannot multiply duration of type ${typeof duration}`);
|
|
38
|
-
}
|
|
39
30
|
/**
|
|
40
31
|
* Normalizes various byte representations into a `Uint8Array` for protobuf compatibility.
|
|
41
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin.js","sourceRoot":"","sources":["../../../gs/builtin/builtin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,GAAG,IAAW;IACpC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;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AG,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpC,KAAK,GAAG,KAAK,CAAA;gBACb,MAAK;YACP,CAAC;QACH,CAAC;QACD,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,EAAE,CAAA;YACP,GAAG,IAAI,MAAM,CAAC,MAAM,CAAA;QACtB,CAAC;aAAM,CAAC;YACN,GAAG,EAAE,CAAA;QACP,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAA6B;IAChE,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,YAAY,CAAA;IACrB,CAAC;IACD,uEAAuE;IACvE,OAAO,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAA;AAC1C,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,OAAO;IACrB,kFAAkF;IAClF,0DAA0D;IAC1D,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -77,7 +77,7 @@ export interface SelectCase<T> {
|
|
|
77
77
|
isSend: boolean;
|
|
78
78
|
channel: Channel<any> | ChannelRef<any> | null;
|
|
79
79
|
value?: any;
|
|
80
|
-
onSelected?: (result: SelectResult<T>) => Promise<
|
|
80
|
+
onSelected?: (result: SelectResult<T>) => Promise<any>;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Helper for 'select' statements. Takes an array of select cases
|
|
@@ -87,7 +87,7 @@ export interface SelectCase<T> {
|
|
|
87
87
|
* @param hasDefault Whether there is a default case
|
|
88
88
|
* @returns A promise that resolves with the result of the selected case
|
|
89
89
|
*/
|
|
90
|
-
export declare function selectStatement<T>(cases: SelectCase<T>[], hasDefault?: boolean): Promise<
|
|
90
|
+
export declare function selectStatement<T, V = void>(cases: SelectCase<T>[], hasDefault?: boolean): Promise<[boolean, V]>;
|
|
91
91
|
/**
|
|
92
92
|
* Helper function for channel send operations that handles nil channels correctly.
|
|
93
93
|
* In Go, sending to a nil channel blocks forever.
|
|
@@ -117,7 +117,9 @@ export declare function chanRecvWithOk<T>(channel: Channel<T> | ChannelRef<T> |
|
|
|
117
117
|
* @param direction Optional direction for the channel. Default is 'both' (bidirectional).
|
|
118
118
|
* @returns A new channel instance or channel reference.
|
|
119
119
|
*/
|
|
120
|
-
export declare
|
|
120
|
+
export declare function makeChannel<T>(bufferSize: number, zeroValue: T, direction: 'send'): SendOnlyChannelRef<T>;
|
|
121
|
+
export declare function makeChannel<T>(bufferSize: number, zeroValue: T, direction: 'receive'): ReceiveOnlyChannelRef<T>;
|
|
122
|
+
export declare function makeChannel<T>(bufferSize: number, zeroValue: T, direction?: 'both'): Channel<T>;
|
|
121
123
|
/**
|
|
122
124
|
* Represents a reference to a channel with a specific direction.
|
|
123
125
|
*/
|