MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getNormalizedPathComponentsFromCombined

Function getNormalizedPathComponentsFromCombined

internal/tspath/path.go:345–385  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

343}
344
345func getNormalizedPathComponentsFromCombined(path string) []string {
346 rootLength := GetRootLength(path)
347 // Always include the root component (empty string for relative paths).
348 components := make([]string, 1, 8)
349 components[0] = path[:rootLength]
350
351 for i := rootLength; i < len(path); {
352 // Skip directory separators (handles consecutive separators and trailing '/').
353 for i < len(path) && path[i] == '/' {
354 i++
355 }
356 if i >= len(path) {
357 break
358 }
359
360 start := i
361 for i < len(path) && path[i] != '/' {
362 i++
363 }
364 component := path[start:i]
365
366 if component == "" || component == "." {
367 continue
368 }
369 if component == ".." {
370 if len(components) > 1 {
371 if components[len(components)-1] != ".." {
372 components = components[:len(components)-1]
373 continue
374 }
375 } else if components[0] != "" {
376 // If this is an absolute path, we can't go above the root.
377 continue
378 }
379 }
380
381 components = append(components, component)
382 }
383
384 return components
385}
386
387func GetNormalizedAbsolutePathWithoutRoot(fileName string, currentDirectory string) string {
388 absolutePath := GetNormalizedAbsolutePath(fileName, currentDirectory)

Callers 1

Calls 4

GetRootLengthFunction · 0.85
lenFunction · 0.85
makeFunction · 0.50
appendFunction · 0.50

Tested by

no test coverage detected