Skip to content

Commit

Permalink
feat: Support async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and tmcw committed Apr 18, 2019
1 parent d1ee0f3 commit d31c3b7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions __tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9823,6 +9823,7 @@ It takes a ",
"todos": Array [],
},
Object {
"async": true,
"augments": Array [],
"context": Object {
"loc": Object {
Expand Down
19 changes: 12 additions & 7 deletions __tests__/lib/infer/kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ test('inferKind', function() {
).kind
).toBe('function');

expect(
inferKind(
toComment(
'/** Export default function */' + 'export default function foo() {}'
)
).kind
).toBe('function');
const asyncFunction = inferKind(
toComment('/** Async function */' + 'async function foo() {}')
);

expect(asyncFunction.kind).toBe('function');
expect(asyncFunction.async).toBe(true);

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

const asyncMethod = inferKind(
toComment('class Foo { /** b */ async b(v) { } }')
);
expect(asyncMethod.kind).toBe('function');
expect(asyncMethod.async).toBe(true);

expect(
inferKind(
toComment(function() {
Expand Down
8 changes: 8 additions & 0 deletions __tests__/lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ test('parse - @arg', function() {});

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

test('parse - @async', function() {
expect(
evaluate(function() {
/** @async */
})[0].async
).toBe(true);
});

test('parse - @augments', function() {
expect(
evaluate(function() {
Expand Down
3 changes: 3 additions & 0 deletions src/infer/kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function inferKind(comment) {
comment.kind = 'class';
} else {
comment.kind = 'function';
if (node.async) {
comment.async = true;
}
}
} else if (t.isTypeAlias(node)) {
comment.kind = 'typedef';
Expand Down
1 change: 1 addition & 0 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const flatteners = {
alias: flattenName,
arg: synonym('param'),
argument: synonym('param'),
async: flattenBoolean,
/**
* Parse tag
* @private
Expand Down

0 comments on commit d31c3b7

Please sign in to comment.