Files
nuclei/pkg/js/devtools/tsgen/parser_external_test.go
dw1andMzack9999 3fdb599603 fix(js): stop tsgen from panicking on non-struct types (#8102)
* fix(js/tsgen): map non-struct external types to any

tsgen treated every type from another package as a struct and queued
it to have its fields scraped into a TypeScript interface. The kind
was checked only at scrape time, as a fatal error, so an interface,
func, or named basic type in an exported signature or field aborted
the whole run. make jsupdate-tsgen panicked on net.Conn, which the
dcerpc, gptransport, mssql, net, and oracle libraries return, and
never wrote the remaining definitions or index.ts.

Check the kind when the type is first seen instead. Structs are still
scraped; other types have no fields to describe and become any, as
external parameter types already do. Names that do not resolve are
still reported.

Fixes: #8099
Signed-off-by: Dwi Siswanto <[email protected]>

* fix(js): exclude gptransport and smbsession from codegen

gptransport and smbsession are shared Go adapters for the smb, dcerpc,
and file protocol code, not JavaScript modules: nothing registers them
with the runtime, and index.ts does not export them. Without the
.nuclei-jsgen-ignore marker that goexec already carries, tsgen and
bindgen treat them as modules, so a full make jsupdate-tsgen run
writes gptransport.ts and smbsession.ts and adds both to index.ts.

Refs: #8099
Signed-off-by: Dwi Siswanto <[email protected]>

* fix returns

---------

Signed-off-by: Dwi Siswanto <[email protected]>
Co-authored-by: Mzack9999 <[email protected]>
2026-11-10 07:01:54 +07:00

34 lines
995 B
Go

package tsgen_test
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v3/pkg/js/devtools/tsgen"
)
func TestParseExternalTypes(t *testing.T) {
t.Parallel()
ep, err := tsgen.NewEntityParser(filepath.Join("testdata", "external"))
require.NoError(t, err)
require.NoError(t, ep.Parse())
entities := make(map[string]tsgen.Entity)
for _, e := range ep.GetEntities() {
entities[e.Name] = e
}
// net.Conn is an interface, so it has no fields to describe.
require.Equal(t, "any | null", entities["Dial"].Function.Returns)
require.Equal(t, []tsgen.Property{{Name: "Conn", Type: "any", Description: ""}}, entities["Session"].Object.Properties)
require.NotContains(t, entities, "Conn")
// url.URL is a struct, so its fields become an interface.
require.Equal(t, "URL | null", entities["Parse"].Function.Returns)
require.Equal(t, "interface", entities["URL"].Type)
require.NotEmpty(t, entities["URL"].Object.Properties)
}