microsoft / microsoft/TypeScript

`getJSDocTags` detects decorators inside code blocks as JSDoc tags

Aperta
#58,992 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con l’API getJSDocTags e riproduci il comportamento usando l’esempio StackBlitz nell’issue. Traccia il modo in cui il commento JSDoc viene analizzato intorno al fenced code block, quindi verifica che venga estratto solo il tag usageNotes e che il testo simile a un decoratore venga ignorato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.