Skip to content

Commit 0da433c

Browse files
committed
fix: methods have now the good line number
1 parent 01eee1a commit 0da433c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
const config = require('./config');
22
const render = require('./lib/core/renderer');
33
const extractVueScript = require('./lib/core/vueScriptExtractor');
4+
const seekExportDefaultLine = require('./lib/core/seekExportDefaultLine');
45
const vueDataTag = require('./lib/tags/vue-data');
56
const vuePropTag = require('./lib/tags/vue-prop');
67
const vueComputedTag = require('./lib/tags/vue-computed');
78

9+
// Used to compute good line number for Vue methods
10+
const exportDefaultLines = {};
11+
const mainDocletLines = {};
12+
813
exports.handlers = {
914
beforeParse(e) {
1015
if (/\.vue$/.test(e.filename)) {
16+
exportDefaultLines[e.filename] = seekExportDefaultLine(e.source);
1117
e.source = extractVueScript(e.filename);
1218
}
1319
},
1420
newDoclet(e) {
1521
if (e.doclet.meta.filename.endsWith('.vue')) {
22+
const fullPath = `${e.doclet.meta.path}/${e.doclet.meta.filename}`;
1623
const componentName = e.doclet.meta.filename.replace(/\.vue$/, '');
1724

1825
// if (e.doclet.memberof === 'module.exports') {
@@ -23,6 +30,11 @@ exports.handlers = {
2330
// e.doclet.longname = e.doclet.longname.replace('module.exports.', componentName)
2431
// }
2532

33+
// The main doclet before `export default {}`
34+
if (e.doclet.longname === 'module.exports') {
35+
mainDocletLines[fullPath] = e.doclet.meta.lineno;
36+
}
37+
2638
if (e.doclet._isVueDoc) {
2739
const { renderer } = config['jsdoc-vuejs'];
2840
const props = e.doclet._vueProps || [];
@@ -43,6 +55,7 @@ exports.handlers = {
4355
if (e.doclet.memberof.endsWith('.methods')) {
4456
e.doclet.scope = 'instance';
4557
e.doclet.memberof = e.doclet.memberof.replace(/\.methods$/, ''); // force method to be displayed
58+
e.doclet.meta.lineno += exportDefaultLines[fullPath] - mainDocletLines[fullPath];
4659
} else {
4760
e.doclet.memberof = null; // don't include Vue hooks
4861
}

0 commit comments

Comments
 (0)