Skip to content

Commit fcb6e0d

Browse files
author
James Brundage
committed
Join-PipeScript: Ensuring end blocks are unnamed if they can be (Fixes #317)
1 parent ae9aa02 commit fcb6e0d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Join-PipeScript.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function Join-PipeScript
294294
# (don't forget to trim leading whitespace)
295295
} else {
296296
# for every other parameter it is the content between parameters.
297-
$lastParameter = $parameter.Parent.Parameters[$parameterIndex - 1]
297+
$lastParameter = $parameter.Parent.Parameters[$parameterIndex - 1]
298298
$relativeOffset = $lastParameter.Extent.EndOffset + 1 - $parameter.Parent.Extent.StartOffset
299299
$distance = $parameter.Extent.StartOffset - $lastParameter.Extent.EndOffset - 1
300300
# (don't forget to trim leading whitespace and commas)
@@ -427,6 +427,13 @@ function Join-PipeScript
427427
#endregion Joining the Scripts
428428

429429
$combinedScriptBlock = [scriptblock]::Create($joinedScript)
430+
if ((-not $combinedScriptBlock.Ast.EndBlock.Unnamed) -and -not (
431+
$combinedScriptBlock.Ast.ProcessBlock -or
432+
$combinedScriptBlock.Ast.BeginBlock -or
433+
$combinedScriptBlock.Ast.DynamicParameterBlock
434+
)) {
435+
$combinedScriptBlock = [ScriptBlock]::Create($combinedScriptBlock.Ast.EndBlock.ToString() -replace '^end\s{0,}\{' -replace '\}$')
436+
}
430437
if ($combinedScriptBlock -and $Transpile) {
431438
$combinedScriptBlock | .>Pipescript
432439
} elseif ($combinedScriptBlock) {

0 commit comments

Comments
 (0)