Skip to content

Commit

Permalink
fix: PipeScript Namespaced Object Improvements ( Fixes #1060 )
Browse files Browse the repository at this point in the history
Exporting singletons
  • Loading branch information
James Brundage committed Mar 16, 2024
1 parent 7ad49e1 commit b5ee836
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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
}
Expand All @@ -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})
Expand Down

0 comments on commit b5ee836

Please sign in to comment.