Skip to content

Commit fef8847

Browse files
committed
Further improvement to "this".
And some missing expressions.
1 parent 59411a2 commit fef8847

4 files changed

Lines changed: 68 additions & 5 deletions

File tree

CSharpToJavaScript/APIs/JS/Math.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using CSharpToJavaScript.Utils;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CSharpToJavaScript.APIs.JS
9+
{
10+
[To(ToAttribute.Default)]
11+
public partial class Math
12+
{
13+
[To(ToAttribute.FirstCharToLowerCase)]
14+
public static double Random()
15+
{
16+
throw new System.NotImplementedException();
17+
}
18+
[To(ToAttribute.FirstCharToLowerCase)]
19+
public static int Floor(double num)
20+
{
21+
throw new System.NotImplementedException();
22+
}
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CSharpToJavaScript.Utils;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CSharpToJavaScript.APIs.JS
9+
{
10+
public partial class Window
11+
{
12+
[To(ToAttribute.FirstCharToLowerCase)]
13+
public dynamic Eval(string jsStr)
14+
{
15+
throw new System.NotImplementedException();
16+
}
17+
}
18+
}

CSharpToJavaScript/CSTOJSOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public class CSTOJSOptions
5252
public List<Type> CustomCSTypesToJS { get; set; } = new();
5353

5454
/// <summary>
55-
/// Add a <c>StringBulder</c> to the front of a javascript file.
55+
/// Add a <c>StringBuilder</c> to the front of a javascript file.
5656
/// </summary>
5757
/// <value>
5858
/// Default: <c>new()</c>
5959
/// </value>
6060
public StringBuilder AddSBInFront { get; set; } = new();
6161
/// <summary>
62-
/// Add a <c>StringBulder</c> to the end of a javascript file.
62+
/// Add a <c>StringBuilder</c> to the end of a javascript file.
6363
/// </summary>
6464
/// <value>
6565
/// Default: <c>new()</c>

CSharpToJavaScript/Walker.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Collections.Immutable;
88
using System.Linq;
9+
using System.Linq.Expressions;
910
using System.Reflection;
1011
using System.Text;
1112

@@ -293,6 +294,7 @@ public override void VisitParameter(ParameterSyntax node)
293294
Visit(asNode);
294295
break;
295296
}
297+
case SyntaxKind.GenericName:
296298
case SyntaxKind.IdentifierName:
297299
case SyntaxKind.PredefinedType:
298300
break;
@@ -407,6 +409,7 @@ public override void VisitExpressionStatement(ExpressionStatementSyntax node)
407409

408410
switch (kind)
409411
{
412+
case SyntaxKind.PostDecrementExpression:
410413
case SyntaxKind.InvocationExpression:
411414
case SyntaxKind.SimpleAssignmentExpression:
412415
{
@@ -454,6 +457,10 @@ public override void VisitArgument(ArgumentSyntax node)
454457

455458
switch (kind)
456459
{
460+
case SyntaxKind.AsExpression:
461+
case SyntaxKind.MultiplyExpression:
462+
case SyntaxKind.InvocationExpression:
463+
case SyntaxKind.AddExpression:
457464
case SyntaxKind.ParenthesizedExpression:
458465
case SyntaxKind.ThisExpression:
459466
case SyntaxKind.ParenthesizedLambdaExpression:
@@ -1162,6 +1169,9 @@ public override void VisitParenthesizedExpression(ParenthesizedExpressionSyntax
11621169

11631170
switch (kind)
11641171
{
1172+
case SyntaxKind.AddExpression:
1173+
Visit(asNode);
1174+
break;
11651175
case SyntaxKind.AsExpression:
11661176
_SNOriginal = (asNode as BinaryExpressionSyntax).Left;
11671177

@@ -1351,6 +1361,12 @@ where e.Kind() == SyntaxKind.IdentifierToken
13511361
{
13521362
JSSB.Append($" {syntaxNode.ToString()}");
13531363
}
1364+
1365+
if (CustomCSNamesToJS(syntaxNode) == false)
1366+
{
1367+
SM.Log($"TODO : {syntaxNode} ||| USE 'CustomCSNamesToJS' TO CONVERT.");
1368+
}
1369+
13541370
}
13551371
break;
13561372
}
@@ -1538,10 +1554,15 @@ where e.Kind() == SyntaxKind.IdentifierToken
15381554

15391555
if (item is FieldDeclarationSyntax f)
15401556
{
1541-
var d3 = from e in f.DescendantTokens()
1557+
IEnumerable<SyntaxNode> vds = (from el in f.DescendantNodes()
1558+
where el.Kind() == SyntaxKind.VariableDeclarator
1559+
select el);
1560+
1561+
var d3 = from e in vds.First().DescendantNodesAndTokens()
15421562
where e.Kind() == SyntaxKind.IdentifierToken
15431563
select e;
1544-
_sT = d3.Last();
1564+
1565+
_sT = (SyntaxToken)d3.First();
15451566
}
15461567

15471568
if (_sT.ToString() == node.ToString())
@@ -1667,7 +1688,7 @@ where e.Kind() == SyntaxKind.IdentifierToken
16671688
SM.Log(item.ToString());
16681689
}
16691690

1670-
SM.Log("ERROR! By reaching this means, a name did not convert to JS. CHECK FOR UPPERCASE CHARACTERS IN NAMES IN THE JS FILE!");
1691+
SM.Log($"ERROR! !-{node}-! By reaching this means, a name did not convert to JS. CHECK FOR UPPERCASE CHARACTERS IN NAMES IN THE JS FILE!");
16711692

16721693
base.VisitIdentifierName(node);
16731694
}

0 commit comments

Comments
 (0)