@@ -138,14 +138,10 @@ export function VariableDeclaration(node, context) {
138138 } ;
139139
140140 if ( declarator . id . type === 'Identifier' ) {
141+ const expression = /** @type {Expression } */ ( context . visit ( value ) ) ;
142+
141143 declarations . push (
142- b . declarator (
143- declarator . id ,
144- create_state_declarator (
145- declarator . id ,
146- /** @type {Expression } */ ( context . visit ( value ) )
147- )
148- )
144+ b . declarator ( declarator . id , create_state_declarator ( declarator . id , expression ) )
149145 ) ;
150146 } else {
151147 const tmp = b . id ( context . state . scope . generate ( 'tmp' ) ) ;
@@ -157,10 +153,8 @@ export function VariableDeclaration(node, context) {
157153 id . name = context . state . scope . generate ( '$$array' ) ;
158154 context . state . transform [ id . name ] = { read : get_value } ;
159155
160- return b . declarator (
161- id ,
162- b . call ( '$.derived' , /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) )
163- ) ;
156+ const expression = /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) ;
157+ return b . declarator ( id , b . call ( '$.derived' , expression ) ) ;
164158 } ) ,
165159 ...paths . map ( ( path ) => {
166160 const value = /** @type {Expression } */ ( context . visit ( path . expression ) ) ;
@@ -205,12 +199,8 @@ export function VariableDeclaration(node, context) {
205199 id . name = context . state . scope . generate ( '$$array' ) ;
206200 context . state . transform [ id . name ] = { read : get_value } ;
207201
208- declarations . push (
209- b . declarator (
210- id ,
211- b . call ( '$.derived' , /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) )
212- )
213- ) ;
202+ const expression = /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) ;
203+ declarations . push ( b . declarator ( id , b . call ( '$.derived' , expression ) ) ) ;
214204 }
215205
216206 for ( const path of paths ) {
@@ -261,12 +251,8 @@ export function VariableDeclaration(node, context) {
261251 id . name = context . state . scope . generate ( '$$array' ) ;
262252 context . state . transform [ id . name ] = { read : get_value } ;
263253
264- declarations . push (
265- b . declarator (
266- id ,
267- b . call ( '$.derived' , /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) )
268- )
269- ) ;
254+ const expression = /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) ;
255+ declarations . push ( b . declarator ( id , b . call ( '$.derived' , expression ) ) ) ;
270256 }
271257
272258 for ( const path of paths ) {
@@ -349,10 +335,8 @@ function create_state_declarators(declarator, context, value) {
349335 id . name = context . state . scope . generate ( '$$array' ) ;
350336 context . state . transform [ id . name ] = { read : get_value } ;
351337
352- return b . declarator (
353- id ,
354- b . call ( '$.derived' , /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) )
355- ) ;
338+ const expression = /** @type {Expression } */ ( context . visit ( b . thunk ( value ) ) ) ;
339+ return b . declarator ( id , b . call ( '$.derived' , expression ) ) ;
356340 } ) ,
357341 ...paths . map ( ( path ) => {
358342 const value = /** @type {Expression } */ ( context . visit ( path . expression ) ) ;
0 commit comments