Skip to content

Commit ca27a9f

Browse files
StartAutomatingStartAutomating
authored andcommitted
[CommandAst].AsSentence: Coercing values consistently (Fixes #288)
1 parent 8c748df commit ca27a9f

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

PipeScript.types.ps1xml

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -642,45 +642,34 @@ foreach ($potentialCommand in $potentialCommands) {
642642
$currentClause = @()
643643
}
644644

645+
$commandElementValue =
646+
if ($commandElement.Value -and
647+
$commandElement -isnot [Management.Automation.Language.ExpandableStringExpressionAst]) {
648+
$commandElement.Value
649+
}
650+
elseif ($commandElement -is [Management.Automation.Language.ScriptBlockExpressionAst]) {
651+
[ScriptBlock]::Create($commandElement.Extent.ToString() -replace '^\{' -replace '\}$')
652+
}
653+
else {
654+
$commandElement
655+
}
656+
645657
# If we have a current parameter
646658
if ($currentParameter) {
647659

648660
# Map the current element to this parameter.
649-
650-
651-
$mappedParameters[$currentParameter] =
661+
$mappedParameters[$currentParameter] =
652662
if ($mappedParameters[$currentParameter]) {
653-
@($mappedParameters[$currentParameter]) + @($commandElement)
663+
@($mappedParameters[$currentParameter]) + $commandElementValue
654664
} else {
655-
if ($commandElement.Value) {
656-
$commandElement.Value
657-
}
658-
elseif ($commandElement -is [Management.Automation.Language.ScriptBlockExpressionAst]) {
659-
[ScriptBlock]::Create($commandElement.Extent.ToString() -replace '^\{' -replace '\}$')
660-
}
661-
else {
662-
$commandElement
663-
}
665+
$commandElementValue
664666
}
665667
$currentClause += $commandElement
666-
667-
668668
} else {
669669
# otherwise add the command element to our unbound parameters.
670-
$unboundParameters +=
671-
if ($commandElement.Value -and
672-
$commandElement -isnot [Management.Automation.Language.ExpandableStringExpressionAst]) {
673-
$commandElement.Value
674-
}
675-
elseif ($commandElement -is [Management.Automation.Language.ScriptBlockExpressionAst]) {
676-
[ScriptBlock]::Create($commandElement.Extent.ToString() -replace '^\{' -replace '\}$')
677-
}
678-
else {
679-
$commandElement
680-
}
670+
$unboundParameters += $commandElementValue
681671
$currentClause += $commandElement
682672
}
683-
684673
}
685674

686675
if ($currentClause) {

0 commit comments

Comments
 (0)