@@ -43,14 +43,7 @@ public IterativeVariableRename(string NewName, int StartLineNumber, int StartCol
43
43
isParam = true ;
44
44
Ast parent = Node ;
45
45
// Look for a target function that the parameterAst will be within if it exists
46
- while ( parent != null )
47
- {
48
- if ( parent is FunctionDefinitionAst )
49
- {
50
- break ;
51
- }
52
- parent = parent . Parent ;
53
- }
46
+ parent = Utilities . LookForParentOfType ( parent , typeof ( FunctionDefinitionAst ) ) ;
54
47
if ( parent != null )
55
48
{
56
49
TargetFunction = ( FunctionDefinitionAst ) parent ;
@@ -95,18 +88,15 @@ public static Ast GetVariableTopAssignment(int StartLineNumber, int StartColumnN
95
88
} ;
96
89
97
90
VariableExpressionAst splatAssignment = null ;
91
+ // A rename of a parameter has been initiated from a splat
98
92
if ( node is StringConstantExpressionAst )
99
93
{
100
94
Ast parent = node ;
101
- while ( parent != null )
95
+ parent = Utilities . LookForParentOfType ( parent , typeof ( AssignmentStatementAst ) ) ;
96
+ if ( parent is not null and AssignmentStatementAst assignmentStatementAst )
102
97
{
103
- if ( parent is AssignmentStatementAst assignmentStatementAst )
104
- {
105
- splatAssignment = ( VariableExpressionAst ) assignmentStatementAst . Left . Find ( ast => ast is VariableExpressionAst , false ) ;
106
-
107
- break ;
108
- }
109
- parent = parent . Parent ;
98
+ splatAssignment = ( VariableExpressionAst ) assignmentStatementAst . Left . Find (
99
+ ast => ast is VariableExpressionAst , false ) ;
110
100
}
111
101
}
112
102
@@ -205,15 +195,8 @@ varDef.Parent is CommandAst &&
205
195
internal static Ast GetAstParentScope ( Ast node )
206
196
{
207
197
Ast parent = node ;
208
- // Walk backwards up the tree lookinf for a ScriptBLock of a FunctionDefinition
209
- while ( parent != null )
210
- {
211
- if ( parent is ScriptBlockAst or FunctionDefinitionAst )
212
- {
213
- break ;
214
- }
215
- parent = parent . Parent ;
216
- }
198
+ // Walk backwards up the tree looking for a ScriptBLock of a FunctionDefinition
199
+ parent = Utilities . LookForParentOfType ( parent , typeof ( ScriptBlockAst ) , typeof ( FunctionDefinitionAst ) ) ;
217
200
if ( parent is ScriptBlockAst && parent . Parent != null && parent . Parent is FunctionDefinitionAst )
218
201
{
219
202
parent = parent . Parent ;
0 commit comments