Skip to content
Permalink
Browse files

feat(es2017): support `async`

  • Loading branch information...
h13i32maru committed Sep 25, 2016
1 parent 1e83c50 commit 50452a1e44a1c8908da1fb377d3aa51eba220256
@@ -40,6 +40,14 @@ export default class FunctionDoc extends AbstractDoc {
this._value.generator = this._node.generator;
}

/**
* use async property of self node.
*/
_$async() {
super._$async();
this._value.async = this._node.async;
}

/** if @param is not exists, guess type of param by using self node. */
_$param() {
super._$param();
@@ -102,4 +102,13 @@ export default class MethodDoc extends AbstractDoc {

this._value.generator = this._node.generator;
}

/**
* use async property of self node.
*/
_$async() {
super._$async();

this._value.async = this._node.async;
}
}
@@ -422,6 +422,8 @@ export default class DocFactory {
return this._decideExpressionStatementType(node);
case 'FunctionDeclaration':
return this._decideFunctionDeclarationType(node);
case 'FunctionExpression':
return this._decideFunctionExpressionType(node);
case 'VariableDeclaration':
return this._decideVariableType(node);
case 'AssignmentExpression':
@@ -471,6 +473,23 @@ export default class DocFactory {
return {type: 'Function', node: node};
}

/**
* decide Doc type from function expression node.
* babylon 6.11.2 judges`export default async function foo(){}` to be `FunctionExpression`.
* I expect `FunctionDeclaration`. this behavior may be bug of babylon.
* for now, workaround for it with this method.
* @param {ASTNode} node - target node that is function expression node.
* @returns {{type: string, node: ASTNode}} decided type.
* @private
* @todo inspect with newer babylon.
*/
_decideFunctionExpressionType(node) {
if (!node.async) return {type: null, node: null};
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.
@@ -373,6 +373,7 @@ export default class DocBuilder {
ice.text('title', title);
ice.loop('target', docs, (i, doc, ice)=>{
ice.text('generator', doc.generator ? '*' : '');
ice.text('async', doc.async ? 'async' : '');
ice.load('name', this._buildDocLinkHTML(doc.longname, null, innerLink, doc.kind));
ice.load('signature', this._buildSignatureHTML(doc));
ice.load('description', shorten(doc, true));
@@ -444,6 +445,7 @@ export default class DocBuilder {
const scope = doc.static ? 'static' : 'instance';
ice.attr('anchor', 'id', `${scope}-${doc.kind}-${doc.name}`);
ice.text('generator', doc.generator ? '*' : '');
ice.text('async', doc.async ? 'async' : '');
ice.text('name', doc.name);
ice.load('signature', this._buildSignatureHTML(doc));
ice.load('description', doc.description);
@@ -6,6 +6,7 @@ <h3 data-ice="anchor">
<span class="kind" data-ice="kind"></span>
<span class="abstract" data-ice="abstract"></span>
<span data-ice="generator"></span>
<span data-ice="async"></span>
<span data-ice="name"></span><span data-ice="signature"></span>
<span class="right-info">
<span class="version" data-ice="version">version </span>
@@ -12,7 +12,9 @@
<td>
<div>
<p>
<span data-ice="generator"></span> <span data-ice="name"></span><span data-ice="signature"></span>
<span data-ice="generator"></span>
<span data-ice="async"></span>
<span data-ice="name"></span><span data-ice="signature"></span>
</p>
</div>
<div>
@@ -0,0 +1,4 @@
/**
* this is testAsyncFunction.
*/
export default async function testAsyncFunction(){}
@@ -0,0 +1,9 @@
/**
* this is TestAsyncMethod.
*/
export default class TestAsyncMethod {
/**
* this is async method1.
*/
async method1(){}
}
@@ -9,8 +9,8 @@ describe('test coverage', ()=> {
it('has coverage summary', ()=> {
assert(badge.includes('79%'));
assert.includes(doc, '[data-ice="coverageBadge"]', './badge.svg', 'src');
assert.includes(doc, '[data-ice="totalCoverageCount"]', '255/322');
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 112);
assert.includes(doc, '[data-ice="totalCoverageCount"]', '258/325');
assert.equal(doc.find('[data-ice="file"] [data-ice="coverage"]').length, 114);
});

/* eslint-disable max-statements */
@@ -30,6 +30,8 @@ describe('test coverage', ()=> {
test('file/src/Access/Method.js.html', '100 %5/5');
test('file/src/Access/Property.js.html#errorLines=5', '83 %5/6');
test('file/src/Access/Variable.js.html', '100 %4/4');
test('file/src/Async/Function.js.html', '100 %1/1');
test('file/src/Async/Method.js.html', '100 %2/2');
test('file/src/Class/Definition.js.html', '100 %8/8');
test('file/src/Computed/Method.js.html', '100 %11/11');
test('file/src/Computed/Property.js.html', '100 %12/12');
@@ -136,6 +138,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, 112);
assert.equal(count, 114);
});
});
@@ -0,0 +1,22 @@
import {readDoc, assert, findParent} from './../../../util.js';

/** @test {FunctionDoc#_$async} */
describe('testAsyncFunction', ()=> {
const doc = readDoc('function/index.html');

describe('in summary', ()=> {
it('has async mark', ()=> {
findParent(doc, '[data-ice="summary"] [href$="#static-function-testAsyncFunction"]', '[data-ice="target"]', (doc)=> {
assert.includes(doc, null, 'public async testAsyncFunction()');
});
});
});

describe('in details', ()=>{
it('has async mark.', ()=>{
findParent(doc, '[id="static-function-testAsyncFunction"]', '[data-ice="detail"]', (doc)=>{
assert.includes(doc, 'h3', 'public async testAsyncFunction()');
});
});
});
});
@@ -0,0 +1,22 @@
import {readDoc, assert, findParent} from './../../../util.js';

/** @test {MethodDoc#_$async} */
describe('TestAsyncMethod', ()=> {
const doc = readDoc('class/src/Async/Method.js~TestAsyncMethod.html');

describe('in summary', ()=> {
it('has async mark.', ()=> {
findParent(doc, '[data-ice="summary"] [href$="#instance-method-method1"]', '[data-ice="target"]', (doc)=> {
assert.includes(doc, null, 'public async method1()');
});
});
});

describe('in details', ()=>{
it('has async mark.', ()=>{
findParent(doc, '[id="instance-method-method1"]', '[data-ice="detail"]', (doc)=>{
assert.includes(doc, 'h3', 'public async method1()');
});
});
});
});

0 comments on commit 50452a1

Please sign in to comment.
You can’t perform that action at this time.