Microsoft/TypeScript

JSDoc comment nodes are not traversed and their parents are sent even if they should not

开放

#14,575 创建于 2017年3月10日

 (3 条评论) (1 个反应) (0 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: APIDomain: JSDocHelp Wanted

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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 JSDocComment nodes parents not to be set.
  • Expected JSDocComment nodes to be traversed using forEachChild.

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.

贡献者指南