Skip to content

Commit 18bbaa7

Browse files
committed
fix: Fix nil reference
1 parent 0cab6a1 commit 18bbaa7

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

alteriso/src/pkg/shutils/debug.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ func PrintJSON(node syntax.Node) {
1717
}
1818

1919
func PrintCode(node syntax.Node) {
20+
21+
if node == nil {
22+
return
23+
}
2024
printer := syntax.NewPrinter(syntax.Minify(true))
2125
err := printer.Print(os.Stdout, node)
2226
if err != nil {

alteriso/src/pkg/shutils/func.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package shutils
22

33
import (
4+
"fmt"
5+
46
"github.com/samber/lo"
57
"mvdan.cc/sh/v3/syntax"
68
)
@@ -17,7 +19,13 @@ func ExtractFunctions(node syntax.Node) []*syntax.FuncDecl {
1719
}
1820

1921
func Func(node syntax.Node, name string) *syntax.FuncDecl {
20-
return lo.Filter(ExtractFunctions(node), func(d *syntax.FuncDecl, n int) bool {
22+
// return lo.Filter(ExtractFunctions(node), func(d *syntax.FuncDecl, n int) bool {
23+
// return d.Name.Value == name
24+
// })[0]
25+
26+
f, _ := lo.Find(ExtractFunctions(node), func(d *syntax.FuncDecl) bool {
2127
return d.Name.Value == name
22-
})[0]
28+
})
29+
fmt.Println(f)
30+
return f
2331
}

0 commit comments

Comments
 (0)