/
function-extractor.ts
33 lines (30 loc) 路 1.24 KB
/
function-extractor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {EntryType, FunctionEntry, ParameterEntry} from '@angular/compiler-cli/src/ngtsc/docs/src/entities';
import ts from 'typescript';
/** Extracts docs for a function, including class method declarations. */
export function extractFunction(fn: ts.FunctionDeclaration|ts.MethodDeclaration): FunctionEntry {
return {
params: extractAllParams(fn.parameters),
// We know that the function has a name here because we would have skipped it
// already before getting to this point if it was anonymous.
name: fn.name!.getText(),
returnType: 'TODO',
entryType: EntryType.function,
};
}
/** Extracts doc info for a collection of function parameters. */
function extractAllParams(params: ts.NodeArray<ts.ParameterDeclaration>): ParameterEntry[] {
// TODO: handle var args
return params.map(param => ({
name: param.name.getText(),
description: 'TODO',
type: 'TODO',
isOptional: !!(param.questionToken || param.initializer),
}));
}