Skip to content

Commit

Permalink
feat(arrow): support exporting arrow function
Browse files Browse the repository at this point in the history
  • Loading branch information
h13i32maru committed Dec 20, 2016
1 parent 8f01190 commit 964eda3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/Factory/DocFactory.js
Expand Up @@ -439,6 +439,8 @@ export default class DocFactory {
return this._decideVariableType(node); return this._decideVariableType(node);
case 'AssignmentExpression': case 'AssignmentExpression':
return this._decideAssignmentType(node); return this._decideAssignmentType(node);
case 'ArrowFunctionExpression':
return this._decideArrowFunctionExpressionType(node);
} }


return {type: null, node: null}; return {type: null, node: null};
Expand Down Expand Up @@ -517,6 +519,18 @@ export default class DocFactory {
return {type: 'Function', node: node}; 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. * decide Doc type from expression statement node.
* @param {ASTNode} node - target node that is expression statement node. * @param {ASTNode} node - target node that is expression statement node.
Expand Down Expand Up @@ -587,6 +601,9 @@ export default class DocFactory {
case 'ClassExpression': case 'ClassExpression':
innerType = 'Class'; innerType = 'Class';
break; break;
case 'ArrowFunctionExpression':
innerType = 'Function';
break;
default: default:
return {type: 'Variable', node: node}; return {type: 'Variable', node: node};
} }
Expand Down
3 changes: 3 additions & 0 deletions src/Publisher/Builder/LintDocBuilder.js
Expand Up @@ -48,6 +48,9 @@ export default class LintDocBuilder extends DocBuilder {
case 'ClassMethod': case 'ClassMethod':
params = node.params || []; params = node.params || [];
break; break;
case 'ArrowFunctionExpression':
params = node.params || [];
break;
default: default:
throw new Error(`unknown node type. type = ${node.type}`); throw new Error(`unknown node type. type = ${node.type}`);
} }
Expand Down
23 changes: 23 additions & 0 deletions test/fixture/package/src/Export/ArrowFunction.js
@@ -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};
7 changes: 4 additions & 3 deletions test/src/HTMLTest/CoverageTest/CoverageTest.js
Expand Up @@ -9,8 +9,8 @@ describe('test coverage', ()=> {
it('has coverage summary', ()=> { it('has coverage summary', ()=> {
assert(badge.includes('80%')); assert(badge.includes('80%'));
assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src'); assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src');
assert.includes(doc, '[data-ice="totalCoverageCount"]', '274/342'); assert.includes(doc, '[data-ice="totalCoverageCount"]', '277/346');
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 118); assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 119);
}); });


/* eslint-disable max-statements */ /* eslint-disable max-statements */
Expand Down Expand Up @@ -60,6 +60,7 @@ describe('test coverage', ()=> {
test('file/src/ExponentiationOperator/Definition.js.html', '100 %2/2'); test('file/src/ExponentiationOperator/Definition.js.html', '100 %2/2');
test('file/src/Export/AnonymousClass.js.html', '100 %1/1'); test('file/src/Export/AnonymousClass.js.html', '100 %1/1');
test('file/src/Export/AnonymousFunction.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/Class.js.html#errorLines=24', '80 %4/5');
test('file/src/Export/ClassIndirectDefault.js.html', '100 %1/1'); test('file/src/Export/ClassIndirectDefault.js.html', '100 %1/1');
test('file/src/Export/Default.js.html', '100 %1/1'); test('file/src/Export/Default.js.html', '100 %1/1');
Expand Down Expand Up @@ -142,6 +143,6 @@ describe('test coverage', ()=> {
test('file/src/Version/Function.js.html', '100 %1/1'); test('file/src/Version/Function.js.html', '100 %1/1');
test('file/src/Version/Variable.js.html', '100 %1/1'); test('file/src/Version/Variable.js.html', '100 %1/1');


assert.equal(count, 118); assert.equal(count, 119);
}); });
}); });
39 changes: 39 additions & 0 deletions test/src/HTMLTest/DocumentTest/ExportTest/ArrowFunctionTest.js
@@ -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.