From e407324ce0218c9d3f14cc34e839ab43543b6e9e Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Fri, 12 Mar 2021 18:22:45 +0100 Subject: [PATCH 1/5] fix(pacmak): .NET submodules don't have namespace docs Propagate submodule docs to namespace docs. --- .../lib/targets/dotnet/dotnetdocgenerator.ts | 4 +- .../lib/targets/dotnet/dotnetgenerator.ts | 27 ++-- .../__snapshots__/target-dotnet.test.ts.snap | 149 +++++++++++------- 3 files changed, 115 insertions(+), 65 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/dotnet/dotnetdocgenerator.ts b/packages/jsii-pacmak/lib/targets/dotnet/dotnetdocgenerator.ts index 8b7f7b9269..193cad5a04 100644 --- a/packages/jsii-pacmak/lib/targets/dotnet/dotnetdocgenerator.ts +++ b/packages/jsii-pacmak/lib/targets/dotnet/dotnetdocgenerator.ts @@ -78,7 +78,7 @@ export class DotNetDocGenerator { const remarks = this.renderRemarks(docs); if (remarks.length > 0) { this.code.line('/// '); - remarks.forEach((r) => this.code.line(`/// ${r}`)); + remarks.forEach((r) => this.code.line(`/// ${r}`.trimRight())); this.code.line('/// '); } @@ -101,7 +101,7 @@ export class DotNetDocGenerator { this.code.line('/// '); for (const line of lines) { - this.code.line(`/// ${line}`); + this.code.line(`/// ${line}`.trimRight()); } this.code.line('/// '); } diff --git a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts index 944c2b4bdf..218390c113 100644 --- a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts +++ b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts @@ -68,7 +68,7 @@ export class DotNetGenerator extends Generator { this.assembly, ); - this.emitNamespaceDocs(); + this.emitAssemblyDocs(); // We need to resolve the dependency tree this.typeresolver.resolveNamespacesDependencies(); @@ -149,9 +149,14 @@ export class DotNetGenerator extends Generator { /** * Namespaces are handled implicitly by openFileIfNeeded(). + * + * Do generate docs if this is for a submodule though. */ - protected onBeginNamespace(_ns: string) { - /* noop */ + protected onBeginNamespace(ns: string) { + const submodule = this.assembly.submodules?.[ns]; + if (submodule) { + this.emitNamespaceDocs(ns, submodule); + } } protected onEndNamespace(_ns: string) { @@ -1074,6 +1079,13 @@ export class DotNetGenerator extends Generator { } } + private emitAssemblyDocs() { + this.emitNamespaceDocs( + this.assembly.targets!.dotnet!.namespace, + this.assembly, + ); + } + /** * Emit an unused, empty class called `NamespaceDoc` to attach the module README to * @@ -1086,18 +1098,15 @@ export class DotNetGenerator extends Generator { * In any case, we need a place to attach the docs where they can be transported around, * might as well be this method. */ - private emitNamespaceDocs() { - if (!this.assembly.readme) { + private emitNamespaceDocs(namespace: string, docSource: spec.Targetable) { + if (!docSource.readme) { return; } - const namespace = this.assembly.targets!.dotnet!.namespace; const className = 'NamespaceDoc'; this.openFileIfNeeded(className, namespace, false, false); - this.dotnetDocGenerator.emitMarkdownAsRemarks( - this.assembly.readme.markdown, - ); + this.dotnetDocGenerator.emitMarkdownAsRemarks(docSource.readme.markdown); this.emitHideAttribute(); // Traditionally this class is made 'internal', but that interacts poorly with DocFX's default filters // which aren't overridable. So we make it public, but use attributes to hide it from users' IntelliSense, diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index 57e34d287b..5ed18c0be2 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -1140,7 +1140,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// (deprecated) Check that enums from \\@scoped packages can be references. /// /// See awslabs/jsii#138 - /// + /// /// Stability: Deprecated /// [JsiiEnum(nativeType: typeof(EnumFromScopedModule), fullyQualifiedName: "@scope/jsii-calc-lib.EnumFromScopedModule")] @@ -1387,7 +1387,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// /// These classes can be greeted with /// a "hello" or "goodbye" blessing and they will respond back in a fun and friendly manner. - /// + /// /// Stability: Deprecated /// [JsiiInterface(nativeType: typeof(IFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")] @@ -1406,7 +1406,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// /// These classes can be greeted with /// a "hello" or "goodbye" blessing and they will respond back in a fun and friendly manner. - /// + /// /// Stability: Deprecated /// [JsiiTypeProxy(nativeType: typeof(IFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")] @@ -1654,7 +1654,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// /// Their presence validates that .NET/Java/jsii-reflect can track all fields /// far enough up the tree. - /// + /// /// Stability: Deprecated /// [JsiiInterface(nativeType: typeof(IThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")] @@ -1672,7 +1672,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// /// Their presence validates that .NET/Java/jsii-reflect can track all fields /// far enough up the tree. - /// + /// /// Stability: Deprecated /// [JsiiTypeProxy(nativeType: typeof(IThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")] @@ -2262,7 +2262,7 @@ namespace Amazon.JSII.Tests.CustomSubmoduleName /// (deprecated) This is a struct, nested within a class. /// /// Normal. - /// + /// /// Stability: Deprecated /// [JsiiInterface(nativeType: typeof(INestedStruct), fullyQualifiedName: "@scope/jsii-calc-lib.submodule.NestingClass.NestedStruct")] @@ -2282,7 +2282,7 @@ namespace Amazon.JSII.Tests.CustomSubmoduleName /// (deprecated) This is a struct, nested within a class. /// /// Normal. - /// + /// /// Stability: Deprecated /// [JsiiTypeProxy(nativeType: typeof(INestedStruct), fullyQualifiedName: "@scope/jsii-calc-lib.submodule.NestingClass.NestedStruct")] @@ -2309,7 +2309,7 @@ namespace Amazon.JSII.Tests.CustomSubmoduleName /// (deprecated) This is a struct, nested within a class. /// /// Normal. - /// + /// /// Stability: Deprecated /// [JsiiByValue(fqn: "@scope/jsii-calc-lib.submodule.NestingClass.NestedStruct")] @@ -2952,6 +2952,11 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┗━ 📄 WithPrivatePropertyInConstructor.cs ┣━ 📄 Amazon.JSII.Tests.CalculatorPackageId.csproj ┣━ 📄 AssemblyInfo.cs + ┣━ 📁 jsii-calc + ┃ ┗━ 📁 submodule + ┃ ┣━ 📁 isolated + ┃ ┃ ┗━ 📄 NamespaceDoc.cs + ┃ ┗━ 📄 NamespaceDoc.cs ┣━ 📄 jsii-calc-3.20.120.tgz ┣━ 📄 LICENSE ┗━ 📄 NOTICE @@ -4010,7 +4015,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// A calculator which maintains a current value and allows adding operations. /// /// Here's how you use it: - /// + /// /// - /// + /// /// I will repeat this example again, but in an @example tag. /// /// @@ -4151,7 +4156,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// The initial value of the calculator. /// /// NOTE: Any number works here, it's fine. - /// + /// /// Default: 0 /// [JsiiOptional] @@ -4410,9 +4415,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// This class has docs. /// /// The docs are great. They're a bunch of tags. - /// + /// /// See: https://aws.amazon.com/ - /// + /// /// CustomAttribute: hasAValue /// /// @@ -5909,7 +5914,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// /// This is the meat of the TSDoc comment. It may contain /// multiple lines and multiple paragraphs. - /// + /// /// Multiple paragraphs are separated by an empty line. /// /// @@ -6982,7 +6987,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// The initial value of the calculator. /// /// NOTE: Any number works here, it's fine. - /// + /// /// Default: 0 /// [JsiiProperty(name: "initialValue", typeJson: "{\\"primitive\\":\\"number\\"}", isOptional: true)] @@ -7020,7 +7025,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// The initial value of the calculator. /// /// NOTE: Any number works here, it's fine. - /// + /// /// Default: 0 /// [JsiiOptional] @@ -8755,7 +8760,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// The container port of the application load balancer attached to your Fargate service. /// /// Corresponds to container port mapping. - /// + /// /// Default: 80 /// [JsiiProperty(name: "containerPort", typeJson: "{\\"primitive\\":\\"number\\"}", isOptional: true)] @@ -8776,9 +8781,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// 1024 (1 vCPU) - Available memory values: 2GB, 3GB, 4GB, 5GB, 6GB, 7GB, 8GB /// 2048 (2 vCPU) - Available memory values: Between 4GB and 16GB in 1GB increments /// 4096 (4 vCPU) - Available memory values: Between 8GB and 30GB in 1GB increments - /// + /// /// This default is set in the underlying FargateTaskDefinition construct. - /// + /// /// Default: 256 /// [JsiiProperty(name: "cpu", typeJson: "{\\"primitive\\":\\"string\\"}", isOptional: true)] @@ -8795,19 +8800,19 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// /// This field is required and you must use one of the following values, which determines your range of valid values /// for the cpu parameter: - /// + /// /// 0.5GB, 1GB, 2GB - Available cpu values: 256 (.25 vCPU) - /// + /// /// 1GB, 2GB, 3GB, 4GB - Available cpu values: 512 (.5 vCPU) - /// + /// /// 2GB, 3GB, 4GB, 5GB, 6GB, 7GB, 8GB - Available cpu values: 1024 (1 vCPU) - /// + /// /// Between 4GB and 16GB in 1GB increments - Available cpu values: 2048 (2 vCPU) - /// + /// /// Between 8GB and 30GB in 1GB increments - Available cpu values: 4096 (4 vCPU) - /// + /// /// This default is set in the underlying FargateTaskDefinition construct. - /// + /// /// Default: 512 /// [JsiiProperty(name: "memoryMiB", typeJson: "{\\"primitive\\":\\"string\\"}", isOptional: true)] @@ -8859,7 +8864,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// The container port of the application load balancer attached to your Fargate service. /// /// Corresponds to container port mapping. - /// + /// /// Default: 80 /// [JsiiOptional] @@ -8877,9 +8882,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// 1024 (1 vCPU) - Available memory values: 2GB, 3GB, 4GB, 5GB, 6GB, 7GB, 8GB /// 2048 (2 vCPU) - Available memory values: Between 4GB and 16GB in 1GB increments /// 4096 (4 vCPU) - Available memory values: Between 8GB and 30GB in 1GB increments - /// + /// /// This default is set in the underlying FargateTaskDefinition construct. - /// + /// /// Default: 256 /// [JsiiOptional] @@ -8893,19 +8898,19 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// /// This field is required and you must use one of the following values, which determines your range of valid values /// for the cpu parameter: - /// + /// /// 0.5GB, 1GB, 2GB - Available cpu values: 256 (.25 vCPU) - /// + /// /// 1GB, 2GB, 3GB, 4GB - Available cpu values: 512 (.5 vCPU) - /// + /// /// 2GB, 3GB, 4GB, 5GB, 6GB, 7GB, 8GB - Available cpu values: 1024 (1 vCPU) - /// + /// /// Between 4GB and 16GB in 1GB increments - Available cpu values: 2048 (2 vCPU) - /// + /// /// Between 8GB and 30GB in 1GB increments - Available cpu values: 4096 (4 vCPU) - /// + /// /// This default is set in the underlying FargateTaskDefinition construct. - /// + /// /// Default: 512 /// [JsiiOptional] @@ -11928,7 +11933,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// The container port of the application load balancer attached to your Fargate service. /// /// Corresponds to container port mapping. - /// + /// /// Default: 80 /// [JsiiOptional] @@ -11947,9 +11952,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// 1024 (1 vCPU) - Available memory values: 2GB, 3GB, 4GB, 5GB, 6GB, 7GB, 8GB /// 2048 (2 vCPU) - Available memory values: Between 4GB and 16GB in 1GB increments /// 4096 (4 vCPU) - Available memory values: Between 8GB and 30GB in 1GB increments - /// + /// /// This default is set in the underlying FargateTaskDefinition construct. - /// + /// /// Default: 256 /// [JsiiOptional] @@ -11964,19 +11969,19 @@ namespace Amazon.JSII.Tests.CalculatorNamespace /// /// This field is required and you must use one of the following values, which determines your range of valid values /// for the cpu parameter: - /// + /// /// 0.5GB, 1GB, 2GB - Available cpu values: 256 (.25 vCPU) - /// + /// /// 1GB, 2GB, 3GB, 4GB - Available cpu values: 512 (.5 vCPU) - /// + /// /// 2GB, 3GB, 4GB, 5GB, 6GB, 7GB, 8GB - Available cpu values: 1024 (1 vCPU) - /// + /// /// Between 4GB and 16GB in 1GB increments - Available cpu values: 2048 (2 vCPU) - /// + /// /// Between 8GB and 30GB in 1GB increments - Available cpu values: 4096 (4 vCPU) - /// + /// /// This default is set in the underlying FargateTaskDefinition construct. - /// + /// /// Default: 512 /// [JsiiOptional] @@ -12137,27 +12142,27 @@ namespace Amazon.JSII.Tests.CalculatorNamespace { /// ///

