Reference Source Test

src/Doc/FunctionDoc.js

  1. import babelGenerator from 'babel-generator';
  2. import AbstractDoc from './AbstractDoc.js';
  3. import NamingUtil from '../Util/NamingUtil.js';
  4.  
  5. /**
  6. * Doc Class from Function declaration AST node.
  7. */
  8. export default class FunctionDoc extends AbstractDoc {
  9. /** specify ``function`` to kind. */
  10. _$kind() {
  11. super._$kind();
  12. this._value.kind = 'function';
  13. }
  14.  
  15. /** take out self name from self node */
  16. _$name() {
  17. super._$name();
  18.  
  19. if (this._node.id) {
  20. if (this._node.id.type === 'MemberExpression') {
  21. // e.g. foo[bar.baz] = function bal(){}
  22. const expression = babelGenerator(this._node.id).code;
  23. this._value.name = `[${expression}]`;
  24. } else {
  25. this._value.name = this._node.id.name;
  26. }
  27. } else {
  28. this._value.name = NamingUtil.filePathToName(this._pathResolver.filePath);
  29. }
  30. }
  31.  
  32. /** take out self name from file path */
  33. _$memberof() {
  34. super._$memberof();
  35. this._value.memberof = this._pathResolver.filePath;
  36. }
  37.  
  38. /** check generator property in self node */
  39. _$generator() {
  40. super._$generator();
  41. this._value.generator = this._node.generator;
  42. }
  43.  
  44. /**
  45. * use async property of self node.
  46. */
  47. _$async() {
  48. super._$async();
  49. this._value.async = this._node.async;
  50. }
  51. }