DocFactory
Doc factory class.
Example:
let factory = new DocFactory(ast, pathResolver);
factory.push(node, parentNode);
let results = factory.results;
Constructor Summary
Public Constructor | ||
public |
constructor(ast: AST, pathResolver: PathResolver) create instance. |
Member Summary
Public Members | ||
public get |
|
Private Members | ||
private |
_ast: * |
|
private |
|
|
private |
_processedClassNodes: *[] |
|
private |
_results: *[] |
Method Summary
Public Methods | ||
public |
push node, and factory processes node. |
Private Methods | ||
private |
deep copy object. |
|
private |
_createDoc(node: ASTNode, tags: Tag[]): AbstractDoc create Doc. |
|
private |
_decideArrowFunctionExpressionType(node: ASTNode): {type: string, node: ASTNode} decide Doc type from arrow function expression node. |
|
private |
_decideAssignmentType(node: ASTNode): {type: string, node: ASTNode} decide Doc type from assignment node. |
|
private |
_decideClassDeclarationType(node: ASTNode): {type: string, node: ASTNode} decide Doc type from class declaration node. |
|
private |
_decideClassPropertyType(node: ASTNode): {type: ?string, node: ?ASTNode} decide Doc type from class property node. |
|
private |
_decideExpressionStatementType(node: ASTNode): {type: ?string, node: ?ASTNode} decide Doc type from expression statement node. |
|
private |
_decideFunctionDeclarationType(node: ASTNode): {type: string, node: ASTNode} decide Doc type from function declaration node. |
|
private |
_decideFunctionExpressionType(node: ASTNode): {type: string, node: ASTNode} decide Doc type from function expression node. |
|
private |
_decideMethodDefinitionType(node: ASTNode): {type: ?string, node: ?ASTNode} decide Doc type from method definition node. |
|
private |
_decideType(tags: Tag[], node: ASTNode): {type: ?string, node: ?ASTNode} decide Doc type by using tags and node. |
|
private |
_decideVariableType(node: ASTNode): {type: string, node: ASTNode} decide Doc type from variable node. |
|
private |
find node while goes up. |
|
private |
inspect ExportDefaultDeclaration. |
|
private |
inspect ExportNamedDeclaration. |
|
private |
_isLastNodeInParent(node: ASTNode, parentNode: ASTNode): boolean judge node is last in parent. |
|
private |
_isTopDepthInBody(node: ASTNode, body: ASTNode[]): boolean judge node is top in body. |
|
private |
traverse comments of node, and create doc object. |
|
private |
_unwrapExportDeclaration(node: ASTNode): ASTNode | null unwrap exported node. |
Public Constructors
public constructor(ast: AST, pathResolver: PathResolver) source
create instance.
Params:
Name | Type | Attribute | Description |
ast | AST | AST of source code. |
|
pathResolver | PathResolver | path resolver of source code. |
Public Members
Private Members
private _ast: * source
private _pathResolver: * source
private _processedClassNodes: *[] source
private _results: *[] source
Public Methods
Private Methods
private _copy(obj: Object): Object source
deep copy object.
Params:
Name | Type | Attribute | Description |
obj | Object | target object. |
private _createDoc(node: ASTNode, tags: Tag[]): AbstractDoc source
create Doc.
private _decideArrowFunctionExpressionType(node: ASTNode): {type: string, node: ASTNode} source
decide Doc type from arrow function expression node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is arrow function expression node. |
private _decideAssignmentType(node: ASTNode): {type: string, node: ASTNode} source
decide Doc type from assignment node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is assignment node. |
private _decideClassDeclarationType(node: ASTNode): {type: string, node: ASTNode} source
decide Doc type from class declaration node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is class declaration node. |
private _decideClassPropertyType(node: ASTNode): {type: ?string, node: ?ASTNode} source
decide Doc type from class property node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is classs property node. |
private _decideExpressionStatementType(node: ASTNode): {type: ?string, node: ?ASTNode} source
decide Doc type from expression statement node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is expression statement node. |
private _decideFunctionDeclarationType(node: ASTNode): {type: string, node: ASTNode} source
decide Doc type from function declaration node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is function declaration node. |
private _decideFunctionExpressionType(node: ASTNode): {type: string, node: ASTNode} source
decide Doc type from function expression node.
babylon 6.11.2 judgesexport default async function foo(){}
to be FunctionExpression
.
I expect FunctionDeclaration
. this behavior may be bug of babylon.
for now, workaround for it with this method.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is function expression node. |
TODO:
- inspect with newer babylon.
private _decideMethodDefinitionType(node: ASTNode): {type: ?string, node: ?ASTNode} source
decide Doc type from method definition node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is method definition node. |
private _decideType(tags: Tag[], node: ASTNode): {type: ?string, node: ?ASTNode} source
decide Doc type by using tags and node.
private _decideVariableType(node: ASTNode): {type: string, node: ASTNode} source
decide Doc type from variable node.
Params:
Name | Type | Attribute | Description |
node | ASTNode | target node that is variable node. |
private _inspectExportDefaultDeclaration() source
inspect ExportDefaultDeclaration.
case1: separated export
class Foo {}
export default Foo;
case2: export instance(directly).
class Foo {}
export default new Foo();
case3: export instance(indirectly).
class Foo {}
let foo = new Foo();
export default foo;
TODO:
- support function export.
private _inspectExportNamedDeclaration() source
inspect ExportNamedDeclaration.
case1: separated export
class Foo {}
export {Foo};
case2: export instance(indirectly).
class Foo {}
let foo = new Foo();
export {foo};
TODO:
- support function export.
private _isLastNodeInParent(node: ASTNode, parentNode: ASTNode): boolean source
judge node is last in parent.
private _isTopDepthInBody(node: ASTNode, body: ASTNode[]): boolean source
judge node is top in body.