File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments