@@ -19,27 +19,24 @@ function MoveUsingStatements {
1919 Param (
2020 # Path to the PSM1 file to amend
2121 [Parameter (Mandatory , ValueFromPipelineByPropertyName , ValueFromPipeline )]
22- $RootModule ,
22+ [System.Management.Automation.Language.Ast ]$AST ,
23+
24+ [Parameter (ValueFromPipelineByPropertyName , ValueFromPipeline )]
25+ [AllowNull ()]
26+ [System.Management.Automation.Language.ParseError []]$ParseErrors ,
2327
2428 # The encoding defaults to UTF8 (or UTF8NoBom on Core)
2529 [Parameter (DontShow)]
2630 [string ]$Encoding = $ (if ($IsCoreCLR ) { " UTF8NoBom" } else { " UTF8" })
2731 )
2832
29- $ParseError = $null
30- $AST = [System.Management.Automation.Language.Parser ]::ParseFile(
31- $RootModule ,
32- [ref ]$null ,
33- [ref ]$ParseError
34- )
35-
3633 # Avoid modifying the file if there's no Parsing Error caused by Using Statements or other errors
37- if (! $ParseError .Where {$_.ErrorId -eq ' UsingMustBeAtStartOfScript' }) {
34+ if (! $ParseErrors .Where {$_.ErrorId -eq ' UsingMustBeAtStartOfScript' }) {
3835 Write-Debug " No Using Statement Error found."
3936 return
4037 }
4138 # Avoid modifying the file if there's other parsing errors than Using Statements misplaced
42- if ($ParseError .Where {$_.ErrorId -ne ' UsingMustBeAtStartOfScript' }) {
39+ if ($ParseErrors .Where {$_.ErrorId -ne ' UsingMustBeAtStartOfScript' }) {
4340 Write-Warning " Parsing errors found. Skipping Moving Using statements."
4441 return
4542 }
@@ -70,13 +67,13 @@ function MoveUsingStatements {
7067 $null = [System.Management.Automation.Language.Parser ]::ParseInput(
7168 $ScriptText ,
7269 [ref ]$null ,
73- [ref ]$ParseError
70+ [ref ]$ParseErrors
7471 )
7572
76- if ($ParseError ) {
73+ if ($ParseErrors ) {
7774 Write-Warning " Oops, it seems that we introduced parsing error(s) while moving the Using Statements. Cancelling changes."
7875 }
7976 else {
8077 $null = Set-Content - Value $ScriptText - Path $RootModule - Encoding $Encoding
8178 }
82- }
79+ }
0 commit comments