File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,8 +143,18 @@ public override void VisitArgument(ArgumentSyntax node)
143143 }
144144 public override void VisitInvocationExpression ( InvocationExpressionSyntax node )
145145 {
146+ //Return if the expression is nameof.
147+ //With an early return, we won't process built-in arguments(if used) in nameof.
148+ if ( node . Expression is IdentifierNameSyntax identifier )
149+ {
150+ if ( identifier . Identifier . Text == "nameof" )
151+ {
152+ return ;
153+ }
154+ }
155+
146156 base . VisitInvocationExpression ( node ) ;
147-
157+
148158 if ( node . Expression is IdentifierNameSyntax ||
149159 node . Expression is GenericNameSyntax )
150160 {
Original file line number Diff line number Diff line change @@ -381,6 +381,32 @@ public WithoutSemanticRewriter(CSTOJSOptions options)
381381
382382 return node ;
383383 }
384+ public override SyntaxNode ? VisitInvocationExpression ( InvocationExpressionSyntax node )
385+ {
386+ if ( node . Expression is IdentifierNameSyntax identifier )
387+ {
388+ if ( identifier . Identifier . Text == "nameof" )
389+ {
390+ ExpressionSyntax _arg = node . ArgumentList . Arguments [ 0 ] . Expression ;
391+ if ( _arg is IdentifierNameSyntax )
392+ {
393+ LiteralExpressionSyntax literal = SyntaxFactory . LiteralExpression ( SyntaxKind . StringLiteralExpression , SyntaxFactory . Literal ( _arg . ToString ( ) ) ) ;
394+ return literal ;
395+ }
396+ else if ( _arg is MemberAccessExpressionSyntax syntax )
397+ {
398+ LiteralExpressionSyntax literal = SyntaxFactory . LiteralExpression ( SyntaxKind . StringLiteralExpression , SyntaxFactory . Literal ( syntax . Name . ToString ( ) ) ) ;
399+ return literal ;
400+ }
401+ else
402+ {
403+ Log . WarningLine ( $ "The argument of a nameof: \" { _arg . Kind ( ) } \" is not supported.") ;
404+ }
405+ }
406+ }
407+
408+ return base . VisitInvocationExpression ( node ) ;
409+ }
384410 public override SyntaxNode ? VisitBaseExpression ( BaseExpressionSyntax node )
385411 {
386412 return SyntaxFactory . IdentifierName ( "super" ) . WithLeadingTrivia ( node . GetLeadingTrivia ( ) ) ;
You can’t perform that action at this time.
0 commit comments