Skip to content

Commit

Permalink
fix: Support for JSDoc @enum tags
Browse files Browse the repository at this point in the history
Resolves #1464
  • Loading branch information
Gerrit0 committed Jan 16, 2021
1 parent 5726d48 commit 66c1652
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/lib/converter/jsdoc.ts
Expand Up @@ -19,10 +19,10 @@ import {
convertTypeParameterNodes,
} from "./factories/signature";

export function convertJsDocTypedef(
export function convertJsDocAlias(
context: Context,
symbol: ts.Symbol,
declaration: ts.JSDocTypedefTag,
declaration: ts.JSDocTypedefTag | ts.JSDocEnumTag,
nameOverride?: string
) {
if (
Expand Down Expand Up @@ -69,7 +69,7 @@ export function convertJsDocCallback(

function convertJsDocInterface(
context: Context,
declaration: ts.JSDocTypedefTag,
declaration: ts.JSDocTypedefTag | ts.JSDocEnumTag,
symbol: ts.Symbol,
nameOverride?: string
) {
Expand Down
15 changes: 10 additions & 5 deletions src/lib/converter/symbols.ts
Expand Up @@ -15,7 +15,7 @@ import { convertDefaultValue } from "./convert-expression";
import { ConverterEvents } from "./converter-events";
import { convertIndexSignature } from "./factories/index-signature";
import { createSignature } from "./factories/signature";
import { convertJsDocCallback, convertJsDocTypedef } from "./jsdoc";
import { convertJsDocAlias, convertJsDocCallback } from "./jsdoc";

function getSymbolExportsWithFlag(symbol: ts.Symbol, flag: ts.SymbolFlags) {
const childSymbols: ts.Symbol[] = [];
Expand Down Expand Up @@ -191,10 +191,12 @@ function convertTypeAlias(
): d is
| ts.TypeAliasDeclaration
| ts.JSDocTypedefTag
| ts.JSDocCallbackTag =>
| ts.JSDocCallbackTag
| ts.JSDocEnumTag =>
ts.isTypeAliasDeclaration(d) ||
ts.isJSDocTypedefTag(d) ||
ts.isJSDocCallbackTag(d)
ts.isJSDocCallbackTag(d) ||
ts.isJSDocEnumTag(d)
);
assert(declaration);

Expand All @@ -213,8 +215,11 @@ function convertTypeAlias(
reflection.typeParameters = declaration.typeParameters?.map((param) =>
createTypeParamReflection(param, context.withScope(reflection))
);
} else if (ts.isJSDocTypedefTag(declaration)) {
convertJsDocTypedef(context, symbol, declaration, nameOverride);
} else if (
ts.isJSDocTypedefTag(declaration) ||
ts.isJSDocEnumTag(declaration)
) {
convertJsDocAlias(context, symbol, declaration, nameOverride);
} else {
convertJsDocCallback(context, symbol, declaration, nameOverride);
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/converter/js/index.js
Expand Up @@ -51,3 +51,9 @@

/** @type {Foo} */
export const usedFoo = () => 1;

/** @enum {string} */
export const ColumnType = {
STRING: "string",
NUMBER: "number",
};

0 comments on commit 66c1652

Please sign in to comment.