diff --git a/Makefile b/Makefile index 420f306..39d52e3 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,11 @@ generate: root build .root/bin/easyjson -stubs \ .root/src/$(PKG)/tests/snake.go \ .root/src/$(PKG)/tests/data.go \ - .root/src/$(PKG)/tests/omitempty.go + .root/src/$(PKG)/tests/omitempty.go \ + .root/src/$(PKG)/tests/nothing.go .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go + .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go .root/bin/easyjson -snake_case .root/src/$(PKG)/tests/snake.go .root/bin/easyjson -omit_empty .root/src/$(PKG)/tests/omitempty.go .root/bin/easyjson -build_tags=use_easyjson .root/src/$(PKG)/benchmark/data.go diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 3a83e94..04aaaad 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -50,11 +50,14 @@ func (g *Generator) writeStub() error { fmt.Fprintln(f, "// compilable during generation.") fmt.Fprintln(f) fmt.Fprintln(f, "package ", g.PkgName) - fmt.Fprintln(f) - fmt.Fprintln(f, "import (") - fmt.Fprintln(f, ` "`+pkgWriter+`"`) - fmt.Fprintln(f, ` "`+pkgLexer+`"`) - fmt.Fprintln(f, ")") + + if len(g.Types) > 0 { + fmt.Fprintln(f) + fmt.Fprintln(f, "import (") + fmt.Fprintln(f, ` "`+pkgWriter+`"`) + fmt.Fprintln(f, ` "`+pkgLexer+`"`) + fmt.Fprintln(f, ")") + } for _, t := range g.Types { fmt.Fprintln(f) @@ -90,8 +93,10 @@ func (g *Generator) writeMain() (path string, err error) { fmt.Fprintln(f, ` "os"`) fmt.Fprintln(f) fmt.Fprintf(f, " %q\n", genPackage) - fmt.Fprintln(f) - fmt.Fprintf(f, " pkg %q\n", g.PkgPath) + if len(g.Types) > 0 { + fmt.Fprintln(f) + fmt.Fprintf(f, " pkg %q\n", g.PkgPath) + } fmt.Fprintln(f, ")") fmt.Fprintln(f) fmt.Fprintln(f, "func main() {") diff --git a/gen/generator.go b/gen/generator.go index 3128594..83bf812 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -156,7 +156,12 @@ func (g *Generator) printHeader() { fmt.Println(")") fmt.Println("") - fmt.Println("var _ = json.RawMessage{} // suppress unused package warning") + fmt.Println("// suppress unused package warning") + fmt.Println("var (") + fmt.Println(" _ = json.RawMessage{}") + fmt.Println(" _ = jlexer.Lexer{}") + fmt.Println(" _ = jwriter.Writer{}") + fmt.Println(")") fmt.Println() } diff --git a/tests/nothing.go b/tests/nothing.go new file mode 100644 index 0000000..35334f5 --- /dev/null +++ b/tests/nothing.go @@ -0,0 +1,3 @@ +package tests + +// No structs in this file