remove unused packages
This commit is contained in:
parent
79197d8157
commit
fb86a3f969
@ -1,29 +0,0 @@
|
|||||||
package module
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/core"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/packagejson"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ModeAwareCache[T any] map[ModeAwareCacheKey]T
|
|
||||||
|
|
||||||
type caches struct {
|
|
||||||
packageJsonInfoCache *packagejson.InfoCache
|
|
||||||
|
|
||||||
// Cached representation for `core.CompilerOptions.paths`.
|
|
||||||
// Doesn't handle other path patterns like in `typesVersions`.
|
|
||||||
parsedPatternsForPathsOnce sync.Once
|
|
||||||
parsedPatternsForPaths *ParsedPatterns
|
|
||||||
}
|
|
||||||
|
|
||||||
func newCaches(
|
|
||||||
currentDirectory string,
|
|
||||||
useCaseSensitiveFileNames bool,
|
|
||||||
options *core.CompilerOptions,
|
|
||||||
) caches {
|
|
||||||
return caches{
|
|
||||||
packageJsonInfoCache: packagejson.NewInfoCache(currentDirectory, useCaseSensitiveFileNames),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,398 +0,0 @@
|
|||||||
package module_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"slices"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/core"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/jsonutil"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/module"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/repo"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/testutil/baseline"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/vfs"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/vfs/vfstest"
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"gotest.tools/v3/assert"
|
|
||||||
"gotest.tools/v3/assert/cmp"
|
|
||||||
)
|
|
||||||
|
|
||||||
var skip = []string{
|
|
||||||
"allowJsCrossMonorepoPackage.ts",
|
|
||||||
"APILibCheck.ts",
|
|
||||||
"APISample_compile.ts",
|
|
||||||
"APISample_jsdoc.ts",
|
|
||||||
"APISample_linter.ts",
|
|
||||||
"APISample_parseConfig.ts",
|
|
||||||
"APISample_transform.ts",
|
|
||||||
"APISample_Watch.ts",
|
|
||||||
"APISample_watcher.ts",
|
|
||||||
"APISample_WatchWithDefaults.ts",
|
|
||||||
"APISample_WatchWithOwnWatchHost.ts",
|
|
||||||
"bundlerNodeModules1(module=esnext).ts",
|
|
||||||
"bundlerNodeModules1(module=preserve).ts",
|
|
||||||
"commonJsExportTypeDeclarationError.ts",
|
|
||||||
"commonSourceDir5.ts",
|
|
||||||
"commonSourceDirectory.ts",
|
|
||||||
"computedEnumMemberSyntacticallyString2(isolatedmodules=false).ts",
|
|
||||||
"computedEnumMemberSyntacticallyString2(isolatedmodules=true).ts",
|
|
||||||
"declarationEmitCommonSourceDirectoryDoesNotContainAllFiles.ts",
|
|
||||||
"declarationEmitForGlobalishSpecifierSymlink.ts",
|
|
||||||
"declarationEmitForGlobalishSpecifierSymlink2.ts",
|
|
||||||
"declarationEmitReexportedSymlinkReference.ts",
|
|
||||||
"declarationEmitReexportedSymlinkReference2.ts",
|
|
||||||
"declarationEmitReexportedSymlinkReference3.ts",
|
|
||||||
"declarationEmitSymlinkPaths.ts",
|
|
||||||
"decoratorMetadataTypeOnlyExport.ts",
|
|
||||||
"decoratorMetadataTypeOnlyImport.ts",
|
|
||||||
"enumNoInitializerFollowsNonLiteralInitializer.ts",
|
|
||||||
"enumWithNonLiteralStringInitializer.ts",
|
|
||||||
"es6ImportWithJsDocTags.ts",
|
|
||||||
"importAttributes9.ts",
|
|
||||||
"importSpecifiers_js.ts",
|
|
||||||
"importTag17.ts",
|
|
||||||
"isolatedModulesShadowGlobalTypeNotValue(isolatedmodules=false,verbatimmodulesyntax=false).ts",
|
|
||||||
"isolatedModulesShadowGlobalTypeNotValue(isolatedmodules=false,verbatimmodulesyntax=true).ts",
|
|
||||||
"isolatedModulesShadowGlobalTypeNotValue(isolatedmodules=true,verbatimmodulesyntax=false).ts",
|
|
||||||
"isolatedModulesShadowGlobalTypeNotValue(isolatedmodules=true,verbatimmodulesyntax=true).ts",
|
|
||||||
"jsDeclarationEmitExportedClassWithExtends.ts",
|
|
||||||
"jsxNamespaceGlobalReexport.tsx",
|
|
||||||
"jsxNamespaceGlobalReexportMissingAliasTarget.tsx",
|
|
||||||
"mergeSymbolReexportedTypeAliasInstantiation.ts",
|
|
||||||
"mergeSymbolReexportInterface.ts",
|
|
||||||
"mergeSymbolRexportFunction.ts",
|
|
||||||
"missingMemberErrorHasShortPath.ts",
|
|
||||||
"moduleResolutionAsTypeReferenceDirective.ts",
|
|
||||||
"moduleResolutionAsTypeReferenceDirectiveAmbient.ts",
|
|
||||||
"moduleResolutionAsTypeReferenceDirectiveScoped.ts",
|
|
||||||
"moduleResolutionWithSymlinks_notInNodeModules.ts",
|
|
||||||
"moduleResolutionWithSymlinks_preserveSymlinks.ts",
|
|
||||||
"moduleResolutionWithSymlinks_referenceTypes.ts",
|
|
||||||
"moduleResolutionWithSymlinks_withOutDir.ts",
|
|
||||||
"moduleResolutionWithSymlinks.ts",
|
|
||||||
"nodeAllowJsPackageSelfName(module=node16).ts",
|
|
||||||
"nodeAllowJsPackageSelfName(module=nodenext).ts",
|
|
||||||
"nodeAllowJsPackageSelfName2.ts",
|
|
||||||
"nodeModulesAllowJsConditionalPackageExports(module=node16).ts",
|
|
||||||
"nodeModulesAllowJsConditionalPackageExports(module=nodenext).ts",
|
|
||||||
"nodeModulesAllowJsPackageExports(module=node16).ts",
|
|
||||||
"nodeModulesAllowJsPackageExports(module=nodenext).ts",
|
|
||||||
"nodeModulesAllowJsPackageImports(module=node16).ts",
|
|
||||||
"nodeModulesAllowJsPackageImports(module=nodenext).ts",
|
|
||||||
"nodeModulesAllowJsPackagePatternExports(module=node16).ts",
|
|
||||||
"nodeModulesAllowJsPackagePatternExports(module=nodenext).ts",
|
|
||||||
"nodeModulesAllowJsPackagePatternExportsTrailers(module=node16).ts",
|
|
||||||
"nodeModulesAllowJsPackagePatternExportsTrailers(module=nodenext).ts",
|
|
||||||
"nodeModulesConditionalPackageExports(module=node16).ts",
|
|
||||||
"nodeModulesConditionalPackageExports(module=nodenext).ts",
|
|
||||||
"nodeModulesDeclarationEmitWithPackageExports(module=node16).ts",
|
|
||||||
"nodeModulesDeclarationEmitWithPackageExports(module=nodenext).ts",
|
|
||||||
"nodeModulesExportsBlocksTypesVersions(module=node16).ts",
|
|
||||||
"nodeModulesExportsBlocksTypesVersions(module=nodenext).ts",
|
|
||||||
"nodeModulesImportResolutionIntoExport(module=node16).ts",
|
|
||||||
"nodeModulesImportResolutionIntoExport(module=nodenext).ts",
|
|
||||||
"nodeModulesImportResolutionNoCycle(module=node16).ts",
|
|
||||||
"nodeModulesImportResolutionNoCycle(module=nodenext).ts",
|
|
||||||
"nodeModulesPackageExports(module=node16).ts",
|
|
||||||
"nodeModulesPackageExports(module=nodenext).ts",
|
|
||||||
"nodeModulesPackagePatternExports(module=node16).ts",
|
|
||||||
"nodeModulesPackagePatternExports(module=nodenext).ts",
|
|
||||||
"nodeModulesPackagePatternExportsExclude(module=node16).ts",
|
|
||||||
"nodeModulesPackagePatternExportsExclude(module=nodenext).ts",
|
|
||||||
"nodeModulesPackagePatternExportsTrailers(module=node16).ts",
|
|
||||||
"nodeModulesPackagePatternExportsTrailers(module=nodenext).ts",
|
|
||||||
"nodeNextImportModeImplicitIndexResolution.ts",
|
|
||||||
"nodeNextImportModeImplicitIndexResolution2.ts",
|
|
||||||
"nodeNextPackageImportMapRootDir.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDir.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDirDeclDir.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDirDeclDirComposite.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDirDeclDirCompositeNestedDirs.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDirDeclDirNestedDirs.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDirDeclDirRootDir.ts",
|
|
||||||
"nodeNextPackageSelfNameWithOutDirRootDir.ts",
|
|
||||||
"resolutionModeImportType1(moduleresolution=bundler).ts",
|
|
||||||
"resolutionModeImportType1(moduleresolution=node10).ts",
|
|
||||||
"resolutionModeTypeOnlyImport1(moduleresolution=bundler).ts",
|
|
||||||
"resolutionModeTypeOnlyImport1(moduleresolution=node10).ts",
|
|
||||||
"selfNameAndImportsEmitInclusion.ts",
|
|
||||||
"selfNameModuleAugmentation.ts",
|
|
||||||
"symbolLinkDeclarationEmitModuleNames.ts",
|
|
||||||
"symbolLinkDeclarationEmitModuleNamesImportRef.ts",
|
|
||||||
"symbolLinkDeclarationEmitModuleNamesRootDir.ts",
|
|
||||||
"symlinkedWorkspaceDependenciesNoDirectLinkGeneratesDeepNonrelativeName.ts",
|
|
||||||
"symlinkedWorkspaceDependenciesNoDirectLinkGeneratesNonrelativeName.ts",
|
|
||||||
"symlinkedWorkspaceDependenciesNoDirectLinkOptionalGeneratesNonrelativeName.ts",
|
|
||||||
"symlinkedWorkspaceDependenciesNoDirectLinkPeerGeneratesNonrelativeName.ts",
|
|
||||||
"typeGuardNarrowsIndexedAccessOfKnownProperty8.ts",
|
|
||||||
"typesVersions.ambientModules.ts",
|
|
||||||
"typesVersions.multiFile.ts",
|
|
||||||
"typesVersionsDeclarationEmit.ambient.ts",
|
|
||||||
"typesVersionsDeclarationEmit.multiFile.ts",
|
|
||||||
"typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.ts",
|
|
||||||
"typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.ts",
|
|
||||||
}
|
|
||||||
|
|
||||||
type vfsModuleResolutionHost struct {
|
|
||||||
mu sync.Mutex
|
|
||||||
fs vfs.FS
|
|
||||||
currentDirectory string
|
|
||||||
traces []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func fixRoot(path string) string {
|
|
||||||
rootLength := tspath.GetRootLength(path)
|
|
||||||
if rootLength == 0 {
|
|
||||||
return tspath.CombinePaths("/.src", path)
|
|
||||||
}
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
func newVFSModuleResolutionHost(files map[string]string, currentDirectory string) *vfsModuleResolutionHost {
|
|
||||||
fs := make(map[string]string, len(files))
|
|
||||||
for name, content := range files {
|
|
||||||
fs[fixRoot(name)] = content
|
|
||||||
}
|
|
||||||
if currentDirectory == "" {
|
|
||||||
currentDirectory = "/.src"
|
|
||||||
} else if currentDirectory[0] != '/' {
|
|
||||||
currentDirectory = "/.src/" + currentDirectory
|
|
||||||
}
|
|
||||||
return &vfsModuleResolutionHost{
|
|
||||||
fs: vfstest.FromMap(fs, true /*useCaseSensitiveFileNames*/),
|
|
||||||
currentDirectory: currentDirectory,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *vfsModuleResolutionHost) FS() vfs.FS {
|
|
||||||
return v.fs
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCurrentDirectory implements ModuleResolutionHost.
|
|
||||||
func (v *vfsModuleResolutionHost) GetCurrentDirectory() string {
|
|
||||||
return v.currentDirectory
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trace implements ModuleResolutionHost.
|
|
||||||
func (v *vfsModuleResolutionHost) Trace(msg string) {
|
|
||||||
v.mu.Lock()
|
|
||||||
defer v.mu.Unlock()
|
|
||||||
v.traces = append(v.traces, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
type functionCall struct {
|
|
||||||
call string
|
|
||||||
args rawArgs
|
|
||||||
returnValue map[string]any
|
|
||||||
}
|
|
||||||
type traceTestCase struct {
|
|
||||||
name string
|
|
||||||
currentDirectory string
|
|
||||||
trace bool
|
|
||||||
compilerOptions *core.CompilerOptions
|
|
||||||
files map[string]string
|
|
||||||
calls []functionCall
|
|
||||||
}
|
|
||||||
type rawFile struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Content string `json:"content"`
|
|
||||||
}
|
|
||||||
type rawArgs struct {
|
|
||||||
// getPackageScopeForPath
|
|
||||||
Directory string `json:"directory"`
|
|
||||||
|
|
||||||
// resolveModuleName, resolveTypeReferenceDirective
|
|
||||||
Name string `json:"name"`
|
|
||||||
ContainingFile string `json:"containingFile"`
|
|
||||||
CompilerOptions *core.CompilerOptions `json:"compilerOptions"`
|
|
||||||
ResolutionMode int `json:"resolutionMode"`
|
|
||||||
RedirectedRef *struct {
|
|
||||||
SourceFile struct {
|
|
||||||
FileName string `json:"fileName"`
|
|
||||||
} `json:"sourceFile"`
|
|
||||||
CommandLine struct {
|
|
||||||
CompilerOptions *core.CompilerOptions `json:"options"`
|
|
||||||
} `json:"commandLine"`
|
|
||||||
} `json:"redirectedReference"`
|
|
||||||
}
|
|
||||||
type rawTest struct {
|
|
||||||
Test string `json:"test"`
|
|
||||||
CurrentDirectory string `json:"currentDirectory"`
|
|
||||||
Trace bool `json:"trace"`
|
|
||||||
Files []rawFile `json:"files"`
|
|
||||||
Call string `json:"call"`
|
|
||||||
Args rawArgs `json:"args"`
|
|
||||||
Return map[string]any `json:"return"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var typesVersionsMessageRegex = regexp.MustCompile(`that matches compiler version '[^']+'`)
|
|
||||||
|
|
||||||
func sanitizeTraceOutput(trace string) string {
|
|
||||||
return typesVersionsMessageRegex.ReplaceAllString(trace, "that matches compiler version '3.1.0-dev'")
|
|
||||||
}
|
|
||||||
|
|
||||||
type RedirectRef struct {
|
|
||||||
fileName string
|
|
||||||
options *core.CompilerOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RedirectRef) ConfigName() string {
|
|
||||||
return r.fileName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RedirectRef) CompilerOptions() *core.CompilerOptions {
|
|
||||||
return r.options
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ module.ResolvedProjectReference = (*RedirectRef)(nil)
|
|
||||||
|
|
||||||
func doCall(t *testing.T, resolver *module.Resolver, call functionCall, skipLocations bool) {
|
|
||||||
switch call.call {
|
|
||||||
case "resolveModuleName", "resolveTypeReferenceDirective":
|
|
||||||
var redirectedReference module.ResolvedProjectReference
|
|
||||||
if call.args.RedirectedRef != nil {
|
|
||||||
redirectedReference = &RedirectRef{
|
|
||||||
fileName: call.args.RedirectedRef.SourceFile.FileName,
|
|
||||||
options: call.args.RedirectedRef.CommandLine.CompilerOptions,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorMessageArgs := []any{call.args.Name, call.args.ContainingFile}
|
|
||||||
if call.call == "resolveModuleName" {
|
|
||||||
resolved, _ := resolver.ResolveModuleName(call.args.Name, call.args.ContainingFile, core.ModuleKind(call.args.ResolutionMode), redirectedReference)
|
|
||||||
assert.Check(t, resolved != nil, "ResolveModuleName should not return nil", errorMessageArgs)
|
|
||||||
if expectedResolvedModule, ok := call.returnValue["resolvedModule"].(map[string]any); ok {
|
|
||||||
assert.Check(t, resolved.IsResolved(), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.ResolvedFileName, expectedResolvedModule["resolvedFileName"].(string)), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.Extension, expectedResolvedModule["extension"].(string)), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.ResolvedUsingTsExtension, expectedResolvedModule["resolvedUsingTsExtension"].(bool)), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.IsExternalLibraryImport, expectedResolvedModule["isExternalLibraryImport"].(bool)), errorMessageArgs)
|
|
||||||
} else {
|
|
||||||
assert.Check(t, !resolved.IsResolved(), errorMessageArgs)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolved, _ := resolver.ResolveTypeReferenceDirective(call.args.Name, call.args.ContainingFile, core.ModuleKind(call.args.ResolutionMode), redirectedReference)
|
|
||||||
assert.Check(t, resolved != nil, "ResolveTypeReferenceDirective should not return nil", errorMessageArgs)
|
|
||||||
if expectedResolvedTypeReferenceDirective, ok := call.returnValue["resolvedTypeReferenceDirective"].(map[string]any); ok {
|
|
||||||
assert.Check(t, resolved.IsResolved(), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.ResolvedFileName, expectedResolvedTypeReferenceDirective["resolvedFileName"].(string)), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.Primary, expectedResolvedTypeReferenceDirective["primary"].(bool)), errorMessageArgs)
|
|
||||||
assert.Check(t, cmp.Equal(resolved.IsExternalLibraryImport, expectedResolvedTypeReferenceDirective["isExternalLibraryImport"].(bool)), errorMessageArgs)
|
|
||||||
} else {
|
|
||||||
assert.Check(t, !resolved.IsResolved(), errorMessageArgs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "getPackageScopeForPath":
|
|
||||||
resolver.GetPackageScopeForPath(call.args.Directory)
|
|
||||||
default:
|
|
||||||
t.Errorf("Unexpected call: %s", call.call)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runTraceBaseline(t *testing.T, test traceTestCase) {
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
host := newVFSModuleResolutionHost(test.files, test.currentDirectory)
|
|
||||||
resolver := module.NewResolver(host, test.compilerOptions, "", "")
|
|
||||||
|
|
||||||
for _, call := range test.calls {
|
|
||||||
doCall(t, resolver, call, false /*skipLocations*/)
|
|
||||||
if t.Failed() {
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("concurrent", func(t *testing.T) {
|
|
||||||
concurrentHost := newVFSModuleResolutionHost(test.files, test.currentDirectory)
|
|
||||||
concurrentResolver := module.NewResolver(concurrentHost, test.compilerOptions, "", "")
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
for _, call := range test.calls {
|
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
|
||||||
doCall(t, concurrentResolver, call, true /*skipLocations*/)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
})
|
|
||||||
|
|
||||||
if test.trace {
|
|
||||||
t.Run("trace", func(t *testing.T) {
|
|
||||||
output, err := jsonutil.MarshalIndent(resolver, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
baseline.Run(
|
|
||||||
t,
|
|
||||||
tspath.RemoveFileExtension(test.name)+".trace.json",
|
|
||||||
sanitizeTraceOutput(string(output)),
|
|
||||||
baseline.Options{Subfolder: "module/resolver"},
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestModuleResolver(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
testsFilePath := filepath.Join(repo.TestDataPath, "fixtures", "module", "resolvertests.json")
|
|
||||||
// Read file one line at a time
|
|
||||||
file, err := os.Open(testsFilePath)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() {
|
|
||||||
file.Close()
|
|
||||||
})
|
|
||||||
decoder := jsontext.NewDecoder(file)
|
|
||||||
var currentTestCase traceTestCase
|
|
||||||
for {
|
|
||||||
if decoder.PeekKind() == 0 {
|
|
||||||
_, err := decoder.ReadToken()
|
|
||||||
if err == io.EOF { //nolint:errorlint
|
|
||||||
break
|
|
||||||
}
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var testJSON rawTest
|
|
||||||
if err := json.UnmarshalDecode(decoder, &testJSON); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if testJSON.Files != nil {
|
|
||||||
if currentTestCase.name != "" && !slices.Contains(skip, currentTestCase.name) {
|
|
||||||
runTraceBaseline(t, currentTestCase)
|
|
||||||
}
|
|
||||||
currentTestCase = traceTestCase{
|
|
||||||
name: testJSON.Test,
|
|
||||||
currentDirectory: testJSON.CurrentDirectory,
|
|
||||||
// !!! no traces are passing yet because of missing cache implementation
|
|
||||||
trace: false,
|
|
||||||
files: make(map[string]string, len(testJSON.Files)),
|
|
||||||
}
|
|
||||||
for _, file := range testJSON.Files {
|
|
||||||
currentTestCase.files[file.Name] = file.Content
|
|
||||||
}
|
|
||||||
} else if testJSON.Call != "" {
|
|
||||||
currentTestCase.calls = append(currentTestCase.calls, functionCall{
|
|
||||||
call: testJSON.Call,
|
|
||||||
args: testJSON.Args,
|
|
||||||
returnValue: testJSON.Return,
|
|
||||||
})
|
|
||||||
if currentTestCase.compilerOptions == nil && testJSON.Args.CompilerOptions != nil {
|
|
||||||
currentTestCase.compilerOptions = testJSON.Args.CompilerOptions
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.Fatalf("Unexpected JSON: %v", testJSON)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,147 +0,0 @@
|
|||||||
package module
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math/bits"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/ast"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/core"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/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
|
|
||||||
|
|
||||||
NodeResolutionFeaturesNone NodeResolutionFeatures = 0
|
|
||||||
NodeResolutionFeaturesAll = NodeResolutionFeaturesImports | NodeResolutionFeaturesSelfName | NodeResolutionFeaturesExports | NodeResolutionFeaturesExportsPatternTrailers
|
|
||||||
NodeResolutionFeaturesNode16Default = NodeResolutionFeaturesImports | NodeResolutionFeaturesSelfName | NodeResolutionFeaturesExports | NodeResolutionFeaturesExportsPatternTrailers
|
|
||||||
NodeResolutionFeaturesNodeNextDefault = NodeResolutionFeaturesAll
|
|
||||||
NodeResolutionFeaturesBundlerDefault = NodeResolutionFeaturesImports | NodeResolutionFeaturesSelfName | NodeResolutionFeaturesExports | NodeResolutionFeaturesExportsPatternTrailers
|
|
||||||
)
|
|
||||||
|
|
||||||
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 LookupLocations struct {
|
|
||||||
FailedLookupLocations []string
|
|
||||||
AffectingLocations []string
|
|
||||||
ResolutionDiagnostics []*ast.Diagnostic
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResolvedModule struct {
|
|
||||||
LookupLocations
|
|
||||||
ResolvedFileName string
|
|
||||||
OriginalPath string
|
|
||||||
Extension string
|
|
||||||
ResolvedUsingTsExtension bool
|
|
||||||
PackageId PackageId
|
|
||||||
IsExternalLibraryImport bool
|
|
||||||
AlternateResult string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ResolvedModule) IsResolved() bool {
|
|
||||||
return r != nil && r.ResolvedFileName != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ResolvedModule) GetLookupLocations() *LookupLocations {
|
|
||||||
return &r.LookupLocations
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResolvedTypeReferenceDirective struct {
|
|
||||||
LookupLocations
|
|
||||||
Primary bool
|
|
||||||
ResolvedFileName string
|
|
||||||
OriginalPath string
|
|
||||||
PackageId PackageId
|
|
||||||
IsExternalLibraryImport bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ResolvedTypeReferenceDirective) IsResolved() bool {
|
|
||||||
return r.ResolvedFileName != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *ResolvedTypeReferenceDirective) GetLookupLocations() *LookupLocations {
|
|
||||||
return &r.LookupLocations
|
|
||||||
}
|
|
||||||
|
|
||||||
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.ExtensionTs, tspath.ExtensionTsx)
|
|
||||||
}
|
|
||||||
if e&extensionsJavaScript != 0 {
|
|
||||||
result = append(result, tspath.ExtensionJs, tspath.ExtensionJsx)
|
|
||||||
}
|
|
||||||
if e&extensionsDeclaration != 0 {
|
|
||||||
result = append(result, tspath.ExtensionDts)
|
|
||||||
}
|
|
||||||
if e&extensionsJson != 0 {
|
|
||||||
result = append(result, tspath.ExtensionJson)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@ -1,155 +0,0 @@
|
|||||||
package module
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/ast"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/core"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/diagnostics"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/semver"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath"
|
|
||||||
)
|
|
||||||
|
|
||||||
var typeScriptVersion = semver.MustParse(core.Version())
|
|
||||||
|
|
||||||
const InferredTypesContainingFile = "__inferred type names__.ts"
|
|
||||||
|
|
||||||
func ParseNodeModuleFromPath(resolved string, isFolder bool) string {
|
|
||||||
path := tspath.NormalizePath(resolved)
|
|
||||||
idx := strings.LastIndex(path, "/node_modules/")
|
|
||||||
if idx == -1 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
indexAfterNodeModules := idx + len("/node_modules/")
|
|
||||||
indexAfterPackageName := moveToNextDirectorySeparatorIfAvailable(path, indexAfterNodeModules, isFolder)
|
|
||||||
if path[indexAfterNodeModules] == '@' {
|
|
||||||
indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName, isFolder)
|
|
||||||
}
|
|
||||||
return path[:indexAfterPackageName]
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParsePackageName(moduleName string) (packageName, rest string) {
|
|
||||||
idx := strings.Index(moduleName, "/")
|
|
||||||
if len(moduleName) > 0 && moduleName[0] == '@' {
|
|
||||||
offset := idx + 1
|
|
||||||
idx = strings.Index(moduleName[offset:], "/")
|
|
||||||
if idx != -1 {
|
|
||||||
idx += offset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if idx == -1 {
|
|
||||||
return moduleName, ""
|
|
||||||
}
|
|
||||||
return moduleName[:idx], moduleName[idx+1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
func MangleScopedPackageName(packageName string) string {
|
|
||||||
if packageName[0] == '@' {
|
|
||||||
idx := strings.Index(packageName, "/")
|
|
||||||
if idx == -1 {
|
|
||||||
return packageName
|
|
||||||
}
|
|
||||||
return packageName[1:idx] + "__" + packageName[idx+1:]
|
|
||||||
}
|
|
||||||
return packageName
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnmangleScopedPackageName(packageName string) string {
|
|
||||||
idx := strings.Index(packageName, "__")
|
|
||||||
if idx != -1 {
|
|
||||||
return "@" + packageName[:idx] + "/" + packageName[idx+2:]
|
|
||||||
}
|
|
||||||
return packageName
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTypesPackageName(packageName string) string {
|
|
||||||
return "@types/" + MangleScopedPackageName(packageName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ComparePatternKeys(a, b string) int {
|
|
||||||
aPatternIndex := strings.Index(a, "*")
|
|
||||||
bPatternIndex := strings.Index(b, "*")
|
|
||||||
baseLenA := len(a)
|
|
||||||
if aPatternIndex != -1 {
|
|
||||||
baseLenA = aPatternIndex + 1
|
|
||||||
}
|
|
||||||
baseLenB := len(b)
|
|
||||||
if bPatternIndex != -1 {
|
|
||||||
baseLenB = bPatternIndex + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if baseLenA > baseLenB {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if baseLenB > baseLenA {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if aPatternIndex == -1 {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if bPatternIndex == -1 {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if len(a) > len(b) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
if len(b) > len(a) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a DiagnosticMessage if we won't include a resolved module due to its extension.
|
|
||||||
// The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to.
|
|
||||||
// This returns a diagnostic even if the module will be an untyped module.
|
|
||||||
func GetResolutionDiagnostic(options *core.CompilerOptions, resolvedModule *ResolvedModule, file *ast.SourceFile) *diagnostics.Message {
|
|
||||||
needJsx := func() *diagnostics.Message {
|
|
||||||
if options.Jsx != core.JsxEmitNone {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set
|
|
||||||
}
|
|
||||||
|
|
||||||
needAllowJs := func() *diagnostics.Message {
|
|
||||||
if options.GetAllowJS() || !options.NoImplicitAny.DefaultIfUnknown(options.Strict).IsTrue() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type
|
|
||||||
}
|
|
||||||
|
|
||||||
needResolveJsonModule := func() *diagnostics.Message {
|
|
||||||
if options.GetResolveJsonModule() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return diagnostics.Module_0_was_resolved_to_1_but_resolveJsonModule_is_not_used
|
|
||||||
}
|
|
||||||
|
|
||||||
needAllowArbitraryExtensions := func() *diagnostics.Message {
|
|
||||||
if file.IsDeclarationFile || options.AllowArbitraryExtensions.IsTrue() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return diagnostics.Module_0_was_resolved_to_1_but_allowArbitraryExtensions_is_not_set
|
|
||||||
}
|
|
||||||
|
|
||||||
switch resolvedModule.Extension {
|
|
||||||
case tspath.ExtensionTs, tspath.ExtensionDts,
|
|
||||||
tspath.ExtensionMts, tspath.ExtensionDmts,
|
|
||||||
tspath.ExtensionCts, tspath.ExtensionDcts:
|
|
||||||
// These are always allowed.
|
|
||||||
return nil
|
|
||||||
case tspath.ExtensionTsx:
|
|
||||||
return needJsx()
|
|
||||||
case tspath.ExtensionJsx:
|
|
||||||
if message := needJsx(); message != nil {
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
return needAllowJs()
|
|
||||||
case tspath.ExtensionJs, tspath.ExtensionMjs, tspath.ExtensionCjs:
|
|
||||||
return needAllowJs()
|
|
||||||
case tspath.ExtensionJson:
|
|
||||||
return needResolveJsonModule()
|
|
||||||
default:
|
|
||||||
return needAllowArbitraryExtensions()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
// Exports interfaces and types defining the node builder - concrete implementations are on top of the checker, but these types and interfaces are used by the emit resolver in the printer
|
|
||||||
package nodebuilder
|
|
||||||
|
|
||||||
import (
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/ast"
|
|
||||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/modulespecifiers"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: previously all symboltracker methods were optional, but now they're required.
|
|
||||||
type SymbolTracker interface {
|
|
||||||
GetModuleSpecifierGenerationHost() modulespecifiers.ModuleSpecifierGenerationHost
|
|
||||||
|
|
||||||
TrackSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node, meaning ast.SymbolFlags) bool
|
|
||||||
ReportInaccessibleThisError()
|
|
||||||
ReportPrivateInBaseOfClassExpression(propertyName string)
|
|
||||||
ReportInaccessibleUniqueSymbolError()
|
|
||||||
ReportCyclicStructureError()
|
|
||||||
ReportLikelyUnsafeImportRequiredError(specifier string)
|
|
||||||
ReportTruncationError()
|
|
||||||
ReportNonlocalAugmentation(containingFile *ast.SourceFile, parentSymbol *ast.Symbol, augmentingSymbol *ast.Symbol)
|
|
||||||
ReportNonSerializableProperty(propertyName string)
|
|
||||||
|
|
||||||
ReportInferenceFallback(node *ast.Node)
|
|
||||||
PushErrorFallbackNode(node *ast.Node)
|
|
||||||
PopErrorFallbackNode()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: If modifying this enum, must modify `TypeFormatFlags` too!
|
|
||||||
type Flags int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
FlagsNone Flags = 0
|
|
||||||
// Options
|
|
||||||
FlagsNoTruncation Flags = 1 << 0
|
|
||||||
FlagsWriteArrayAsGenericType Flags = 1 << 1
|
|
||||||
FlagsGenerateNamesForShadowedTypeParams Flags = 1 << 2
|
|
||||||
FlagsUseStructuralFallback Flags = 1 << 3
|
|
||||||
FlagsForbidIndexedAccessSymbolReferences Flags = 1 << 4
|
|
||||||
FlagsWriteTypeArgumentsOfSignature Flags = 1 << 5
|
|
||||||
FlagsUseFullyQualifiedType Flags = 1 << 6
|
|
||||||
FlagsUseOnlyExternalAliasing Flags = 1 << 7
|
|
||||||
FlagsSuppressAnyReturnType Flags = 1 << 8
|
|
||||||
FlagsWriteTypeParametersInQualifiedName Flags = 1 << 9
|
|
||||||
FlagsMultilineObjectLiterals Flags = 1 << 10
|
|
||||||
FlagsWriteClassExpressionAsTypeLiteral Flags = 1 << 11
|
|
||||||
FlagsUseTypeOfFunction Flags = 1 << 12
|
|
||||||
FlagsOmitParameterModifiers Flags = 1 << 13
|
|
||||||
FlagsUseAliasDefinedOutsideCurrentScope Flags = 1 << 14
|
|
||||||
FlagsUseSingleQuotesForStringLiteralType Flags = 1 << 28
|
|
||||||
FlagsNoTypeReduction Flags = 1 << 29
|
|
||||||
FlagsOmitThisParameter Flags = 1 << 25
|
|
||||||
FlagsWriteCallStyleSignature Flags = 1 << 27
|
|
||||||
// Error handling
|
|
||||||
FlagsAllowThisInObjectLiteral Flags = 1 << 15
|
|
||||||
FlagsAllowQualifiedNameInPlaceOfIdentifier Flags = 1 << 16
|
|
||||||
FlagsAllowAnonymousIdentifier Flags = 1 << 17
|
|
||||||
FlagsAllowEmptyUnionOrIntersection Flags = 1 << 18
|
|
||||||
FlagsAllowEmptyTuple Flags = 1 << 19
|
|
||||||
FlagsAllowUniqueESSymbolType Flags = 1 << 20
|
|
||||||
FlagsAllowEmptyIndexInfoType Flags = 1 << 21
|
|
||||||
// Errors (cont.)
|
|
||||||
FlagsAllowNodeModulesRelativePaths Flags = 1 << 26
|
|
||||||
FlagsIgnoreErrors Flags = FlagsAllowThisInObjectLiteral | FlagsAllowQualifiedNameInPlaceOfIdentifier | FlagsAllowAnonymousIdentifier | FlagsAllowEmptyUnionOrIntersection | FlagsAllowEmptyTuple | FlagsAllowEmptyIndexInfoType | FlagsAllowNodeModulesRelativePaths
|
|
||||||
// State
|
|
||||||
FlagsInObjectTypeLiteral Flags = 1 << 22
|
|
||||||
FlagsInTypeAlias Flags = 1 << 23
|
|
||||||
FlagsInInitialEntityName Flags = 1 << 24
|
|
||||||
)
|
|
||||||
|
|
||||||
/** @internal */
|
|
||||||
|
|
||||||
type InternalFlags int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
InternalFlagsNone InternalFlags = 0
|
|
||||||
InternalFlagsWriteComputedProps InternalFlags = 1 << 0
|
|
||||||
InternalFlagsNoSyntacticPrinter InternalFlags = 1 << 1
|
|
||||||
InternalFlagsDoNotIncludeSymbolChain InternalFlags = 1 << 2
|
|
||||||
InternalFlagsAllowUnresolvedNames InternalFlags = 1 << 3
|
|
||||||
)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user