@@ -100,7 +100,7 @@ fn visit_children(node: Node, import_name: &str, context: &mut Context) {
100100 } else {
101101 context. text_changes . push ( TextChange {
102102 range : create_range ( ident. start ( ) , ident. end ( ) , context) ,
103- new_text : "globalThis" . to_string ( ) ,
103+ new_text : get_replacement_text ( ident , "globalThis" , context ) ,
104104 } ) ;
105105 }
106106 }
@@ -126,7 +126,11 @@ fn visit_children(node: Node, import_name: &str, context: &mut Context) {
126126 {
127127 context. text_changes . push ( TextChange {
128128 range : create_range ( ident. start ( ) , ident. end ( ) , context) ,
129- new_text : format ! ( "{}.{}" , import_name, ident_text) ,
129+ new_text : get_replacement_text (
130+ ident,
131+ & format ! ( "{}.{}" , import_name, ident_text) ,
132+ context,
133+ ) ,
130134 } ) ;
131135 context. import_shim = true ;
132136 return ;
@@ -171,11 +175,30 @@ fn get_global_this_text_change(
171175 } else {
172176 Some ( TextChange {
173177 range : create_range ( ident. start ( ) , ident. end ( ) , context) ,
174- new_text : format ! ( "{}.dntGlobalThis" , import_name) ,
178+ new_text : get_replacement_text (
179+ ident,
180+ & format ! ( "{}.dntGlobalThis" , import_name) ,
181+ context,
182+ ) ,
175183 } )
176184 }
177185}
178186
187+ /// Gets the text to replace an identifier with, expanding an object literal's
188+ /// shorthand property so that the property name is kept
189+ /// (ex. `{ prompt }` -> `{ prompt: dntShim.prompt }`).
190+ fn get_replacement_text (
191+ ident : & Ident ,
192+ new_text : & str ,
193+ context : & Context ,
194+ ) -> String {
195+ if matches ! ( ident. parent( ) , Node :: ObjectLit ( _) ) {
196+ format ! ( "{}: {}" , ident. text_fast( context. program) , new_text)
197+ } else {
198+ new_text. to_string ( )
199+ }
200+ }
201+
179202fn should_ignore_global_this ( ident : & Ident , context : & Context ) -> bool {
180203 if has_ignore_comment ( ident. into ( ) , context)
181204 || is_declaration_ident ( ident. into ( ) )
0 commit comments