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

Function reducePathComponents

internal/tspath/path.go:286–312  ·  view source on GitHub ↗
(components []string)

Source from the content-addressed store, hash-verified

284}
285
286func reducePathComponents(components []string) []string {
287 if len(components) == 0 {
288 return []string{}
289 }
290 reduced := []string{components[0]}
291 for i := 1; i < len(components); i++ {
292 component := components[i]
293 if component == "" {
294 continue
295 }
296 if component == "." {
297 continue
298 }
299 if component == ".." {
300 if len(reduced) > 1 {
301 if reduced[len(reduced)-1] != ".." {
302 reduced = reduced[:len(reduced)-1]
303 continue
304 }
305 } else if reduced[0] != "" {
306 continue
307 }
308 }
309 reduced = append(reduced, component)
310 }
311 return reduced
312}
313
314// Combines and resolves paths. If a path is absolute, it replaces any previous path. Any
315// `.` and `..` path components are resolved. Trailing directory separators are preserved.

Callers 6

ComparePathsFunction · 0.85
ContainsPathFunction · 0.85
GetCommonParentsFunction · 0.85
TestReducePathComponentsFunction · 0.85
normalizePath_oldFunction · 0.85

Calls 2

lenFunction · 0.85
appendFunction · 0.50

Tested by 2

TestReducePathComponentsFunction · 0.68
normalizePath_oldFunction · 0.68