Skip to content

Commit f691747

Browse files
committed
Fix: syntax error in resulting d.ts file
1 parent 86d53ab commit f691747

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

apps/api-extractor/src/generators/ApiReportGenerator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { AstNamespaceImport } from '../analyzer/AstNamespaceImport';
2121
import type { AstEntity } from '../analyzer/AstEntity';
2222
import type { IAstModuleExportInfo } from '../analyzer/AstModule';
2323
import { SourceFileLocationFormatter } from '../analyzer/SourceFileLocationFormatter';
24+
import { SyntaxHelpers } from '../analyzer/SyntaxHelpers';
2425
import { ExtractorMessageId } from '../api/ExtractorMessageId';
2526
import type { ApiReportVariant } from '../api/IConfigFile';
2627
import type { SymbolMetadata } from '../collector/SymbolMetadata';
@@ -224,7 +225,10 @@ export class ApiReportGenerator {
224225
if (collectorEntity.nameForEmit === exportedName) {
225226
exportClauses.push(collectorEntity.nameForEmit);
226227
} else {
227-
exportClauses.push(`${collectorEntity.nameForEmit} as ${exportedName}`);
228+
const safeExportedName: string = SyntaxHelpers.isSafeUnquotedMemberIdentifier(exportedName)
229+
? exportedName
230+
: JSON.stringify(exportedName);
231+
exportClauses.push(`${collectorEntity.nameForEmit} as ${safeExportedName}`);
228232
}
229233
}
230234
writer.writeLine(exportClauses.join(',\n'));

apps/api-extractor/src/generators/DtsRollupGenerator.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { DeclarationMetadata } from '../collector/DeclarationMetadata';
2121
import { AstNamespaceImport } from '../analyzer/AstNamespaceImport';
2222
import type { IAstModuleExportInfo } from '../analyzer/AstModule';
2323
import { SourceFileLocationFormatter } from '../analyzer/SourceFileLocationFormatter';
24+
import { SyntaxHelpers } from '../analyzer/SyntaxHelpers';
2425
import type { AstEntity } from '../analyzer/AstEntity';
2526

2627
/**
@@ -216,7 +217,10 @@ export class DtsRollupGenerator {
216217
if (collectorEntity.nameForEmit === exportedName) {
217218
exportClauses.push(collectorEntity.nameForEmit);
218219
} else {
219-
exportClauses.push(`${collectorEntity.nameForEmit} as ${exportedName}`);
220+
const safeExportedName: string = SyntaxHelpers.isSafeUnquotedMemberIdentifier(exportedName)
221+
? exportedName
222+
: JSON.stringify(exportedName);
223+
exportClauses.push(`${collectorEntity.nameForEmit} as ${safeExportedName}`);
220224
}
221225
}
222226
writer.writeLine(exportClauses.join(',\n'));

0 commit comments

Comments
 (0)