@@ -36,6 +36,9 @@ export function SvelteBoundary(node, context) {
3636 /** @type {Statement[] } */
3737 const external_statements = [ ] ;
3838
39+ /** @type {Statement[] } */
40+ const internal_statements = [ ] ;
41+
3942 const snippets_visits = [ ] ;
4043
4144 // Capture the `failed` implicit snippet prop
@@ -54,7 +57,20 @@ export function SvelteBoundary(node, context) {
5457 /** @type {Statement[] } */
5558 const init = [ ] ;
5659 context . visit ( child , { ...context . state , init } ) ;
57- external_statements . push ( ...init ) ;
60+
61+ if ( dev ) {
62+ // In dev we must separate the declarations from the code
63+ // that eagerly evaluate the expression...
64+ for ( const statement of init ) {
65+ if ( statement . type === 'VariableDeclaration' ) {
66+ external_statements . push ( statement ) ;
67+ } else {
68+ internal_statements . push ( statement ) ;
69+ }
70+ }
71+ } else {
72+ external_statements . push ( ...init ) ;
73+ }
5874 } else {
5975 nodes . push ( child ) ;
6076 }
@@ -64,8 +80,8 @@ export function SvelteBoundary(node, context) {
6480
6581 const block = /** @type {BlockStatement } */ ( context . visit ( { ...node . fragment , nodes } ) ) ;
6682
67- if ( dev && node . const_dev_statements ) {
68- block . body . unshift ( ...node . const_dev_statements ) ;
83+ if ( dev && internal_statements . length ) {
84+ block . body . unshift ( ...internal_statements ) ;
6985 }
7086
7187 const boundary = b . stmt (
0 commit comments