MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / extractMethodDocs

Function extractMethodDocs

lib/command/list.js:66–122  ·  view source on GitHub ↗
(helper, helperName, config, testsPath, partials)

Source from the content-addressed store, hash-verified

64}
65
66function extractMethodDocs(helper, helperName, config, testsPath, partials) {
67 const result = new Map()
68 const sourceFile = resolveHelperSource(helper, helperName, config, testsPath)
69 if (!sourceFile) return result
70
71 let source
72 try {
73 source = fs.readFileSync(sourceFile, 'utf8')
74 } catch {
75 return result
76 }
77
78 const comments = []
79 let ast
80 try {
81 ast = acorn.parse(source, {
82 ecmaVersion: 'latest',
83 sourceType: 'module',
84 locations: true,
85 onComment: comments,
86 })
87 } catch {
88 return result
89 }
90
91 const classNode = findClassNode(ast)
92 if (!classNode) return result
93
94 const blockComments = comments
95 .filter(c => c.type === 'Block' && c.value.startsWith('*'))
96 .sort((a, b) => a.start - b.start)
97
98 let cursor = 0
99 for (const member of classNode.body.body) {
100 if (member.type !== 'MethodDefinition') continue
101 if (member.kind === 'constructor' || member.static) continue
102 const name = member.key?.name
103 if (!name || name.startsWith('_')) continue
104
105 let attached = null
106 let attachedIdx = -1
107 for (let i = cursor; i < blockComments.length; i++) {
108 const c = blockComments[i]
109 if (c.end > member.start) break
110 attached = c
111 attachedIdx = i
112 }
113 if (attached) {
114 cursor = attachedIdx + 1
115 const stripped = stripJsDoc(attached.value)
116 const resolved = resolvePartials(stripped, partials)
117 result.set(name, resolved)
118 }
119 }
120
121 return result
122}
123

Callers 1

list.jsFile · 0.85

Calls 5

resolveHelperSourceFunction · 0.85
findClassNodeFunction · 0.85
stripJsDocFunction · 0.85
resolvePartialsFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected