Reference Source Test
import DocFactory from 'esdoc2/out/src/Factory/DocFactory.js'
public class | source

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
private

_results: *[]

Method Summary

Public Methods
public

push(node: ASTNode, parentNode: ASTNode)

push node, and factory processes node.

Private Methods
private

deep copy object.

private

_createDoc(node: ASTNode, tags: Tag[]): AbstractDoc

create Doc.

private

decide Doc type from arrow function expression node.

private

_decideAssignmentType(node: ASTNode): {type: string, node: ASTNode}

decide Doc type from assignment node.

private

decide Doc type from class declaration node.

private

_decideClassPropertyType(node: ASTNode): {type: ?string, node: ?ASTNode}

decide Doc type from class property node.

private

decide Doc type from expression statement node.

private

decide Doc type from function declaration node.

private

decide Doc type from function expression node.

private

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

_findUp(node: ASTNode, types: string[]): ASTNode | null

find node while goes up.

private

inspect ExportDefaultDeclaration.

private

inspect ExportNamedDeclaration.

private

judge node is last in parent.

private

judge node is top in body.

private

_traverseComments(parentNode: ASTNode | AST, node: ASTNode, comments: ASTNode[]): DocObject[]

traverse comments of node, and create doc object.

private

unwrap exported node.

Public Constructors

public constructor(ast: AST, pathResolver: PathResolver) source

create instance.

Params:

NameTypeAttributeDescription
ast AST

AST of source code.

pathResolver PathResolver

path resolver of source code.

Public Members

public get results: DocObject[] source

Private Members

private _ast: * source

private _pathResolver: * source

private _processedClassNodes: *[] source

private _results: *[] source

Public Methods

public push(node: ASTNode, parentNode: ASTNode) source

push node, and factory processes node.

Params:

NameTypeAttributeDescription
node ASTNode

target node.

parentNode ASTNode

parent node of target node.

Private Methods

private _copy(obj: Object): Object source

deep copy object.

Params:

NameTypeAttributeDescription
obj Object

target object.

Return:

Object

copied object.

private _createDoc(node: ASTNode, tags: Tag[]): AbstractDoc source

create Doc.

Params:

NameTypeAttributeDescription
node ASTNode

target node.

tags Tag[]

tags of target node.

Return:

AbstractDoc

created Doc.

private _decideArrowFunctionExpressionType(node: ASTNode): {type: string, node: ASTNode} source

decide Doc type from arrow function expression node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is arrow function expression node.

Return:

{type: string, node: ASTNode}

decided type.

private _decideAssignmentType(node: ASTNode): {type: string, node: ASTNode} source

decide Doc type from assignment node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is assignment node.

Return:

{type: string, node: ASTNode}

decided type.

private _decideClassDeclarationType(node: ASTNode): {type: string, node: ASTNode} source

decide Doc type from class declaration node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is class declaration node.

Return:

{type: string, node: ASTNode}

decided type.

private _decideClassPropertyType(node: ASTNode): {type: ?string, node: ?ASTNode} source

decide Doc type from class property node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is classs property node.

Return:

{type: ?string, node: ?ASTNode}

decided type.

private _decideExpressionStatementType(node: ASTNode): {type: ?string, node: ?ASTNode} source

decide Doc type from expression statement node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is expression statement node.

Return:

{type: ?string, node: ?ASTNode}

decided type.

private _decideFunctionDeclarationType(node: ASTNode): {type: string, node: ASTNode} source

decide Doc type from function declaration node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is function declaration node.

Return:

{type: string, node: ASTNode}

decided type.

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:

NameTypeAttributeDescription
node ASTNode

target node that is function expression node.

Return:

{type: string, node: ASTNode}

decided type.

TODO:

  • inspect with newer babylon.

private _decideMethodDefinitionType(node: ASTNode): {type: ?string, node: ?ASTNode} source

decide Doc type from method definition node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is method definition node.

Return:

{type: ?string, node: ?ASTNode}

decided type.

private _decideType(tags: Tag[], node: ASTNode): {type: ?string, node: ?ASTNode} source

decide Doc type by using tags and node.

Params:

NameTypeAttributeDescription
tags Tag[]

tags of node.

node ASTNode

target node.

Return:

{type: ?string, node: ?ASTNode}

decided type.

private _decideVariableType(node: ASTNode): {type: string, node: ASTNode} source

decide Doc type from variable node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is variable node.

Return:

{type: string, node: ASTNode}

decided type.

private _findUp(node: ASTNode, types: string[]): ASTNode | null source

find node while goes up.

Params:

NameTypeAttributeDescription
node ASTNode

start node.

types string[]

ASTNode types.

Return:

ASTNode | null

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

Params:

NameTypeAttributeDescription
node ASTNode

target node.

parentNode ASTNode

target parent node.

Return:

boolean

if true, the node is last in parent.

private _isTopDepthInBody(node: ASTNode, body: ASTNode[]): boolean source

judge node is top in body.

Params:

NameTypeAttributeDescription
node ASTNode

target node.

body ASTNode[]

target body node.

Return:

boolean

if true, the node is top in body.

private _traverseComments(parentNode: ASTNode | AST, node: ASTNode, comments: ASTNode[]): DocObject[] source

traverse comments of node, and create doc object.

Params:

NameTypeAttributeDescription
parentNode ASTNode | AST

parent of target node.

node ASTNode
  • nullable: true

target node.

comments ASTNode[]

comment nodes.

Return:

DocObject[]

created doc objects.

private _unwrapExportDeclaration(node: ASTNode): ASTNode | null source

unwrap exported node.

Params:

NameTypeAttributeDescription
node ASTNode

target node that is export declaration node.

Return:

ASTNode | null

unwrapped child node of exported node.