scripts/docgen/generate-docs.js
async function generateNodeSource() {
  const sourceText = await fs.readFile(sourceFile, 'utf8');

  // Parse index.d.ts. A dummy filename is required but it doesn't create a
  // file.
  let typescriptSourceFile = typescript.createSourceFile(
    'temp.d.ts',
    sourceText,
    typescript.ScriptTarget.ES2015,
    /*setParentNodes */ false
  );

  /**
   * Typescript transformer function. Removes nodes tagged with @webonly.
   */
  const removeWebOnlyNodes = context => rootNode => {
    function visit(node) {
      if (
        node.jsDoc &&
        node.jsDoc.some(
          item =>
            item.tags &&
            item.tags.some(tag => tag.tagName.escapedText === 'webonly')
        )
      ) {
        return null;
      }
      return typescript.visitEachChild(node, visit, context);
    }
    return typescript.visitNode(rootNode, visit);
  };

  // Use above transformer on source AST to remove nodes tagged with @webonly.
  const result = typescript.transform(typescriptSourceFile, [
    removeWebOnlyNodes
  ]);

  // Convert transformed AST to text and write to file.
  const printer = typescript.createPrinter();
  return fs.writeFile(
    tempNodeSourcePath,
    printer.printFile(result.transformed[0])
  );
}
async function generateNodeSource() {
  const sourceText = await fs.readFile(sourceFile, 'utf8');

  // Parse index.d.ts. A dummy filename is required but it doesn't create a
  // file.
  let typescriptSourceFile = typescript.createSourceFile(
    'temp.d.ts',
    sourceText,
    typescript.ScriptTarget.ES2015,
    /*setParentNodes */ false
  );

  /**
   * Typescript transformer function. Removes nodes tagged with @webonly.
   */
  const removeWebOnlyNodes = context => rootNode => {
    function visit(node) {
      if (
        node.jsDoc &&
        node.jsDoc.some(
          item =>
            item.tags &&
            item.tags.some(tag => tag.tagName.escapedText === 'webonly')
        )
      ) {
        return null;
      }
      return typescript.visitEachChild(node, visit, context);
    }
    return typescript.visitNode(rootNode, visit);
  };

  // Use above transformer on source AST to remove nodes tagged with @webonly.
  const result = typescript.transform(typescriptSourceFile, [
    removeWebOnlyNodes
  ]);

  // Convert transformed AST to text and write to file.
  const printer = typescript.createPrinter();
  return fs.writeFile(
    tempNodeSourcePath,
    printer.printFile(result.transformed[0])
  );
}
async function generateNodeSource ( ) { const sourceText = await fs . readFile ( sourceFile , 'utf8' ) ; // Parse index.d.ts. A dummy filename is required but it doesn't create a // file. let typescriptSourceFile = typescript . createSourceFile ( 'temp.d.ts' , sourceText , typescript . ScriptTarget . ES2015 , /*setParentNodes */ false ) ; /**
   * Typescript transformer function. Removes nodes tagged with @webonly.
   */ const removeWebOnlyNodes = context => rootNode => { function visit ( node ) { if ( node . jsDoc && node . jsDoc . some ( item => item . tags && item . tags . some ( tag => tag . tagName . escapedText === 'webonly' ) ) ) { return null ; } return typescript . visitEachChild ( node , visit , context ) ; } return typescript . visitNode ( rootNode , visit ) ; } ; // Use above transformer on source AST to remove nodes tagged with @webonly. const result = typescript . transform ( typescriptSourceFile , [ removeWebOnlyNodes ] ) ; // Convert transformed AST to text and write to file. const printer = typescript . createPrinter ( ) ; return fs . writeFile ( tempNodeSourcePath , printer . printFile ( result . transformed [ 0 ] ) ) ; }
Generate an temporary abridged version of index.d.ts used to create
Node docs.
Generate an temporary abridged version of index . d . ts used to create Node docs .