Skip to content

Commit 8c748df

Browse files
author
James Brundage
committed
[CommandAst].AsSentence: Coercing values consistently (Fixes #288)
1 parent 117f8c9 commit 8c748df

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

Types/CommandAST/AsSentence.ps1

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -360,45 +360,34 @@ foreach ($potentialCommand in $potentialCommands) {
360360
$currentClause = @()
361361
}
362362

363+
$commandElementValue =
364+
if ($commandElement.Value -and
365+
$commandElement -isnot [Management.Automation.Language.ExpandableStringExpressionAst]) {
366+
$commandElement.Value
367+
}
368+
elseif ($commandElement -is [Management.Automation.Language.ScriptBlockExpressionAst]) {
369+
[ScriptBlock]::Create($commandElement.Extent.ToString() -replace '^\{' -replace '\}$')
370+
}
371+
else {
372+
$commandElement
373+
}
374+
363375
# If we have a current parameter
364376
if ($currentParameter) {
365377

366378
# Map the current element to this parameter.
367-
368-
369-
$mappedParameters[$currentParameter] =
379+
$mappedParameters[$currentParameter] =
370380
if ($mappedParameters[$currentParameter]) {
371-
@($mappedParameters[$currentParameter]) + @($commandElement)
381+
@($mappedParameters[$currentParameter]) + $commandElementValue
372382
} else {
373-
if ($commandElement.Value) {
374-
$commandElement.Value
375-
}
376-
elseif ($commandElement -is [Management.Automation.Language.ScriptBlockExpressionAst]) {
377-
[ScriptBlock]::Create($commandElement.Extent.ToString() -replace '^\{' -replace '\}$')
378-
}
379-
else {
380-
$commandElement
381-
}
383+
$commandElementValue
382384
}
383385
$currentClause += $commandElement
384-
385-
386386
} else {
387387
# otherwise add the command element to our unbound parameters.
388-
$unboundParameters +=
389-
if ($commandElement.Value -and
390-
$commandElement -isnot [Management.Automation.Language.ExpandableStringExpressionAst]) {
391-
$commandElement.Value
392-
}
393-
elseif ($commandElement -is [Management.Automation.Language.ScriptBlockExpressionAst]) {
394-
[ScriptBlock]::Create($commandElement.Extent.ToString() -replace '^\{' -replace '\}$')
395-
}
396-
else {
397-
$commandElement
398-
}
388+
$unboundParameters += $commandElementValue
399389
$currentClause += $commandElement
400390
}
401-
402391
}
403392

404393
if ($currentClause) {

0 commit comments

Comments
 (0)