@@ -165,36 +165,27 @@ export const javascript_visitors_runes = {
165
165
166
166
for ( const property of declarator . id . properties ) {
167
167
if ( property . type === 'Property' ) {
168
- assert . ok ( property . key . type === 'Identifier' || property . key . type === 'Literal' ) ;
169
- let name ;
170
- if ( property . key . type === 'Identifier' ) {
171
- name = property . key . name ;
172
- } else if ( property . key . type === 'Literal' ) {
173
- name = /** @type {string } */ ( property . key . value ) . toString ( ) ;
174
- } else {
175
- throw new Error ( 'unreachable' ) ;
176
- }
168
+ const key = /** @type {import('estree').Identifier | import('estree').Literal } */ (
169
+ property . key
170
+ ) ;
171
+ const name = key . type === 'Identifier' ? key . name : /** @type {string } */ ( key . value ) ;
177
172
178
173
seen . push ( name ) ;
179
174
180
- if ( property . value . type === 'Identifier' ) {
181
- const binding = /** @type {import('#compiler').Binding } */ (
182
- state . scope . get ( property . value . name )
183
- ) ;
184
- declarations . push (
185
- b . declarator ( property . value , get_props_method ( binding , state , name ) )
186
- ) ;
187
- } else if ( property . value . type === 'AssignmentPattern' ) {
188
- assert . equal ( property . value . left . type , 'Identifier' ) ;
189
- const binding = /** @type {import('#compiler').Binding } */ (
190
- state . scope . get ( property . value . left . name )
191
- ) ;
192
- declarations . push (
193
- b . declarator (
194
- property . value . left ,
195
- get_props_method ( binding , state , name , property . value . right )
196
- )
197
- ) ;
175
+ let id = property . value ;
176
+ let initial = undefined ;
177
+
178
+ if ( property . value . type === 'AssignmentPattern' ) {
179
+ id = property . value . left ;
180
+ initial = property . value . right ;
181
+ }
182
+
183
+ assert . equal ( id . type , 'Identifier' ) ;
184
+
185
+ const binding = /** @type {import('#compiler').Binding } */ ( state . scope . get ( id . name ) ) ;
186
+
187
+ if ( binding . reassigned || state . analysis . accessors || initial ) {
188
+ declarations . push ( b . declarator ( id , get_props_method ( binding , state , name , initial ) ) ) ;
198
189
}
199
190
} else {
200
191
// RestElement
0 commit comments