File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -58,3 +58,15 @@ test('empty selector string', (t) => {
58
58
} ) . process ( '' ) . result ;
59
59
} ) ;
60
60
} ) ;
61
+
62
+ test ( 'async parser' , ( t ) => {
63
+ t . plan ( 1 ) ;
64
+
65
+ t . notThrows ( ( ) => {
66
+ return parser ( ( ) => new Promise ( ( res ) => {
67
+ res ( ) ;
68
+ } ) ) . process ( '' ) . result . then ( ( ) => {
69
+ t . pass ( ) ;
70
+ } ) ;
71
+ } ) ;
72
+ } ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Parser from './parser';
3
3
export default class Processor {
4
4
constructor ( func ) {
5
5
this . func = func || function noop ( ) { } ;
6
+ this . funcRes = null ;
6
7
return this ;
7
8
}
8
9
@@ -15,11 +16,17 @@ export default class Processor {
15
16
options : options ,
16
17
} ) ;
17
18
this . res = input ;
18
- this . func ( input ) ;
19
+ this . funcRes = this . func ( input ) ;
19
20
return this ;
20
21
}
21
22
22
23
get result ( ) {
24
+ let isPromise = this . funcRes &&
25
+ typeof this . funcRes . then === 'function' ;
26
+
27
+ if ( isPromise ) {
28
+ return this . funcRes . then ( ( ) => String ( this . res ) ) ;
29
+ }
23
30
return String ( this . res ) ;
24
31
}
25
32
}
You can’t perform that action at this time.
0 commit comments