Microsoft/TypeScript

JSDocTag width is inconsistent

Open

#35 455 ouverte le 3 déc. 2019

Voir sur GitHub
 (6 commentaires) (0 réactions) (1 assigné)TypeScript (6 726 forks)batch import
BugDomain: JSDocEffort: ModerateHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

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.

Guide contributeur