Skip to content

Commit

Permalink
fix(vue): Make vue parser tolerant of components that don't contain s…
Browse files Browse the repository at this point in the history
…cripts

Fixes #1060
  • Loading branch information
tmcw committed Apr 24, 2018
1 parent d2516e5 commit bdc5a27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ Array [
]
`;

exports[`Vue file 2`] = `Array []`;

exports[`config 1`] = `
"<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

Expand Down
7 changes: 7 additions & 0 deletions __tests__/fixture/vue-no-script.input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div>not relevant</div>
</template>

<style>
</style>
10 changes: 10 additions & 0 deletions __tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ test('Vue file', async function() {
expect(data).toMatchSnapshot();
});

test('Vue file', async function() {
await pify(chdir)(__dirname);
const data = await documentation.build(
'__tests__/fixture/vue-no-script.input.vue',
{}
);
normalize(data);
expect(data).toMatchSnapshot();
});

test('Use Source attribute only', async function() {
await pify(chdir)(__dirname);
const documentationSource = `
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const vuecompiler = require('vue-template-compiler');
* @returns {Array<Object>} an array of parsed comments
*/
function parseVueScript(data: Object, config: DocumentationConfig) {
data.source = vuecompiler.parseComponent(data.source).script.content;
const component = vuecompiler.parseComponent(data.source);
if (!component.script) return [];
data.source = component.script.content;
return parseJavaScript(data, config);
}

Expand Down

0 comments on commit bdc5a27

Please sign in to comment.