Permalink
Browse files

feat(arrow): support exporting arrow function

  • Loading branch information...
h13i32maru committed Dec 20, 2016
1 parent 8f01190 commit 964eda3d4e2da6e5d92b3a6502a4b2d01422b692
View
@@ -439,6 +439,8 @@ export default class DocFactory {
return this._decideVariableType(node);
case 'AssignmentExpression':
return this._decideAssignmentType(node);
+ case 'ArrowFunctionExpression':
+ return this._decideArrowFunctionExpressionType(node);
}
return {type: null, node: null};
@@ -517,6 +519,18 @@ export default class DocFactory {
return {type: 'Function', node: node};
}
+ /**
+ * decide Doc type from arrow function expression node.
+ * @param {ASTNode} node - target node that is arrow function expression node.
+ * @returns {{type: string, node: ASTNode}} decided type.
+ * @private
+ */
+ _decideArrowFunctionExpressionType(node) {
+ if (!this._isTopDepthInBody(node, this._ast.program.body)) return {type: null, node: null};
+
+ return {type: 'Function', node: node};
+ }
+
/**
* decide Doc type from expression statement node.
* @param {ASTNode} node - target node that is expression statement node.
@@ -587,6 +601,9 @@ export default class DocFactory {
case 'ClassExpression':
innerType = 'Class';
break;
+ case 'ArrowFunctionExpression':
+ innerType = 'Function';
+ break;
default:
return {type: 'Variable', node: node};
}
@@ -48,6 +48,9 @@ export default class LintDocBuilder extends DocBuilder {
case 'ClassMethod':
params = node.params || [];
break;
+ case 'ArrowFunctionExpression':
+ params = node.params || [];
+ break;
default:
throw new Error(`unknown node type. type = ${node.type}`);
}
@@ -0,0 +1,23 @@
+/**
+ * this is ArrowFunction.
+ */
+export default ()=>{}
+
+/**
+ * this is testExportArrowFunction2.
+ */
+export const testExportArrowFunction2 = ()=>{};
+
+/**
+ * this is testExportArrowFunction3.
+ */
+const testExportArrowFunction3 = ()=>{};
+
+// this is undocument
+export const testExportArrowFunction4 = ()=>{};
+
+/**
+ * this is testExportArrowFunction5.
+ */
+const testExportArrowFunction5 = ()=>{};
+export {testExportArrowFunction5};
@@ -9,8 +9,8 @@ describe('test coverage', ()=> {
it('has coverage summary', ()=> {
assert(badge.includes('80%'));
assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src');
- assert.includes(doc, '[data-ice="totalCoverageCount"]', '274/342');
- assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 118);
+ assert.includes(doc, '[data-ice="totalCoverageCount"]', '277/346');
+ assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 119);
});
/* eslint-disable max-statements */
@@ -60,6 +60,7 @@ describe('test coverage', ()=> {
test('file/src/ExponentiationOperator/Definition.js.html', '100 %2/2');
test('file/src/Export/AnonymousClass.js.html', '100 %1/1');
test('file/src/Export/AnonymousFunction.js.html', '100 %1/1');
+ test('file/src/Export/ArrowFunction.js.html#errorLines=17', '75 %3/4');
test('file/src/Export/Class.js.html#errorLines=24', '80 %4/5');
test('file/src/Export/ClassIndirectDefault.js.html', '100 %1/1');
test('file/src/Export/Default.js.html', '100 %1/1');
@@ -142,6 +143,6 @@ describe('test coverage', ()=> {
test('file/src/Version/Function.js.html', '100 %1/1');
test('file/src/Version/Variable.js.html', '100 %1/1');
- assert.equal(count, 118);
+ assert.equal(count, 119);
});
});
@@ -0,0 +1,39 @@
+import {readDoc, assert, findParent} from './../../../util.js';
+
+/** @test {FunctionDoc#@_name} */
+describe('test export arrow function', ()=> {
+ const doc = readDoc('function/index.html');
+
+ it('has default import path with direct arrow function definition.', ()=> {
+ findParent(doc, '[id="static-function-ArrowFunction"]', '[data-ice="detail"]', (doc)=>{
+ assert.includes(doc, '[data-ice="importPath"]', `import ArrowFunction from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
+ });
+ });
+
+ it('has named import path with direct arrow function definition.', ()=>{
+ findParent(doc, '[id="static-function-testExportArrowFunction2"]', '[data-ice="detail"]', (doc)=>{
+ assert.includes(doc, '[data-ice="importPath"]', `import {testExportArrowFunction2} from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
+ });
+ });
+
+ it('is not documented with direct arrow function expression', ()=> {
+ try {
+ findParent(doc, '[id="static-function-testExportArrowFunction3"]', '[data-ice="detail"]', ()=>{});
+ } catch (e) {
+ return;
+ }
+ assert(false);
+ });
+
+ it('has named import path with undocument', ()=>{
+ findParent(doc, '[id="static-function-testExportArrowFunction4"]', '[data-ice="detail"]', (doc)=>{
+ assert.includes(doc, '[data-ice="importPath"]', `import {testExportArrowFunction4} from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
+ });
+ });
+
+ it('has named import path with indirect function definition.', ()=> {
+ findParent(doc, '[id="static-function-testExportArrowFunction5"]', '[data-ice="detail"]', (doc)=>{
+ assert.includes(doc, '[data-ice="importPath"]', `import {testExportArrowFunction5} from 'esdoc-test-fixture/src/Export/ArrowFunction.js'`);
+ });
+ });
+});

0 comments on commit 964eda3

Please sign in to comment.