Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/tsgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ func getFormatOpts(host ts.CompilerHost) *diagnosticwriter.FormattingOptions {
return &diagnosticwriter.FormattingOptions{
NewLine: host.NewLine(),
ComparePathsOptions: tspath.ComparePathsOptions{
CurrentDirectory: host.GetCurrentDirectory(),
UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(),
CurrentDirectory: host.GetCurrentDirectory(),
CaseSensitivity: host.FS().CaseSensitivity(),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BenchmarkBind(b *testing.B) {
f.SkipIfNotExist(b)

fileName := tspath.GetNormalizedAbsolutePath(f.Path(), "/")
path := tspath.ToPath(fileName, "/", osvfs.FS().UseCaseSensitiveFileNames())
path := tspath.ToPath(fileName, "/", osvfs.FS().CaseSensitivity())
sourceText := f.ReadFile(b)

sourceFiles := make([]*ast.SourceFile, b.N)
Expand Down
5 changes: 3 additions & 2 deletions internal/bundled/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/microsoft/typescript-go/internal/tspath"
"github.com/microsoft/typescript-go/internal/vfs"
)

Expand Down Expand Up @@ -37,8 +38,8 @@ func wrapFS(fs vfs.FS) vfs.FS {
return &wrappedFS{fs: fs}
}

func (vfs *wrappedFS) UseCaseSensitiveFileNames() bool {
return vfs.fs.UseCaseSensitiveFileNames()
func (vfs *wrappedFS) CaseSensitivity() tspath.CaseSensitivity {
return vfs.fs.CaseSensitivity()
}

func (vfs *wrappedFS) FileExists(path string) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ foo.bar;`
"compilerOptions": {}
}
`,
}, false /*useCaseSensitiveFileNames*/)
}, tspath.CaseInsensitive)
fs = bundled.WrapFS(fs)

