Skip to content

Commit 887cd5c

Browse files
committed
bugfix for issue #122
1 parent d5f3ecf commit 887cd5c

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

PSModuleDevelopment/functions/refactor/Export-PSMDString.ps1

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<#
44
.SYNOPSIS
55
Parses a module that uses the PSFramework localization feature for strings and their value.
6-
6+
77
.DESCRIPTION
88
Parses a module that uses the PSFramework localization feature for strings and their value.
99
This command can be used to generate and update the language files used by the module.
1010
It is also used in automatic tests, ensuring no abandoned string has been left behind and no key is unused.
11-
11+
1212
.PARAMETER ModuleRoot
1313
The root of the module to process.
1414
Must be the root folder where the psd1 file is stored in.
15-
15+
1616
.EXAMPLE
1717
PS C:\> Export-PSMDString -ModuleRoot 'C:\Code\Github\MyModuleProject\MyModule'
18-
18+
1919
Generates the strings data for the MyModule module.
2020
#>
2121
[CmdletBinding()]
@@ -25,7 +25,7 @@
2525
[string]
2626
$ModuleRoot
2727
)
28-
28+
2929
process
3030
{
3131
#region Find Language Files : $languageFiles
@@ -40,7 +40,7 @@
4040
}
4141
}
4242
#endregion Find Language Files : $languageFiles
43-
43+
4444
#region Find Keys : $foundKeys
4545
$foundKeys = foreach ($file in (Get-ChildItem -Path $ModuleRoot -Recurse | Where-Object Extension -match '^\.ps1$|^\.psm1$'))
4646
{
@@ -51,12 +51,12 @@
5151
if (-not ($args[0].CommandElements.ParameterName -match '^String$|^ActionString$')) { return $false }
5252
$true
5353
}, $true)
54-
54+
5555
foreach ($commandAst in $commandAsts)
5656
{
5757
$stringParam = $commandAst.CommandElements | Where-Object ParameterName -match '^String$|^ActionString$'
5858
$stringParamValue = $commandAst.CommandElements[($commandAst.CommandElements.IndexOf($stringParam) + 1)].Value
59-
59+
6060
$stringValueParam = $commandAst.CommandElements | Where-Object ParameterName -match '^StringValues$|^ActionStringValues$'
6161
if ($stringValueParam)
6262
{
@@ -72,7 +72,7 @@
7272
StringValues = $stringValueParamValue
7373
}
7474
}
75-
75+
7676
# Additional checks for splatted commands
7777
# find all splatted commands
7878
$splattedVariables = $ast.FindAll( {
@@ -109,10 +109,13 @@
109109
{
110110
# find any String or ActionString
111111
$splatParam = $splatAssignmentAst.Right.Expression.KeyValuePairs | Where-Object Item1 -match '^String$|^ActionString$'
112-
# The kvp.item.extent.text returns nested quotes where as the commandast.extent.text doesn't so strip them off
113-
$splatParamValue = $splatParam.Item2.Extent.Text.Trim('"').Trim("'")
114-
# find any StringValue or ActionStringValue
115-
$splatValueParam = $splatAssignmentAst.Right.Expression.KeyValuePairs | Where-Object Item1 -match '^StringValues$|^ActionStringValues$'
112+
if ($splatParam)
113+
{
114+
# The kvp.item.extent.text returns nested quotes where as the commandast.extent.text doesn't so strip them off
115+
$splatParamValue = $splatParam.Item2.Extent.Text.Trim('"').Trim("'")
116+
# find any StringValue or ActionStringValue
117+
$splatValueParam = $splatAssignmentAst.Right.Expression.KeyValuePairs | Where-Object Item1 -match '^StringValues$|^ActionStringValues$'
118+
}
116119
if ($splatValueParam)
117120
{
118121
# The kvp.item.extent.text returns nested quotes whereas the commandast.extent.text doesn't so strip them off
@@ -139,7 +142,7 @@
139142
if (-not ($args[0].NamedArguments.ArgumentName -eq 'ErrorString')) { return $false }
140143
$true
141144
}, $true)
142-
145+
143146
foreach ($validateAst in $validateAsts)
144147
{
145148
[PSCustomObject]@{
@@ -153,7 +156,7 @@
153156
}
154157
}
155158
#endregion Find Keys : $foundKeys
156-
159+
157160
#region Report Findings
158161
$totalResults = foreach ($languageFile in $languageFiles.Keys)
159162
{
@@ -166,7 +169,7 @@
166169
$results[$foundKey.String].Entries += $foundKey
167170
continue
168171
}
169-
172+
170173
$results[$foundKey.String] = [PSCustomObject] @{
171174
PSTypeName = 'PSmoduleDevelopment.String.LanguageFinding'
172175
Language = $languageFile
@@ -180,7 +183,7 @@
180183
}
181184
$results.Values
182185
#endregion Phase 1: Matching parsed strings to language file
183-
186+
184187
#region Phase 2: Finding unneeded strings
185188
foreach ($key in $languageFiles[$languageFile].Keys)
186189
{

0 commit comments

Comments
 (0)