Help us shape the future of Go! Take the 2026 Go Developer Survey

typescript

package
v0.34.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTestFile

func IsTestFile(filePath string) bool

IsTestFile reports whether the given TypeScript/JavaScript path is a test file.

func ParsePackageJSONScripts added in v0.34.0

func ParsePackageJSONScripts(data []byte) map[string]string

ParsePackageJSONScripts extracts the "scripts" field of a package.json as script name -> command line. Returns nil if the field is missing or the document is malformed.

func ResolvePackageJSONScriptPaths added in v0.34.0

func ResolvePackageJSONScriptPaths(
	absPath string,
	suppliedFiles map[string]bool,
	contentReader vcs.ContentReader,
) ([]string, error)

ResolvePackageJSONScriptPaths extracts shell-script references from a package.json's "scripts" field and returns the supplied project paths they resolve to.

Returns (nil, nil) for any file that isn't literally named package.json — callers route every ".json" file through here, since npm-workspace discovery (npm_workspace.go) already established that as the only JSON file this provider understands.

func ResolveTypeScriptImportPath

func ResolveTypeScriptImportPath(sourceFile, importPath string, suppliedFiles map[string]bool) []string

ResolveTypeScriptImportPath resolves a TypeScript import path to possible file paths

func ResolveTypeScriptProjectImports

func ResolveTypeScriptProjectImports(
	absPath string,
	filePath string,
	ext string,
	suppliedFiles map[string]bool,
	contentReader vcs.ContentReader,
) ([]string, error)

func ShellScriptReferences added in v0.34.0

func ShellScriptReferences(command string) []string

ShellScriptReferences splits an npm script command line on shell word boundaries and returns the tokens that look like a reference to a .sh file (a relative or bare path ending in ".sh"), in first-seen order with surrounding quotes and glued shell operators ("&&", ";", "|") stripped.

This is a lightweight token scan, not a shell parser: it is meant to catch the common "./scripts/foo.sh" / "bash scripts/foo.sh" shapes, not to fully understand arbitrary shell syntax (subshells, variable expansion, heredocs).

Types

type ECMAScriptDeclarationLocation added in v0.30.0

type ECMAScriptDeclarationLocation struct {
	Name string
	Kind string
	Line int
}

ECMAScriptDeclarationLocation is one JavaScript/TypeScript declaration.

func ParseECMAScriptDeclarationLocations added in v0.30.0

func ParseECMAScriptDeclarationLocations(source []byte) []ECMAScriptDeclarationLocation

ParseECMAScriptDeclarationLocations returns declarations with 1-based lines.

type ECMAScriptImportLocation added in v0.30.0

type ECMAScriptImportLocation struct {
	Path     string
	Imported string
	Local    string
	Kind     string
	Line     int
}

ECMAScriptImportLocation is one imported or re-exported binding.

func ParseECMAScriptImportLocations added in v0.30.0

func ParseECMAScriptImportLocations(source []byte) []ECMAScriptImportLocation

ParseECMAScriptImportLocations returns imported and re-exported bindings.

type ECMAScriptReferenceLocation added in v0.30.0

type ECMAScriptReferenceLocation struct {
	Name string
	Path string
	Kind string
	Line int
}

ECMAScriptReferenceLocation is one use of an imported binding.

func ExtractECMAScriptReferenceLocations added in v0.30.0

func ExtractECMAScriptReferenceLocations(
	source []byte,
	imports []ECMAScriptImportLocation,
) []ECMAScriptReferenceLocation

ExtractECMAScriptReferenceLocations returns uses of imported bindings.

type ExternalImport

type ExternalImport struct {
	// contains filtered or unexported fields
}

ExternalImport represents an external npm package import

func (ExternalImport) IsTypeOnly

func (e ExternalImport) IsTypeOnly() bool

func (ExternalImport) Path

func (e ExternalImport) Path() string

type InternalImport

type InternalImport struct {
	// contains filtered or unexported fields
}

InternalImport represents an internal project file import (./, ../, @/)

func (InternalImport) IsTypeOnly

func (i InternalImport) IsTypeOnly() bool

func (InternalImport) Path

func (i InternalImport) Path() string

type NodeBuiltinImport

type NodeBuiltinImport struct {
	// contains filtered or unexported fields
}

NodeBuiltinImport represents a Node.js built-in module import (fs, path, http, node:fs)

func (NodeBuiltinImport) IsTypeOnly

func (n NodeBuiltinImport) IsTypeOnly() bool

func (NodeBuiltinImport) Path

func (n NodeBuiltinImport) Path() string

type Provider added in v0.27.0

type Provider struct{}

func (Provider) Extensions added in v0.27.0

func (Provider) Extensions() []string

func (Provider) IsTestFile added in v0.27.0

func (Provider) IsTestFile(filePath string, _ vcs.ContentReader) bool

func (Provider) Maturity added in v0.27.0

func (Provider) Maturity() moduleapi.MaturityLevel

func (Provider) Name added in v0.27.0

func (Provider) Name() string

func (Provider) NewResolver added in v0.27.0

func (Provider) NewResolver(ctx *moduleapi.Context, contentReader vcs.ContentReader) moduleapi.Resolver

type TypeScriptImport

type TypeScriptImport interface {
	Path() string
	IsTypeOnly() bool
}

TypeScriptImport represents an import in a TypeScript/TSX file

func ParseTypeScriptImports

func ParseTypeScriptImports(sourceCode []byte, isTSX bool) ([]TypeScriptImport, error)

ParseTypeScriptImports parses TypeScript source code and extracts imports

func TypeScriptImports

func TypeScriptImports(filePath string) ([]TypeScriptImport, error)

TypeScriptImports parses a TypeScript/TSX file and returns its imports

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL