Skip to content

Commit

Permalink
Merge pull request #70 from ekhaled/multi-named-exports
Browse files Browse the repository at this point in the history
fix #69: comments parsing fix for multiple named exports in single statement
  • Loading branch information
alexprey committed Aug 27, 2021
2 parents 2472b5a + 25b1fd8 commit 9a3ea2d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/v3/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,15 @@ class ScriptParser extends EventEmitter {

const variables = parseVariableDeclaration(declaration);

variables.forEach(variable => {
variables.forEach((variable, index) => {

if (level === 0) {
this.emitDataItem(variable, context, visibility, comment);
let _comment = comment;
if (index > 0) {
_comment = getCommentFromSourceCode(variable.declarator, context.sourceCode, { defaultVisibility: visibility, useLeading: true, useTrailing: false });
}

this.emitDataItem(variable, context, visibility, _comment);
}

if (!variable.declarator.init) {
Expand Down
10 changes: 10 additions & 0 deletions test/svelte3/integration/data/data.exportNamed.many.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
/* The `a` variable description */
export let a = 1,
/* The `b` variable description */
b = 'Test',
c = 'TestC',
/* The `d` variable description */
d = 2;
</script>
53 changes: 53 additions & 0 deletions test/svelte3/integration/data/data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,59 @@ describe('SvelteDoc v3 - Props', () => {
});
});

it('Export statements with multiple named exports should be parsed with matching descriptions', done => {
parser.parse({
version: 3,
filename: path.resolve(__dirname, 'data.exportNamed.many.svelte'),
features: ['data'],
includeSourceLocations: true,
ignoredVisibilities: []
}).then((doc) => {
expect(doc, 'Document should be provided').to.exist;
expect(doc.data, 'Document data should be parsed').to.exist;

expect(doc.data.length).to.equal(4);

const prop1 = doc.data.find(d => d.name === 'a');

expect(prop1.name).to.equal('a');
expect(prop1.visibility).to.equal('public');
expect(prop1.static).to.be.false;
expect(prop1.description).to.be.equal('The `a` variable description');
expect(prop1.type).to.eql({ kind: 'type', type: 'number', text: 'number' });

expect(prop1.locations, 'Code location should be parsed').to.be.exist;

const prop2 = doc.data.find(d => d.name === 'b');

expect(prop2.name).to.equal('b');
expect(prop2.visibility).to.equal('public');
expect(prop2.static).to.be.false;
expect(prop2.description).to.be.equal('The `b` variable description');
expect(prop2.type).to.eql({ kind: 'type', type: 'string', text: 'string' });

const prop3 = doc.data.find(d => d.name === 'c');

expect(prop3.name).to.equal('c');
expect(prop3.visibility).to.equal('public');
expect(prop3.static).to.be.false;
expect(prop3.description).to.be.null;
expect(prop3.type).to.eql({ kind: 'type', type: 'string', text: 'string' });

const prop4 = doc.data.find(d => d.name === 'd');

expect(prop4.name).to.equal('d');
expect(prop4.visibility).to.equal('public');
expect(prop4.static).to.be.false;
expect(prop4.description).to.be.equal('The `d` variable description');
expect(prop4.type).to.eql({ kind: 'type', type: 'number', text: 'number' });

done();
}).catch(e => {
done(e);
});
});

it('Export object statement with multiple variables should be parsed as public props', done => {
parser.parse({
version: 3,
Expand Down

0 comments on commit 9a3ea2d

Please sign in to comment.