File tree 3 files changed +60
-2
lines changed
test/runtime/samples/await-then-shorthand
3 files changed +60
-2
lines changed Original file line number Diff line number Diff line change @@ -283,14 +283,22 @@ export default function mustache(parser: Parser) {
283
283
}
284
284
}
285
285
286
+ let awaitBlockShorthand = type === 'AwaitBlock' && parser . eat ( 'then' ) ;
287
+ if ( awaitBlockShorthand ) {
288
+ parser . requireWhitespace ( ) ;
289
+ block . value = parser . readIdentifier ( ) ;
290
+ parser . allowWhitespace ( ) ;
291
+ }
292
+
286
293
parser . eat ( '}}' , true ) ;
287
294
288
295
parser . current ( ) . children . push ( block ) ;
289
296
parser . stack . push ( block ) ;
290
297
291
298
if ( type === 'AwaitBlock' ) {
292
- block . pending . start = parser . index ;
293
- parser . stack . push ( block . pending ) ;
299
+ const childBlock = awaitBlockShorthand ? block . then : block . pending ;
300
+ childBlock . start = parser . index ;
301
+ parser . stack . push ( childBlock ) ;
294
302
}
295
303
} else if ( parser . eat ( 'yield' ) ) {
296
304
// {{yield}}
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
+ data : {
9
+ thePromise
10
+ } ,
11
+
12
+ html : `` ,
13
+
14
+ test ( assert , component , target ) {
15
+ fulfil ( 42 ) ;
16
+
17
+ return thePromise
18
+ . then ( ( ) => {
19
+ assert . htmlEqual ( target . innerHTML , `
20
+ <p>the value is 42</p>
21
+ ` ) ;
22
+
23
+ let reject ;
24
+
25
+ thePromise = new Promise ( ( f , r ) => {
26
+ reject = r ;
27
+ } ) ;
28
+
29
+ component . set ( {
30
+ thePromise
31
+ } ) ;
32
+
33
+ assert . htmlEqual ( target . innerHTML , `` ) ;
34
+
35
+ reject ( new Error ( 'something broke' ) ) ;
36
+
37
+ return thePromise . catch ( ( ) => { } ) ;
38
+ } )
39
+ . then ( ( ) => {
40
+ assert . htmlEqual ( target . innerHTML , `
41
+ <p>oh no! something broke</p>
42
+ ` ) ;
43
+ } ) ;
44
+ }
45
+ } ;
Original file line number Diff line number Diff line change
1
+ {{#await thePromise then theValue}}
2
+ < p > the value is {{theValue}}</ p >
3
+ {{catch theError}}
4
+ < p > oh no! {{theError.message}}</ p >
5
+ {{/await}}
You can’t perform that action at this time.
0 commit comments