Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deprecated symbol stripping does not strip out heritage clause with imported type #2783

Merged
merged 7 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/jsii/lib/transforms/deprecated-remover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ class Transformation {
const symbol = typeChecker.getSymbolAtLocation(
ts.getNameOfDeclaration(node as ts.Declaration) ?? node,
);
return symbol && typeChecker.getFullyQualifiedName(symbol);
// 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);
}

private static typeReference(
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 ///
///////////////////////
"
`);
});