File tree Expand file tree Collapse file tree 5 files changed +154
-6
lines changed
await-catch-no-expression Expand file tree Collapse file tree 5 files changed +154
-6
lines changed Original file line number Diff line number Diff line change @@ -290,16 +290,24 @@ export default function mustache(parser: Parser) {
290
290
291
291
const await_block_shorthand = type === 'AwaitBlock' && parser . eat ( 'then' ) ;
292
292
if ( await_block_shorthand ) {
293
- parser . require_whitespace ( ) ;
294
- block . value = read_context ( parser ) ;
295
- parser . allow_whitespace ( ) ;
293
+ if ( parser . match_regex ( / \s * } / ) ) {
294
+ parser . allow_whitespace ( ) ;
295
+ } else {
296
+ parser . require_whitespace ( ) ;
297
+ block . value = read_context ( parser ) ;
298
+ parser . allow_whitespace ( ) ;
299
+ }
296
300
}
297
301
298
302
const await_block_catch_shorthand = ! await_block_shorthand && type === 'AwaitBlock' && parser . eat ( 'catch' ) ;
299
303
if ( await_block_catch_shorthand ) {
300
- parser . require_whitespace ( ) ;
301
- block . error = read_context ( parser ) ;
302
- parser . allow_whitespace ( ) ;
304
+ if ( parser . match_regex ( / \s * } / ) ) {
305
+ parser . allow_whitespace ( ) ;
306
+ } else {
307
+ parser . require_whitespace ( ) ;
308
+ block . error = read_context ( parser ) ;
309
+ parser . allow_whitespace ( ) ;
310
+ }
303
311
}
304
312
305
313
parser . eat ( '}' , true ) ;
Original file line number Diff line number Diff line change
1
+ let fulfil ;
2
+
3
+ let thePromise = new Promise ( f => {
4
+ fulfil = f ;
5
+ } ) ;
6
+
7
+ export default {
8
+ props : {
9
+ thePromise
10
+ } ,
11
+
12
+ html : `
13
+ <br />
14
+ <p>the promise is pending</p>
15
+ ` ,
16
+
17
+ async test ( { assert, component, target } ) {
18
+ fulfil ( 42 ) ;
19
+
20
+ await thePromise ;
21
+
22
+ assert . htmlEqual ( target . innerHTML , '<br />' ) ;
23
+
24
+ let reject ;
25
+
26
+ thePromise = new Promise ( ( f , r ) => {
27
+ reject = r ;
28
+ } ) ;
29
+
30
+ component . thePromise = thePromise ;
31
+
32
+ assert . htmlEqual ( target . innerHTML , `
33
+ <br />
34
+ <p>the promise is pending</p>
35
+ ` ) ;
36
+
37
+ reject ( new Error ( ) ) ;
38
+
39
+ await thePromise . catch ( ( ) => { } ) ;
40
+
41
+ assert . htmlEqual ( target . innerHTML , `
42
+ <p>oh no! Something broke!</p>
43
+ <br />
44
+ <p>oh no! Something broke!</p>
45
+ ` ) ;
46
+ }
47
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let thePromise;
3
+ </script >
4
+
5
+ {#await thePromise catch }
6
+ <p >oh no! Something broke!</p >
7
+ {/await }
8
+
9
+ <br />
10
+
11
+ {#await thePromise }
12
+ <p >the promise is pending</p >
13
+ {:catch }
14
+ <p >oh no! Something broke!</p >
15
+ {/await }
Original file line number Diff line number Diff line change
1
+ let fulfil ;
2
+
3
+ let thePromise = new Promise ( f => {
4
+ fulfil = f ;
5
+ } ) ;
6
+
7
+ export default {
8
+ props : {
9
+ thePromise
10
+ } ,
11
+
12
+ html : `
13
+ <br>
14
+ <br>
15
+ <p>the promise is pending</p>
16
+ ` ,
17
+
18
+ async test ( { assert, component, target } ) {
19
+ fulfil ( ) ;
20
+
21
+ await thePromise ;
22
+
23
+ assert . htmlEqual ( target . innerHTML , `
24
+ <p>the promise is resolved</p>
25
+ <br>
26
+ <p>the promise is resolved</p>
27
+ <br>
28
+ <p>the promise is resolved</p>
29
+ ` ) ;
30
+
31
+ let reject ;
32
+
33
+ thePromise = new Promise ( ( f , r ) => {
34
+ reject = r ;
35
+ } ) ;
36
+
37
+ component . thePromise = thePromise ;
38
+
39
+ assert . htmlEqual ( target . innerHTML , `
40
+ <br>
41
+ <br>
42
+ <p>the promise is pending</p>
43
+ ` ) ;
44
+
45
+ reject ( new Error ( 'something broke' ) ) ;
46
+
47
+ await thePromise . catch ( ( ) => { } ) ;
48
+
49
+ assert . htmlEqual ( target . innerHTML , `
50
+ <p>oh no! something broke</p>
51
+ <br>
52
+ <br>
53
+ ` ) ;
54
+ }
55
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let thePromise;
3
+ </script >
4
+
5
+ {#await thePromise then }
6
+ <p >the promise is resolved</p >
7
+ {:catch theError }
8
+ <p >oh no! {theError .message }</p >
9
+ {/await }
10
+
11
+ <br />
12
+
13
+ {#await thePromise then }
14
+ <p >the promise is resolved</p >
15
+ {/await }
16
+
17
+ <br />
18
+
19
+ {#await thePromise }
20
+ <p >the promise is pending</p >
21
+ {:then }
22
+ <p >the promise is resolved</p >
23
+ {/await }
You can’t perform that action at this time.
0 commit comments