question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose API for getting JSDoc nodes in TypeScript files

See original GitHub issue

Closure adds various semantic JSDoc annotations that aren’t currently modeled by TypeScript, such as @export (unrelated to TS export) and @nosideeffects. https://developers.google.com/closure/compiler/docs/js-for-compiler#overview

As part of our tool chain to run TypeScript through Closure we’d like to be able to munge these via the TypeScript API. It appears TypeScript gathers JSDoc comments when parsing JavaScript – is there a good reason to not gather these in TypeScript as well?

Specifically, I believe my suggestion amounts to removing the “if” statement in the below code (though I’m not certain this is the right place) in parser.ts:

        function addJSDocComment<T extends Node>(node: T): T {
            if (contextFlags & NodeFlags.JavaScriptFile) {
                ...all of the code is in here...
            }
        }

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:3
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

8reactions
evmarcommented, Jan 9, 2017

It appears that TS maybe now gathers JSDoc always. That is, given a ts.Node you can call getDocumentationComment() on it and it updates the (internal property) node.jsDoc (and does some caching).

However, there’s still no way to get at the parsed JSDoc there. getDocumentationComment() only returns the comment portion of the JSDoc, not the tags. So my request still stands, but now it’s just a request to expose API to retrieve the full JSDoc of a node.

5reactions
tonyhallettcommented, Aug 15, 2018

I have not checked every code path but it does appear that Parser.parseSourceFile will call createNodeWithJsDoc for JsDocContainer nodes. Can we just remove the internal comment ?

export interface JSDocContainer {
        /* @internal */ jsDoc?: JSDoc[];                      // JSDoc that directly precedes this node
        /* @internal */ jsDocCache?: ReadonlyArray<JSDocTag>; // Cache for getJSDocTags
    }

To save doing var classDeclaration:ts.ClassDeclaration=getFromSomewhere(); var jsDocs=:ts.JSDoc[]=(classDeclaration as any).jsDoc

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSDoc Reference - TypeScript: Documentation
JSDoc Reference. The list below outlines which constructs are currently supported when using JSDoc annotations to provide type information in JavaScript files.
Read more >
How to Document an Express API with Swagger UI and JSDoc
In your Express API's app. js file, add the following code below the list of required modules: // app. js const swaggerJSDoc =...
Read more >
Is there any way to use `jsdoc` with `.ts` files? Maybe transpile ...
Although as stated by @Remi TypeDoc is a better fit for TypeScript, I use JSDoc for better jsdoc to markdown conversion (as of...
Read more >
express-jsdoc-swagger
exposeApiDocs : false, // Open API JSON Docs endpoint. ... baseDir: __dirname, // Glob pattern to find your jsdoc files (multiple patterns can...
Read more >
NodeJS Swagger API Documentation Tutorial ... - YouTube
In this video we'll build an ExpressJS CRUD application and document it using Swagger. We'll use swagger- jsdoc to write the specs and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found