Skip to content

Commit 73a3498

Browse files
committed
Improve the error message for not yet supported "export * as ___ from" syntax
1 parent fcc005a commit 73a3498

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

apps/api-extractor/src/analyzer/ExportAnalyzer.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,26 @@ export class ExportAnalyzer {
445445
// Example: " ExportName as RenamedName"
446446
const exportSpecifier: ts.ExportSpecifier = declaration as ts.ExportSpecifier;
447447
exportName = (exportSpecifier.propertyName || exportSpecifier.name).getText().trim();
448+
} else if (declaration.kind === ts.SyntaxKind.NamespaceExport) {
449+
// EXAMPLE:
450+
// "export * as theLib from 'the-lib';"
451+
//
452+
// ExportDeclaration:
453+
// ExportKeyword: pre=[export] sep=[ ]
454+
// NamespaceExport:
455+
// AsteriskToken: pre=[*] sep=[ ]
456+
// AsKeyword: pre=[as] sep=[ ]
457+
// Identifier: pre=[theLib] sep=[ ]
458+
// FromKeyword: pre=[from] sep=[ ]
459+
// StringLiteral: pre=['the-lib']
460+
// SemicolonToken: pre=[;]
461+
462+
// Issue tracking this feature: https://github.com/microsoft/rushstack/issues/2780
463+
throw new Error(
464+
`The "export * as ___" syntax is not supported yet; as a workaround,` +
465+
` use "import * as ___" with a separate "export { ___ }" declaration\n` +
466+
SourceFileLocationFormatter.formatDeclaration(declaration)
467+
);
448468
} else {
449469
throw new InternalError(
450470
`Unimplemented export declaration kind: ${declaration.getText()}\n` +
@@ -505,9 +525,8 @@ export class ExportAnalyzer {
505525

506526
if (externalModulePath === undefined) {
507527
const astModule: AstModule = this._fetchSpecifierAstModule(importDeclaration, declarationSymbol);
508-
let namespaceImport: AstNamespaceImport | undefined = this._astNamespaceImportByModule.get(
509-
astModule
510-
);
528+
let namespaceImport: AstNamespaceImport | undefined =
529+
this._astNamespaceImportByModule.get(astModule);
511530
if (namespaceImport === undefined) {
512531
namespaceImport = new AstNamespaceImport({
513532
namespaceName: declarationSymbol.name,

0 commit comments

Comments
 (0)