diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index c13d34517..cbfa02d94 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -1,5 +1,286 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Use Source attribute only 1`] = ` +Array [ + Object { + "augments": Array [], + "context": Object { + "loc": SourceLocation { + "end": Position { + "column": 1, + "line": 18, + }, + "start": Position { + "column": 0, + "line": 6, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 29, + "line": 1, + "offset": 28, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This Vue Component is a test", + }, + ], + "position": Position { + "end": Object { + "column": 29, + "line": 1, + "offset": 28, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 29, + "line": 1, + "offset": 28, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [ + Object { + "message": "could not determine @name for hierarchy", + }, + ], + "examples": Array [], + "loc": SourceLocation { + "end": Position { + "column": 3, + "line": 5, + }, + "start": Position { + "column": 0, + "line": 2, + }, + }, + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "", + "namespace": "", + "params": Array [], + "path": Array [ + Object { + "kind": undefined, + "name": "", + }, + ], + "properties": Array [], + "returns": Array [ + Object { + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 21, + "line": 1, + "offset": 20, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "vue-tested component", + }, + ], + "position": Position { + "end": Object { + "column": 21, + "line": 1, + "offset": 20, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 21, + "line": 1, + "offset": 20, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "title": "returns", + "type": Object { + "name": "vue-tested", + "type": "NameExpression", + }, + }, + ], + "sees": Array [], + "tags": Array [ + Object { + "description": "vue-tested component", + "lineNumber": 2, + "title": "returns", + "type": Object { + "name": "vue-tested", + "type": "NameExpression", + }, + }, + ], + "throws": Array [], + "todos": Array [], + }, + Object { + "augments": Array [], + "context": Object { + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 16, + }, + "start": Position { + "column": 4, + "line": 13, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 17, + "line": 1, + "offset": 16, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "This is a number", + }, + ], + "position": Position { + "end": Object { + "column": 17, + "line": 1, + "offset": 16, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 17, + "line": 1, + "offset": 16, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [], + "examples": Array [], + "loc": SourceLocation { + "end": Position { + "column": 7, + "line": 12, + }, + "start": Position { + "column": 4, + "line": 10, + }, + }, + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "myNumber", + "namespace": "myNumber", + "params": Array [], + "path": Array [ + Object { + "kind": undefined, + "name": "myNumber", + }, + ], + "properties": Array [], + "returns": Array [], + "sees": Array [], + "tags": Array [], + "throws": Array [], + "todos": Array [], + }, +] +`; + exports[`Vue file 1`] = ` Array [ Object { diff --git a/__tests__/test.js b/__tests__/test.js index 69ba36f0d..824630635 100644 --- a/__tests__/test.js +++ b/__tests__/test.js @@ -241,3 +241,30 @@ test('Vue file', async function() { normalize(data); expect(data).toMatchSnapshot(); }); + +test('Use Source attribute only', async function() { + await pify(chdir)(__dirname); + const documentationSource = ` +/** + * This Vue Component is a test + * @returns {vue-tested} vue-tested component + */ +export default { + + props: { + + /** + * This is a number + */ + myNumber: { + default: 42, + type: Number + } + } +}`; + const data = await documentation.build([{ source: documentationSource }], { + shallow: true + }); + normalize(data); + expect(data).toMatchSnapshot(); +}); diff --git a/src/index.js b/src/index.js index 81deb259d..49490e1f2 100644 --- a/src/index.js +++ b/src/index.js @@ -105,6 +105,10 @@ function buildInternal(inputsAndConfig) { sourceFile.source = fs.readFileSync(sourceFile.file, 'utf8'); } + if (!sourceFile.file) { + sourceFile.file = ''; + } + if (path.extname(sourceFile.file) === '.vue') { return parseVueScript(sourceFile, config).map(buildPipeline); }