spatools / ts2jsdoc

A JSDoc plugin with an optional template which automatically adds JSDoc comments based on Typescript definitions.
MIT License
13 stars 5 forks source link

Cannot read property 'type' of null at common.js:6 #1

Closed evil-shrike closed 8 years ago

evil-shrike commented 9 years ago
C:\Work\src\lib>ts2jsdoc --module amd --target es5 core.ts
Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\common.js:6
    var nodeType = node.type;
                       ^
TypeError: Cannot read property 'type' of null
    at addTypeToTag (Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\common.js:6:24)
    at Object.addName (Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\common.js:65:13)
    at Object.forVar (Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\syntax.js:16:16)
    at Object.process (Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\processor.js:36:20)
    at createComments (Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\ast.js:20:15)
    at Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\ast.js:22:9
    at children (Z:\Prog\nodejs\node_modules\typescript\bin\typescriptServices.js:3476:34)
    at Object.forEachChild (Z:\Prog\nodejs\node_modules\typescript\bin\typescriptServices.js:3565:52)
    at createComments (Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\ast.js:21:8)
    at Z:\Prog\nodejs\node_modules\ts2jsdoc\lib\ast.js:22:9

common.js at lineno 65 addName calls to function addTypeToTag with null for 3rd argument:

function addName(comments, tagName, node, checker) {
    var tag = comments.getOrAddTag(tagName), nodeType = node.type, initializer = node.initializer;
    tag.name = utils.getNodeName(node);
    if (checker) {
        if (nodeType) {
            addTypeToTag(comments, tag, node, checker);
        }
        if (initializer && initializer.kind === 6 /* FirstLiteralToken */) {
            if (tagName === "member") {
                comments.getOrAddTag("default").name = initializer.getText();
            }
            else {
                tag.name += "=" + initializer.getText();
            }
        }
        if (initializer && !nodeType) {
            addTypeToTag(comments, tag, null, checker, initializer.contextualType);6
        }
    }
}

But addTypeToTag doesn't expect null for its 3rd arg (node):

function addTypeToTag(comments, tag, node, checker, type) {
    var nodeType = node.type;
SomaticIT commented 8 years ago

Hi,

As of now, you should use ts2jsdoc only on declaration files (.d.ts). But the project is outdated and need some help to be upgraded to Typescript 1.8+

Thanks.