Skip to content

Commit ef724c7

Browse files
welkeyeverAsterDY
authored andcommitted
fix: skip process sys imports and their function calls (cloudwego#4)
1 parent 97b8466 commit ef724c7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/compress/golang/plugin/go_ast.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (p *goParser) parseFile(filePath string) ([]Function, error) {
4141

4242
thirdPartyImports := make(map[string]struct{})
4343
projectImports := make(map[string]string)
44+
sysImports := make(map[string]string)
4445
for _, imp := range f.Imports {
4546
importPath := imp.Path.Value[1 : len(imp.Path.Value)-1] // remove the quotes
4647
importBaseName := filepath.Base(importPath)
@@ -53,6 +54,10 @@ func (p *goParser) parseFile(filePath string) ([]Function, error) {
5354

5455
isSysPkg := !strings.Contains(strings.Split(importPath, "/")[0], ".")
5556

57+
if isSysPkg {
58+
sysImports[importAlias] = importPath
59+
}
60+
5661
// Ignoring golang standard libraries(like net/http)
5762
if !isSysPkg {
5863
// Distinguish between project packages and third party packages
@@ -113,6 +118,11 @@ func (p *goParser) parseFile(filePath string) ([]Function, error) {
113118
return true
114119
}
115120

121+
// skip sys imports
122+
if _, ok = sysImports[x.(*ast.Ident).Name]; ok {
123+
return true
124+
}
125+
116126
methodCalls = append(methodCalls, funcName)
117127
return true
118128
case *ast.Ident:

0 commit comments

Comments
 (0)