Skip to content

Commit 55d6ba3

Browse files
committed
Further improvement to the debug output.
1 parent 28b9900 commit 55d6ba3

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

CSharpToJavaScript/Walker.cs

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
297297
if (_Options.Debug)
298298
{
299299
JSSB.Append("/*");
300-
JSSB.Append(node.WithMembers([]).ToFullString().Replace("*/", ""));
301-
JSSB.Append("*/");
300+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
301+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
302+
JSSB.AppendLine("*/");
302303
}
303304

304305
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -383,8 +384,9 @@ public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax no
383384
if (_Options.Debug)
384385
{
385386
JSSB.Append("/*");
386-
JSSB.Append(node.WithBody(null).ToFullString().Replace("*/", ""));
387-
JSSB.Append("*/");
387+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
388+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
389+
JSSB.AppendLine("*/");
388390
}
389391

390392
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -661,8 +663,9 @@ public override void VisitLocalDeclarationStatement(LocalDeclarationStatementSyn
661663
if (_Options.Debug)
662664
{
663665
JSSB.Append("/*");
664-
JSSB.Append(node.ToFullString().Replace("*/", ""));
665-
JSSB.Append("*/");
666+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
667+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
668+
JSSB.AppendLine("*/");
666669
}
667670

668671
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -714,8 +717,9 @@ public override void VisitExpressionStatement(ExpressionStatementSyntax node)
714717
if (_Options.Debug)
715718
{
716719
JSSB.Append("/*");
717-
JSSB.Append(node.ToFullString().Replace("*/", ""));
718-
JSSB.Append("*/");
720+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
721+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
722+
JSSB.AppendLine("*/");
719723
}
720724

721725
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -813,6 +817,9 @@ public override void VisitArgument(ArgumentSyntax node)
813817
case SyntaxKind.ModuloAssignmentExpression:
814818
Visit(asNode);
815819
break;
820+
case SyntaxKind.NullLiteralExpression:
821+
VisitLiteralExpression((LiteralExpressionSyntax)asNode);
822+
break;
816823
case SyntaxKind.DivideExpression:
817824
case SyntaxKind.AsExpression:
818825
case SyntaxKind.CoalesceExpression:
@@ -1142,8 +1149,9 @@ public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
11421149
if (_Options.Debug)
11431150
{
11441151
JSSB.Append("/*");
1145-
JSSB.Append(node.WithBody(null).ToFullString().Replace("*/", ""));
1146-
JSSB.Append("*/");
1152+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
1153+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
1154+
JSSB.AppendLine("*/");
11471155
}
11481156

11491157
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -1217,8 +1225,9 @@ public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
12171225
if (_Options.Debug)
12181226
{
12191227
JSSB.Append("/*");
1220-
JSSB.Append(node.ToFullString().Replace("*/", ""));
1221-
JSSB.Append("*/");
1228+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
1229+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
1230+
JSSB.AppendLine("*/");
12221231
}
12231232

12241233
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -1278,8 +1287,9 @@ public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
12781287
if (_Options.Debug)
12791288
{
12801289
JSSB.Append("/*");
1281-
JSSB.Append(node.ToFullString().Replace("*/", ""));
1282-
JSSB.Append("*/");
1290+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
1291+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
1292+
JSSB.AppendLine("*/");
12831293
}
12841294

12851295
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -1919,8 +1929,9 @@ public override void VisitForEachStatement(ForEachStatementSyntax node)
19191929
if (_Options.Debug)
19201930
{
19211931
JSSB.Append("/*");
1922-
JSSB.Append(node.WithStatement(SyntaxFactory.EmptyStatement()).ToFullString().Replace(";", "").Replace("*/", ""));
1923-
JSSB.Append("*/");
1932+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
1933+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
1934+
JSSB.AppendLine("*/");
19241935
}
19251936

19261937
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -3229,8 +3240,9 @@ public override void VisitBreakStatement(BreakStatementSyntax node)
32293240
if (_Options.Debug)
32303241
{
32313242
JSSB.Append("/*");
3232-
JSSB.Append(node.ToFullString().Replace("*/", ""));
3233-
JSSB.Append("*/");
3243+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
3244+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
3245+
JSSB.AppendLine("*/");
32343246
}
32353247

32363248
if (_Options.Debug)
@@ -3250,8 +3262,9 @@ public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node)
32503262
if (_Options.Debug)
32513263
{
32523264
JSSB.Append("/*");
3253-
JSSB.Append(node.ToFullString().Replace("*/", ""));
3254-
JSSB.Append("*/");
3265+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
3266+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
3267+
JSSB.AppendLine("*/");
32553268
}
32563269

