@@ -587,9 +587,18 @@ type globVisitor struct {
587587 results [][]string
588588}
589589
590- func (v * globVisitor ) visit (path , absolutePath string , depth int ) {
590+ // visit walks a directory tree, collecting files that match the glob patterns.
591+ // resolvedRealPath, when non-empty, is the already-resolved real path for this
592+ // directory (computed incrementally from the parent). When empty, Realpath is
593+ // called to resolve symlinks.
594+ func (v * globVisitor ) visit (path , absolutePath string , depth int , resolvedRealPath string ) {
591595 // Detect symlink cycles
592- realPath := v .host .Realpath (absolutePath )
596+ var realPath string
597+ if resolvedRealPath != "" {
598+ realPath = resolvedRealPath
599+ } else {
600+ realPath = v .host .Realpath (absolutePath )
601+ }
593602 canonicalPath := tspath .GetCanonicalFileName (realPath , v .useCaseSensitiveFileNames )
594603 if v .visited .Has (canonicalPath ) {
595604 return
@@ -622,7 +631,17 @@ func (v *globVisitor) visit(path, absolutePath string, depth int) {
622631 continue
623632 }
624633 absDir := absPrefix + dir
625- v .visit (pathPrefix + dir , absDir , depth )
634+ var childRealPath string
635+ if entries .Symlinks != nil {
636+ if _ , isSymlink := entries .Symlinks [dir ]; ! isSymlink {
637+ // Non-symlink directory: compute realpath incrementally.
638+ childRealPath = tspath .CombinePaths (realPath , dir )
639+ }
640+ // else: symlink directory; leave childRealPath empty to force Realpath call.
641+ }
642+ // If Symlinks is nil, the FS doesn't track symlinks;
643+ // leave childRealPath empty to call Realpath (preserving old behavior).
644+ v .visit (pathPrefix + dir , absDir , depth , childRealPath )
626645 }
627646}
628647
@@ -644,7 +663,7 @@ func matchFiles(path string, extensions, excludes, includes []string, useCaseSen
644663 }
645664
646665 for _ , basePath := range getBasePaths (path , includes , useCaseSensitiveFileNames ) {
647- v .visit (basePath , tspath .CombinePaths (currentDirectory , basePath ), depth )
666+ v .visit (basePath , tspath .CombinePaths (currentDirectory , basePath ), depth , "" )
648667 }
649668
650669 // Fast path: a single include bucket (or no includes) doesn't need flattening.
0 commit comments