Skip to content

Commit

Permalink
fix: Correctly handle export * from...
Browse files Browse the repository at this point in the history
Closes #1186
  • Loading branch information
Gerrit0 committed Jan 21, 2020
1 parent f2d9c18 commit 9ce64c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/lib/converter/factories/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export function createReferenceReflection(context: Context, source: ts.Symbol, t
context.scope.children = [];
}
context.scope.children.push(reflection);
context.registerReflection(reflection, source);

// target === source happens when doing export * from ...
// and the original symbol is not renamed and exported from the imported module.
context.registerReflection(reflection, target === source ? undefined : source);
context.trigger(Converter.EVENT_CREATE_DECLARATION, reflection);

return reflection;
Expand Down
16 changes: 5 additions & 11 deletions src/lib/converter/nodes/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,13 @@ export class ExportDeclarationConverter extends ConverterNodeComponent<ts.Export
}
});
} else if (node.moduleSpecifier) { // export * from ...
const thisModule = context.getSymbolAtLocation(node.getSourceFile())!;
const sourceFileSymbol = context.getSymbolAtLocation(node.moduleSpecifier);
sourceFileSymbol?.exports?.forEach((symbol, key) => {
// Default exports are not re-exported with export * from
if (key === 'default' as ts.__String) {
return;
}
const source = context.checker.tryGetMemberInModuleExports(key.toString().replace(/^__/, '_'), thisModule);
if (source) {
const target = context.resolveAliasedSymbol(symbol);
createReferenceReflection(context, source, target);
for (const symbol of context.checker.getExportsOfModule(sourceFileSymbol!)) {
if (symbol.name === 'default') { // Default exports are not re-exported with export *
continue;
}
});
createReferenceReflection(context, symbol, context.resolveAliasedSymbol(symbol));
}
}

return context.scope;
Expand Down

0 comments on commit 9ce64c5

Please sign in to comment.