From 38c04c90f1206bbb94c9230384cbf5e46322f4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 Aug 2022 15:26:26 +0200 Subject: [PATCH 01/11] JSExport on struct and records. --- .../JSImportGenerator/JSImportStubContext.cs | 14 +++++++-- .../JavaScript/JSImportExportTest.cs | 7 +++++ .../JavaScript/JavaScriptTestHelper.cs | 30 +++++++++++++++++++ .../JavaScript/JavaScriptTestHelper.mjs | 18 +++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs index 055e81315e68e4..cd96c05b3cf8ce 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics; using System.Linq; using System.Threading; @@ -16,6 +17,14 @@ namespace Microsoft.Interop.JavaScript { internal sealed class JSSignatureContext : IEquatable { + private static SymbolDisplayPartKind[] nameKinds = new[] + { + SymbolDisplayPartKind.ClassName, + SymbolDisplayPartKind.StructName, + SymbolDisplayPartKind.RecordClassName, + SymbolDisplayPartKind.RecordStructName + }; + internal static readonly string GeneratorName = typeof(JSImportGenerator).Assembly.GetName().Name; internal static readonly string GeneratorVersion = typeof(JSImportGenerator).Assembly.GetName().Version.ToString(); @@ -118,12 +127,11 @@ public static JSSignatureContext Create( }; int typesHash = Math.Abs((int)hash); - - var fullName = $"{method.ContainingType.ToDisplayString()}.{method.Name}"; string qualifiedName; + var ns = string.Join(".", method.ContainingType.ToDisplayParts().Where(p => p.Kind == SymbolDisplayPartKind.NamespaceName).Select(x => x.ToString()).ToArray()); - var cn = string.Join("/", method.ContainingType.ToDisplayParts().Where(p => p.Kind == SymbolDisplayPartKind.ClassName).Select(x => x.ToString()).ToArray()); + var cn = string.Join("/", method.ContainingType.ToDisplayParts().Where(p => Array.IndexOf(nameKinds, p.Kind) >= 0).Select(x => x.ToString()).ToArray()); var qclasses = method.ContainingType.ContainingNamespace == null ? ns : ns + "." + cn; qualifiedName = $"[{env.Compilation.AssemblyName}]{qclasses}:{method.Name}"; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index 71a795545f3317..9b34caaa7c172d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -1202,6 +1202,13 @@ public void JsExportStringNoNs() Assert.Equal("test!", actual); } + [Fact] + public void JsExportStructClassRecords() + { + var actual = JavaScriptTestHelper.invokeStructClassRecords("test", nameof(JavaScriptTestHelperNoNamespace.EchoString)); + Assert.Equal("test!", actual); + } + [Fact] public void JsImportNative() { diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index aaa5d16c2b8cdb..bd6a226fefc472 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -250,6 +250,9 @@ public static int EchoInt32([JSMarshalAs] int arg1) [JSImport("invoke2", "JavaScriptTestHelper")] [return: JSMarshalAs] internal static partial string invoke2_String([JSMarshalAs] string value, [JSMarshalAs] string name); + [JSImport("invokeStructClassRecords", "JavaScriptTestHelper")] + [return: JSMarshalAs] + internal static partial string invokeStructClassRecords([JSMarshalAs] string value, [JSMarshalAs] string name); [JSExport] [return: JSMarshalAs] public static string EchoString([JSMarshalAs] string arg1) @@ -943,3 +946,30 @@ public static string EchoString(string message) return message + "!"; } } + +public partial class JavaScriptTestHelperStruct +{ + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } +} + +public partial record class JavaScriptTestHelperRecordClass +{ + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } +} + +public partial record struct JavaScriptTestHelperRecordStruct +{ + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } +} \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs index c3cc24ed73979d..9ceb86026fcde2 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs @@ -171,6 +171,24 @@ export function invoke2(arg1, name) { return res; } +export function invokeStructClassRecords(arg1, name) { + let result = null; + + ["JavaScriptTestHelperNoNamespace", "JavaScriptTestHelperStruct", "JavaScriptTestHelperRecordClass", "JavaScriptTestHelperRecordStruct"].forEach(obj => { + const fn = dllExports[obj][name]; + const currentResult = fn(arg1); + if (result) { + if (result !== currentResult) { + throw new Error(`Un expected change in result from '${result}' to '${currentResult}'`); + } + } else { + result = currentResult; + } + }) + + return result; +} + export async function awaitvoid(arg1) { // console.log("awaitvoid:" + typeof arg1); await arg1; From 4e7462c5ea18a5e11c270b5a543b81e20f0f4297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 Aug 2022 18:54:21 +0200 Subject: [PATCH 02/11] Feedback. --- .../JavaScript/JSImportExportTest.cs | 6 +- .../JavaScript/JavaScriptTestHelper.cs | 148 +++++++++++++++++- .../JavaScript/JavaScriptTestHelper.mjs | 39 +++-- 3 files changed, 173 insertions(+), 20 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index 9b34caaa7c172d..2878bc733d5d4d 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -1205,8 +1205,10 @@ public void JsExportStringNoNs() [Fact] public void JsExportStructClassRecords() { - var actual = JavaScriptTestHelper.invokeStructClassRecords("test", nameof(JavaScriptTestHelperNoNamespace.EchoString)); - Assert.Equal("test!", actual); + var actual = JavaScriptTestHelper.invokeStructClassRecords("test"); + Assert.Equal(20, actual.Length); + for (int i = 0; i < actual.Length; i++) + Assert.Equal("test!", actual[i]); } [Fact] diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index bd6a226fefc472..3f64a18e89d961 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -251,8 +251,8 @@ public static int EchoInt32([JSMarshalAs] int arg1) [return: JSMarshalAs] internal static partial string invoke2_String([JSMarshalAs] string value, [JSMarshalAs] string name); [JSImport("invokeStructClassRecords", "JavaScriptTestHelper")] - [return: JSMarshalAs] - internal static partial string invokeStructClassRecords([JSMarshalAs] string value, [JSMarshalAs] string name); + [return: JSMarshalAs>] + internal static partial string[] invokeStructClassRecords([JSMarshalAs] string value); [JSExport] [return: JSMarshalAs] public static string EchoString([JSMarshalAs] string arg1) @@ -945,6 +945,42 @@ public static string EchoString(string message) { return message + "!"; } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } } public partial class JavaScriptTestHelperStruct @@ -954,6 +990,42 @@ public static string EchoString(string message) { return message + "!"; } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } } public partial record class JavaScriptTestHelperRecordClass @@ -963,6 +1035,42 @@ public static string EchoString(string message) { return message + "!"; } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } } public partial record struct JavaScriptTestHelperRecordStruct @@ -972,4 +1080,40 @@ public static string EchoString(string message) { return message + "!"; } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "!"; + } + } } \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs index 9ceb86026fcde2..c6bcc59aa7d29a 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs @@ -171,22 +171,29 @@ export function invoke2(arg1, name) { return res; } -export function invokeStructClassRecords(arg1, name) { - let result = null; - - ["JavaScriptTestHelperNoNamespace", "JavaScriptTestHelperStruct", "JavaScriptTestHelperRecordClass", "JavaScriptTestHelperRecordStruct"].forEach(obj => { - const fn = dllExports[obj][name]; - const currentResult = fn(arg1); - if (result) { - if (result !== currentResult) { - throw new Error(`Un expected change in result from '${result}' to '${currentResult}'`); - } - } else { - result = currentResult; - } - }) - - return result; +export function invokeStructClassRecords(arg1) { + return [ + dllExports.JavaScriptTestHelperNoNamespace.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperStruct.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperStruct.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperStruct.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperStruct.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClass.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClass.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClass.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClass.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStruct.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStruct.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStruct.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStruct.NestedRecordStruct.EchoString(arg1), + ]; } export async function awaitvoid(arg1) { From 9a6729ce8f182a46c5cfb99fe54d18ce5b9aa083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 Aug 2022 19:38:14 +0200 Subject: [PATCH 03/11] Namespace variants. --- .../JavaScript/JSImportExportTest.cs | 46 +++- .../JavaScript/JavaScriptTestHelper.cs | 229 ++++++++++++++++-- .../JavaScript/JavaScriptTestHelper.mjs | 50 ++-- 3 files changed, 283 insertions(+), 42 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index 2878bc733d5d4d..b9dfd39b5e5ee9 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -1199,16 +1199,54 @@ public void JsExportString(string value) public void JsExportStringNoNs() { var actual = JavaScriptTestHelper.invoke2_String("test", nameof(JavaScriptTestHelperNoNamespace.EchoString)); - Assert.Equal("test!", actual); + Assert.Equal("test51", actual); } [Fact] public void JsExportStructClassRecords() { var actual = JavaScriptTestHelper.invokeStructClassRecords("test"); - Assert.Equal(20, actual.Length); - for (int i = 0; i < actual.Length; i++) - Assert.Equal("test!", actual[i]); + Assert.Equal(40, actual.Length); + Assert.Equal("test11", actual[0]); + Assert.Equal("test12", actual[1]); + Assert.Equal("test13", actual[2]); + Assert.Equal("test14", actual[3]); + Assert.Equal("test15", actual[4]); + Assert.Equal("test21", actual[5]); + Assert.Equal("test22", actual[6]); + Assert.Equal("test23", actual[7]); + Assert.Equal("test24", actual[8]); + Assert.Equal("test25", actual[9]); + Assert.Equal("test31", actual[10]); + Assert.Equal("test32", actual[11]); + Assert.Equal("test33", actual[12]); + Assert.Equal("test34", actual[13]); + Assert.Equal("test35", actual[14]); + Assert.Equal("test41", actual[15]); + Assert.Equal("test42", actual[16]); + Assert.Equal("test43", actual[17]); + Assert.Equal("test44", actual[18]); + Assert.Equal("test45", actual[19]); + Assert.Equal("test51", actual[20]); + Assert.Equal("test52", actual[21]); + Assert.Equal("test53", actual[22]); + Assert.Equal("test54", actual[23]); + Assert.Equal("test55", actual[24]); + Assert.Equal("test61", actual[25]); + Assert.Equal("test62", actual[26]); + Assert.Equal("test63", actual[27]); + Assert.Equal("test64", actual[28]); + Assert.Equal("test65", actual[29]); + Assert.Equal("test71", actual[30]); + Assert.Equal("test72", actual[31]); + Assert.Equal("test73", actual[32]); + Assert.Equal("test74", actual[33]); + Assert.Equal("test75", actual[34]); + Assert.Equal("test81", actual[35]); + Assert.Equal("test82", actual[36]); + Assert.Equal("test83", actual[37]); + Assert.Equal("test84", actual[38]); + Assert.Equal("test85", actual[39]); } [Fact] diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index 3f64a18e89d961..503f081311f095 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -938,12 +938,195 @@ public static async Task InitializeAsync() } } +namespace JavaScriptTestHelperNamespace +{ + public partial class JavaScriptTestHelper + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "11"; + } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "12"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "13"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "14"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "15"; + } + } + } + + public partial class JavaScriptTestHelperStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "21"; + } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "22"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "23"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "24"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "25"; + } + } + } + + public partial record class JavaScriptTestHelperRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "31"; + } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "32"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "33"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "34"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "35"; + } + } + } + + public partial record struct JavaScriptTestHelperRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "41"; + } + + public partial class NestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "42"; + } + } + + public partial record class NestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "43"; + } + } + + public partial struct NestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "44"; + } + } + + public partial record struct NestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) + { + return message + "45"; + } + } + } +} + public partial class JavaScriptTestHelperNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "51"; } public partial class NestedClass @@ -951,7 +1134,7 @@ public partial class NestedClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "52"; } } @@ -960,7 +1143,7 @@ public partial record class NestedRecordClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "53"; } } @@ -969,7 +1152,7 @@ public partial struct NestedStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "54"; } } @@ -978,17 +1161,17 @@ public partial record struct NestedRecordStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "55"; } } } -public partial class JavaScriptTestHelperStruct +public partial class JavaScriptTestHelperStructNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "61"; } public partial class NestedClass @@ -996,7 +1179,7 @@ public partial class NestedClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "62"; } } @@ -1005,7 +1188,7 @@ public partial record class NestedRecordClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "63"; } } @@ -1014,7 +1197,7 @@ public partial struct NestedStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "64"; } } @@ -1023,17 +1206,17 @@ public partial record struct NestedRecordStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "65"; } } } -public partial record class JavaScriptTestHelperRecordClass +public partial record class JavaScriptTestHelperRecordClassNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "71"; } public partial class NestedClass @@ -1041,7 +1224,7 @@ public partial class NestedClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "72"; } } @@ -1050,7 +1233,7 @@ public partial record class NestedRecordClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "73"; } } @@ -1059,7 +1242,7 @@ public partial struct NestedStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "74"; } } @@ -1068,17 +1251,17 @@ public partial record struct NestedRecordStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "75"; } } } -public partial record struct JavaScriptTestHelperRecordStruct +public partial record struct JavaScriptTestHelperRecordStructNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "81"; } public partial class NestedClass @@ -1086,7 +1269,7 @@ public partial class NestedClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "82"; } } @@ -1095,7 +1278,7 @@ public partial record class NestedRecordClass [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "83"; } } @@ -1104,7 +1287,7 @@ public partial struct NestedStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "84"; } } @@ -1113,7 +1296,7 @@ public partial record struct NestedRecordStruct [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) { - return message + "!"; + return message + "85"; } } } \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs index c6bcc59aa7d29a..be86c6dfef4aa5 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs @@ -173,26 +173,46 @@ export function invoke2(arg1, name) { export function invokeStructClassRecords(arg1) { return [ + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordClass.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordClass.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordClass.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordClass.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordStruct.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordStruct.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordStruct.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordStruct.NestedRecordStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedClass.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedRecordClass.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedRecordStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperStruct.NestedClass.EchoString(arg1), - dllExports.JavaScriptTestHelperStruct.NestedRecordClass.EchoString(arg1), - dllExports.JavaScriptTestHelperStruct.NestedStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperStruct.NestedRecordStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordClass.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordClass.NestedClass.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordClass.NestedRecordClass.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordClass.NestedStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordClass.NestedRecordStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordStruct.NestedClass.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordStruct.NestedRecordClass.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordStruct.NestedStruct.EchoString(arg1), - dllExports.JavaScriptTestHelperRecordStruct.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperStructNoNamespace.EchoString(arg1), + dllExports.JavaScriptTestHelperStructNoNamespace.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperStructNoNamespace.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperStructNoNamespace.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperStructNoNamespace.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClassNoNamespace.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClassNoNamespace.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClassNoNamespace.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClassNoNamespace.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordClassNoNamespace.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStructNoNamespace.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStructNoNamespace.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStructNoNamespace.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStructNoNamespace.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperRecordStructNoNamespace.NestedRecordStruct.EchoString(arg1), ]; } From 6df9f9a09a6cba592c063a0d214c15a5fd92d259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 Aug 2022 19:58:12 +0200 Subject: [PATCH 04/11] Rewrite reading class name and namespace name. --- .../JSImportGenerator/JSImportStubContext.cs | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs index cd96c05b3cf8ce..069d3f400beffa 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs @@ -6,6 +6,7 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Linq; +using System.Text; using System.Threading; using Microsoft.CodeAnalysis; @@ -128,12 +129,7 @@ public static JSSignatureContext Create( int typesHash = Math.Abs((int)hash); var fullName = $"{method.ContainingType.ToDisplayString()}.{method.Name}"; - string qualifiedName; - - var ns = string.Join(".", method.ContainingType.ToDisplayParts().Where(p => p.Kind == SymbolDisplayPartKind.NamespaceName).Select(x => x.ToString()).ToArray()); - var cn = string.Join("/", method.ContainingType.ToDisplayParts().Where(p => Array.IndexOf(nameKinds, p.Kind) >= 0).Select(x => x.ToString()).ToArray()); - var qclasses = method.ContainingType.ContainingNamespace == null ? ns : ns + "." + cn; - qualifiedName = $"[{env.Compilation.AssemblyName}]{qclasses}:{method.Name}"; + string qualifiedName = GetQualifiedName(env, method); return new JSSignatureContext() { @@ -151,6 +147,54 @@ public static JSSignatureContext Create( }; } + private static string GetQualifiedName(StubEnvironment env, IMethodSymbol method) + { + bool isFirstTypeName = true; + string? namespaceName = null; + string? className; + StringBuilder nameBuilder = new StringBuilder(); + ImmutableArray nameParts = method.ContainingType.ToDisplayParts(); + foreach (SymbolDisplayPart namePart in nameParts) + { + if (namePart.Kind == SymbolDisplayPartKind.NamespaceName) + { + if (!isFirstTypeName) + throw new InvalidOperationException($"Found namespace name '{namePart}' after some type names '{nameBuilder}'"); + + if (nameBuilder.Length != 0) + nameBuilder.Append('.'); + + nameBuilder.Append(namePart); + } + else if (Array.IndexOf(nameKinds, namePart.Kind) >= 0) + { + if (isFirstTypeName) + { + namespaceName = nameBuilder.ToString(); + nameBuilder.Clear(); + isFirstTypeName = false; + } + + if (nameBuilder.Length != 0) + nameBuilder.Append('/'); + + nameBuilder.Append(namePart); + } + else + { + throw new InvalidOperationException($"Name kind '{namePart.Kind}' should be reached"); + } + } + + if (isFirstTypeName) + throw new InvalidOperationException($"Type name not found in '{nameParts}'"); + else + className = nameBuilder.ToString(); + + string qualifiedClassName = namespaceName == null ? className : namespaceName + "." + className; + return $"[{env.Compilation.AssemblyName}]{qualifiedClassName}:{method.Name}"; + } + private static (ImmutableArray, IMarshallingGeneratorFactory) GenerateTypeInformation(IMethodSymbol method, GeneratorDiagnostics diagnostics, StubEnvironment env) { var jsMarshallingAttributeParser = new JSMarshallingAttributeInfoParser(env.Compilation, diagnostics, method); From 6807257460b2319b55f1ff3c9ee6514c5b3f7e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 Aug 2022 13:15:28 +0200 Subject: [PATCH 05/11] Use expression bodies in test. --- .../JavaScript/JavaScriptTestHelper.cs | 200 ++++-------------- 1 file changed, 40 insertions(+), 160 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index 503f081311f095..7946cfc3e6374e 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -943,180 +943,120 @@ namespace JavaScriptTestHelperNamespace public partial class JavaScriptTestHelper { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "11"; - } + public static string EchoString(string message) => message + "11"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "12"; - } + public static string EchoString(string message) => message + "12"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "13"; - } + public static string EchoString(string message) => message + "13"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "14"; - } + public static string EchoString(string message) => message + "14"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "15"; - } + public static string EchoString(string message) => message + "15"; } } public partial class JavaScriptTestHelperStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "21"; - } + public static string EchoString(string message) => message + "21"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "22"; - } + public static string EchoString(string message) => message + "22"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "23"; - } + public static string EchoString(string message) => message + "23"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "24"; - } + public static string EchoString(string message) => message + "24"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "25"; - } + public static string EchoString(string message) => message + "25"; } } public partial record class JavaScriptTestHelperRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "31"; - } + public static string EchoString(string message) => message + "31"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "32"; - } + public static string EchoString(string message) => message + "32"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "33"; - } + public static string EchoString(string message) => message + "33"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "34"; - } + public static string EchoString(string message) => message + "34"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "35"; - } + public static string EchoString(string message) => message + "35"; } } public partial record struct JavaScriptTestHelperRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "41"; - } + public static string EchoString(string message) => message + "41"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "42"; - } + public static string EchoString(string message) => message + "42"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "43"; - } + public static string EchoString(string message) => message + "43"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "44"; - } + public static string EchoString(string message) => message + "44"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "45"; - } + public static string EchoString(string message) => message + "45"; } } } @@ -1124,179 +1064,119 @@ public static string EchoString(string message) public partial class JavaScriptTestHelperNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "51"; - } + public static string EchoString(string message) => message + "51"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "52"; - } + public static string EchoString(string message) => message + "52"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "53"; - } + public static string EchoString(string message) => message + "53"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "54"; - } + public static string EchoString(string message) => message + "54"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "55"; - } + public static string EchoString(string message) => message + "55"; } } public partial class JavaScriptTestHelperStructNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "61"; - } + public static string EchoString(string message) => message + "61"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "62"; - } + public static string EchoString(string message) => message + "62"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "63"; - } + public static string EchoString(string message) => message + "63"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "64"; - } + public static string EchoString(string message) => message + "64"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "65"; - } + public static string EchoString(string message) => message + "65"; } } public partial record class JavaScriptTestHelperRecordClassNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "71"; - } + public static string EchoString(string message) => message + "71"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "72"; - } + public static string EchoString(string message) => message + "72"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "73"; - } + public static string EchoString(string message) => message + "73"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "74"; - } + public static string EchoString(string message) => message + "74"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "75"; - } + public static string EchoString(string message) => message + "75"; } } public partial record struct JavaScriptTestHelperRecordStructNoNamespace { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "81"; - } + public static string EchoString(string message) => message + "81"; public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "82"; - } + public static string EchoString(string message) => message + "82"; } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "83"; - } + public static string EchoString(string message) => message + "83"; } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "84"; - } + public static string EchoString(string message) => message + "84"; } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) - { - return message + "85"; - } + public static string EchoString(string message) => message + "85"; } } \ No newline at end of file From 7f81ccef292215a8cce2deb5699294e8ea45cc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 Aug 2022 10:06:34 +0200 Subject: [PATCH 06/11] Double nested classes. --- .../JSImportGenerator/JSImportStubContext.cs | 2 +- .../JavaScript/JSImportExportTest.cs | 80 ++++++++++--------- .../JavaScript/JavaScriptTestHelper.cs | 60 ++++++++++++-- .../JavaScript/JavaScriptTestHelper.mjs | 8 ++ 4 files changed, 107 insertions(+), 43 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs index 069d3f400beffa..28ecec4951e5c7 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs @@ -180,7 +180,7 @@ private static string GetQualifiedName(StubEnvironment env, IMethodSymbol method nameBuilder.Append(namePart); } - else + else if (namePart.Kind != SymbolDisplayPartKind.Punctuation) { throw new InvalidOperationException($"Name kind '{namePart.Kind}' should be reached"); } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index b9dfd39b5e5ee9..a8966dcaf521d0 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -1206,47 +1206,55 @@ public void JsExportStringNoNs() public void JsExportStructClassRecords() { var actual = JavaScriptTestHelper.invokeStructClassRecords("test"); - Assert.Equal(40, actual.Length); + Assert.Equal(48, actual.Length); Assert.Equal("test11", actual[0]); Assert.Equal("test12", actual[1]); Assert.Equal("test13", actual[2]); Assert.Equal("test14", actual[3]); Assert.Equal("test15", actual[4]); - Assert.Equal("test21", actual[5]); - Assert.Equal("test22", actual[6]); - Assert.Equal("test23", actual[7]); - Assert.Equal("test24", actual[8]); - Assert.Equal("test25", actual[9]); - Assert.Equal("test31", actual[10]); - Assert.Equal("test32", actual[11]); - Assert.Equal("test33", actual[12]); - Assert.Equal("test34", actual[13]); - Assert.Equal("test35", actual[14]); - Assert.Equal("test41", actual[15]); - Assert.Equal("test42", actual[16]); - Assert.Equal("test43", actual[17]); - Assert.Equal("test44", actual[18]); - Assert.Equal("test45", actual[19]); - Assert.Equal("test51", actual[20]); - Assert.Equal("test52", actual[21]); - Assert.Equal("test53", actual[22]); - Assert.Equal("test54", actual[23]); - Assert.Equal("test55", actual[24]); - Assert.Equal("test61", actual[25]); - Assert.Equal("test62", actual[26]); - Assert.Equal("test63", actual[27]); - Assert.Equal("test64", actual[28]); - Assert.Equal("test65", actual[29]); - Assert.Equal("test71", actual[30]); - Assert.Equal("test72", actual[31]); - Assert.Equal("test73", actual[32]); - Assert.Equal("test74", actual[33]); - Assert.Equal("test75", actual[34]); - Assert.Equal("test81", actual[35]); - Assert.Equal("test82", actual[36]); - Assert.Equal("test83", actual[37]); - Assert.Equal("test84", actual[38]); - Assert.Equal("test85", actual[39]); + Assert.Equal("test16", actual[5]); + Assert.Equal("test17", actual[6]); + Assert.Equal("test18", actual[7]); + Assert.Equal("test19", actual[8]); + Assert.Equal("test21", actual[9]); + Assert.Equal("test22", actual[10]); + Assert.Equal("test23", actual[11]); + Assert.Equal("test24", actual[12]); + Assert.Equal("test25", actual[13]); + Assert.Equal("test31", actual[14]); + Assert.Equal("test32", actual[15]); + Assert.Equal("test33", actual[16]); + Assert.Equal("test34", actual[17]); + Assert.Equal("test35", actual[18]); + Assert.Equal("test41", actual[19]); + Assert.Equal("test42", actual[20]); + Assert.Equal("test43", actual[21]); + Assert.Equal("test44", actual[22]); + Assert.Equal("test45", actual[23]); + Assert.Equal("test51", actual[24]); + Assert.Equal("test52", actual[25]); + Assert.Equal("test53", actual[26]); + Assert.Equal("test54", actual[27]); + Assert.Equal("test55", actual[28]); + Assert.Equal("test56", actual[29]); + Assert.Equal("test57", actual[30]); + Assert.Equal("test58", actual[31]); + Assert.Equal("test59", actual[32]); + Assert.Equal("test61", actual[33]); + Assert.Equal("test62", actual[34]); + Assert.Equal("test63", actual[35]); + Assert.Equal("test64", actual[36]); + Assert.Equal("test65", actual[37]); + Assert.Equal("test71", actual[38]); + Assert.Equal("test72", actual[39]); + Assert.Equal("test73", actual[40]); + Assert.Equal("test74", actual[41]); + Assert.Equal("test75", actual[42]); + Assert.Equal("test81", actual[43]); + Assert.Equal("test82", actual[44]); + Assert.Equal("test83", actual[45]); + Assert.Equal("test84", actual[46]); + Assert.Equal("test85", actual[47]); } [Fact] diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index 7946cfc3e6374e..da3039cf3e464a 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -949,24 +949,48 @@ public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) => message + "12"; + + public partial class DoubleNestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "13"; + } } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "13"; + public static string EchoString(string message) => message + "14"; + + public partial record class DoubleNestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "15"; + } } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "14"; + public static string EchoString(string message) => message + "16"; + + public partial struct DoubleNestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "17"; + } } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "15"; + public static string EchoString(string message) => message + "18"; + + public partial record struct DoubleNestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "19"; + } } } @@ -1070,24 +1094,48 @@ public partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) => message + "52"; + + public partial class DoubleNestedClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "53"; + } } public partial record class NestedRecordClass { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "53"; + public static string EchoString(string message) => message + "54"; + + public partial record class DoubleNestedRecordClass + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "55"; + } } public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "54"; + public static string EchoString(string message) => message + "56"; + + public partial struct DoubleNestedStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "57"; + } } public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "55"; + public static string EchoString(string message) => message + "58"; + + public partial record struct DoubleNestedRecordStruct + { + [System.Runtime.InteropServices.JavaScript.JSExport] + public static string EchoString(string message) => message + "59"; + } } } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs index be86c6dfef4aa5..314e715e16b815 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.mjs @@ -175,9 +175,13 @@ export function invokeStructClassRecords(arg1) { return [ dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedClass.DoubleNestedClass.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedRecordClass.DoubleNestedRecordClass.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedStruct.DoubleNestedStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelper.NestedRecordStruct.DoubleNestedRecordStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.NestedClass.EchoString(arg1), dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperStruct.NestedRecordClass.EchoString(arg1), @@ -195,9 +199,13 @@ export function invokeStructClassRecords(arg1) { dllExports.JavaScriptTestHelperNamespace.JavaScriptTestHelperRecordStruct.NestedRecordStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedClass.DoubleNestedClass.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedRecordClass.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedRecordClass.DoubleNestedRecordClass.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedStruct.DoubleNestedStruct.EchoString(arg1), dllExports.JavaScriptTestHelperNoNamespace.NestedRecordStruct.EchoString(arg1), + dllExports.JavaScriptTestHelperNoNamespace.NestedRecordStruct.DoubleNestedRecordStruct.EchoString(arg1), dllExports.JavaScriptTestHelperStructNoNamespace.EchoString(arg1), dllExports.JavaScriptTestHelperStructNoNamespace.NestedClass.EchoString(arg1), dllExports.JavaScriptTestHelperStructNoNamespace.NestedRecordClass.EchoString(arg1), From ffafa04499c93d16629c12c9e01e556398cc9cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 Aug 2022 10:25:08 +0200 Subject: [PATCH 07/11] Fix JSExport for expression bodied methods. --- .../gen/JSImportGenerator/JSExportGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs index 82fb93b871026b..f6590136448336 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSExportGenerator.cs @@ -319,7 +319,7 @@ private static bool ShouldVisitNode(SyntaxNode syntaxNode) // Verify the method has no generic types or defined implementation // and is marked static and partial. if (methodSyntax.TypeParameterList is not null - || methodSyntax.Body is null + || (methodSyntax.Body is null && methodSyntax.ExpressionBody is null) || !methodSyntax.Modifiers.Any(SyntaxKind.StaticKeyword) || methodSyntax.Modifiers.Any(SyntaxKind.PartialKeyword)) { From 73f4ec0c1322159791426537be6f95972f0e3a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 Aug 2022 11:02:33 +0200 Subject: [PATCH 08/11] Refactoring GetQualifiedName using mostly formatting from roslyn. --- .../JSImportGenerator/JSImportStubContext.cs | 66 +++++-------------- .../JavaScript/JavaScriptTestHelper.cs | 10 +++ 2 files changed, 25 insertions(+), 51 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs index 28ecec4951e5c7..efc931a99d2d6c 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs @@ -18,13 +18,14 @@ namespace Microsoft.Interop.JavaScript { internal sealed class JSSignatureContext : IEquatable { - private static SymbolDisplayPartKind[] nameKinds = new[] - { - SymbolDisplayPartKind.ClassName, - SymbolDisplayPartKind.StructName, - SymbolDisplayPartKind.RecordClassName, - SymbolDisplayPartKind.RecordStructName - }; + private static SymbolDisplayFormat typeNameFormat { get; } = new SymbolDisplayFormat( + globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted, + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + miscellaneousOptions: + SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | + SymbolDisplayMiscellaneousOptions.UseSpecialTypes + ); internal static readonly string GeneratorName = typeof(JSImportGenerator).Assembly.GetName().Name; @@ -129,7 +130,7 @@ public static JSSignatureContext Create( int typesHash = Math.Abs((int)hash); var fullName = $"{method.ContainingType.ToDisplayString()}.{method.Name}"; - string qualifiedName = GetQualifiedName(env, method); + string qualifiedName = GetFullyQualifiedMethodName(env, method); return new JSSignatureContext() { @@ -147,52 +148,15 @@ public static JSSignatureContext Create( }; } - private static string GetQualifiedName(StubEnvironment env, IMethodSymbol method) + private static string GetFullyQualifiedMethodName(StubEnvironment env, IMethodSymbol method) { - bool isFirstTypeName = true; - string? namespaceName = null; - string? className; - StringBuilder nameBuilder = new StringBuilder(); - ImmutableArray nameParts = method.ContainingType.ToDisplayParts(); - foreach (SymbolDisplayPart namePart in nameParts) - { - if (namePart.Kind == SymbolDisplayPartKind.NamespaceName) - { - if (!isFirstTypeName) - throw new InvalidOperationException($"Found namespace name '{namePart}' after some type names '{nameBuilder}'"); - - if (nameBuilder.Length != 0) - nameBuilder.Append('.'); - - nameBuilder.Append(namePart); - } - else if (Array.IndexOf(nameKinds, namePart.Kind) >= 0) - { - if (isFirstTypeName) - { - namespaceName = nameBuilder.ToString(); - nameBuilder.Clear(); - isFirstTypeName = false; - } - - if (nameBuilder.Length != 0) - nameBuilder.Append('/'); - - nameBuilder.Append(namePart); - } - else if (namePart.Kind != SymbolDisplayPartKind.Punctuation) - { - throw new InvalidOperationException($"Name kind '{namePart.Kind}' should be reached"); - } - } + // Mono style nested class name format. + string typeName = method.ContainingType.ToDisplayString(typeNameFormat).Replace(".", "/"); - if (isFirstTypeName) - throw new InvalidOperationException($"Type name not found in '{nameParts}'"); - else - className = nameBuilder.ToString(); + if (!method.ContainingType.ContainingNamespace.IsGlobalNamespace) + typeName = $"{method.ContainingType.ContainingNamespace.ToDisplayString()}.{typeName}"; - string qualifiedClassName = namespaceName == null ? className : namespaceName + "." + className; - return $"[{env.Compilation.AssemblyName}]{qualifiedClassName}:{method.Name}"; + return $"[{env.Compilation.AssemblyName}]{typeName}:{method.Name}"; } private static (ImmutableArray, IMarshallingGeneratorFactory) GenerateTypeInformation(IMethodSymbol method, GeneratorDiagnostics diagnostics, StubEnvironment env) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index da3039cf3e464a..6d31aece081c23 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -940,6 +940,16 @@ public static async Task InitializeAsync() namespace JavaScriptTestHelperNamespace { + + + + + + + + + + public partial class JavaScriptTestHelper { [System.Runtime.InteropServices.JavaScript.JSExport] From ed242589129ec8bec349ddd9c6f5de37ea8263c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 Aug 2022 11:05:11 +0200 Subject: [PATCH 09/11] Drop extra blank lines. --- .../InteropServices/JavaScript/JavaScriptTestHelper.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index 6d31aece081c23..da3039cf3e464a 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -940,16 +940,6 @@ public static async Task InitializeAsync() namespace JavaScriptTestHelperNamespace { - - - - - - - - - - public partial class JavaScriptTestHelper { [System.Runtime.InteropServices.JavaScript.JSExport] From 143aa297114bbfd8ffb6e815ec926fd609c42f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 Aug 2022 11:34:42 +0200 Subject: [PATCH 10/11] Simplify name format. --- .../gen/JSImportGenerator/JSImportStubContext.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs index efc931a99d2d6c..58590f7f2109f6 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs @@ -21,7 +21,6 @@ internal sealed class JSSignatureContext : IEquatable private static SymbolDisplayFormat typeNameFormat { get; } = new SymbolDisplayFormat( globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted, typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes, - genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes From 2288ddeab54200cbc3c5ea2f9e9a1fe11d5f8a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 Aug 2022 14:53:50 +0200 Subject: [PATCH 11/11] Feedback. --- .../gen/JSImportGenerator/JSImportStubContext.cs | 9 +++------ .../JavaScript/JavaScriptTestHelper.cs | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs index 58590f7f2109f6..005e30581affea 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/gen/JSImportGenerator/JSImportStubContext.cs @@ -18,12 +18,9 @@ namespace Microsoft.Interop.JavaScript { internal sealed class JSSignatureContext : IEquatable { - private static SymbolDisplayFormat typeNameFormat { get; } = new SymbolDisplayFormat( + private static SymbolDisplayFormat s_typeNameFormat { get; } = new SymbolDisplayFormat( globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Omitted, - typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes, - miscellaneousOptions: - SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | - SymbolDisplayMiscellaneousOptions.UseSpecialTypes + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypes ); internal static readonly string GeneratorName = typeof(JSImportGenerator).Assembly.GetName().Name; @@ -150,7 +147,7 @@ public static JSSignatureContext Create( private static string GetFullyQualifiedMethodName(StubEnvironment env, IMethodSymbol method) { // Mono style nested class name format. - string typeName = method.ContainingType.ToDisplayString(typeNameFormat).Replace(".", "/"); + string typeName = method.ContainingType.ToDisplayString(s_typeNameFormat).Replace(".", "/"); if (!method.ContainingType.ContainingNamespace.IsGlobalNamespace) typeName = $"{method.ContainingType.ContainingNamespace.ToDisplayString()}.{typeName}"; diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index da3039cf3e464a..b5a89b7f48fe98 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -943,7 +943,10 @@ namespace JavaScriptTestHelperNamespace public partial class JavaScriptTestHelper { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "11"; + public static string EchoString(string message) + { + return message + "11"; + } public partial class NestedClass { @@ -1014,7 +1017,10 @@ public partial record class NestedRecordClass public partial struct NestedStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "24"; + public static string EchoString(string message) + { + return message + "24"; + } } public partial record struct NestedRecordStruct @@ -1080,7 +1086,10 @@ public partial struct NestedStruct public partial record struct NestedRecordStruct { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) => message + "45"; + public static string EchoString(string message) + { + return message + "45"; + } } } }