From b5ee8365541412335989473373d651d5f3f21b01 Mon Sep 17 00:00:00 2001 From: James Brundage <@github.com> Date: Sat, 16 Mar 2024 15:03:18 -0700 Subject: [PATCH] fix: PipeScript Namespaced Object Improvements ( Fixes #1060 ) Exporting singletons --- .../PipeScript-Template-NamespacedObject.ps.ps1 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Languages/PipeScript/Templates/Syntax/PipeScript-Template-NamespacedObject.ps.ps1 b/Languages/PipeScript/Templates/Syntax/PipeScript-Template-NamespacedObject.ps.ps1 index 5c18a5e98..789252386 100644 --- a/Languages/PipeScript/Templates/Syntax/PipeScript-Template-NamespacedObject.ps.ps1 +++ b/Languages/PipeScript/Templates/Syntax/PipeScript-Template-NamespacedObject.ps.ps1 @@ -83,6 +83,8 @@ Template function PipeScript.NamespacedObject { $SingletonForms = 'singleton','single','constant','const','the','c','s','t' $singletonPattern = "(?>$($SingletonForms -join '|'))" + + $defineInstance = if ($objectDefinition -is [Management.Automation.Language.HashtableAst]) { @@ -97,6 +99,11 @@ Template function PipeScript.NamespacedObject { \#\> # the closing tag ", 'IgnoreCase,IgnorePatternWhitespace', '00:00:01') $foundBlockComments = $objectDefinition -match $findBlockComments + $objectDefinition = "{ +$($objectDefinition -replace '^\{' -replace '\}$') +Export-ModuleMember -Function * -Alias * -Cmdlet * -Variable * +}" + if ($foundBlockComments -and $matches.Block) { $blockComments = $null,"<#",$($matches.Block),"#>",$null -join [Environment]::Newline } @@ -112,12 +119,7 @@ Template function PipeScript.NamespacedObject { elseif ($matches.0 -eq '<') { '>' } } ) -ne '' -join '' - - $objectDefinition = "{ -$($objectDefinition -replace '^\{' -replace '\}$') -Export-ModuleMember -Function * -Alias * -Cmdlet * -Variable * -}" - + $objectDefinition = if ($objectType -match $singletonPattern) { "{$(if ($blockComments) {$blockComments})