Skip to content

Commit

Permalink
feat: AST.GetRelativeIndex ( Fixes #1082 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Mar 20, 2024
1 parent d124a6c commit 632d546
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Types/AST/Alias.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
"GetCollectionAndIndex" = "GetRelativeIndex"
}
22 changes: 22 additions & 0 deletions Types/AST/GetRelativeIndex.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

$thisCollection,$thisIndex = $null,-1
:FindThisIndex foreach ($parentProperty in $this.Parent.psobject.Properties) {
if ($parentProperty -is [PSScriptProperty] -or $parentProperty -is [PSNoteProperty]) {
continue FindThisIndex
}
$currentProperty = $this.Parent.($parentProperty.Name)
if (-not $currentProperty.IndexOf) { continue }


if ($currentProperty.IndexOf($this) -ge 0) {
$thisCollection = $currentProperty
$thisIndex = $thisCollection.IndexOf($this)
break FindThisIndex
}

}

return ([PSCustomObject][Ordered]@{
Collection = $thisCollection
Index = $thisIndex
})

0 comments on commit 632d546

Please sign in to comment.