Microsoft/TypeScript

JSDocTag width is inconsistent

Open

#35,455 opened on Dec 3, 2019

View on GitHub
 (6 comments) (0 reactions) (1 assignee)TypeScript (48,455 stars) (6,726 forks)batch import
BugDomain: JSDocEffort: ModerateHelp Wanted

Description

TypeScript Version: 3.8.0-dev.20191128

Search Terms: JSDocTag parsing JS doc

Code

import * as ts from "typescript";

console.log(ts.version); // 3.8.0-dev.20191128

const testFilePath = "/file.ts";
const testFileText = `
/**
 * @example Some text.
 * @param someParam - Some text.
 */
function test() {}`;

const testSourceFile = ts.createSourceFile(testFilePath, testFileText, ts.ScriptTarget.Latest, true);
const funcDec = testSourceFile.statements.find(ts.isFunctionDeclaration)!;
const tags = ts.getJSDocTags(funcDec);
const firstTag = tags[0];

console.log(firstTag.getText(testSourceFile)); // "@example"
console.log(firstTag.tagName.getText(testSourceFile)); // "example"
console.log(firstTag.comment); // "Some text."
console.log(firstTag.pos); // 8
console.log(firstTag.end); // 17
console.log(firstTag.getWidth(testSourceFile)); // 9

const secondTag = tags[1];

console.log(secondTag.getText(testSourceFile)); // "@param someParam - SomeText.\n"
console.log(secondTag.tagName.getText(testSourceFile)); // "param"
console.log(secondTag.comment); // "- Some text."
console.log(secondTag.pos); // 31
console.log(secondTag.end); // 62
console.log(secondTag.getWidth(testSourceFile)); // 31

image

image

Expected behavior: The width would act the same for both.

Actual behavior: It's inconsistent or I'm missing something about JSDocParameterTag.

Contributor guide