MCPcopy Index your code
hub / github.com/microsoft/typescript-go / GetNormalizedAbsolutePath

Function GetNormalizedAbsolutePath

internal/tspath/path.go:393–512  ·  view source on GitHub ↗
(fileName string, currentDirectory string)

Source from the content-addressed store, hash-verified

391}
392
393func GetNormalizedAbsolutePath(fileName string, currentDirectory string) string {
394 rootLength := GetRootLength(fileName)
395 if rootLength == 0 && currentDirectory != "" {
396 fileName = CombinePaths(currentDirectory, fileName)
397 } else {
398 // CombinePaths normalizes slashes, so not necessary in other branch
399 fileName = NormalizeSlashes(fileName)
400 }
401 rootLength = GetRootLength(fileName)
402
403 if simpleNormalized, ok := simpleNormalizePath(fileName); ok {
404 length := len(simpleNormalized)
405 if length > rootLength {
406 return RemoveTrailingDirectorySeparator(simpleNormalized)
407 }
408 if length == rootLength && rootLength != 0 {
409 return EnsureTrailingDirectorySeparator(simpleNormalized)
410 }
411 return simpleNormalized
412 }
413
414 length := len(fileName)
415 root := fileName[:rootLength]
416 // `normalized` is only initialized once `fileName` is determined to be non-normalized.
417 // `changed` is set at the same time.
418 var changed bool
419 var normalized string
420 var segmentStart int
421 index := rootLength
422 normalizedUpTo := index
423 seenNonDotDotSegment := rootLength != 0
424 for index < length {
425 // At beginning of segment
426 segmentStart = index
427 ch := fileName[index]
428 for ch == '/' {
429 index++
430 if index < length {
431 ch = fileName[index]
432 } else {
433 break
434 }
435 }
436 if index > segmentStart {
437 // Seen superfluous separator
438 if !changed {
439 normalized = fileName[:max(rootLength, segmentStart-1)]
440 changed = true
441 }
442 if index == length {
443 break
444 }
445 segmentStart = index
446 }
447 // Past any superfluous separators
448 segmentEnd := strings.IndexByte(fileName[index+1:], '/')
449 if segmentEnd == -1 {
450 segmentEnd = length

Calls 9

GetRootLengthFunction · 0.85
CombinePathsFunction · 0.85
NormalizeSlashesFunction · 0.85
lenFunction · 0.85
maxFunction · 0.85
simpleNormalizePathFunction · 0.70

Tested by 8

TestUntitledPathHandlingFunction · 0.74
BenchmarkParseFunction · 0.74
getParsedWithJsonApiFunction · 0.74
baselineParseConfigWithFunction · 0.74
BenchmarkBindFunction · 0.74