Skip to content

Commit

Permalink
tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Niranjan Jayakar committed Apr 12, 2021
1 parent 80bdbab commit 6049a91
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/jsii/lib/transforms/deprecated-remover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ class Transformation {
const symbol = typeChecker.getSymbolAtLocation(
ts.getNameOfDeclaration(node as ts.Declaration) ?? node,
);
// This symbol ☝️ does not contain enough information in some cases - when
// an imported type is part of a heritage clause - to produce the fqn.
// Round tripping this to its type and back to a symbol seems to fix this.
const type = symbol && typeChecker.getDeclaredTypeOfSymbol(symbol);
return type?.symbol && typeChecker.getFullyQualifiedName(type.symbol);
}
Expand Down
41 changes: 41 additions & 0 deletions packages/jsii/test/deprecated-remover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,44 @@ test('produces correct output', async () => {
"
`);
});

test('cross-file deprecated heritage', async () => {
const result = await compileJsiiForTest(
{
'index.ts': `
import { IDeprecated } from './deprecated';
export * from './deprecated';
export interface INotDeprecated extends IDeprecated {}
`,
'deprecated.ts': `
${DEPRECATED}
export interface IDeprecated {}
`,
},
undefined /* callback */,
{ stripDeprecated: true },
);

const output = Object.entries(result.files)
.filter(([name]) => name.endsWith('.d.ts'))
.map(([name, content]) => {
const separator = '/'.repeat(name.length + 8);
return `${separator}\n/// ${name} ///\n${content}${separator}\n`;
})
.join('\n\n');
expect(output).toMatchInlineSnapshot(`
"//////////////////
/// index.d.ts ///
import './deprecated';
import './deprecated';
export interface INotDeprecated {
}
//////////////////
///////////////////////
/// deprecated.d.ts ///
///////////////////////
"
`);
});

0 comments on commit 6049a91

Please sign in to comment.