mirror of
https://github.com/burrowers/garble.git
synced 2025-12-24 12:58:05 +08:00
Fix removing named imports and fix removing imports with init() methods
This commit is contained in:
4
main.go
4
main.go
@@ -1493,9 +1493,7 @@ func (tf *transformer) removeUnnecessaryImports(file *ast.File) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !astutil.DeleteImport(fset, file, path) {
|
||||
panic(fmt.Sprintf("cannot delete unused import: %q", path))
|
||||
}
|
||||
imp.Name = ast.NewIdent("_")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
testdata/mod/gopkg.in_garbletestconst.v2_v2.999.0.txt
vendored
Normal file
32
testdata/mod/gopkg.in_garbletestconst.v2_v2.999.0.txt
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
module gopkg.in/garbletestconst.v2@v2.999.0
|
||||
|
||||
-- .mod --
|
||||
module gopkg.in/garbletestconst.v2
|
||||
|
||||
go 1.17
|
||||
|
||||
-- .info --
|
||||
{"Version":"v2.999.0","Time":"2020-11-17T15:46:20Z"}
|
||||
-- go.mod --
|
||||
module gopkg.in/garbletestconst.v2
|
||||
|
||||
go 1.17
|
||||
-- consts.go --
|
||||
package garbletestconst
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
const StrConst = "42"
|
||||
|
||||
func init() {
|
||||
sql.Register("dummy", dummy{})
|
||||
}
|
||||
|
||||
type dummy struct{}
|
||||
|
||||
func (dummy) Open(string) (driver.Conn, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
9
testdata/scripts/imports.txt
vendored
9
testdata/scripts/imports.txt
vendored
@@ -49,6 +49,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
gopkg.in/garbletest.v2 v2.999.0
|
||||
gopkg.in/garbletestconst.v2 v2.999.0
|
||||
rsc.io/quote v1.5.2
|
||||
)
|
||||
|
||||
@@ -62,6 +63,8 @@ golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekuf
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/garbletest.v2 v2.999.0 h1:XHlBQi3MAcJL2fjNiEPAPAilkzc7hAv4vyyjY5w+IUY=
|
||||
gopkg.in/garbletest.v2 v2.999.0/go.mod h1:MI9QqKJD8i8oL8mW/bR0qq19/VuezEdJbVvl2B8Pa40=
|
||||
gopkg.in/garbletestconst.v2 v2.999.0 h1:VABqc63EJolbOSh1+WlSSQmX8ZT7VIs53mKCGxECTH8=
|
||||
gopkg.in/garbletestconst.v2 v2.999.0/go.mod h1:QA2FI8zGZhhsdLJGUrq78ah+ohEZo9ZDw3ex+C2WVEc=
|
||||
rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
|
||||
rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
|
||||
rsc.io/sampler v1.3.0 h1:+lXbM7nYGGOYhnMEiMtjCwcUfjn4sajeMm15HMT6SnU=
|
||||
@@ -73,11 +76,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"database/sql"
|
||||
|
||||
"test/main/importedpkg"
|
||||
|
||||
"rsc.io/quote"
|
||||
garbletest "gopkg.in/garbletest.v2"
|
||||
garbletestconst "gopkg.in/garbletestconst.v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -90,6 +95,8 @@ func main() {
|
||||
|
||||
fmt.Println(quote.Go())
|
||||
garbletest.Test()
|
||||
fmt.Println(garbletestconst.StrConst)
|
||||
fmt.Println(sql.Drivers()[0])
|
||||
}
|
||||
-- notag_fail.go --
|
||||
// +build !buildtag
|
||||
@@ -159,3 +166,5 @@ imported const value
|
||||
x
|
||||
{3 {23} 0}
|
||||
Don't communicate by sharing memory, share memory by communicating.
|
||||
42
|
||||
dummy
|
||||
Reference in New Issue
Block a user