Skip to content

Commit

Permalink
Fix crash when converting undefined default export
Browse files Browse the repository at this point in the history
Closes #2175
Closes #2176

Co-Authored-By: Remi Cattiau <remi@cattiau.com>
  • Loading branch information
Gerrit0 and loopingz committed Feb 26, 2023
1 parent 6ee136a commit 3343cc4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,13 @@
# Unreleased

### Bug Fixes

- Fix crash when converting `export default undefined`, #2175

### Thanks!

- @loopingz

## v0.23.25 (2023-02-11)

### Breaking Changes
Expand Down
11 changes: 6 additions & 5 deletions src/lib/converter/comments/index.ts
Expand Up @@ -103,13 +103,14 @@ export function getComment(
logger: Logger,
commentStyle: CommentStyle
): Comment | undefined {
const declarations = symbol.declarations || [];

if (
symbol
.getDeclarations()
?.every((d) => jsDocCommentKinds.includes(d.kind))
declarations.length &&
declarations.every((d) => jsDocCommentKinds.includes(d.kind))
) {
return getJsDocComment(
symbol.declarations![0] as ts.JSDocPropertyLikeTag,
declarations[0] as ts.JSDocPropertyLikeTag,
config,
logger
);
Expand All @@ -119,7 +120,7 @@ export function getComment(
discoverComment(symbol, kind, logger, commentStyle),
config,
logger,
symbol.declarations?.some(ts.isSourceFile) || false
declarations.some(ts.isSourceFile)
);

if (!comment && kind === ReflectionKind.Property) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/converter2/issues/gh2175.ts
@@ -0,0 +1,5 @@
/**
* `undefined` is special in that it has no declarations, so we can have
* an export without any declarations so long as it is undefined.
*/
export default undefined;
6 changes: 6 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -848,4 +848,10 @@ export const issueTests: {
"Is documented"
);
},

gh2175(project) {
const def = query(project, "default");
equal(def.type?.type, "intrinsic");
equal(def.type.toString(), "undefined");
},
};

0 comments on commit 3343cc4

Please sign in to comment.