@@ -123,7 +123,7 @@ function convertAttribute(
123123 loc : attribute . loc ,
124124 range : attribute . range ,
125125 }
126- ctx . scriptLet . addExpression ( key , sAttr , ( es ) => {
126+ ctx . scriptLet . addExpression ( key , sAttr , null , ( es ) => {
127127 sAttr . key = es
128128 sAttr . value = es
129129 } )
@@ -177,7 +177,7 @@ function convertSpreadAttribute(
177177 end : spreadStart + 3 ,
178178 } )
179179
180- ctx . scriptLet . addExpression ( node . expression , attribute , ( es ) => {
180+ ctx . scriptLet . addExpression ( node . expression , attribute , null , ( es ) => {
181181 attribute . argument = es
182182 } )
183183
@@ -203,6 +203,7 @@ function convertBindingDirective(
203203 return ctx . scriptLet . addExpression (
204204 expression ,
205205 directive ,
206+ null ,
206207 ( es , { getInnermostScope } ) => {
207208 directive . expression = es
208209 const scope = getInnermostScope ( es )
@@ -238,11 +239,20 @@ function convertEventHandlerDirective(
238239 parent,
239240 ...ctx . getConvertLocation ( node ) ,
240241 }
242+ const isCustomEvent =
243+ parent . parent . type === "SvelteElement" &&
244+ ( parent . parent . kind === "component" || parent . parent . kind === "special" )
241245 processDirective (
242246 node ,
243247 directive ,
244248 ctx ,
245- buildProcessExpressionForExpression ( directive , ctx ) ,
249+ buildProcessExpressionForExpression (
250+ directive ,
251+ ctx ,
252+ isCustomEvent
253+ ? "(e:CustomEvent<any>)=>void"
254+ : `(e:HTMLElementEventMap['${ node . name } '])=>void` ,
255+ ) ,
246256 )
247257 return directive
248258}
@@ -266,7 +276,7 @@ function convertClassDirective(
266276 node ,
267277 directive ,
268278 ctx ,
269- buildProcessExpressionForExpression ( directive , ctx ) ,
279+ buildProcessExpressionForExpression ( directive , ctx , null ) ,
270280 )
271281 return directive
272282}
@@ -292,7 +302,7 @@ function convertTransitionDirective(
292302 node ,
293303 directive ,
294304 ctx ,
295- buildProcessExpressionForExpression ( directive , ctx ) ,
305+ buildProcessExpressionForExpression ( directive , ctx , null ) ,
296306 ( name ) => ctx . scriptLet . addExpression ( name , directive ) ,
297307 )
298308 return directive
@@ -317,7 +327,7 @@ function convertAnimationDirective(
317327 node ,
318328 directive ,
319329 ctx ,
320- buildProcessExpressionForExpression ( directive , ctx ) ,
330+ buildProcessExpressionForExpression ( directive , ctx , null ) ,
321331 ( name ) => ctx . scriptLet . addExpression ( name , directive ) ,
322332 )
323333 return directive
@@ -342,7 +352,7 @@ function convertActionDirective(
342352 node ,
343353 directive ,
344354 ctx ,
345- buildProcessExpressionForExpression ( directive , ctx ) ,
355+ buildProcessExpressionForExpression ( directive , ctx , null ) ,
346356 ( name ) => ctx . scriptLet . addExpression ( name , directive ) ,
347357 )
348358 return directive
@@ -370,15 +380,15 @@ function convertLetDirective(
370380 ( pattern ) => {
371381 return ctx . letDirCollections
372382 . getCollection ( )
373- . addPattern ( pattern , directive )
383+ . addPattern ( pattern , directive , "any" )
374384 } ,
375385 node . expression
376386 ? undefined
377387 : ( name ) => {
378388 // shorthand
379389 return ctx . letDirCollections
380390 . getCollection ( )
381- . addPattern ( name , directive , ( es ) => {
391+ . addPattern ( name , directive , "any" , ( es ) => {
382392 directive . expression = es
383393 } )
384394 } ,
@@ -463,9 +473,6 @@ function processDirective<
463473 } )
464474 } else {
465475 ctx . addToken ( "HTMLIdentifier" , nameRange )
466- // ctx.scriptLet.addExpression(directive.name, directive, (es) => {
467- // directive.name = es
468- // })
469476 }
470477 }
471478}
@@ -474,8 +481,9 @@ function processDirective<
474481function buildProcessExpressionForExpression (
475482 directive : SvelteDirective & { expression : null | ESTree . Expression } ,
476483 ctx : Context ,
484+ typing : string | null ,
477485) : ( expression : ESTree . Expression ) => ScriptLetCallback < ESTree . Expression > [ ] {
478486 return ( expression ) => {
479- return ctx . scriptLet . addExpression ( expression , directive )
487+ return ctx . scriptLet . addExpression ( expression , directive , typing )
480488 }
481489}
0 commit comments