From 028a1410582151e0699752d932e4c83de095f9d1 Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Fri, 25 Aug 2023 13:05:15 -0600 Subject: [PATCH] feat(default-value): treat as code block for better styling (#2370) * feat(default-value): treat as code block for better styling * refactor(parser): consider defaultValue * chore: apply prettier --- src/lib/converter/comments/parser.ts | 5 ++++- src/test/behavior.c2.test.ts | 13 +++++++++++++ src/test/converter2/behavior/defaultValueTag.ts | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/converter2/behavior/defaultValueTag.ts diff --git a/src/lib/converter/comments/parser.ts b/src/lib/converter/comments/parser.ts index eea8bb4b1..6fcf65fd3 100644 --- a/src/lib/converter/comments/parser.ts +++ b/src/lib/converter/comments/parser.ts @@ -215,7 +215,10 @@ function blockTag( let content: CommentDisplayPart[]; if (tagName === "@example" && config.jsDocCompatibility.exampleTag) { content = exampleBlockContent(comment, lexer, config, warning); - } else if (tagName === "@default" && config.jsDocCompatibility.defaultTag) { + } else if ( + (tagName === "@default" && config.jsDocCompatibility.defaultTag) || + tagName === "@defaultValue" + ) { content = defaultBlockContent(comment, lexer, config, warning); } else { content = blockContent(comment, lexer, config, warning); diff --git a/src/test/behavior.c2.test.ts b/src/test/behavior.c2.test.ts index 177568362..181802eb3 100644 --- a/src/test/behavior.c2.test.ts +++ b/src/test/behavior.c2.test.ts @@ -277,6 +277,19 @@ describe("Behavior Tests", () => { logger.expectNoOtherMessages(); }); + it("Handles @defaultValue tags", () => { + const project = convert("defaultValueTag"); + const foo = query(project, "foo"); + const tags = foo.comment?.blockTags.map((tag) => tag.content); + + equal(tags, [ + [{ kind: "code", text: "```ts\n\n```" }], + [{ kind: "code", text: "```ts\nfn({})\n```" }], + ]); + + logger.expectNoOtherMessages(); + }); + it("Handles @example tags with JSDoc compat turned on", () => { const project = convert("exampleTags"); const foo = query(project, "foo"); diff --git a/src/test/converter2/behavior/defaultValueTag.ts b/src/test/converter2/behavior/defaultValueTag.ts new file mode 100644 index 000000000..3823d6667 --- /dev/null +++ b/src/test/converter2/behavior/defaultValueTag.ts @@ -0,0 +1,5 @@ +/** + * @defaultValue + * @defaultValue fn({}) + */ +export const foo = 1;