@@ -42,19 +42,23 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
42
42
CommandElementAst commandElementAst = commandAst . CommandElements [ 0 ] ;
43
43
if ( commandAst . InvocationOperator . Equals ( TokenKind . Dot ) )
44
44
{
45
- if ( commandElementAst is StringConstantExpressionAst stringConstantExpressionAst )
45
+ string path ;
46
+ switch ( commandElementAst )
46
47
{
47
- // Strip any quote characters off of the string
48
- DotSourcedFiles . Add ( PathUtils . NormalizePathSeparators ( stringConstantExpressionAst . Value ) ) ;
49
- }
50
- else if ( commandElementAst is ExpandableStringExpressionAst expandableStringExpressionAst )
51
- {
52
- var path = GetPathFromExpandableStringExpression ( expandableStringExpressionAst ) ;
53
- if ( path != null )
54
- {
55
- DotSourcedFiles . Add ( PathUtils . NormalizePathSeparators ( path ) ) ;
56
- }
48
+ case StringConstantExpressionAst stringConstantExpressionAst :
49
+ path = stringConstantExpressionAst . Value ;
50
+ break ;
51
+
52
+ case ExpandableStringExpressionAst expandableStringExpressionAst :
53
+ path = GetPathFromExpandableStringExpression ( expandableStringExpressionAst ) ;
54
+ break ;
55
+
56
+ default :
57
+ path = null ;
58
+ break ;
57
59
}
60
+
61
+ DotSourcedFiles . Add ( PathUtils . NormalizePathSeparators ( path ) ) ;
58
62
}
59
63
60
64
return base . VisitCommand ( commandAst ) ;
@@ -65,6 +69,7 @@ private string GetPathFromExpandableStringExpression(ExpandableStringExpressionA
65
69
var path = expandableStringExpressionAst . Value ;
66
70
foreach ( var nestedExpression in expandableStringExpressionAst . NestedExpressions )
67
71
{
72
+ // If the string contains the variable $PSScriptRoot, we replace it with the corresponding value.
68
73
if ( nestedExpression is VariableExpressionAst variableExpressionAst
69
74
&& variableExpressionAst . VariablePath . UserPath . Equals ( "PSScriptRoot" , StringComparison . CurrentCultureIgnoreCase ) )
70
75
{
0 commit comments