Skip to content

Commit 1e16697

Browse files
author
James Brundage
committed
Updating Define (only applying attribute to variables to start) (re #299)
1 parent 2466770 commit 1e16697

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

Transpilers/Define.psx.ps1

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<#
22
.SYNOPSIS
3-
defines a variable
3+
Defines a variable
44
.DESCRIPTION
5-
Defines a variable using a value provided during a build
5+
Defines a variable using a value provided at build time.
66
.EXAMPLE
77
{
88
[Define(Value={Get-Random})]$RandomNumber
@@ -25,11 +25,6 @@ $Value,
2525
[Management.Automation.Language.VariableExpressionast]
2626
$VariableAst,
2727

28-
# A scriptblock the definition will be applied to
29-
[Parameter(Mandatory,ParameterSetName='ScriptBlock', ValueFromPipeline)]
30-
[scriptblock]
31-
$ScriptBlock = {},
32-
3328
# The name of the variable. If define is applied as an attribute of a variable, this does not need to be provided.
3429
[Alias('Name')]
3530
[string]
@@ -122,14 +117,14 @@ $($value | ConvertTo-Json -Depth 100)
122117
"begin"
123118
} elseif ($scriptBlock.Ast.processblock.Statements) {
124119
"process"
125-
} else {
126-
""
120+
} else { ''}
121+
$toCreate =
122+
if ($blockName) {
123+
"$blockName {`$$VariableName =$definedValue }"
127124
}
128-
if ($blockName) {
129-
[ScriptBlock]::Create("$blockName {'$' + $VariableName + ' = ' + $definedValue}"), $ScriptBlock | Join-PipeScript
130-
}
131-
else {
132-
[ScriptBlock]::Create('$' + $VariableName + ' = ' + $definedValue), $ScriptBlock | Join-PipeScript
133-
}
125+
else {
126+
"param() `$$VariableName = $definedValue"
127+
}
128+
[scriptblock]::Create($toCreate), $scriptblock | Join-PipeScript
134129
}
135130
}

0 commit comments

Comments
 (0)