modulespecifiers

package
v0.0.0-...-563c3ff Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsNodeModules

func ContainsNodeModules(s string) bool

func CountPathComponents

func CountPathComponents(path string) int

func GetModuleSpecifier

func GetModuleSpecifier(
	compilerOptions *core.CompilerOptions,
	host ModuleSpecifierGenerationHost,
	importingSourceFile *ast.SourceFile,
	importingSourceFileName string,
	oldImportSpecifier string,
	toFileName string,
	options ModuleSpecifierOptions,
) string

`importingSourceFile` and `importingSourceFileName`? Why not just use `importingSourceFile.path`? Because when this is called by the declaration emitter, `importingSourceFile` is the implementation file, but `importingSourceFileName` and `toFileName` refer to declaration files (the former to the one currently being produced; the latter to the one being imported). We need an implementation file just to get its `impliedNodeFormat` and to detect certain preferences from existing import module specifiers.

func GetModuleSpecifiers

func GetModuleSpecifiers(
	moduleSymbol *ast.Symbol,
	checker CheckerShape,
	compilerOptions *core.CompilerOptions,
	importingSourceFile SourceFileForSpecifierGeneration,
	host ModuleSpecifierGenerationHost,
	userPreferences UserPreferences,
	options ModuleSpecifierOptions,
	forAutoImports bool,
) []string

func GetNodeModulesPackageName

func GetNodeModulesPackageName(
	compilerOptions *core.CompilerOptions,
	importingSourceFile *ast.SourceFile,
	nodeModulesFileName string,
	host ModuleSpecifierGenerationHost,
	preferences UserPreferences,
	options ModuleSpecifierOptions,
) string

func GetPackageNameFromTypesPackageName

func GetPackageNameFromTypesPackageName(mangledName string) string

func PathIsBareSpecifier

func PathIsBareSpecifier(path string) bool

Types

type CheckerShape

type CheckerShape interface {
	GetSymbolAtLocation(node *ast.Node) *ast.Symbol
	GetAliasedSymbol(symbol *ast.Symbol) *ast.Symbol
}

type ImportModuleSpecifierEndingPreference

type ImportModuleSpecifierEndingPreference string
const (
	ImportModuleSpecifierEndingPreferenceNone    ImportModuleSpecifierEndingPreference = ""
	ImportModuleSpecifierEndingPreferenceAuto    ImportModuleSpecifierEndingPreference = "auto"
	ImportModuleSpecifierEndingPreferenceMinimal ImportModuleSpecifierEndingPreference = "minimal"
	ImportModuleSpecifierEndingPreferenceIndex   ImportModuleSpecifierEndingPreference = "index"
	ImportModuleSpecifierEndingPreferenceJs      ImportModuleSpecifierEndingPreference = "js"
)

type ImportModuleSpecifierPreference

type ImportModuleSpecifierPreference string
const (
	ImportModuleSpecifierPreferenceNone            ImportModuleSpecifierPreference = ""
	ImportModuleSpecifierPreferenceShortest        ImportModuleSpecifierPreference = "shortest"
	ImportModuleSpecifierPreferenceProjectRelative ImportModuleSpecifierPreference = "project-relative"
	ImportModuleSpecifierPreferenceRelative        ImportModuleSpecifierPreference = "relative"
	ImportModuleSpecifierPreferenceNonRelative     ImportModuleSpecifierPreference = "non-relative"
)

type Info

type Info struct {
	UseCaseSensitiveFileNames bool
	ImportingSourceFileName   string
	SourceDirectory           string
}

type MatchingMode

type MatchingMode uint8
const (
	MatchingModeExact MatchingMode = iota
	MatchingModeDirectory
	MatchingModePattern
)

type ModulePath

type ModulePath struct {
	FileName        string
	IsInNodeModules bool
	IsRedirect      bool
}

func GetEachFileNameOfModule

