Microsoft/TypeScript

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

Ouverte

#14 575 ouverte le 10 mars 2017

 (3 commentaires) (1 réaction) (0 personne assignée)TypeScript (13 395 forks)batch import
BugDomain: APIDomain: JSDocHelp Wanted

Métriques du dépôt

Stars
 (108 860 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

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 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.

Guide contributeur