UNPKG

esdoc

Version:

Good Documentation Generator For JavaScript

53 lines (45 loc) 1.45 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _AbstractDoc = require('./AbstractDoc.js'); var _AbstractDoc2 = _interopRequireDefault(_AbstractDoc); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Doc Class from Variable Declaration AST node. */ class VariableDoc extends _AbstractDoc2.default { /** specify ``variable`` to kind. */ _$kind() { super._$kind(); this._value.kind = 'variable'; } /** set name by using self node. */ _$name() { super._$name(); const type = this._node.declarations[0].id.type; switch (type) { case 'Identifier': this._value.name = this._node.declarations[0].id.name; break; case 'ObjectPattern': // TODO: optimize for multi variables. // e.g. export const {a, b} = obj this._value.name = this._node.declarations[0].id.properties[0].key.name; break; case 'ArrayPattern': // TODO: optimize for multi variables. // e.g. export cont [a, b] = arr this._value.name = this._node.declarations[0].id.elements.find(v => v).name; break; default: throw new Error(`unknown declarations type: ${type}`); } } /** set memberof by using file path. */ _$memberof() { super._$memberof(); this._value.memberof = this._pathResolver.filePath; } } exports.default = VariableDoc;