Skip to content

Commit 8f9bc7b

Browse files
authored
fix(vue): Make vue parser tolerant of components that don't contain scripts (#1061)
Fixes #1060
1 parent d2516e5 commit 8f9bc7b

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

__tests__/__snapshots__/test.js.snap

+2
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ Array [
558558
]
559559
`;
560560

561+
exports[`Vue file 2`] = `Array []`;
562+
561563
exports[`config 1`] = `
562564
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
563565

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div>not relevant</div>
3+
</template>
4+
5+
<style>
6+
7+
</style>

__tests__/test.js

+10
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ test('Vue file', async function() {
242242
expect(data).toMatchSnapshot();
243243
});
244244

245+
test('Vue file', async function() {
246+
await pify(chdir)(__dirname);
247+
const data = await documentation.build(
248+
'__tests__/fixture/vue-no-script.input.vue',
249+
{}
250+
);
251+
normalize(data);
252+
expect(data).toMatchSnapshot();
253+
});
254+
245255
test('Use Source attribute only', async function() {
246256
await pify(chdir)(__dirname);
247257
const documentationSource = `

src/parsers/vue.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const vuecompiler = require('vue-template-compiler');
1212
* @returns {Array<Object>} an array of parsed comments
1313
*/
1414
function parseVueScript(data: Object, config: DocumentationConfig) {
15-
data.source = vuecompiler.parseComponent(data.source).script.content;
15+
const component = vuecompiler.parseComponent(data.source);
16+
if (!component.script) return [];
17+
data.source = component.script.content;
1618
return parseJavaScript(data, config);
1719
}
1820

0 commit comments

Comments
 (0)