diff --git a/packages/jsii-rosetta/lib/translate.ts b/packages/jsii-rosetta/lib/translate.ts index d3f0217c13..d1f0456811 100644 --- a/packages/jsii-rosetta/lib/translate.ts +++ b/packages/jsii-rosetta/lib/translate.ts @@ -57,7 +57,9 @@ export class Translator { }), ); - this.#diagnostics.push(...translator.diagnostics); + if (snip.parameters?.infused === undefined) { + this.#diagnostics.push(...translator.diagnostics); + } return TranslatedSnippet.fromSchema({ translations: { diff --git a/packages/jsii-rosetta/test/commands/extract.test.ts b/packages/jsii-rosetta/test/commands/extract.test.ts index 74ff8da273..ecc6c0c0c4 100644 --- a/packages/jsii-rosetta/test/commands/extract.test.ts +++ b/packages/jsii-rosetta/test/commands/extract.test.ts @@ -456,7 +456,7 @@ test('infused examples skip loose mode', async () => { try { const cacheToFile = path.join(otherAssembly.moduleDirectory, 'test.tabl.json'); - // Without exampleMetadata infused=true, expect an error + // Without exampleMetadata infused, expect an error await expect( extract.extractSnippets([otherAssembly.moduleDirectory], { cacheToFile, @@ -465,8 +465,7 @@ test('infused examples skip loose mode', async () => { ).rejects.toThrowError(/Sample uses literate source/); // Add infused=true to metadata and update assembly - otherAssembly.assembly.types!['my_assembly.ClassA'].docs!.custom!.exampleMetadata = - 'lit=integ.test.ts infused=true'; + otherAssembly.assembly.types!['my_assembly.ClassA'].docs!.custom!.exampleMetadata = 'lit=integ.test.ts infused'; await otherAssembly.updateAssembly(); // Expect same function call to succeed now @@ -484,6 +483,44 @@ test('infused examples skip loose mode', async () => { } }); +test('infused examples have no diagnostics', async () => { + const otherAssembly = await TestJsiiModule.fromSource( + { + 'index.ts': ` + /** + * ClassA + * + * @exampleMetadata infused + * @example x + */ + export class ClassA { + public someMethod() { + } + } + `, + }, + { + name: 'my_assembly', + jsii: { + ...DUMMY_JSII_CONFIG, + }, + }, + ); + try { + const cacheToFile = path.join(otherAssembly.moduleDirectory, 'test.tabl.json'); + + const results = await extract.extractSnippets([otherAssembly.moduleDirectory], { + cacheToFile, + includeCompilerDiagnostics: true, + loose: false, + }); + + expect(results.diagnostics).toEqual([]); + } finally { + await otherAssembly.cleanup(); + } +}); + class MockTranslator extends RosettaTranslator { public constructor(opts: RosettaTranslatorOptions, translatorFn: jest.Mock) { super(opts);