Skip to content

Commit

Permalink
Correct handling of comment tags on function type aliases
Browse files Browse the repository at this point in the history
Resolves #1734.
  • Loading branch information
Gerrit0 committed Oct 10, 2021
1 parent d6fc617 commit 0d04c08
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
- Fixed flash when navigating to a second page when OS theme does not match selected theme, #1709.
- Fixed improper quoting of `as const` style enums, #1727.
- Fixed handling of `@typeParam` on type aliases, #1733.
- Fixed handling of comment tags on function type aliases, #1734.

### Thanks!

Expand Down
4 changes: 3 additions & 1 deletion src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -346,7 +346,9 @@ export class CommentPlugin extends ConverterComponent {
childComment.shortText ||= comment.shortText;
childComment.text ||= comment.text;
childComment.returns ||= comment.returns;
childComment.tags ||= [...comment.tags];
childComment.tags = childComment.tags.length
? childComment.tags
: [...comment.tags];
}

signature.parameters?.forEach((parameter, index) => {
Expand Down
6 changes: 2 additions & 4 deletions src/test/converter.test.ts
@@ -1,7 +1,6 @@
import { deepStrictEqual as equal, ok } from "assert";
import * as FS from "fs";
import * as Path from "path";
import type * as ts from "typescript";
import { normalizePath, ProjectReflection, resetReflectionID } from "..";
import { getExpandedEntryPointsForPaths } from "../lib/utils";
import {
Expand All @@ -13,10 +12,9 @@ import {
describe("Converter", function () {
const base = getConverterBase();
const app = getConverterApp();
let program: ts.Program;

it("Compiles", () => {
program = getConverterProgram();
getConverterProgram();
});

const checks: [string, () => void, () => void][] = [
Expand Down Expand Up @@ -63,7 +61,7 @@ describe("Converter", function () {
app.logger,
[path],
app.options,
[program]
[getConverterProgram()]
);
ok(entryPoints, "Failed to get entry points");
result = app.converter.convert(entryPoints);
Expand Down
6 changes: 3 additions & 3 deletions src/test/converter2.test.ts
@@ -1,7 +1,6 @@
import { ok } from "assert";
import { existsSync } from "fs";
import { join } from "path";
import type * as ts from "typescript";
import type { ProjectReflection } from "../lib/models";
import { behaviorTests } from "./behaviorTests";
import { issueTests } from "./issueTests";
Expand All @@ -13,14 +12,15 @@ import {

const base = getConverter2Base();
const app = getConverter2App();
let program: ts.Program;

function runTest(
title: string,
entry: string,
check: (project: ProjectReflection) => void
) {
it(title, () => {
const program = getConverter2Program();

const entryPoint = [
join(base, `${entry}.ts`),
join(base, `${entry}.d.ts`),
Expand All @@ -46,7 +46,7 @@ function runTest(

describe("Converter2", () => {
it("Compiles", () => {
program = getConverter2Program();
getConverter2Program();
});

for (const [entry, check] of Object.entries(issueTests)) {
Expand Down
4 changes: 4 additions & 0 deletions src/test/converter2/issues/gh1734.ts
@@ -0,0 +1,4 @@
/**
* @asdf Some example text
*/
export type Foo = (arg: string) => string;
16 changes: 16 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -5,6 +5,9 @@ import {
QueryType,
ReflectionKind,
SignatureReflection,
ReflectionType,
Comment,
CommentTag,
} from "../lib/models";

function query(project: ProjectReflection, name: string) {
Expand Down Expand Up @@ -242,4 +245,17 @@ export const issueTests: {
const cls = query(project, "Bar");
equal(cls.typeParameters?.[0].comment?.shortText.trim(), "T docs");
},

gh1734(project) {
const alias = query(project, "Foo");
const type = alias.type;
ok(type instanceof ReflectionType);

const expectedComment = new Comment();
expectedComment.returns = undefined;
expectedComment.tags = [
new CommentTag("asdf", void 0, "Some example text\n"),
];
equal(type.declaration.signatures?.[0].comment, expectedComment);
},
};

0 comments on commit 0d04c08

Please sign in to comment.