Skip to content

Commit

Permalink
Improve the error message for not yet supported "export * as ___ from…
Browse files Browse the repository at this point in the history
…" syntax
  • Loading branch information
octogonz committed Jun 30, 2021
1 parent fcc005a commit 73a3498
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions apps/api-extractor/src/analyzer/ExportAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,26 @@ export class ExportAnalyzer {
// Example: " ExportName as RenamedName"
const exportSpecifier: ts.ExportSpecifier = declaration as ts.ExportSpecifier;
exportName = (exportSpecifier.propertyName || exportSpecifier.name).getText().trim();
} else if (declaration.kind === ts.SyntaxKind.NamespaceExport) {
// EXAMPLE:
// "export * as theLib from 'the-lib';"
//
// ExportDeclaration:
// ExportKeyword: pre=[export] sep=[ ]
// NamespaceExport:
// AsteriskToken: pre=[*] sep=[ ]
// AsKeyword: pre=[as] sep=[ ]
// Identifier: pre=[theLib] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['the-lib']
// SemicolonToken: pre=[;]

// Issue tracking this feature: https://github.com/microsoft/rushstack/issues/2780
throw new Error(
`The "export * as ___" syntax is not supported yet; as a workaround,` +
` use "import * as ___" with a separate "export { ___ }" declaration\n` +
SourceFileLocationFormatter.formatDeclaration(declaration)
);
} else {
throw new InternalError(
`Unimplemented export declaration kind: ${declaration.getText()}\n` +
Expand Down Expand Up @@ -505,9 +525,8 @@ export class ExportAnalyzer {

if (externalModulePath === undefined) {
const astModule: AstModule = this._fetchSpecifierAstModule(importDeclaration, declarationSymbol);
let namespaceImport: AstNamespaceImport | undefined = this._astNamespaceImportByModule.get(
astModule
);
let namespaceImport: AstNamespaceImport | undefined =
this._astNamespaceImportByModule.get(astModule);
if (namespaceImport === undefined) {
namespaceImport = new AstNamespaceImport({
namespaceName: declarationSymbol.name,
Expand Down

0 comments on commit 73a3498

Please sign in to comment.