@@ -433,22 +433,24 @@ func (c *PkgContext) translateExpr(expr ast.Expr) string {
433433 case * ast.SliceExpr :
434434 b , isBasic := c .info .Types [e .X ].(* types.Basic )
435435 isString := isBasic && b .Info ()& types .IsString != 0
436- method := "Go$subslice"
437- if isString {
438- method = "substring"
439- }
440436 slice := c .translateExprToType (e .X , exprType )
441437 if e .High == nil {
442438 if e .Low == nil {
443439 return slice
444440 }
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 ))
446445 }
447446 low := "0"
448447 if e .Low != nil {
449448 low = c .translateExpr (e .Low )
450449 }
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 ))
452454
453455 case * ast.SelectorExpr :
454456 sel := c .info .Selections [e ]
@@ -498,7 +500,7 @@ func (c *PkgContext) translateExpr(expr ast.Expr) string {
498500 switch t2 := c .info .Types [e .Args [0 ]].Underlying ().(type ) {
499501 case * types.Slice :
500502 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 ]))
502504 }
503505 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 ]))
504506 default :
@@ -749,7 +751,7 @@ func (c *PkgContext) translateExprToType(expr ast.Expr, desiredType types.Type)
749751 case t .Kind () == types .UnsafePointer :
750752 if unary , isUnary := expr .(* ast.UnaryExpr ); isUnary && unary .Op == token .AND {
751753 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 )))
753755 }
754756 if ident , isIdent := unary .X .(* ast.Ident ); isIdent && ident .Name == "_zero" {
755757 return "new Uint8Array(0)"
@@ -783,7 +785,7 @@ func (c *PkgContext) translateExprToType(expr ast.Expr, desiredType types.Type)
783785 }
784786 _ , desiredIsNamed := desiredType .(* types.Named )
785787 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 ))
787789 }
788790 return c .translateExpr (expr )
789791
0 commit comments