jsii Calculator

- /// + /// /// This library is used to demonstrate and test the features of JSII - /// + /// ///

How to use running sum API:

- /// + /// /// First, create a calculator: - /// + /// /// - /// + /// /// Then call some operations: - /// + /// /// - /// + /// ///

Code Samples

- /// + /// /// /dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc/submodule/NamespaceDoc.cs 1`] = ` +#pragma warning disable CS0672,CS0809,CS1591 + +namespace jsii-calc.submodule +{ + /// + ///

Read you, read me

+ /// + /// This is the readme of the jsii-calc.submodule module. + ///
+ [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public class NamespaceDoc + { + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc/submodule/isolated/NamespaceDoc.cs 1`] = ` +#pragma warning disable CS0672,CS0809,CS1591 + +namespace jsii-calc.submodule.isolated +{ + /// + ///

Read you, read me

+ /// + /// This is the readme of the jsii-calc.submodule.isolated module. + ///
+ [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public class NamespaceDoc + { + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc-3.20.120.tgz 1`] = `dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc-3.20.120.tgz is a tarball`; From c1ccfd6cbf52b0f3e3f0cf579373828bcdd9501b Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 15 Mar 2021 09:21:19 +0100 Subject: [PATCH 2/5] Lookup namespace name --- .../lib/targets/dotnet/dotnetgenerator.ts | 11 ++- .../__snapshots__/target-dotnet.test.ts.snap | 82 +++++++++---------- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts index 218390c113..53a2443f1b 100644 --- a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts +++ b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts @@ -152,10 +152,15 @@ export class DotNetGenerator extends Generator { * * Do generate docs if this is for a submodule though. */ - protected onBeginNamespace(ns: string) { - const submodule = this.assembly.submodules?.[ns]; + protected onBeginNamespace(jsiiNs: string) { + const submodule = this.assembly.submodules?.[jsiiNs]; if (submodule) { - this.emitNamespaceDocs(ns, submodule); + const dotnetNs = this.typeresolver.resolveNamespace( + this.assembly, + this.assembly.name, + jsiiNs, + ); + this.emitNamespaceDocs(dotnetNs, submodule); } } diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index 5ed18c0be2..d08e8756b3 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -2825,6 +2825,11 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┣━ 📄 Jsii487Derived.cs ┃ ┣━ 📄 Jsii496Derived.cs ┃ ┣━ 📄 JsiiAgent.cs + ┃ ┣━ 📁 JsiiCalc + ┃ ┃ ┗━ 📁 Submodule + ┃ ┃ ┣━ 📁 Isolated + ┃ ┃ ┃ ┗━ 📄 NamespaceDoc.cs + ┃ ┃ ┗━ 📄 NamespaceDoc.cs ┃ ┣━ 📄 JSObjectLiteralForInterface.cs ┃ ┣━ 📄 JSObjectLiteralToNative.cs ┃ ┣━ 📄 JSObjectLiteralToNativeClass.cs @@ -2952,11 +2957,6 @@ exports[`Generated code for "jsii-calc": / 1`] = ` ┃ ┗━ 📄 WithPrivatePropertyInConstructor.cs ┣━ 📄 Amazon.JSII.Tests.CalculatorPackageId.csproj ┣━ 📄 AssemblyInfo.cs - ┣━ 📁 jsii-calc - ┃ ┗━ 📁 submodule - ┃ ┣━ 📁 isolated - ┃ ┃ ┗━ 📄 NamespaceDoc.cs - ┃ ┗━ 📄 NamespaceDoc.cs ┣━ 📄 jsii-calc-3.20.120.tgz ┣━ 📄 LICENSE ┗━ 📄 NOTICE @@ -11671,6 +11671,42 @@ namespace Amazon.JSII.Tests.CalculatorNamespace `; +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/JsiiCalc/Submodule/Isolated/NamespaceDoc.cs 1`] = ` +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.JsiiCalc.Submodule.Isolated +{ + /// + ///

Read you, read me

+ /// + /// This is the readme of the jsii-calc.submodule.isolated module. + ///
+ [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public class NamespaceDoc + { + } +} + +`; + +exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/JsiiCalc/Submodule/NamespaceDoc.cs 1`] = ` +#pragma warning disable CS0672,CS0809,CS1591 + +namespace Amazon.JSII.Tests.CalculatorNamespace.JsiiCalc.Submodule +{ + /// + ///

Read you, read me

+ /// + /// This is the readme of the jsii-calc.submodule module. + ///
+ [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] + public class NamespaceDoc + { + } +} + +`; + exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/JsonFormatter.cs 1`] = ` using Amazon.JSII.Runtime.Deputy; @@ -16833,40 +16869,4 @@ Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. `; -exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc/submodule/NamespaceDoc.cs 1`] = ` -#pragma warning disable CS0672,CS0809,CS1591 - -namespace jsii-calc.submodule -{ - /// - ///

Read you, read me

- /// - /// This is the readme of the jsii-calc.submodule module. - ///
- [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public class NamespaceDoc - { - } -} - -`; - -exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc/submodule/isolated/NamespaceDoc.cs 1`] = ` -#pragma warning disable CS0672,CS0809,CS1591 - -namespace jsii-calc.submodule.isolated -{ - /// - ///

Read you, read me

- /// - /// This is the readme of the jsii-calc.submodule.isolated module. - ///
- [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] - public class NamespaceDoc - { - } -} - -`; - exports[`Generated code for "jsii-calc": /dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc-3.20.120.tgz 1`] = `dotnet/Amazon.JSII.Tests.CalculatorPackageId/jsii-calc-3.20.120.tgz is a tarball`; From 85ee910f4e5efeeb5926b00249c6801a512100ce Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 15 Mar 2021 11:38:15 +0100 Subject: [PATCH 3/5] More snapshot updates from `main` --- .../generated-code/__snapshots__/target-dotnet.test.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap index f393c1db67..f4e80e7e7a 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-dotnet.test.ts.snap @@ -1060,9 +1060,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace /// The method foo has a parameter that uses a type /// from a dependent module. Since Go "reimplments" this method, it will also need /// to include an "import" statement for the calc-base module. - /// + /// /// Stability: Deprecated - /// + /// /// See: https://github.com/aws/jsii/issues/2647 ///
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.BaseFor2647), fullyQualifiedName: "@scope/jsii-calc-lib.BaseFor2647", parametersJson: "[{\\"name\\":\\"very\\",\\"type\\":{\\"fqn\\":\\"@scope/jsii-calc-base-of-base.Very\\"}}]")] From aa2cb96f3010bdf0c088c7441840bc1d69aebc85 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 16 Mar 2021 15:34:07 +0100 Subject: [PATCH 4/5] Add exception handler when parsing HTML --- .../jsii-rosetta/lib/markdown/xml-comment-renderer.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts b/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts index 3cb3f927e2..01c5969735 100644 --- a/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts +++ b/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts @@ -79,8 +79,14 @@ export class CSharpXmlCommentRenderer extends MarkdownRenderer { */ public html_inline(node: cm.Node, _context: RendererContext) { const html = node.literal ?? ''; - const doc = new DOMParser().parseFromString(html, 'text/html'); - return new XMLSerializer().serializeToString(doc); + try { + const doc = new DOMParser().parseFromString(html, 'text/html'); + return new XMLSerializer().serializeToString(doc); + } catch (e) { + // There may be errors in parsing HTML. Don't let that stop us! + console.error(e.message); + return para(``); + } } /** From d3ef7a2667ea377dab36f83944a1ddd983711dc4 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 16 Mar 2021 18:08:07 +0100 Subject: [PATCH 5/5] Just render invalid HTML as text --- .../lib/markdown/xml-comment-renderer.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts b/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts index 01c5969735..7c9390f05e 100644 --- a/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts +++ b/packages/jsii-rosetta/lib/markdown/xml-comment-renderer.ts @@ -85,7 +85,7 @@ export class CSharpXmlCommentRenderer extends MarkdownRenderer { } catch (e) { // There may be errors in parsing HTML. Don't let that stop us! console.error(e.message); - return para(``); + return ESCAPE.text(html); } } @@ -97,7 +97,13 @@ export class CSharpXmlCommentRenderer extends MarkdownRenderer { */ public html_block(node: cm.Node, _context: RendererContext) { const html = node.literal ?? ''; - const doc = new DOMParser().parseFromString(html, 'text/html'); - return new XMLSerializer().serializeToString(doc); + try { + const doc = new DOMParser().parseFromString(html, 'text/html'); + return new XMLSerializer().serializeToString(doc); + } catch (e) { + // There may be errors in parsing HTML. Don't let that stop us! + console.error(e.message); + return ESCAPE.text(html); + } } }