32573270
if (_Options.Debug)
@@ -3479,8 +3492,9 @@ public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node)
34793492
if (_Options.Debug)
34803493
{
34813494
JSSB.Append("/*");
3482-
JSSB.Append(node.ToFullString().Replace(";", "").Replace("*/", ""));
3483-
JSSB.Append("*/");
3495+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
3496+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
3497+
JSSB.AppendLine("*/");
34843498
}
34853499

34863500
if (_Options.Debug)
@@ -3736,8 +3750,9 @@ public override void VisitForStatement(ForStatementSyntax node)
37363750
if (_Options.Debug)
37373751
{
37383752
JSSB.Append("/*");
3739-
JSSB.Append(node.WithStatement(SyntaxFactory.EmptyStatement()).ToFullString().Replace("*/", ""));
3740-
JSSB.Append("*/");
3753+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
3754+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
3755+
JSSB.AppendLine("*/");
37413756
}
37423757

37433758
if (_Options.Debug)
@@ -3862,8 +3877,9 @@ public override void VisitIfStatement(IfStatementSyntax node)
38623877
if (_Options.Debug)
38633878
{
38643879
JSSB.Append("/*");
3865-
JSSB.Append(node.WithStatement(SyntaxFactory.EmptyStatement()).WithElse(null).ToFullString().Replace(";","").Replace("*/", ""));
3866-
JSSB.Append("*/");
3880+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
3881+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
3882+
JSSB.AppendLine("*/");
38673883
}
38683884

38693885
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -4509,8 +4525,9 @@ public override void VisitReturnStatement(ReturnStatementSyntax node)
45094525
if (_Options.Debug)
45104526
{
45114527
JSSB.Append("/*");
4512-
JSSB.Append(node.ToFullString().Replace("*/", ""));
4513-
JSSB.Append("*/");
4528+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
4529+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
4530+
JSSB.AppendLine("*/");
45144531
}
45154532

45164533
if (_Options.Debug)
@@ -4635,8 +4652,9 @@ public override void VisitSwitchStatement(SwitchStatementSyntax node)
46354652
if (_Options.Debug)
46364653
{
46374654
JSSB.Append("/*");
4638-
JSSB.Append(node.WithSections([]).ToFullString().Replace("*/", ""));
4639-
JSSB.Append("*/");
4655+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
4656+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
4657+
JSSB.AppendLine("*/");
46404658
}
46414659

46424660
if (_Options.Debug)
@@ -4811,8 +4829,9 @@ public override void VisitWhileStatement(WhileStatementSyntax node)
48114829
if (_Options.Debug)
48124830
{
48134831
JSSB.Append("/*");
4814-
JSSB.Append(node.WithStatement(SyntaxFactory.EmptyStatement()).ToFullString().Replace(";", "").Replace("*/", ""));
4815-
JSSB.Append("*/");
4832+
string[] strings = node.ToFullString().Split(["\r\n", "\r", "\n"], StringSplitOptions.RemoveEmptyEntries);
4833+
JSSB.Append(string.IsNullOrWhiteSpace(strings[0]) ? strings[1] : strings[0]);
4834+
JSSB.AppendLine("*/");
48164835
}
48174836

48184837
if (_Options.Debug)

0 commit comments

Comments
 (0)