Skip to content

Commit fcf0c6c

Browse files
author
James Brundage
committed
Join-PipeScript: Fixing End Block Behavior (Fixes #383)
1 parent 5e2f1c8 commit fcf0c6c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Join-PipeScript.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function Join-PipeScript
406406
$blocks = @($AllScriptBlocks.Ast.EndBlock)
407407
if ($blocks -ne $null) {
408408
$blockOpen = $false # see if there was anything in them.
409-
409+
$unnamedBlocks = @($blocks.Unnamed)
410410
foreach ($block in $blocks) {
411411
if (-not $block) { continue }
412412
# Empty(ish) scripts may have an end bock that is an empty param block
@@ -424,11 +424,12 @@ function Join-PipeScript
424424
$blockOpen = $true
425425
} elseif ($block.Statements.Count) {
426426
# where as if it is a series of statements, it doesn't necessarily need to be.
427-
# Unless it's the first block and it's unnamed.
428-
if ($block.Unnamed -and -not $blockOpen) {
427+
# Unless it's the first block and it's unnamed, and other blocks are named.
428+
if ($block.Unnamed -and -not $blockOpen -and
429+
$unnamedBlocks.Length -ne $blocks.Length) {
429430
' ' * ($block | MeasureIndent) + 'end {'
430431
$blockOpen = $true
431-
$closeEndBlock = $true
432+
$closeEndBlock = $false
432433
}
433434
if ($StatementsToAdd) {
434435
$StatementsToAdd -join [Environment]::NewLine

0 commit comments

Comments
 (0)