mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
138 lines
4.0 KiB
Go
138 lines
4.0 KiB
Go
package module
|
|
|
|
import (
|
|
"fmt"
|
|
"math/bits"
|
|
"strings"
|
|
|
|
"github.com/microsoft/typescript-go/internal/ast"
|
|
"github.com/microsoft/typescript-go/internal/core"
|
|
"github.com/microsoft/typescript-go/internal/tspath"
|
|
"github.com/microsoft/typescript-go/internal/vfs"
|
|
)
|
|
|
|
type ResolutionHost interface {
|
|
FS() vfs.FS
|
|
GetCurrentDirectory() string
|
|
}
|
|
|
|
type ModeAwareCacheKey struct {
|
|
Name string
|
|
Mode core.ResolutionMode
|
|
}
|
|
|
|
type ResolvedProjectReference interface {
|
|
ConfigName() string
|
|
CompilerOptions() *core.CompilerOptions
|
|
}
|
|
|
|
type NodeResolutionFeatures int32
|
|
|
|
const (
|
|
NodeResolutionFeaturesImports NodeResolutionFeatures = 1 << iota
|
|
NodeResolutionFeaturesSelfName
|
|
NodeResolutionFeaturesExports
|
|
NodeResolutionFeaturesExportsPatternTrailers
|
|
// allowing `#/` root imports in package.json imports field
|
|
// not supported until mass adoption - https://github.com/nodejs/node/pull/60864
|
|
NodeResolutionFeaturesImportsPatternRoot
|
|
|
|
NodeResolutionFeaturesNone NodeResolutionFeatures = 0
|
|
NodeResolutionFeaturesAll = NodeResolutionFeaturesImports | NodeResolutionFeaturesSelfName | NodeResolutionFeaturesExports | NodeResolutionFeaturesExportsPatternTrailers | NodeResolutionFeaturesImportsPatternRoot
|
|
NodeResolutionFeaturesNode16Default = NodeResolutionFeaturesImports | NodeResolutionFeaturesSelfName | NodeResolutionFeaturesExports | NodeResolutionFeaturesExportsPatternTrailers
|
|
NodeResolutionFeaturesNodeNextDefault = NodeResolutionFeaturesAll
|
|
NodeResolutionFeaturesBundlerDefault = NodeResolutionFeaturesImports | NodeResolutionFeaturesSelfName | NodeResolutionFeaturesExports | NodeResolutionFeaturesExportsPatternTrailers | NodeResolutionFeaturesImportsPatternRoot
|
|
)
|
|
|
|
type PackageId struct {
|
|
Name string
|
|
SubModuleName string
|
|
Version string
|
|
PeerDependencies string
|
|
}
|
|
|
|
func (p *PackageId) String() string {
|
|
return fmt.Sprintf("%s@%s%s", p.PackageName(), p.Version, p.PeerDependencies)
|
|
}
|
|
|
|
func (p *PackageId) PackageName() string {
|
|
if p.SubModuleName != "" {
|
|
return p.Name + "/" + p.SubModuleName
|
|
}
|
|
return p.Name
|
|
}
|
|
|
|
type ResolvedModule struct {
|
|
ResolutionDiagnostics []*ast.Diagnostic
|
|
ResolvedFileName string
|
|
OriginalPath string
|
|
Extension string
|
|
ResolvedUsingTsExtension bool
|
|
ResolvedUsingExtraExtensions bool
|
|
PackageId PackageId
|
|
IsExternalLibraryImport bool
|
|
AlternateResult string
|
|
}
|
|
|
|
func (r *ResolvedModule) IsResolved() bool {
|
|
return r != nil && r.ResolvedFileName != ""
|
|
}
|
|
|
|
type ResolvedTypeReferenceDirective struct {
|
|
ResolutionDiagnostics []*ast.Diagnostic
|
|
Primary bool
|
|
ResolvedFileName string
|
|
OriginalPath string
|
|
PackageId PackageId
|
|
IsExternalLibraryImport bool
|
|
}
|
|
|
|
func (r *ResolvedTypeReferenceDirective) IsResolved() bool {
|
|
return r.ResolvedFileName != ""
|
|
}
|
|
|
|
type extensions int32
|
|
|
|
const (
|
|
extensionsTypeScript extensions = 1 << iota
|
|
extensionsJavaScript
|
|
extensionsDeclaration
|
|
extensionsJson
|
|
|
|
extensionsImplementationFiles = extensionsTypeScript | extensionsJavaScript
|
|
)
|
|
|
|
func (e extensions) String() string {
|
|
result := make([]string, 0, bits.OnesCount(uint(e)))
|
|
if e&extensionsTypeScript != 0 {
|
|
result = append(result, "TypeScript")
|
|
}
|
|
if e&extensionsJavaScript != 0 {
|
|
result = append(result, "JavaScript")
|
|
}
|
|
if e&extensionsDeclaration != 0 {
|
|
result = append(result, "Declaration")
|
|
}
|
|
if e&extensionsJson != 0 {
|
|
result = append(result, "JSON")
|
|
}
|
|
return strings.Join(result, ", ")
|
|
}
|
|
|
|
func (e extensions) Array() []string {
|
|
result := []string{}
|
|
if e&extensionsTypeScript != 0 {
|
|
result = append(result, tspath.SupportedTSImplementationExtensions...)
|
|
}
|
|
if e&extensionsJavaScript != 0 {
|
|
result = append(result, tspath.SupportedJSExtensionsFlat...)
|
|
}
|
|
if e&extensionsDeclaration != 0 {
|
|
result = append(result, tspath.SupportedDeclarationExtensions...)
|
|
}
|
|
if e&extensionsJson != 0 {
|
|
result = append(result, tspath.ExtensionJson)
|
|
}
|
|
return result
|
|
}
|