microsoft / microsoft/TypeScript
`getJSDocTags` detects decorators inside code blocks as JSDoc tags
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the getJSDocTags API and reproduce the behavior using the StackBlitz example in the issue. Trace how the JSDoc comment is parsed around the fenced code block, then verify that only the usageNotes tag is extracted and the decorator-like text is ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100