Skip to content

Commit c4510ee

Browse files
committed
Changed the way built-in types/generics method work.
1 parent 7b319e8 commit c4510ee

File tree

1 file changed

+89
-41
lines changed

1 file changed

+89
-41
lines changed

CSharpToJavaScript/Walker.cs

Lines changed: 89 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ where e.IsKind(SyntaxKind.IdentifierToken)
15501550
{
15511551
if (CustomCSNamesToJS(syntaxNode) == false)
15521552
{
1553-
if (BuildInTypesGenerics(syntaxNode, iSymbol) == false)
1553+
if (BuiltInTypesGenerics(syntaxNode, iSymbol) == false)
15541554
{
15551555
JSSB.Append($" Object");
15561556
SM.Log($"TODO : {syntaxNode} ||| USE 'CustomCSNamesToJS' TO CONVERT.");
@@ -1569,7 +1569,7 @@ where e.IsKind(SyntaxKind.IdentifierToken)
15691569
if (CustomCSNamesToJS(syntaxNode) == false)
15701570
{
15711571
JSSB.Append($" ");
1572-
if (BuildInTypesGenerics(syntaxNode.WithoutLeadingTrivia(), iSymbol) == false)
1572+
if (BuiltInTypesGenerics(syntaxNode.WithoutLeadingTrivia(), iSymbol) == false)
15731573
{
15741574
SM.Log($"TODO : {syntaxNode} ||| USE 'CustomCSNamesToJS' TO CONVERT.");
15751575
}
@@ -1775,7 +1775,7 @@ public bool IdentifierToken(SyntaxNode node)
17751775
else
17761776
iSymbol = symbolInfo?.Symbol;
17771777

1778-
if (iSymbol != null && iSymbol.Kind != SymbolKind.ErrorType)
1778+
if (iSymbol != null && iSymbol.Kind != SymbolKind.ErrorType && iSymbol.Kind != SymbolKind.DynamicType)
17791779
{
17801780
if (iSymbol.ContainingNamespace.ToString().Contains(nameof(APIs.JS)))
17811781
{
@@ -1986,7 +1986,7 @@ where e.IsKind(SyntaxKind.IdentifierToken)
19861986

19871987
if (CustomCSNamesToJS(node) == false)
19881988
{
1989-
if (BuildInTypesGenerics(node, iSymbol) == false)
1989+
if (BuiltInTypesGenerics(node, iSymbol) == false)
19901990
{
19911991
if (_Options.Debug)
19921992
{
@@ -2036,7 +2036,7 @@ private bool CustomCSNamesToJS(SyntaxNode node)
20362036
return false;
20372037
}
20382038

2039-
private bool BuildInTypesGenerics(SyntaxNode nodeL, ISymbol symbol)
2039+
private bool BuiltInTypesGenerics(SyntaxNode nodeL, ISymbol symbol)
20402040
{
20412041
IdentifierNameSyntax node = nodeL as IdentifierNameSyntax;
20422042

@@ -2055,115 +2055,163 @@ private bool BuildInTypesGenerics(SyntaxNode nodeL, ISymbol symbol)
20552055
VisitLeadingTrivia(_genericName.Identifier);
20562056
}
20572057

2058-
SymbolKind symbolKind = symbol.Kind;
2058+
ISymbol typeSymbol = symbol;
2059+
2060+
if(typeSymbol.Kind != SymbolKind.NamedType)
2061+
{
2062+
typeSymbol = symbol.ContainingSymbol;
2063+
2064+
if(typeSymbol.Kind != SymbolKind.NamedType)
2065+
{
2066+
SM.Log($"WARNING! node: \"{node}\", typeSymbol is \"{typeSymbol.Kind}\". USE \"CustomCSNamesToJS\"!");
2067+
return false;
2068+
}
2069+
}
2070+
2071+
string typeName = typeSymbol.Name;
20592072
ToAttribute toAttribute = new(ToAttribute.Default);
20602073

2061-
switch (symbolKind)
2074+
switch (typeName)
20622075
{
2063-
case SymbolKind.NamedType:
2076+
case string str when str.Contains(nameof(System.Text.Json.JsonSerializer)):
20642077
{
20652078
string _name = symbol.Name;
20662079
switch (_name)
20672080
{
2068-
case string str when str.Contains(nameof(System.Text.Json.JsonSerializer)):
2081+
case string _str when _str == typeName:
20692082
{
20702083
JSSB.Append($"JSON");
20712084
return true;
20722085
}
2073-
case string str when str.Contains("List"):
2086+
case string _str when _str.Contains(nameof(System.Text.Json.JsonSerializer.Deserialize)):
20742087
{
2075-
JSSB.Append($"Array");
2088+
JSSB.Append($"parse");
20762089
return true;
20772090
}
2078-
case string str when str.Contains(nameof(Console)):
2091+
case string _str when _str.Contains(nameof(System.Text.Json.JsonSerializer.Serialize)):
20792092
{
2080-
toAttribute.To = ToAttribute.FirstCharToLowerCase;
2081-
JSSB.Append($"{toAttribute.Convert(node.Identifier.Text)}");
2093+
JSSB.Append($"stringify");
20822094
return true;
20832095
}
20842096
default:
2085-
SM.Log($"WARNING! node: \"{node}\", symbol: \"{symbol}\", as \"{symbolKind}\" Is not supported! USE \"CustomCSNamesToJS\"");
2097+
SM.Log($"WARNING! node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\"");
20862098
return false;
20872099
}
20882100
}
2089-
case SymbolKind.Method:
2101+
case string str when str.Contains(nameof(Console)):
20902102
{
20912103
string _name = symbol.Name;
20922104
switch (_name)
20932105
{
2094-
case string str when str.Contains(nameof(System.Threading.Tasks.Task.ContinueWith)):
2106+
case string _str when _str == typeName:
20952107
{
2096-
JSSB.Append($"then");
2108+
toAttribute.To = ToAttribute.FirstCharToLowerCase;
2109+
JSSB.Append($"{toAttribute.Convert(node.Identifier.Text)}");
20972110
return true;
20982111
}
2099-
case string str when str.Contains(nameof(System.Text.Json.JsonSerializer.Serialize)):
2112+
case string _str when _str.Contains(nameof(Console.WriteLine)):
21002113
{
2101-
JSSB.Append($"stringify");
2114+
JSSB.Append($"log");
21022115
return true;
21032116
}
2104-
case string str when str.Contains(nameof(List<dynamic>.Add)):
2117+
default:
2118+
SM.Log($"WARNING! node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\"");
2119+
return false;
2120+
}
2121+
}
2122+
case string str when str.Contains(nameof(List<dynamic>)):
2123+
{
2124+
string _name = symbol.Name;
2125+
switch (_name)
2126+
{
2127+
case string _str when _str == typeName:
21052128
{
2106-
JSSB.Append($"push");
2129+
JSSB.Append($"Array");
21072130
return true;
21082131
}
2109-
case string str when
2110-
str.Contains(nameof(string.Substring)) ||
2111-
str.Contains(nameof(string.StartsWith)) ||
2112-
str.Contains(nameof(string.Replace)):
2132+
case string _str when _str.Contains(nameof(List<dynamic>.Sort)):
21132133
{
21142134
toAttribute.To = ToAttribute.FirstCharToLowerCase;
21152135
JSSB.Append($"{toAttribute.Convert(node.Identifier.Text)}");
21162136
return true;
21172137
}
2118-
case string str when str.Contains(nameof(string.Contains)):
2138+
case string _str when _str.Contains(nameof(List<dynamic>.Count)):
21192139
{
2120-
JSSB.Append($"includes");
2140+
JSSB.Append($"length");
21212141
return true;
21222142
}
2123-
case string str when str.Contains(nameof(Console.WriteLine)):
2143+
case string _str when _str.Contains(nameof(List<dynamic>.Add)):
21242144
{
2125-
JSSB.Append($"log");
2145+
JSSB.Append($"push");
2146+
return true;
2147+
}
2148+
case string _str when _str.Contains(nameof(List<dynamic>.Contains)):
2149+
{
2150+
JSSB.Append($"includes");
21262151
return true;
21272152
}
21282153
default:
2129-
SM.Log($"WARNING! node: \"{node}\", symbol: \"{symbol}\", as \"{symbolKind}\" Is not supported! USE \"CustomCSNamesToJS\"");
2154+
SM.Log($"WARNING! node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\"");
21302155
return false;
21312156
}
21322157
}
2133-
case SymbolKind.Property:
2158+
case string str when str.Contains(nameof(String)):
21342159
{
21352160
string _name = symbol.Name;
21362161
switch (_name)
21372162
{
2138-
case string str when str.Contains(nameof(List<string>.Count)):
2163+
case string _str when _str.Contains(nameof(string.Contains)):
21392164
{
2140-
JSSB.Append($"length");
2165+
JSSB.Append($"includes");
21412166
return true;
21422167
}
2143-
case string str when str.Contains(nameof(Array.Length)):
2168+
case string _str when
2169+
_str.Contains(nameof(string.Substring)) ||
2170+
_str.Contains(nameof(string.StartsWith)) ||
2171+
_str.Contains(nameof(string.Replace)):
21442172
{
21452173
toAttribute.To = ToAttribute.FirstCharToLowerCase;
21462174
JSSB.Append($"{toAttribute.Convert(node.Identifier.Text)}");
21472175
return true;
21482176
}
21492177
default:
2150-
SM.Log($"WARNING! node: \"{node}\", symbol: \"{symbol}\", as \"{symbolKind}\" Is not supported! USE \"CustomCSNamesToJS\"");
2178+
SM.Log($"WARNING! node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\"");
21512179
return false;
21522180
}
21532181
}
2154-
/*
2155-
case SymbolKind.Field:
2182+
case string str when str.Contains(nameof(System.Threading.Tasks.Task<dynamic>)):
21562183
{
21572184
string _name = symbol.Name;
21582185
switch (_name)
21592186
{
2187+
case string _str when _str.Contains(nameof(System.Threading.Tasks.Task.ContinueWith)):
2188+
{
2189+
JSSB.Append($"then");
2190+
return true;
2191+
}
21602192
default:
2161-
SM.Log($"WARNING! node: \"{node}\", symbol: \"{symbol}\", as \"{symbolKind}\" Is not supported! USE \"CustomCSNamesToJS\"");
2193+
SM.Log($"WARNING! node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\"");
21622194
return false;
21632195
}
2164-
}*/
2196+
}
2197+
case string str when str.Contains(nameof(Array)):
2198+
{
2199+
string _name = symbol.Name;
2200+
switch (_name)
2201+
{
2202+
case string _str when _str.Contains(nameof(Array.Length)):
2203+
{
2204+
toAttribute.To = ToAttribute.FirstCharToLowerCase;
2205+
JSSB.Append($"{toAttribute.Convert(node.Identifier.Text)}");
2206+
return true;
2207+
}
2208+
default:
2209+
SM.Log($"WARNING! node: \"{node}\", typeSymbol: \"{typeSymbol}\", symbol: \"{symbol}\", Is not supported! USE \"CustomCSNamesToJS\"");
2210+
return false;
2211+
}
2212+
}
21652213
default:
2166-
SM.Log($"WARNING! symbol kind: \"{symbolKind}\" Is not supported! USE \"CustomCSNamesToJS\"");
2214+
SM.Log($"WARNING! typeSymbol: \"{typeSymbol}\" Is not supported! USE \"CustomCSNamesToJS\"");
21672215
return false;
21682216
}
21692217
}

0 commit comments

Comments
 (0)