Skip to content

Commit b95482a

Browse files
committed
Fixed No Namespace issue found in Accessors, Methods, Properties and constructors.
1 parent 894823a commit b95482a

File tree

19 files changed

+198
-34
lines changed

19 files changed

+198
-34
lines changed

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ string source
6060
).GetAwaiter().GetResult();
6161

6262
// Use for testing the generated AST
63-
File.WriteAllText(
64-
Path.Combine(
65-
".",
66-
"AstParser",
67-
"NodeImpl",
68-
"NodeJS",
69-
"_generated",
70-
"ast.json"
71-
),
72-
result
73-
);
63+
//File.WriteAllText(
64+
// Path.Combine(
65+
// ".",
66+
// "AstParser",
67+
// "NodeImpl",
68+
// "NodeJS",
69+
// "_generated",
70+
// "ast.json"
71+
// ),
72+
// result
73+
//);
7474
var ast = JsonSerializer.Deserialize<ASTModel>(
7575
result,
7676
new JsonSerializerOptions

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ClassGenerationTemplates templates
4646
var entityNamespace = string.Join(
4747
", ",
4848
namespaceParts.Select(part => @$"""{part}""")
49-
);
49+
) + ", ";
5050
var property = accessor.Name;
5151
var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate;
5252
var cacheSection = string.Empty;
@@ -57,6 +57,11 @@ ClassGenerationTemplates templates
5757
template = templates.AccessorWithSetter;
5858
}
5959

60+
if (entityNamespace == @""""", ")
61+
{
62+
entityNamespace = string.Empty;
63+
}
64+
6065
if (accessor.IsStatic)
6166
{
6267
root = $"\"{namespaceParts.FirstOrDefault()}\"";
@@ -73,6 +78,11 @@ ClassGenerationTemplates templates
7378
else
7479
{
7580
property = $"{classStatement.Name}.{accessor.Name}";
81+
if (entityNamespace == string.Empty)
82+
{
83+
root = $"\"{classStatement.Name}\"";
84+
property = accessor.Name;
85+
}
7686
}
7787
}
7888

@@ -96,11 +106,6 @@ ClassGenerationTemplates templates
96106
propertyGetterResultType = templates.InteropGetArray;
97107
}
98108

99-
if (entityNamespace == @"""")
100-
{
101-
entityNamespace = string.Empty;
102-
}
103-
104109
template = template
105110
.Replace(
106111
"[[PROPERTY_GETTER]]",

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ ClassGenerationTemplates templates
5454
classStatement.Namespace
5555
.Split(".")
5656
.Select(part => @$"""{part}""")
57-
);
57+
) + ", ";
5858

59-
if (entityNamespace == @"""""")
59+
if (entityNamespace == @""""", ")
6060
{
6161
entityNamespace = string.Empty;
6262
}

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/MethodsSectionWriter.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ ClassGenerationTemplates templates
6060
var returnTypeContent = templates.InteropFunc;
6161
var arguments = string.Empty;
6262
var argumentStrings = new List<string>();
63+
var classNamespace = classStatement.Namespace;
6364
var namespacedMethod = string.Join(
6465
".",
65-
classStatement.Namespace,
66+
classNamespace,
6667
classStatement.Name,
6768
method.Name
6869
);
@@ -78,6 +79,15 @@ ClassGenerationTemplates templates
7879
var taskAsync = string.Empty;
7980
var taskAwait = string.Empty;
8081

82+
if (classNamespace == string.Empty)
83+
{
84+
namespacedMethod = string.Join(
85+
".",
86+
classStatement.Name,
87+
method.Name
88+
);
89+
}
90+
8191
// Argument Generation
8292
if (isAction)
8393
{
@@ -223,12 +233,22 @@ ClassGenerationTemplates templates
223233

224234
if (method.IsStatic)
225235
{
236+
var classStatementIdentitiferList = new string[] {
237+
classStatement.Name,
238+
};
239+
if (classNamespace != string.Empty)
240+
{
241+
classStatementIdentitiferList = new string[]
242+
{
243+
classStatement.Namespace,
244+
classStatement.Name,
245+
};
246+
}
226247
propertyIdentifier = string.Join(
227248
", ",
228249
string.Join(
229250
".",
230-
classStatement.Namespace,
231-
classStatement.Name
251+
classStatementIdentitiferList
232252
).Split(".").Select(part => @$"""{part}""")
233253
);
234254
}

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ClassGenerationTemplates templates
5252
var entityNamespace = string.Join(
5353
", ",
5454
namespaceParts.Select(part => @$"""{part}""")
55-
);
55+
) + ", ";
5656
var propertyIdentifier = property.Name;
5757
var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate;
5858
var cacheSection = string.Empty;
@@ -63,6 +63,11 @@ ClassGenerationTemplates templates
6363
template = templates.Accessor;
6464
}
6565

66+
if (entityNamespace == @""""", ")
67+
{
68+
entityNamespace = string.Empty;
69+
}
70+
6671
if (property.IsStatic)
6772
{
6873

@@ -80,6 +85,11 @@ ClassGenerationTemplates templates
8085
else
8186
{
8287
propertyIdentifier = $"{classStatement.Name}.{property.Name}";
88+
if (entityNamespace == string.Empty)
89+
{
90+
root = $"\"{classStatement.Name}\"";
91+
propertyIdentifier = property.Name;
92+
}
8393
}
8494
}
8595

@@ -116,11 +126,6 @@ ClassGenerationTemplates templates
116126
template = "// [[NAME]] is not supported by the platform yet";
117127
}
118128

119-
if (entityNamespace == @"""")
120-
{
121-
entityNamespace = string.Empty;
122-
}
123-
124129
template = template
125130
.Replace(
126131
"[[PROPERTY_GETTER]]",

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class CSharpTextClass : CachedEntityObject
108108

109109
public CSharpTextClass(object target = null)
110110
{
111-
var entity = EventHorizonBlazorInterop.New(new string[]{"", "CSharpTextClass"}, target);
111+
var entity = EventHorizonBlazorInterop.New(new string[]{"CSharpTextClass"}, target);
112112
___guid = entity.___guid;
113113
}
114114

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt renamed to Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.Expected.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class ExampleClass : CachedEntityObject
5151
{
5252
___guid = entity.___guid;
5353
}
54+
55+
5456
#endregion
5557

5658
#region Methods

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts renamed to Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.ts

File renamed without changes.

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/AccessorsGenerationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ASTParserType parserType
5555
[InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.Sdcb)]
5656
[InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.Sdcb)]
5757
[InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.Sdcb)]
58+
[InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)]
5859
[InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.Sdcb)]
5960
public void ShouldGenerateAccessorScenarioStringsWithSdcb(
6061
string sourceFile,
@@ -117,6 +118,7 @@ ASTParserType parserType
117118
[InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.NodeJS)]
118119
[InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.NodeJS)]
119120
[InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.NodeJS)]
121+
[InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)]
120122
[InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.NodeJS)]
121123
public void ShouldGenerateAccessorScenarioStringsWithNodeJS(
122124
string sourceFile,

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt renamed to Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.Expected.txt

File renamed without changes.

0 commit comments

Comments
 (0)