@@ -433,22 +433,24 @@ func (c *PkgContext) translateExpr(expr ast.Expr) string {
433
433
case * ast.SliceExpr :
434
434
b , isBasic := c .info .Types [e .X ].(* types.Basic )
435
435
isString := isBasic && b .Info ()& types .IsString != 0
436
- method := "Go$subslice"
437
- if isString {
438
- method = "substring"
439
- }
440
436
slice := c .translateExprToType (e .X , exprType )
441
437
if e .High == nil {
442
438
if e .Low == nil {
443
439
return slice
444
440
}
445
- return fmt .Sprintf ("%s.%s(%s)" , slice , method , c .translateExpr (e .Low ))
441
+ if isString {
442
+ return fmt .Sprintf ("%s.substring(%s)" , slice , c .translateExpr (e .Low ))
443
+ }
444
+ return fmt .Sprintf ("Go$subslice(%s, %s)" , slice , c .translateExpr (e .Low ))
446
445
}
447
446
low := "0"
448
447
if e .Low != nil {
449
448
low = c .translateExpr (e .Low )
450
449
}
451
- return fmt .Sprintf ("%s.%s(%s, %s)" , slice , method , low , c .translateExpr (e .High ))
450
+ if isString {
451
+ return fmt .Sprintf ("%s.substring(%s, %s)" , slice , low , c .translateExpr (e .High ))
452
+ }
453
+ return fmt .Sprintf ("Go$subslice(%s, %s, %s)" , slice , low , c .translateExpr (e .High ))
452
454
453
455
case * ast.SelectorExpr :
454
456
sel := c .info .Selections [e ]
@@ -498,7 +500,7 @@ func (c *PkgContext) translateExpr(expr ast.Expr) string {
498
500
switch t2 := c .info .Types [e .Args [0 ]].Underlying ().(type ) {
499
501
case * types.Slice :
500
502
if len (e .Args ) == 3 {
501
- return fmt .Sprintf ("new %s(Go$clear(new %s(%s))).Go$subslice( 0, %s)" , c .typeName (c .info .Types [e .Args [0 ]]), toArrayType (t2 .Elem ()), c .translateExpr (e .Args [2 ]), c .translateExpr (e .Args [1 ]))
503
+ return fmt .Sprintf ("Go$subslice( new %s(Go$clear(new %s(%s))), 0, %s)" , c .typeName (c .info .Types [e .Args [0 ]]), toArrayType (t2 .Elem ()), c .translateExpr (e .Args [2 ]), c .translateExpr (e .Args [1 ]))
502
504
}
503
505
return fmt .Sprintf ("new %s(Go$clear(new %s(%s)))" , c .typeName (c .info .Types [e .Args [0 ]]), toArrayType (t2 .Elem ()), c .translateExpr (e .Args [1 ]))
504
506
default :
@@ -749,7 +751,7 @@ func (c *PkgContext) translateExprToType(expr ast.Expr, desiredType types.Type)
749
751
case t .Kind () == types .UnsafePointer :
750
752
if unary , isUnary := expr .(* ast.UnaryExpr ); isUnary && unary .Op == token .AND {
751
753
if indexExpr , isIndexExpr := unary .X .(* ast.IndexExpr ); isIndexExpr {
752
- return fmt .Sprintf ("%s. Go$toArray( )" , c .translateExprToType (indexExpr .X , types .NewSlice (nil )))
754
+ return fmt .Sprintf ("Go$sliceToArray(%s )" , c .translateExprToType (indexExpr .X , types .NewSlice (nil )))
753
755
}
754
756
if ident , isIdent := unary .X .(* ast.Ident ); isIdent && ident .Name == "_zero" {
755
757
return "new Uint8Array(0)"
@@ -783,7 +785,7 @@ func (c *PkgContext) translateExprToType(expr ast.Expr, desiredType types.Type)
783
785
}
784
786
_ , desiredIsNamed := desiredType .(* types.Named )
785
787
if desiredIsNamed && ! types .IsIdentical (exprType , desiredType ) {
786
- return fmt .Sprintf ("(Go$obj = %s, (new %s(Go$obj.array)).Go$subslice( Go$obj.offset, Go$obj.offset + Go$obj.length))" , c .translateExpr (expr ), c .typeName (desiredType ))
788
+ return fmt .Sprintf ("(Go$obj = %s, Go$subslice (new %s(Go$obj.array), Go$obj.offset, Go$obj.offset + Go$obj.length))" , c .translateExpr (expr ), c .typeName (desiredType ))
787
789
}
788
790
return c .translateExpr (expr )
789
791
0 commit comments