Skip to content

Commit d31c3b7

Browse files
devongovetttmcw
authored andcommittedApr 18, 2019
feat: Support async functions
1 parent d1ee0f3 commit d31c3b7

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed
 

‎__tests__/__snapshots__/test.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -9823,6 +9823,7 @@ It takes a ",
98239823
"todos": Array [],
98249824
},
98259825
Object {
9826+
"async": true,
98269827
"augments": Array [],
98279828
"context": Object {
98289829
"loc": Object {

‎__tests__/lib/infer/kind.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,12 @@ test('inferKind', function() {
8282
).kind
8383
).toBe('function');
8484

85-
expect(
86-
inferKind(
87-
toComment(
88-
'/** Export default function */' + 'export default function foo() {}'
89-
)
90-
).kind
91-
).toBe('function');
85+
const asyncFunction = inferKind(
86+
toComment('/** Async function */' + 'async function foo() {}')
87+
);
88+
89+
expect(asyncFunction.kind).toBe('function');
90+
expect(asyncFunction.async).toBe(true);
9291

9392
expect(
9493
inferKind(toComment('class Foo { /** set b */ set b(v) { } }')).kind
@@ -106,6 +105,12 @@ test('inferKind', function() {
106105
'function'
107106
);
108107

108+
const asyncMethod = inferKind(
109+
toComment('class Foo { /** b */ async b(v) { } }')
110+
);
111+
expect(asyncMethod.kind).toBe('function');
112+
expect(asyncMethod.async).toBe(true);
113+
109114
expect(
110115
inferKind(
111116
toComment(function() {

‎__tests__/lib/parse.js

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ test('parse - @arg', function() {});
7272

7373
test('parse - @argument', function() {});
7474

75+
test('parse - @async', function() {
76+
expect(
77+
evaluate(function() {
78+
/** @async */
79+
})[0].async
80+
).toBe(true);
81+
});
82+
7583
test('parse - @augments', function() {
7684
expect(
7785
evaluate(function() {

‎src/infer/kind.js

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function inferKind(comment) {
2525
comment.kind = 'class';
2626
} else {
2727
comment.kind = 'function';
28+
if (node.async) {
29+
comment.async = true;
30+
}
2831
}
2932
} else if (t.isTypeAlias(node)) {
3033
comment.kind = 'typedef';

‎src/parse.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const flatteners = {
2323
alias: flattenName,
2424
arg: synonym('param'),
2525
argument: synonym('param'),
26+
async: flattenBoolean,
2627
/**
2728
* Parse tag
2829
* @private

0 commit comments

Comments
 (0)
Please sign in to comment.