From 8ab9119cf69c6a769a295179e5eab7b55449294c Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Fri, 6 Jul 2018 14:53:44 -0500 Subject: [PATCH] Fix a double dash in the previewer if an @param jsdoc tag has a hyphen after the param name (#53365) * Fix a double dash if the @param has a hyphen * Moved into the other regex * Add test for ignoring hypen after @param * Fixed test and moved to previewer.test.ts --- .../src/test/previewer.test.ts | 22 +++++++++++++++++++ .../src/utils/previewer.ts | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 extensions/typescript-language-features/src/test/previewer.test.ts diff --git a/extensions/typescript-language-features/src/test/previewer.test.ts b/extensions/typescript-language-features/src/test/previewer.test.ts new file mode 100644 index 00000000000..011187b2af4 --- /dev/null +++ b/extensions/typescript-language-features/src/test/previewer.test.ts @@ -0,0 +1,22 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as assert from 'assert'; +import 'mocha'; +import { tagsMarkdownPreview } from '../utils/previewer'; + +suite('typescript.previewer', () => { + test('Should ignore hyphens after a param tag', async () => { + assert.strictEqual( + tagsMarkdownPreview([ + { + name: 'param', + text: 'a - b' + } + ]), + '*@param* `a` — b'); + }); +}); + diff --git a/extensions/typescript-language-features/src/utils/previewer.ts b/extensions/typescript-language-features/src/utils/previewer.ts index 647ae3bf91b..ce10fcbbe04 100644 --- a/extensions/typescript-language-features/src/utils/previewer.ts +++ b/extensions/typescript-language-features/src/utils/previewer.ts @@ -27,7 +27,7 @@ function getTagBodyText(tag: Proto.JSDocTagInfo): string | undefined { function getTagDocumentation(tag: Proto.JSDocTagInfo): string | undefined { switch (tag.name) { case 'param': - const body = (tag.text || '').split(/^([\w\.]+)\s*/); + const body = (tag.text || '').split(/^([\w\.]+)\s*-?\s*/); if (body && body.length === 3) { const param = body[1]; const doc = body[2]; @@ -81,4 +81,4 @@ export function addMarkdownDocumentation( out.appendMarkdown('\n\n' + tagsPreview); } return out; -} \ No newline at end of file +}