Microsoft/TypeScript
Ver no GitHubJSDoc comment nodes are not traversed and their parents are sent even if they should not
Open
#14.575 aberto em 10 de mar. de 2017
BugDomain: APIDomain: JSDocHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
TypeScript Version: 2.2.1
Code
const ts = require('typescript');
const source = `
/**
* Some fancy comment
*
* @function sum
* @param {number} a
* @param {number} b
* @returns {number}
*/
function sum(a: number, b: number): number {
return a + b;
}
`;
let sourceFile = ts.createSourceFile(
'input.ts',
source,
ts.ScriptTarget.ESNext,
false // <-- don't set parents
);
ts.forEachChild(sourceFile, function (node) {
if (node.kind === ts.SyntaxKind.FunctionDeclaration) {
console.assert(!!node.jsDoc);
console.assert(node.jsDoc.length === 1);
console.assert(node.jsDoc[0].parent === undefined);
} else if (node.kind === ts.SyntaxKind.JSDocComment) {
console.assert(false);
}
});
Expected behavior:
- Expected
JSDocCommentnodes parents not to be set. - Expected
JSDocCommentnodes to be traversed usingforEachChild.
Actual behavior:
When explicitly passing false to createSourceFile for not setting parents in nodes, they are set anyway in all JSDocComment nodes. Also, JSDocComments (and therefore all their children) are not traversed when calling forEachChild. I don't know if that last part is expected behavior, but it is definitely weird that they are not traversed.