@@ -700,7 +700,8 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
700
700
701
701
VariableAnalysis previousOuter = OuterAnalysis ;
702
702
703
- // We already run variable analysis in these cases so check
703
+ // We already run variable analysis if the parent is a function so skip these.
704
+ // Otherwise, we have to do variable analysis using the outer scope variables.
704
705
if ( ! ( scriptBlockAst . Parent is FunctionDefinitionAst ) && ! ( scriptBlockAst . Parent is FunctionMemberAst ) )
705
706
{
706
707
OuterAnalysis = Helper . Instance . InitializeVariableAnalysisHelper ( scriptBlockAst , OuterAnalysis ) ;
@@ -726,8 +727,15 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
726
727
scriptBlockAst . EndBlock . Visit ( this ) ;
727
728
}
728
729
730
+ VariableAnalysis innerAnalysis = OuterAnalysis ;
729
731
OuterAnalysis = previousOuter ;
730
732
733
+ if ( ! ( scriptBlockAst . Parent is FunctionDefinitionAst ) && ! ( scriptBlockAst . Parent is FunctionMemberAst ) )
734
+ {
735
+ // Update the variable analysis of the outer script block
736
+ VariableAnalysis . UpdateOuterAnalysis ( OuterAnalysis , innerAnalysis ) ;
737
+ }
738
+
731
739
return null ;
732
740
}
733
741
@@ -889,6 +897,13 @@ public object VisitCatchClause(CatchClauseAst catchClauseAst)
889
897
/// <returns></returns>
890
898
public object VisitCommand ( CommandAst commandAst )
891
899
{
900
+ if ( commandAst == null ) return null ;
901
+
902
+ foreach ( CommandElementAst ceAst in commandAst . CommandElements )
903
+ {
904
+ ceAst . Visit ( this ) ;
905
+ }
906
+
892
907
return null ;
893
908
}
894
909
@@ -1219,12 +1234,19 @@ public object VisitParenExpression(ParenExpressionAst parenExpressionAst)
1219
1234
}
1220
1235
1221
1236
/// <summary>
1222
- /// Do nothing
1237
+ /// Visit pipeline
1223
1238
/// </summary>
1224
1239
/// <param name="pipelineAst"></param>
1225
1240
/// <returns></returns>
1226
1241
public object VisitPipeline ( PipelineAst pipelineAst )
1227
1242
{
1243
+ if ( pipelineAst == null ) return null ;
1244
+
1245
+ foreach ( var command in pipelineAst . PipelineElements )
1246
+ {
1247
+ command . Visit ( this ) ;
1248
+ }
1249
+
1228
1250
return null ;
1229
1251
}
1230
1252
0 commit comments