Skip to content

JSDocTag - Nodes on properties do not have parent set when setParentNodes is true #28331

@dsherret

Description

@dsherret

TypeScript Version: 3.2.0-dev.20181103

Search Terms: jsdoc no parent

Code

import * as ts from "typescript";

console.log(ts.version);

const testFilePath = "/file.ts";
const testFileText = `
class Test {
    /** @internal */
    test() {
    }
}
`;

const testSourceFile = ts.createSourceFile(testFilePath, testFileText, ts.ScriptTarget.Latest, true);
const classDec = testSourceFile.statements.find(ts.isClassDeclaration)!;
const method = classDec.members.find(ts.isMethodDeclaration)!;
const tag = ts.getJSDocTags(method)[0];
const tagName = tag.tagName; // also happens with atToken

console.log(tag.parent != null); // true, good
console.log(tagName.parent); // undefined, problem

Expected behavior: Should return the tag as the parent.

Actual behavior: Returns undefined.

IdentifierObject {
  pos: 23,
  end: 31,
  flags: 0,
  parent: undefined,
  escapedText: 'internal'
}

Fix?

I believe the fix here would be to have forEachChild visit the tagName and atToken for JSDocTags and the nodes that extend them. I'm not sure though...

tag.forEachChild(node => {
    console.log("here"); // never happens
});

Metadata

Metadata

Assignees

Labels

APIRelates to the public API for TypeScriptBugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generation

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions