22/** @import { AST } from '#compiler' */
33/** @import { ComponentContext } from '../types' */
44import { dev } from '../../../../state.js' ;
5- import { extract_identifiers } from '../../../../utils/ast.js' ;
5+ import { extract_identifiers , is_expression_async } from '../../../../utils/ast.js' ;
66import * as b from '#compiler/builders' ;
77import { create_derived } from '../utils.js' ;
88import { get_value } from './shared/declarations.js' ;
@@ -17,7 +17,7 @@ export function ConstTag(node, context) {
1717 // TODO we can almost certainly share some code with $derived(...)
1818 if ( declaration . id . type === 'Identifier' ) {
1919 const init = build_expression ( context , declaration . init , node . metadata . expression ) ;
20- let expression = create_derived ( context . state , b . thunk ( init ) ) ;
20+ let expression = create_derived ( context . state , b . thunk ( init , is_expression_async ( init ) ) ) ;
2121
2222 if ( dev ) {
2323 expression = b . call ( '$.tag' , expression , b . literal ( declaration . id . name ) ) ;
@@ -58,7 +58,8 @@ export function ConstTag(node, context) {
5858 b . block ( [
5959 b . const ( /** @type {Pattern } */ ( context . visit ( declaration . id , child_state ) ) , init ) ,
6060 b . return ( b . object ( identifiers . map ( ( node ) => b . prop ( 'init' , node , node ) ) ) )
61- ] )
61+ ] ) ,
62+ is_expression_async ( init )
6263 ) ;
6364
6465 let expression = create_derived ( context . state , fn ) ;
0 commit comments