Skip to content

Commit

Permalink
fix: add support Vue 3 fixed documentationjs#1339
Browse files Browse the repository at this point in the history
Vue dependencies was moved to optionalDependencies
So, that mean if you need Vue support you also have to add in own package.json
new dependency for Vue 2 is vue-template-compiler, Vue 3 is @vue/compiler-sfc
  • Loading branch information
anthony-redFox committed Apr 21, 2021
1 parent 8a3b15d commit 931eb77
Show file tree
Hide file tree
Showing 3 changed files with 279 additions and 5 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@
"vfile-sort": "^2.1.0",
"vinyl": "^2.1.0",
"vinyl-fs": "^3.0.2",
"vue-template-compiler": "^2.5.16",
"yargs": "^15.3.1"
},
"optionalDependencies": {
"vue-template-compiler": "^2.6.12",
"@vue/compiler-sfc": "^3.0.11"
},
"devDependencies": {
"chdir": "0.0.0",
"cz-conventional-changelog": "2.1.0",
Expand Down
18 changes: 16 additions & 2 deletions src/parsers/vue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const parseJavaScript = require('./javascript');
const vuecompiler = require('vue-template-compiler');

/**
* Receives a module-dep item,
Expand All @@ -10,9 +9,24 @@ const vuecompiler = require('vue-template-compiler');
* @returns {Array<Object>} an array of parsed comments
*/
function parseVueScript(data, config) {
const component = vuecompiler.parseComponent(data.source);
let component = {};
try {
const vuecompiler = require('@vue/compiler-sfc');
component = vuecompiler.parse(data.source).descriptor;
} catch (e) {
try {
const vuecompiler = require('vue-template-compiler');
component = vuecompiler.parseComponent(data.source);
} catch (e) {
console.error(
'You need to load package vue-template-compiler for Vue 2 or @vue/compiler-sfc for Vue 3'
);
}
}

if (!component.script) return [];
data.source = component.script.content;

return parseJavaScript(data, config);
}

Expand Down
Loading

0 comments on commit 931eb77

Please sign in to comment.