goscript 0.0.45 → 0.0.48
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 +198 -504
- package/compiler/compiler.go +20 -70
- package/compiler/decl.go +52 -38
- package/compiler/expr-call-async.go +101 -0
- package/compiler/expr-call-builtins.go +133 -0
- package/compiler/expr-call-helpers.go +138 -0
- package/compiler/expr-call-make.go +568 -0
- package/compiler/expr-call-type-conversion.go +424 -0
- package/compiler/expr-call.go +59 -1305
- package/compiler/expr.go +126 -4
- package/compiler/spec-struct.go +22 -9
- package/compiler/spec.go +53 -118
- package/compiler/type.go +51 -0
- package/dist/gs/builtin/builtin.d.ts +3 -1
- package/dist/gs/builtin/builtin.js +6 -0
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +12 -1
- package/dist/gs/io/fs/fs.js +106 -30
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +1 -3
- package/dist/gs/os/types_js.gs.js +2 -1
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.js +2 -2
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/gs/builtin/builtin.ts +7 -2
- package/gs/io/fs/fs.ts +100 -31
- package/gs/io/fs/godoc.txt +370 -17
- package/gs/os/types_js.gs.ts +2 -2
- package/gs/os/types_unix.gs.ts +2 -2
- package/package.json +1 -1
package/compiler/expr.go
CHANGED
|
@@ -251,6 +251,113 @@ func (c *GoToTSCompiler) getTypeNameString(typeExpr ast.Expr) string {
|
|
|
251
251
|
return "unknown"
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
// getFinalUnderlyingType traverses the chain of named types to find the ultimate underlying type.
|
|
255
|
+
// This handles cases like: type A B; type B C; type C string.
|
|
256
|
+
// Returns the final underlying type and whether the original type was a named type.
|
|
257
|
+
func (c *GoToTSCompiler) getFinalUnderlyingType(t types.Type) (types.Type, bool) {
|
|
258
|
+
if t == nil {
|
|
259
|
+
return nil, false
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Check if this is a named type
|
|
263
|
+
namedType, isNamed := t.(*types.Named)
|
|
264
|
+
if !isNamed {
|
|
265
|
+
return t, false
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Follow the chain of named types to find the ultimate underlying type
|
|
269
|
+
ultimate := namedType
|
|
270
|
+
for {
|
|
271
|
+
underlying := ultimate.Underlying()
|
|
272
|
+
if underlyingNamed, isNamedUnderlying := underlying.(*types.Named); isNamedUnderlying {
|
|
273
|
+
// Continue following the chain
|
|
274
|
+
ultimate = underlyingNamed
|
|
275
|
+
} else {
|
|
276
|
+
// We've reached the final underlying type
|
|
277
|
+
return underlying, true
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// isNamedNumericType checks if a given type is a named type with an underlying numeric type.
|
|
283
|
+
func (c *GoToTSCompiler) isNamedNumericType(t types.Type) bool {
|
|
284
|
+
finalType, wasNamed := c.getFinalUnderlyingType(t)
|
|
285
|
+
if !wasNamed {
|
|
286
|
+
return false
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if basicType, isBasic := finalType.(*types.Basic); isBasic {
|
|
290
|
+
info := basicType.Info()
|
|
291
|
+
return (info&types.IsInteger) != 0 || (info&types.IsFloat) != 0
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return false
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// isWrapperType checks if a type is implemented as a wrapper class with valueOf() method
|
|
298
|
+
// This is true for named types that have methods defined on them
|
|
299
|
+
func (c *GoToTSCompiler) isWrapperType(t types.Type) bool {
|
|
300
|
+
if t == nil {
|
|
301
|
+
return false
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Follow any type aliases to get to the actual named type
|
|
305
|
+
namedType, ok := t.(*types.Named)
|
|
306
|
+
if !ok {
|
|
307
|
+
return false
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// If the named type has methods, it's implemented as a class with valueOf()
|
|
311
|
+
numMethods := namedType.NumMethods()
|
|
312
|
+
return numMethods > 0
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// needsValueOfForBitwiseOp checks if an operand in a bitwise operation needs .valueOf() to be called
|
|
316
|
+
// This is needed for custom types (like FileMode) that have a valueOf() method and need to be treated as numbers
|
|
317
|
+
func (c *GoToTSCompiler) needsValueOfForBitwiseOp(expr ast.Expr) bool {
|
|
318
|
+
if c.pkg == nil || c.pkg.TypesInfo == nil {
|
|
319
|
+
return false
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
exprType := c.pkg.TypesInfo.TypeOf(expr)
|
|
323
|
+
if exprType == nil {
|
|
324
|
+
return false
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Don't add valueOf() for basic literals (numeric, string, bool literals)
|
|
328
|
+
switch expr.(type) {
|
|
329
|
+
case *ast.BasicLit:
|
|
330
|
+
return false
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Check if this is a compile-time constant of a primitive type
|
|
334
|
+
if tv, ok := c.pkg.TypesInfo.Types[expr]; ok {
|
|
335
|
+
if tv.Value != nil {
|
|
336
|
+
// This is a constant expression - but only skip valueOf() if it's truly a primitive type
|
|
337
|
+
// (not a named type with methods that happens to be constant)
|
|
338
|
+
if _, isBasic := exprType.(*types.Basic); isBasic {
|
|
339
|
+
// Primitive constant, don't add valueOf()
|
|
340
|
+
return false
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Check if this type is implemented as a wrapper class with valueOf()
|
|
346
|
+
return c.isWrapperType(exprType)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// writeBitwiseOperand writes an operand for a bitwise operation, adding .valueOf() if needed
|
|
350
|
+
func (c *GoToTSCompiler) writeBitwiseOperand(expr ast.Expr) error {
|
|
351
|
+
if c.needsValueOfForBitwiseOp(expr) {
|
|
352
|
+
if err := c.WriteValueExpr(expr); err != nil {
|
|
353
|
+
return err
|
|
354
|
+
}
|
|
355
|
+
c.tsw.WriteLiterally(".valueOf()")
|
|
356
|
+
return nil
|
|
357
|
+
}
|
|
358
|
+
return c.WriteValueExpr(expr)
|
|
359
|
+
}
|
|
360
|
+
|
|
254
361
|
// WriteBinaryExpr translates a Go binary expression (`ast.BinaryExpr`) into its
|
|
255
362
|
// TypeScript equivalent.
|
|
256
363
|
// It handles several cases:
|
|
@@ -435,8 +542,15 @@ func (c *GoToTSCompiler) WriteBinaryExpr(exp *ast.BinaryExpr) error {
|
|
|
435
542
|
c.tsw.WriteLiterally("(") // Add opening parenthesis for bitwise operations
|
|
436
543
|
}
|
|
437
544
|
|
|
438
|
-
|
|
439
|
-
|
|
545
|
+
// For bitwise operations, use special operand writing that adds .valueOf() when needed
|
|
546
|
+
if isBitwise {
|
|
547
|
+
if err := c.writeBitwiseOperand(exp.X); err != nil {
|
|
548
|
+
return fmt.Errorf("failed to write binary expression left operand: %w", err)
|
|
549
|
+
}
|
|
550
|
+
} else {
|
|
551
|
+
if err := c.WriteValueExpr(exp.X); err != nil {
|
|
552
|
+
return fmt.Errorf("failed to write binary expression left operand: %w", err)
|
|
553
|
+
}
|
|
440
554
|
}
|
|
441
555
|
c.tsw.WriteLiterally(" ")
|
|
442
556
|
tokStr, ok := TokenToTs(exp.Op)
|
|
@@ -446,8 +560,16 @@ func (c *GoToTSCompiler) WriteBinaryExpr(exp *ast.BinaryExpr) error {
|
|
|
446
560
|
|
|
447
561
|
c.tsw.WriteLiterally(tokStr)
|
|
448
562
|
c.tsw.WriteLiterally(" ")
|
|
449
|
-
|
|
450
|
-
|
|
563
|
+
|
|
564
|
+
// For bitwise operations, use special operand writing that adds .valueOf() when needed
|
|
565
|
+
if isBitwise {
|
|
566
|
+
if err := c.writeBitwiseOperand(exp.Y); err != nil {
|
|
567
|
+
return fmt.Errorf("failed to write binary expression right operand: %w", err)
|
|
568
|
+
}
|
|
569
|
+
} else {
|
|
570
|
+
if err := c.WriteValueExpr(exp.Y); err != nil {
|
|
571
|
+
return fmt.Errorf("failed to write binary expression right operand: %w", err)
|
|
572
|
+
}
|
|
451
573
|
}
|
|
452
574
|
|
|
453
575
|
if isBitwise {
|
package/compiler/spec-struct.go
CHANGED
|
@@ -63,7 +63,7 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
63
63
|
if fieldType == nil {
|
|
64
64
|
fieldType = types.Typ[types.Invalid]
|
|
65
65
|
}
|
|
66
|
-
c.writeGetterSetter(fieldName, fieldType, field.Doc, field.Comment)
|
|
66
|
+
c.writeGetterSetter(fieldName, fieldType, field.Doc, field.Comment, field.Type)
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,7 +72,17 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
72
72
|
field := underlyingStruct.Field(i)
|
|
73
73
|
if field.Anonymous() {
|
|
74
74
|
fieldKeyName := c.getEmbeddedFieldKeyName(field.Type())
|
|
75
|
-
c.writeGetterSetter(fieldKeyName, field.Type(), nil, nil)
|
|
75
|
+
c.writeGetterSetter(fieldKeyName, field.Type(), nil, nil, nil)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Create a mapping from field names to AST types for preserving qualified names
|
|
80
|
+
fieldASTTypes := make(map[string]ast.Expr)
|
|
81
|
+
for _, field := range t.Fields.List {
|
|
82
|
+
if len(field.Names) > 0 {
|
|
83
|
+
for _, name := range field.Names {
|
|
84
|
+
fieldASTTypes[name.Name] = field.Type
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
|
|
@@ -93,14 +103,17 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
93
103
|
if fieldKeyName == "_" {
|
|
94
104
|
continue
|
|
95
105
|
}
|
|
96
|
-
|
|
106
|
+
|
|
107
|
+
// Use AST-based type string when available, fall back to types-based
|
|
108
|
+
astType := fieldASTTypes[fieldKeyName]
|
|
109
|
+
fieldTsType := c.getASTTypeString(astType, field.Type())
|
|
97
110
|
c.tsw.WriteLinef("%s: $.VarRef<%s>;", fieldKeyName, fieldTsType)
|
|
98
111
|
}
|
|
99
112
|
c.tsw.Indent(-1)
|
|
100
113
|
c.tsw.WriteLine("}")
|
|
101
114
|
|
|
102
115
|
// Generate the flattened type string for the constructor init parameter
|
|
103
|
-
flattenedInitType := c.generateFlattenedInitTypeString(goStructType)
|
|
116
|
+
flattenedInitType := c.generateFlattenedInitTypeString(goStructType, fieldASTTypes)
|
|
104
117
|
|
|
105
118
|
c.tsw.WriteLine("")
|
|
106
119
|
c.tsw.WriteLinef("constructor(init?: Partial<%s>) {", flattenedInitType)
|
|
@@ -132,7 +145,7 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
132
145
|
c.tsw.WriteLine(",")
|
|
133
146
|
}
|
|
134
147
|
|
|
135
|
-
c.writeVarRefedFieldInitializer(fieldKeyName, fieldType, field.Anonymous())
|
|
148
|
+
c.writeVarRefedFieldInitializer(fieldKeyName, fieldType, field.Anonymous(), fieldASTTypes[fieldKeyName])
|
|
136
149
|
firstFieldWritten = true
|
|
137
150
|
}
|
|
138
151
|
if firstFieldWritten {
|
|
@@ -481,7 +494,7 @@ func (c *GoToTSCompiler) WriteStructTypeSpec(a *ast.TypeSpec, t *ast.StructType)
|
|
|
481
494
|
//
|
|
482
495
|
// The resulting string is sorted by field name for deterministic output and represents
|
|
483
496
|
// the shape of the object expected by the struct's TypeScript constructor.
|
|
484
|
-
func (c *GoToTSCompiler) generateFlattenedInitTypeString(structType *types.Named) string {
|
|
497
|
+
func (c *GoToTSCompiler) generateFlattenedInitTypeString(structType *types.Named, fieldASTTypes map[string]ast.Expr) string {
|
|
485
498
|
if structType == nil {
|
|
486
499
|
return "{}"
|
|
487
500
|
}
|
|
@@ -519,8 +532,8 @@ func (c *GoToTSCompiler) generateFlattenedInitTypeString(structType *types.Named
|
|
|
519
532
|
embeddedName := named.Obj().Name()
|
|
520
533
|
// Check if the embedded type is an interface
|
|
521
534
|
if _, isInterface := fieldType.Underlying().(*types.Interface); isInterface {
|
|
522
|
-
// For embedded interfaces, use the interface type
|
|
523
|
-
embeddedTypeMap[c.getEmbeddedFieldKeyName(field.Type())] =
|
|
535
|
+
// For embedded interfaces, use the full qualified interface type
|
|
536
|
+
embeddedTypeMap[c.getEmbeddedFieldKeyName(field.Type())] = c.getTypeString(field.Type())
|
|
524
537
|
} else {
|
|
525
538
|
// For embedded structs, use ConstructorParameters for field-based initialization
|
|
526
539
|
embeddedTypeMap[c.getEmbeddedFieldKeyName(field.Type())] = fmt.Sprintf("Partial<ConstructorParameters<typeof %s>[0]>", embeddedName)
|
|
@@ -528,7 +541,7 @@ func (c *GoToTSCompiler) generateFlattenedInitTypeString(structType *types.Named
|
|
|
528
541
|
}
|
|
529
542
|
continue
|
|
530
543
|
}
|
|
531
|
-
fieldMap[fieldName] = c.
|
|
544
|
+
fieldMap[fieldName] = c.getASTTypeString(fieldASTTypes[fieldName], field.Type())
|
|
532
545
|
}
|
|
533
546
|
|
|
534
547
|
// Promoted fields (handled by Go's embedding, init should use direct/embedded names)
|
package/compiler/spec.go
CHANGED
|
@@ -56,8 +56,14 @@ func (c *GoToTSCompiler) getEmbeddedFieldKeyName(fieldType types.Type) string {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
func (c *GoToTSCompiler) writeGetterSetter(fieldName string, fieldType types.Type, doc, comment *ast.CommentGroup) {
|
|
60
|
-
|
|
59
|
+
func (c *GoToTSCompiler) writeGetterSetter(fieldName string, fieldType types.Type, doc, comment *ast.CommentGroup, astType ast.Expr) {
|
|
60
|
+
// Use AST type information if available to preserve qualified names
|
|
61
|
+
var fieldTypeStr string
|
|
62
|
+
if astType != nil {
|
|
63
|
+
fieldTypeStr = c.getASTTypeString(astType, fieldType)
|
|
64
|
+
} else {
|
|
65
|
+
fieldTypeStr = c.getTypeString(fieldType)
|
|
66
|
+
}
|
|
61
67
|
|
|
62
68
|
// Generate getter
|
|
63
69
|
if doc != nil {
|
|
@@ -81,7 +87,7 @@ func (c *GoToTSCompiler) writeGetterSetter(fieldName string, fieldType types.Typ
|
|
|
81
87
|
c.tsw.WriteLine("")
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
func (c *GoToTSCompiler) writeVarRefedFieldInitializer(fieldName string, fieldType types.Type, isEmbedded bool) {
|
|
90
|
+
func (c *GoToTSCompiler) writeVarRefedFieldInitializer(fieldName string, fieldType types.Type, isEmbedded bool, astType ast.Expr) {
|
|
85
91
|
c.tsw.WriteLiterally(fieldName)
|
|
86
92
|
c.tsw.WriteLiterally(": $.varRef(")
|
|
87
93
|
|
|
@@ -119,7 +125,47 @@ func (c *GoToTSCompiler) writeVarRefedFieldInitializer(fieldName string, fieldTy
|
|
|
119
125
|
c.tsw.WriteLiterallyf("init?.%s?.clone() ?? new %s()", fieldName, structTypeNameForClone)
|
|
120
126
|
} else {
|
|
121
127
|
c.tsw.WriteLiterallyf("init?.%s ?? ", fieldName)
|
|
122
|
-
|
|
128
|
+
// Check if this is a named type or type alias and use constructor instead of null
|
|
129
|
+
if named, isNamed := fieldType.(*types.Named); isNamed {
|
|
130
|
+
// This is a named type
|
|
131
|
+
// Check if underlying type is an interface
|
|
132
|
+
if _, isInterface := named.Underlying().(*types.Interface); isInterface {
|
|
133
|
+
// For interfaces, use null as the zero value
|
|
134
|
+
c.tsw.WriteLiterally("null")
|
|
135
|
+
} else if _, isStruct := named.Underlying().(*types.Struct); !isStruct {
|
|
136
|
+
// For non-struct, non-interface named types, use constructor
|
|
137
|
+
c.tsw.WriteLiterally("new ")
|
|
138
|
+
c.WriteNamedType(named)
|
|
139
|
+
c.tsw.WriteLiterally("(")
|
|
140
|
+
c.WriteZeroValueForType(named.Underlying())
|
|
141
|
+
c.tsw.WriteLiterally(")")
|
|
142
|
+
} else {
|
|
143
|
+
c.WriteZeroValueForType(fieldType)
|
|
144
|
+
}
|
|
145
|
+
} else if alias, isAlias := fieldType.(*types.Alias); isAlias {
|
|
146
|
+
// This is a type alias (like os.FileMode)
|
|
147
|
+
// Check if underlying type is an interface
|
|
148
|
+
if _, isInterface := alias.Underlying().(*types.Interface); isInterface {
|
|
149
|
+
// For interface type aliases, use null as the zero value
|
|
150
|
+
c.tsw.WriteLiterally("null")
|
|
151
|
+
} else if _, isStruct := alias.Underlying().(*types.Struct); !isStruct {
|
|
152
|
+
// For non-struct, non-interface type aliases, use constructor
|
|
153
|
+
c.tsw.WriteLiterally("new ")
|
|
154
|
+
// Use AST type information if available to preserve qualified names
|
|
155
|
+
if astType != nil {
|
|
156
|
+
c.WriteTypeExpr(astType)
|
|
157
|
+
} else {
|
|
158
|
+
c.WriteGoType(fieldType, GoTypeContextGeneral)
|
|
159
|
+
}
|
|
160
|
+
c.tsw.WriteLiterally("(")
|
|
161
|
+
c.WriteZeroValueForType(alias.Underlying())
|
|
162
|
+
c.tsw.WriteLiterally(")")
|
|
163
|
+
} else {
|
|
164
|
+
c.WriteZeroValueForType(fieldType)
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
c.WriteZeroValueForType(fieldType)
|
|
168
|
+
}
|
|
123
169
|
}
|
|
124
170
|
}
|
|
125
171
|
|
|
@@ -294,123 +340,12 @@ func (c *GoToTSCompiler) WriteNamedTypeWithMethods(a *ast.TypeSpec) error {
|
|
|
294
340
|
|
|
295
341
|
// writeNamedTypeMethod writes a method for a named type, handling receiver binding properly
|
|
296
342
|
func (c *GoToTSCompiler) writeNamedTypeMethod(decl *ast.FuncDecl) error {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Determine if method is async
|
|
302
|
-
var isAsync bool
|
|
303
|
-
if obj := c.pkg.TypesInfo.Defs[decl.Name]; obj != nil {
|
|
304
|
-
isAsync = c.analysis.IsAsyncFunc(obj)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Methods are typically public in the TS output
|
|
308
|
-
c.tsw.WriteLiterally("public ")
|
|
309
|
-
|
|
310
|
-
// Add async modifier if needed
|
|
311
|
-
if isAsync {
|
|
312
|
-
c.tsw.WriteLiterally("async ")
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
// Keep original Go casing for method names
|
|
316
|
-
if err := c.WriteValueExpr(decl.Name); err != nil { // Method name is a value identifier
|
|
343
|
+
_, err := c.writeMethodSignature(decl)
|
|
344
|
+
if err != nil {
|
|
317
345
|
return err
|
|
318
346
|
}
|
|
319
347
|
|
|
320
|
-
|
|
321
|
-
funcType := decl.Type
|
|
322
|
-
c.tsw.WriteLiterally("(")
|
|
323
|
-
if funcType.Params != nil {
|
|
324
|
-
c.WriteFieldList(funcType.Params, true) // true = arguments
|
|
325
|
-
}
|
|
326
|
-
c.tsw.WriteLiterally(")")
|
|
327
|
-
|
|
328
|
-
// Handle return type
|
|
329
|
-
if funcType.Results != nil && len(funcType.Results.List) > 0 {
|
|
330
|
-
c.tsw.WriteLiterally(": ")
|
|
331
|
-
if isAsync {
|
|
332
|
-
c.tsw.WriteLiterally("Promise<")
|
|
333
|
-
}
|
|
334
|
-
if len(funcType.Results.List) == 1 {
|
|
335
|
-
// Single return value
|
|
336
|
-
resultType := funcType.Results.List[0].Type
|
|
337
|
-
c.WriteTypeExpr(resultType)
|
|
338
|
-
} else {
|
|
339
|
-
// Multiple return values -> tuple type
|
|
340
|
-
c.tsw.WriteLiterally("[")
|
|
341
|
-
for i, field := range funcType.Results.List {
|
|
342
|
-
if i > 0 {
|
|
343
|
-
c.tsw.WriteLiterally(", ")
|
|
344
|
-
}
|
|
345
|
-
c.WriteTypeExpr(field.Type)
|
|
346
|
-
}
|
|
347
|
-
c.tsw.WriteLiterally("]")
|
|
348
|
-
}
|
|
349
|
-
if isAsync {
|
|
350
|
-
c.tsw.WriteLiterally(">")
|
|
351
|
-
}
|
|
352
|
-
} else {
|
|
353
|
-
// No return value -> void
|
|
354
|
-
if isAsync {
|
|
355
|
-
c.tsw.WriteLiterally(": Promise<void>")
|
|
356
|
-
} else {
|
|
357
|
-
c.tsw.WriteLiterally(": void")
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
c.tsw.WriteLiterally(" ")
|
|
362
|
-
|
|
363
|
-
// For named types with methods, bind receiver name to this._value conditionally
|
|
364
|
-
if recvField := decl.Recv.List[0]; len(recvField.Names) > 0 {
|
|
365
|
-
recvName := recvField.Names[0].Name
|
|
366
|
-
if recvName != "_" {
|
|
367
|
-
// Check if receiver is actually used
|
|
368
|
-
var needsReceiverBinding bool
|
|
369
|
-
if obj := c.pkg.TypesInfo.Defs[decl.Name]; obj != nil {
|
|
370
|
-
needsReceiverBinding = c.analysis.IsReceiverUsed(obj)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
c.tsw.WriteLine("{")
|
|
374
|
-
c.tsw.Indent(1)
|
|
375
|
-
|
|
376
|
-
if needsReceiverBinding {
|
|
377
|
-
// Bind the receiver name to this._value for value types
|
|
378
|
-
sanitizedRecvName := c.sanitizeIdentifier(recvName)
|
|
379
|
-
c.tsw.WriteLinef("const %s = this._value", sanitizedRecvName)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// Add using statement if needed
|
|
383
|
-
if c.analysis.NeedsDefer(decl.Body) {
|
|
384
|
-
if c.analysis.IsInAsyncFunction(decl) {
|
|
385
|
-
c.tsw.WriteLine("await using __defer = new $.AsyncDisposableStack();")
|
|
386
|
-
} else {
|
|
387
|
-
c.tsw.WriteLine("using cleanup = new $.DisposableStack();")
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Declare named return variables and initialize them to their zero values
|
|
392
|
-
if err := c.writeNamedReturnDeclarations(decl.Type.Results); err != nil {
|
|
393
|
-
return fmt.Errorf("failed to write named return declarations: %w", err)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// write method body without outer braces
|
|
397
|
-
for _, stmt := range decl.Body.List {
|
|
398
|
-
if err := c.WriteStmt(stmt); err != nil {
|
|
399
|
-
return fmt.Errorf("failed to write statement in function body: %w", err)
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
c.tsw.Indent(-1)
|
|
403
|
-
c.tsw.WriteLine("}")
|
|
404
|
-
|
|
405
|
-
return nil
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
// no named receiver, write whole body
|
|
409
|
-
if err := c.WriteStmt(decl.Body); err != nil {
|
|
410
|
-
return fmt.Errorf("failed to write function body: %w", err)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return nil
|
|
348
|
+
return c.writeMethodBodyWithReceiverBinding(decl, "this._value")
|
|
414
349
|
}
|
|
415
350
|
|
|
416
351
|
// WriteTypeSpec writes the type specification to the output.
|
package/compiler/type.go
CHANGED
|
@@ -72,6 +72,38 @@ func (c *GoToTSCompiler) WriteGoType(typ types.Type, context GoTypeContext) {
|
|
|
72
72
|
case *types.Struct:
|
|
73
73
|
c.WriteStructType(t)
|
|
74
74
|
case *types.Alias:
|
|
75
|
+
// Check if this type alias is from an imported package
|
|
76
|
+
aliasObj := t.Obj()
|
|
77
|
+
if aliasObj != nil && aliasObj.Pkg() != nil && aliasObj.Pkg() != c.pkg.Types {
|
|
78
|
+
// This type alias is from an imported package, find the import alias
|
|
79
|
+
aliasPkg := aliasObj.Pkg()
|
|
80
|
+
aliasPkgPath := aliasPkg.Path()
|
|
81
|
+
aliasPkgName := aliasPkg.Name() // Get the actual package name
|
|
82
|
+
|
|
83
|
+
// Try to find the import alias by matching the package name or path
|
|
84
|
+
for importAlias := range c.analysis.Imports {
|
|
85
|
+
// First, try to match by the actual package name
|
|
86
|
+
if importAlias == aliasPkgName {
|
|
87
|
+
// Write the qualified name: importAlias.TypeName
|
|
88
|
+
c.tsw.WriteLiterally(importAlias)
|
|
89
|
+
c.tsw.WriteLiterally(".")
|
|
90
|
+
c.tsw.WriteLiterally(aliasObj.Name())
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Fallback: try to match by path-based package name (for backwards compatibility)
|
|
95
|
+
pts := strings.Split(aliasPkgPath, "/")
|
|
96
|
+
defaultPkgName := pts[len(pts)-1]
|
|
97
|
+
if importAlias == defaultPkgName || importAlias == aliasPkgPath {
|
|
98
|
+
// Write the qualified name: importAlias.TypeName
|
|
99
|
+
c.tsw.WriteLiterally(importAlias)
|
|
100
|
+
c.tsw.WriteLiterally(".")
|
|
101
|
+
c.tsw.WriteLiterally(aliasObj.Name())
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// For local type aliases or unmatched imports, expand to underlying type
|
|
75
107
|
c.WriteGoType(t.Underlying(), context)
|
|
76
108
|
case *types.TypeParam:
|
|
77
109
|
// For type parameters, write the type parameter name (e.g., "T", "K", etc.)
|
|
@@ -694,6 +726,25 @@ func (c *GoToTSCompiler) getTypeString(goType types.Type) string {
|
|
|
694
726
|
return typeStr.String()
|
|
695
727
|
}
|
|
696
728
|
|
|
729
|
+
// getASTTypeString is a utility function that converts a Go type to its TypeScript
|
|
730
|
+
// type string representation, preferring AST-based type writing when available to
|
|
731
|
+
// preserve qualified names like os.FileMode. Falls back to types.Type-based writing
|
|
732
|
+
// when AST information is not available.
|
|
733
|
+
func (c *GoToTSCompiler) getASTTypeString(astType ast.Expr, goType types.Type) string {
|
|
734
|
+
var typeStr strings.Builder
|
|
735
|
+
writer := NewTSCodeWriter(&typeStr)
|
|
736
|
+
tempCompiler := NewGoToTSCompiler(writer, c.pkg, c.analysis)
|
|
737
|
+
|
|
738
|
+
if astType != nil {
|
|
739
|
+
// Use AST-based type writing to preserve qualified names
|
|
740
|
+
tempCompiler.WriteTypeExpr(astType)
|
|
741
|
+
} else {
|
|
742
|
+
// Fall back to types.Type-based writing
|
|
743
|
+
tempCompiler.WriteGoType(goType, GoTypeContextGeneral)
|
|
744
|
+
}
|
|
745
|
+
return typeStr.String()
|
|
746
|
+
}
|
|
747
|
+
|
|
697
748
|
// WriteStructType translates a Go struct type definition (`ast.StructType`)
|
|
698
749
|
// into a TypeScript anonymous object type (e.g., `{ Field1: Type1; Field2: Type2 }`).
|
|
699
750
|
// If the struct has no fields, it writes `{}`. Otherwise, it delegates to
|
|
@@ -10,7 +10,9 @@ export declare function println(...args: any[]): void;
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function panic(...args: any[]): void;
|
|
12
12
|
export type Bytes = Uint8Array | Slice<number>;
|
|
13
|
-
export declare function int(value: number
|
|
13
|
+
export declare function int(value: number | {
|
|
14
|
+
valueOf(): number | null;
|
|
15
|
+
}): number;
|
|
14
16
|
export declare function multiplyDuration(duration: any, multiplier: number): any;
|
|
15
17
|
/**
|
|
16
18
|
* Normalizes various byte representations into a `Uint8Array` for protobuf compatibility.
|
|
@@ -20,8 +20,14 @@ export function int(value) {
|
|
|
20
20
|
// we need to handle the conversion properly. The issue is that JavaScript's number type
|
|
21
21
|
// can represent values larger than 32-bit signed integers, but when cast in certain contexts
|
|
22
22
|
// they get interpreted as signed 32-bit integers.
|
|
23
|
+
//
|
|
23
24
|
// For Go's int type on 64-bit systems, we should preserve the full value
|
|
24
25
|
// since JavaScript numbers can safely represent integers up to Number.MAX_SAFE_INTEGER
|
|
26
|
+
//
|
|
27
|
+
// For this we use Math.trunc.
|
|
28
|
+
if (typeof value === 'object' && 'valueOf' in value) {
|
|
29
|
+
return Math.trunc(value.valueOf() ?? 0);
|
|
30
|
+
}
|
|
25
31
|
return Math.trunc(value);
|
|
26
32
|
}
|
|
27
33
|
// Duration multiplication helper for time package operations
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin.js","sourceRoot":"","sources":["../../../gs/builtin/builtin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA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|
|
38
38
|
};
|
|
39
|
-
export
|
|
39
|
+
export declare class FileMode {
|
|
40
|
+
private _value;
|
|
41
|
+
constructor(_value: number);
|
|
42
|
+
valueOf(): number;
|
|
43
|
+
toString(): string;
|
|
44
|
+
static from(value: number): FileMode;
|
|
45
|
+
IsDir(): boolean;
|
|
46
|
+
IsRegular(): boolean;
|
|
47
|
+
Perm(): FileMode;
|
|
48
|
+
String(): string;
|
|
49
|
+
Type(): FileMode;
|
|
50
|
+
}
|
|
40
51
|
export declare let ModeDir: FileMode;
|
|
41
52
|
export declare let ModeAppend: FileMode;
|
|
42
53
|
export declare let ModeExclusive: FileMode;
|