microsoft / microsoft/TypeScript

`getJSDocTags` detects decorators inside code blocks as JSDoc tags

Offen
#58,992 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 Search Terms
  • jsdoc
  • getJSDocTags
  • decorators
🕗 Version & Regression Information

This is faulty behavior

⏯ Playground Link

https://stackblitz.com/edit/gettextofjsdoccomment-d88fzj?file=main.ts,package.json

💻 Code
import ts from 'typescript';

const filename = 'example.ts';
const code = `
/** 
 * 
 * @usageNotes
 *
 * Use \`afterNextRender\` to read or write the DOM once,
 * for example to initialize a non-Angular library.
 *
 * ### Example
 * \`\`\`ts
 * @Component({
 *   selector: 'my-chart-cmp',
 *   template: \`<div #chart>{{ ... }}</div>\`,
 * })
 * export class MyChartCmp {
 *   @ViewChild('chart') chartRef: ElementRef;
 *   chart: MyChart|null;
 *
 *   constructor() {
 * 
 *   }
 * }
 * \`\`\`
 */
class Foo  {};
`;

const sourceFile = ts.createSourceFile(
  filename,
  code,
  ts.ScriptTarget.ESNext,
  true
);

const visitNode = (node: ts.Node) => {
  ts.forEachChild(node, visitNode);
  const tags = ts.getJSDocTags(node);
  if (tags.length) {
    tags.forEach((tag) => {
      const comment = tag.comment!.slice(1) as any;

      console.log(
        '> ',
        tag.tagName.getText(),
        ' | ',
        ts.getTextOfJSDocComment(comment)
      );
    });
  }
};

ts.forEachChild(sourceFile, visitNode);
🙁 Actual behavior

We get 2 distinct tags:

>  usageNotes  |  se `afterNextRender` to read or write the DOM once,
for example to initialize a non-Angular library.

### Example
```ts
>  Component  |  {
selector: 'my-chart-cmp',
template: `<div #chart>{{ ... }}</div>`,
})
export class MyChartCmp {
>  ViewChild  |  'chart') chartRef: ElementRef;
chart: MyChart|null;

constructor() {

}
}
🙂 Expected behavior

Only one tag should be extracted : usagenotes

Additional information about the issue

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der API getJSDocTags und reproduziere das Verhalten anhand des StackBlitz-Beispiels im Issue. Verfolge, wie der JSDoc-Kommentar rund um den fenced code block geparst wird, und überprüfe anschließend, dass nur das usageNotes-Tag extrahiert wird und der decorator-ähnliche Text ignoriert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.