Microsoft/TypeScript

JSDocTag width is inconsistent

开放

#35,455 创建于 2019年12月3日

 (6 条评论) (0 个反应) (1 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: JSDocEffort: ModerateHelp Wanted

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南