func GetEachFileNameOfModule(
	importingFileName string,
	importedFileName string,
	host ModuleSpecifierGenerationHost,
	preferSymlinks bool,
) []ModulePath

type ModuleSpecifierEnding

type ModuleSpecifierEnding uint8
const (
	ModuleSpecifierEndingMinimal ModuleSpecifierEnding = iota
	ModuleSpecifierEndingIndex
	ModuleSpecifierEndingJsExtension
	ModuleSpecifierEndingTsExtension
)

type ModuleSpecifierGenerationHost

type ModuleSpecifierGenerationHost interface {
	// GetModuleResolutionCache() any // !!! TODO: adapt new resolution cache model
	// GetSymlinkCache() any // !!! TODO: adapt new resolution cache model
	// GetFileIncludeReasons() any // !!! TODO: adapt new resolution cache model
	CommonSourceDirectory() string
	GetGlobalTypingsCacheLocation() string
	UseCaseSensitiveFileNames() bool
	GetCurrentDirectory() string

	GetProjectReferenceFromSource(path tspath.Path) *tsoptions.SourceOutputAndProjectReference
	GetRedirectTargets(path tspath.Path) []string
	GetSourceOfProjectReferenceIfOutputIncluded(file ast.HasFileName) string

	FileExists(path string) bool

	GetNearestAncestorDirectoryWithPackageJson(dirname string) string
	GetPackageJsonInfo(pkgJsonPath string) PackageJsonInfo
	GetDefaultResolutionModeForFile(file ast.HasFileName) core.ResolutionMode
	GetResolvedModuleFromModuleSpecifier(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) *module.ResolvedModule
	GetModeForUsageLocation(file ast.HasFileName, moduleSpecifier *ast.StringLiteralLike) core.ResolutionMode
}

type ModuleSpecifierOptions

type ModuleSpecifierOptions struct {
	OverrideImportMode core.ResolutionMode
}

type ModuleSpecifierPreferences

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

type NodeModulePathParts

type NodeModulePathParts struct {
	TopLevelNodeModulesIndex int
	TopLevelPackageNameIndex int
	PackageRootIndex         int
	FileNameIndex            int
}

func GetNodeModulePathParts

func GetNodeModulePathParts(fullPath string) *NodeModulePathParts

type PackageJsonInfo

type PackageJsonInfo interface {
	GetDirectory() string
	GetContents() *packagejson.PackageJson
}

type RelativePreferenceKind

type RelativePreferenceKind uint8
const (
	RelativePreferenceRelative RelativePreferenceKind = iota
	RelativePreferenceNonRelative
	RelativePreferenceShortest
	RelativePreferenceExternalNonRelative
)

type ResultKind

type ResultKind uint8
const (
	ResultKindNone ResultKind = iota
	ResultKindNodeModules
	ResultKindPaths
	ResultKindRedirect
	ResultKindRelative
	ResultKindAmbient
)

func GetModuleSpecifiersWithInfo

func GetModuleSpecifiersWithInfo(
	moduleSymbol *ast.Symbol,
	checker CheckerShape,
	compilerOptions *core.CompilerOptions,
	importingSourceFile SourceFileForSpecifierGeneration,
	host ModuleSpecifierGenerationHost,
	userPreferences UserPreferences,
	options ModuleSpecifierOptions,
	forAutoImports bool,
) ([]string, ResultKind)

type SourceFileForSpecifierGeneration

type SourceFileForSpecifierGeneration interface {
	Path() tspath.Path
	FileName() string
	Imports() []*ast.StringLiteralLike
	IsJS() bool
}

type UserPreferences

type UserPreferences struct {
	ImportModuleSpecifierPreference       ImportModuleSpecifierPreference
	ImportModuleSpecifierEndingPreference ImportModuleSpecifierEndingPreference
	AutoImportSpecifierExcludeRegexes     []string
}

Jump to

Keyboard shortcuts

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