cd := "/"
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/emitHost.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WriteFileData struct {
type EmitHost interface {
Options() *core.CompilerOptions
SourceFiles() []*ast.SourceFile
UseCaseSensitiveFileNames() bool
CaseSensitivity() tspath.CaseSensitivity
GetCurrentDirectory() string
CommonSourceDirectory() string
IsEmitBlocked(file string) bool
Expand All @@ -39,8 +39,8 @@ func (host *emitHost) Options() *core.CompilerOptions { return host.program.Opti
func (host *emitHost) SourceFiles() []*ast.SourceFile { return host.program.SourceFiles() }
func (host *emitHost) GetCurrentDirectory() string { return host.program.host.GetCurrentDirectory() }
func (host *emitHost) CommonSourceDirectory() string { return host.program.CommonSourceDirectory() }
func (host *emitHost) UseCaseSensitiveFileNames() bool {
return host.program.host.FS().UseCaseSensitiveFileNames()
func (host *emitHost) CaseSensitivity() tspath.CaseSensitivity {
return host.program.host.FS().CaseSensitivity()
}

func (host *emitHost) IsEmitBlocked(file string) bool {
Expand Down
24 changes: 12 additions & 12 deletions internal/compiler/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func (e *emitter) printSourceFile(jsFilePath string, sourceMapFilePath string, s
getSourceRoot(options),
e.getSourceMapDirectory(options, jsFilePath, sourceFile),
tspath.ComparePathsOptions{
UseCaseSensitiveFileNames: e.host.UseCaseSensitiveFileNames(),
CurrentDirectory: e.host.GetCurrentDirectory(),
CaseSensitivity: e.host.CaseSensitivity(),
CurrentDirectory: e.host.GetCurrentDirectory(),
},
)
}
Expand Down Expand Up @@ -219,12 +219,12 @@ func (e *emitter) printSourceFile(jsFilePath string, sourceMapFilePath string, s
return !data.SkippedDtsWrite
}

func getSourceFilePathInNewDir(fileName string, newDirPath string, currentDirectory string, commonSourceDirectory string, useCaseSensitiveFileNames bool) string {
func getSourceFilePathInNewDir(fileName string, newDirPath string, currentDirectory string, commonSourceDirectory string, caseSensitivity tspath.CaseSensitivity) string {
sourceFilePath := tspath.GetNormalizedAbsolutePath(fileName, currentDirectory)
commonSourceDirectory = tspath.EnsureTrailingDirectorySeparator(commonSourceDirectory)
isSourceFileInCommonSourceDirectory := tspath.ContainsPath(commonSourceDirectory, sourceFilePath, tspath.ComparePathsOptions{
UseCaseSensitiveFileNames: useCaseSensitiveFileNames,
CurrentDirectory: currentDirectory,
CaseSensitivity: caseSensitivity,
CurrentDirectory: currentDirectory,
})
if isSourceFileInCommonSourceDirectory {
sourceFilePath = sourceFilePath[len(commonSourceDirectory):]
Expand All @@ -242,7 +242,7 @@ func getOwnEmitOutputFilePath(fileName string, host EmitHost, extension string)
compilerOptions.OutDir,
currentDirectory,
host.CommonSourceDirectory(),
host.UseCaseSensitiveFileNames(),
host.CaseSensitivity(),
))
} else {
emitOutputFilePathWithoutExtension = tspath.RemoveFileExtension(fileName)
Expand Down Expand Up @@ -286,7 +286,7 @@ func (e *emitter) getSourceMapDirectory(mapOptions *core.CompilerOptions, filePa
sourceMapDir,
e.host.GetCurrentDirectory(),
e.host.CommonSourceDirectory(),
e.host.UseCaseSensitiveFileNames(),
e.host.CaseSensitivity(),
))
}
if tspath.GetRootLength(sourceMapDir) == 0 {
Expand Down Expand Up @@ -317,7 +317,7 @@ func (e *emitter) getSourceMappingURL(mapOptions *core.CompilerOptions, sourceMa
sourceMapDir,
e.host.GetCurrentDirectory(),
e.host.CommonSourceDirectory(),
e.host.UseCaseSensitiveFileNames(),
e.host.CaseSensitivity(),
))
}
if tspath.GetRootLength(sourceMapDir) == 0 {
Expand All @@ -329,8 +329,8 @@ func (e *emitter) getSourceMappingURL(mapOptions *core.CompilerOptions, sourceMa
tspath.CombinePaths(sourceMapDir, sourceMapFile), // this is where user expects to see sourceMap
/*isAbsolutePathAnUrl*/ true,
tspath.ComparePathsOptions{
UseCaseSensitiveFileNames: e.host.UseCaseSensitiveFileNames(),
CurrentDirectory: e.host.GetCurrentDirectory(),
CaseSensitivity: e.host.CaseSensitivity(),
CurrentDirectory: e.host.GetCurrentDirectory(),
},
),
)
Expand Down Expand Up @@ -362,8 +362,8 @@ func getOutputPathsFor(sourceFile *ast.SourceFile, host EmitHost, forceDtsEmit b
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
isJsonEmittedToSameLocation := isJsonFile &&
tspath.ComparePaths(sourceFile.FileName(), ownOutputFilePath, tspath.ComparePathsOptions{
CurrentDirectory: host.GetCurrentDirectory(),
UseCaseSensitiveFileNames: host.UseCaseSensitiveFileNames(),
CurrentDirectory: host.GetCurrentDirectory(),
CaseSensitivity: host.CaseSensitivity(),
}) == 0
paths := &outputPaths{}
if options.EmitDeclarationOnly != core.TSTrue && !isJsonEmittedToSameLocation {
Expand Down
6 changes: 3 additions & 3 deletions internal/compiler/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func processAllProgramFiles(
resolver: resolver,
defaultLibraryPath: tspath.GetNormalizedAbsolutePath(host.DefaultLibraryPath(), host.GetCurrentDirectory()),
comparePathsOptions: tspath.ComparePathsOptions{
UseCaseSensitiveFileNames: host.FS().UseCaseSensitiveFileNames(),
CurrentDirectory: host.GetCurrentDirectory(),
CaseSensitivity: host.FS().CaseSensitivity(),
CurrentDirectory: host.GetCurrentDirectory(),
},
wg: core.NewWorkGroup(programOptions.SingleThreaded),
rootTasks: make([]*parseTask, 0, len(rootFiles)+len(libs)),
Expand Down Expand Up @@ -266,7 +266,7 @@ func (p *fileLoader) loadSourceFileMetaData(path tspath.Path) *ast.SourceFileMet
}

func (p *fileLoader) parseSourceFile(fileName string) *ast.SourceFile {
path := tspath.ToPath(fileName, p.host.GetCurrentDirectory(), p.host.FS().UseCaseSensitiveFileNames())
path := tspath.ToPath(fileName, p.host.GetCurrentDirectory(), p.host.FS().CaseSensitivity())
sourceFile := p.host.GetSourceFile(fileName, path, p.compilerOptions.GetEmitScriptTarget())
return sourceFile
}
Expand Down
74 changes: 37 additions & 37 deletions internal/compiler/module/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ type caches struct {

func newCaches(
currentDirectory string,
useCaseSensitiveFileNames bool,
caseSensitivity tspath.CaseSensitivity,
options *core.CompilerOptions,
) caches {
optionsToRedirectsKey := make(map[*core.CompilerOptions]string)
getOriginalOrResolvedModuleFileName := func(result *ResolvedModule) tspath.Path {
if result.OriginalPath != "" {
return tspath.ToPath(result.OriginalPath, currentDirectory, useCaseSensitiveFileNames)
return tspath.ToPath(result.OriginalPath, currentDirectory, caseSensitivity)
}
return tspath.ToPath(result.ResolvedFileName, currentDirectory, useCaseSensitiveFileNames)
return tspath.ToPath(result.ResolvedFileName, currentDirectory, caseSensitivity)
}
getOriginalOrResolvedTypeReferenceFileName := func(result *ResolvedTypeReferenceDirective) tspath.Path {
if result.OriginalPath != "" {
return tspath.ToPath(result.OriginalPath, currentDirectory, useCaseSensitiveFileNames)
return tspath.ToPath(result.OriginalPath, currentDirectory, caseSensitivity)
}
return tspath.ToPath(result.ResolvedFileName, currentDirectory, useCaseSensitiveFileNames)
return tspath.ToPath(result.ResolvedFileName, currentDirectory, caseSensitivity)
}
return caches{
moduleNameCache: newResolutionCache(currentDirectory, useCaseSensitiveFileNames, options, getOriginalOrResolvedModuleFileName, optionsToRedirectsKey, false /*isReadonly*/),
typeReferenceDirectiveCache: newResolutionCache(currentDirectory, useCaseSensitiveFileNames, options, getOriginalOrResolvedTypeReferenceFileName, optionsToRedirectsKey, false /*isReadonly*/),
packageJsonInfoCache: packagejson.NewInfoCache(currentDirectory, useCaseSensitiveFileNames),
moduleNameCache: newResolutionCache(currentDirectory, caseSensitivity, options, getOriginalOrResolvedModuleFileName, optionsToRedirectsKey, false /*isReadonly*/),
typeReferenceDirectiveCache: newResolutionCache(currentDirectory, caseSensitivity, options, getOriginalOrResolvedTypeReferenceFileName, optionsToRedirectsKey, false /*isReadonly*/),
packageJsonInfoCache: packagejson.NewInfoCache(currentDirectory, caseSensitivity),
}
}

Expand All @@ -59,15 +59,15 @@ type resolutionCache[T comparable] struct {

func newResolutionCache[T comparable](
currentDirectory string,
useCaseSensitiveFileNames bool,
caseSensitivity tspath.CaseSensitivity,
options *core.CompilerOptions,
getResolvedFileName func(result T) tspath.Path,
optionsToRedirectsKey map[*core.CompilerOptions]string,
isReadonly bool,
) *resolutionCache[T] {
return &resolutionCache[T]{
perDirectoryResolutionCache: newPerDirectoryResolutionCache[T](currentDirectory, useCaseSensitiveFileNames, options, optionsToRedirectsKey),
nonRelativeNameResolutionCache: newNonRelativeNameResolutionCache(currentDirectory, useCaseSensitiveFileNames, options, getResolvedFileName, optionsToRedirectsKey),
perDirectoryResolutionCache: newPerDirectoryResolutionCache[T](currentDirectory, caseSensitivity, options, optionsToRedirectsKey),
nonRelativeNameResolutionCache: newNonRelativeNameResolutionCache(currentDirectory, caseSensitivity, options, getResolvedFileName, optionsToRedirectsKey),
isReadonly: isReadonly,
}
}
Expand Down Expand Up @@ -101,31 +101,31 @@ func (c *resolutionCache[T]) appendLookupLocations(resolved T, failedLookupLocat
}

type perDirectoryResolutionCache[T any] struct {
mu sync.RWMutex
currentDirectory string
useCaseSensitiveFileNames bool
options *core.CompilerOptions
directoryToModuleNameMap *cacheWithRedirects[tspath.Path, ModeAwareCache[T]]
mu sync.RWMutex
currentDirectory string
caseSensitivity tspath.CaseSensitivity
options *core.CompilerOptions
directoryToModuleNameMap *cacheWithRedirects[tspath.Path, ModeAwareCache[T]]
}

func newPerDirectoryResolutionCache[T any](
currentDirectory string,
useCaseSensitiveFileNames bool,
caseSensitivity tspath.CaseSensitivity,
options *core.CompilerOptions,
optionsToRedirectsKey map[*core.CompilerOptions]string,
) perDirectoryResolutionCache[T] {
return perDirectoryResolutionCache[T]{
currentDirectory: currentDirectory,
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
options: options,
directoryToModuleNameMap: newCacheWithRedirects[tspath.Path, ModeAwareCache[T]](options, optionsToRedirectsKey),
currentDirectory: currentDirectory,
caseSensitivity: caseSensitivity,
options: options,
directoryToModuleNameMap: newCacheWithRedirects[tspath.Path, ModeAwareCache[T]](options, optionsToRedirectsKey),
}
}

func (c *perDirectoryResolutionCache[T]) getFromDirectoryCache(nameAndMode ModeAwareCacheKey, directory string, redirectedReference *ResolvedProjectReference) (T, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
result, ok := c.directoryToModuleNameMap.getMapOfCacheRedirects(redirectedReference)[tspath.ToPath(directory, c.currentDirectory, c.useCaseSensitiveFileNames)][nameAndMode]
result, ok := c.directoryToModuleNameMap.getMapOfCacheRedirects(redirectedReference)[tspath.ToPath(directory, c.currentDirectory, c.caseSensitivity)][nameAndMode]
return result, ok
}

Expand All @@ -139,7 +139,7 @@ func (c *perDirectoryResolutionCache[T]) setInDirectoryCache(nameAndMode ModeAwa
func (c *perDirectoryResolutionCache[T]) getOrCreateCacheForDirectory(directory string, redirectedReference *ResolvedProjectReference) ModeAwareCache[T] {
c.mu.RLock()
cache := c.directoryToModuleNameMap.getOrCreateMapOfCacheRedirects(redirectedReference)
key := tspath.ToPath(directory, c.currentDirectory, c.useCaseSensitiveFileNames)
key := tspath.ToPath(directory, c.currentDirectory, c.caseSensitivity)
result, ok := cache[key]
c.mu.RUnlock()
if ok {
Expand All @@ -154,27 +154,27 @@ func (c *perDirectoryResolutionCache[T]) getOrCreateCacheForDirectory(directory
}

type nonRelativeNameResolutionCache[T any] struct {
mu sync.RWMutex
currentDirectory string
useCaseSensitiveFileNames bool
options *core.CompilerOptions
getResolvedFileName func(result T) tspath.Path
moduleNameToDirectoryMap *cacheWithRedirects[ModeAwareCacheKey, *perNonRelativeNameCache[T]]
mu sync.RWMutex
currentDirectory string
caseSensitivity tspath.CaseSensitivity
options *core.CompilerOptions
getResolvedFileName func(result T) tspath.Path
moduleNameToDirectoryMap *cacheWithRedirects[ModeAwareCacheKey, *perNonRelativeNameCache[T]]
}

func newNonRelativeNameResolutionCache[T any](
currentDirectory string,
useCaseSensitiveFileNames bool,
caseSensitivity tspath.CaseSensitivity,
options *core.CompilerOptions,
getResolvedFileName func(result T) tspath.Path,
optionsToRedirectsKey map[*core.CompilerOptions]string,
) nonRelativeNameResolutionCache[T] {
return nonRelativeNameResolutionCache[T]{
currentDirectory: currentDirectory,
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
options: options,
getResolvedFileName: getResolvedFileName,
moduleNameToDirectoryMap: newCacheWithRedirects[ModeAwareCacheKey, *perNonRelativeNameCache[T]](options, optionsToRedirectsKey),
currentDirectory: currentDirectory,
caseSensitivity: caseSensitivity,
options: options,
getResolvedFileName: getResolvedFileName,
moduleNameToDirectoryMap: newCacheWithRedirects[ModeAwareCacheKey, *perNonRelativeNameCache[T]](options, optionsToRedirectsKey),
}
}

Expand All @@ -184,7 +184,7 @@ func (c *nonRelativeNameResolutionCache[T]) getFromNonRelativeNameCache(nameAndM
}
c.mu.RLock()
defer c.mu.RUnlock()
return c.moduleNameToDirectoryMap.getMapOfCacheRedirects(redirectedReference)[nameAndMode].get(tspath.ToPath(directoryName, c.currentDirectory, c.useCaseSensitiveFileNames))
return c.moduleNameToDirectoryMap.getMapOfCacheRedirects(redirectedReference)[nameAndMode].get(tspath.ToPath(directoryName, c.currentDirectory, c.caseSensitivity))
}

func (c *nonRelativeNameResolutionCache[T]) setInNonRelativeNameCache(nameAndMode ModeAwareCacheKey, directoryName string, value T, redirectedReference *ResolvedProjectReference) {
Expand All @@ -194,7 +194,7 @@ func (c *nonRelativeNameResolutionCache[T]) setInNonRelativeNameCache(nameAndMod
cache := c.getOrCreateCacheForNonRelativeName(nameAndMode, redirectedReference)
c.mu.Lock()
defer c.mu.Unlock()
cache.set(tspath.ToPath(directoryName, c.currentDirectory, c.useCaseSensitiveFileNames), value, c.getResolvedFileName)
cache.set(tspath.ToPath(directoryName, c.currentDirectory, c.caseSensitivity), value, c.getResolvedFileName)
}

func (c *nonRelativeNameResolutionCache[T]) getOrCreateCacheForNonRelativeName(nameAndMode ModeAwareCacheKey, redirectedReference *ResolvedProjectReference) *perNonRelativeNameCache[T] {
Expand Down
8 changes: 4 additions & 4 deletions internal/compiler/module/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func NewResolver(
) *Resolver {
return &Resolver{
host: host,
caches: newCaches(host.GetCurrentDirectory(), host.FS().UseCaseSensitiveFileNames(), options),
caches: newCaches(host.GetCurrentDirectory(), host.FS().CaseSensitivity(), options),
compilerOptions: options,
}
}
Expand Down Expand Up @@ -1028,8 +1028,8 @@ func (r *resolutionState) createResolvedTypeReferenceDirective(resolved *resolve
func (r *resolutionState) getOriginalAndResolvedFileName(fileName string) (string, string) {
resolvedFileName := r.realPath(fileName)
comparePathsOptions := tspath.ComparePathsOptions{
UseCaseSensitiveFileNames: r.resolver.host.FS().UseCaseSensitiveFileNames(),
CurrentDirectory: r.resolver.host.GetCurrentDirectory(),
CaseSensitivity: r.resolver.host.FS().CaseSensitivity(),
CurrentDirectory: r.resolver.host.GetCurrentDirectory(),
}
if tspath.ComparePaths(fileName, resolvedFileName, comparePathsOptions) == 0 {
// If the fileName and realpath are differing only in casing, prefer fileName
Expand Down Expand Up @@ -1345,7 +1345,7 @@ func (r *resolutionState) loadNodeModuleFromDirectoryWorker(ext extensions, cand
onlyRecordFailuresForPackageFile bool
versionPaths packagejson.VersionPaths
)
if packageInfo.Exists() && tspath.ComparePaths(candidate, packageInfo.PackageDirectory, tspath.ComparePathsOptions{UseCaseSensitiveFileNames: r.resolver.host.FS().UseCaseSensitiveFileNames()}) == 0 {
if packageInfo.Exists() && tspath.ComparePaths(candidate, packageInfo.PackageDirectory, tspath.ComparePathsOptions{CaseSensitivity: r.resolver.host.FS().CaseSensitivity()}) == 0 {
if file, ok := r.getPackageFile(ext, packageInfo); ok {
packageFile = file
onlyRecordFailuresForPackageFile = !r.resolver.host.FS().DirectoryExists(tspath.GetDirectoryPath(file))
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/module/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func newVFSModuleResolutionHost(files map[string]string, currentDirectory string
currentDirectory = "/.src/" + currentDirectory
}
return &vfsModuleResolutionHost{
fs: vfstest.FromMap(fs, true /*useCaseSensitiveFileNames*/),
fs: vfstest.FromMap(fs, tspath.CaseSensitive),
currentDirectory: currentDirectory,
}
}
Expand Down
Loading