Skip to content

Commit 964eda3

Browse files
committed
feat(arrow): support exporting arrow function
1 parent 8f01190 commit 964eda3

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed

src/Factory/DocFactory.js

+17
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ export default class DocFactory {
439439
return this._decideVariableType(node);
440440
case 'AssignmentExpression':
441441
return this._decideAssignmentType(node);
442+
case 'ArrowFunctionExpression':
443+
return this._decideArrowFunctionExpressionType(node);
442444
}
443445

444446
return {type: null, node: null};
@@ -517,6 +519,18 @@ export default class DocFactory {
517519
return {type: 'Function', node: node};
518520
}
519521

522+
/**
523+
* decide Doc type from arrow function expression node.
524+
* @param {ASTNode} node - target node that is arrow function expression node.
525+
* @returns {{type: string, node: ASTNode}} decided type.
526+
* @private
527+
*/
528+
_decideArrowFunctionExpressionType(node) {
529+
if (!this._isTopDepthInBody(node, this._ast.program.body)) return {type: null, node: null};
530+
531+
return {type: 'Function', node: node};
532+
}
533+
520534
/**
521535
* decide Doc type from expression statement node.
522536
* @param {ASTNode} node - target node that is expression statement node.
@@ -587,6 +601,9 @@ export default class DocFactory {
587601
case 'ClassExpression':
588602
innerType = 'Class';
589603
break;
604+
case 'ArrowFunctionExpression':
605+
innerType = 'Function';
606+
break;
590607
default:
591608
return {type: 'Variable', node: node};
592609
}

src/Publisher/Builder/LintDocBuilder.js

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export default class LintDocBuilder extends DocBuilder {
4848
case 'ClassMethod':
4949
params = node.params || [];
5050
break;
51+
case 'ArrowFunctionExpression':
52+
params = node.params || [];
53+
break;
5154
default:
5255
throw new Error(`unknown node type. type = ${node.type}`);
5356
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* this is ArrowFunction.
3+
*/
4+
export default ()=>{}
5+
6+
/**
7+
* this is testExportArrowFunction2.
8+
*/
9+
export const testExportArrowFunction2 = ()=>{};
10+
11+
/**
12+
* this is testExportArrowFunction3.
13+
*/
14+
const testExportArrowFunction3 = ()=>{};
15+
16+
// this is undocument
17+
export const testExportArrowFunction4 = ()=>{};
18+
19+
/**
20+
* this is testExportArrowFunction5.
21+
*/
22+
const testExportArrowFunction5 = ()=>{};
23+
export {testExportArrowFunction5};

test/src/HTMLTest/CoverageTest/CoverageTest.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('test coverage', ()=> {
99
it('has coverage summary', ()=> {
1010
assert(badge.includes('80%'));
1111
assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src');
12-
assert.includes(doc, '[data-ice="totalCoverageCount"]', '274/342');
13-
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 118);
12+
assert.includes(doc, '[data-ice="totalCoverageCount"]', '277/346');
13+
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 119);
1414
});
1515

1616
/* eslint-disable max-statements */
@@ -60,6 +60,7 @@ describe('test coverage', ()=> {
6060
test('file/src/ExponentiationOperator/Definition.js.html', '100 %2/2');
6161
test('file/src/Export/AnonymousClass.js.html', '100 %1/1');
6262
test('file/src/Export/AnonymousFunction.js.html', '100 %1/1');
63+
test('file/src/Export/ArrowFunction.js.html#errorLines=17', '75 %3/4');
6364
test('file/src/Export/Class.js.html#errorLines=24', '80 %4/5');
6465
test('file/src/Export/ClassIndirectDefault.js.html', '100 %1/1');
6566
test('file/src/Export/Default.js.html', '100 %1/1');
@@ -142,6 +143,6 @@ describe('test coverage', ()=> {
142143
test('file/src/Version/Function.js.html', '100 %1/1');
143144
test('file/src/Version/Variable.js.html', '100 %1/1');
144145

145-
assert.equal(count, 118);
146+
assert.equal(count, 119);
146147
});
147148
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {readDoc, assert, findParent} from './../../../util.js';
2+
3+
/** @test {FunctionDoc#@_name} */
4+
describe('test export arrow function', ()=> {
5+
const doc = readDoc('function/index.html');
6+
7+
it('has default import path with direct arrow function definition.', ()=> {
8+
findParent(doc, '[id="static-function-ArrowFunction"]', '[data-ice="detail"]', (doc)=>{
9+
assert.includes(doc, '[data-ice="importPath"]', `import ArrowFunction from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
10+
});
11+
});
12+
13+
it('has named import path with direct arrow function definition.', ()=>{
14+
findParent(doc, '[id="static-function-testExportArrowFunction2"]', '[data-ice="detail"]', (doc)=>{
15+
assert.includes(doc, '[data-ice="importPath"]', `import {testExportArrowFunction2} from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
16+
});
17+
});
18+
19+
it('is not documented with direct arrow function expression', ()=> {
20+
try {
21+
findParent(doc, '[id="static-function-testExportArrowFunction3"]', '[data-ice="detail"]', ()=>{});
22+
} catch (e) {
23+
return;
24+
}
25+
assert(false);
26+
});
27+
28+
it('has named import path with undocument', ()=>{
29+
findParent(doc, '[id="static-function-testExportArrowFunction4"]', '[data-ice="detail"]', (doc)=>{
30+
assert.includes(doc, '[data-ice="importPath"]', `import {testExportArrowFunction4} from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
31+
});
32+
});
33+
34+
it('has named import path with indirect function definition.', ()=> {
35+
findParent(doc, '[id="static-function-testExportArrowFunction5"]', '[data-ice="detail"]', (doc)=>{
36+
assert.includes(doc, '[data-ice="importPath"]', `import {testExportArrowFunction5} from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)