@@ -213,23 +213,31 @@ export function convertAwaitBlock(
213213 const thenStart = awaitBlock . pending ? node . then . start : node . start
214214 const thenBlock : SvelteAwaitThenBlock = {
215215 type : "SvelteAwaitThenBlock" ,
216- value : null as any ,
216+ value : null ,
217217 children : [ ] ,
218218 parent : awaitBlock ,
219219 ...ctx . getConvertLocation ( {
220220 start : thenStart ,
221221 end : node . then . end ,
222222 } ) ,
223223 }
224- ctx . scriptLet . nestBlock (
225- thenBlock ,
226- [ node . value ] ,
227- [ thenBlock ] ,
228- ( [ value ] ) => {
229- thenBlock . value = value
230- } ,
231- [ `typeof ${ ctx . getText ( node . expression ) } ` ] ,
232- )
224+ if ( node . value ) {
225+ ctx . scriptLet . nestBlock (
226+ thenBlock ,
227+ [ node . value ] ,
228+ [ thenBlock ] ,
229+ ( [ value ] ) => {
230+ thenBlock . value = value
231+ } ,
232+ [
233+ `Parameters<Parameters<(typeof ${ ctx . getText (
234+ node . expression ,
235+ ) } )["then"]>[0]>[0]`,
236+ ] ,
237+ )
238+ } else {
239+ ctx . scriptLet . nestBlock ( thenBlock )
240+ }
233241 thenBlock . children . push ( ...convertChildren ( node . then , thenBlock , ctx ) )
234242 if ( awaitBlock . pending ) {
235243 extractMustacheBlockTokens ( thenBlock , ctx , { startOnly : true } )
@@ -253,7 +261,7 @@ export function convertAwaitBlock(
253261 : node . start
254262 const catchBlock : SvelteAwaitCatchBlock = {
255263 type : "SvelteAwaitCatchBlock" ,
256- error : null as any ,
264+ error : null ,
257265 children : [ ] ,
258266 parent : awaitBlock ,
259267 ...ctx . getConvertLocation ( {
@@ -262,15 +270,19 @@ export function convertAwaitBlock(
262270 } ) ,
263271 }
264272
265- ctx . scriptLet . nestBlock (
266- catchBlock ,
267- [ node . error ] ,
268- [ catchBlock ] ,
269- ( [ error ] ) => {
270- catchBlock . error = error
271- } ,
272- [ "Error" ] ,
273- )
273+ if ( node . error ) {
274+ ctx . scriptLet . nestBlock (
275+ catchBlock ,
276+ [ node . error ] ,
277+ [ catchBlock ] ,
278+ ( [ error ] ) => {
279+ catchBlock . error = error
280+ } ,
281+ [ "Error" ] ,
282+ )
283+ } else {
284+ ctx . scriptLet . nestBlock ( catchBlock )
285+ }
274286 catchBlock . children . push (
275287 ...convertChildren ( node . catch , catchBlock , ctx ) ,
276288 )
0 commit comments