@@ -56,9 +56,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
5656 return 0 ;
5757 }
5858
59- self . is_declaration = false ;
60-
61- self . transform_class ( class, ctx) ;
59+ self . transform_class ( class, false , ctx) ;
6260
6361 // Return number of expressions to be inserted before/after the class
6462 let mut expr_count = self . insert_before . len ( ) + self . insert_after_exprs . len ( ) ;
@@ -184,9 +182,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
184182 return ;
185183 }
186184
187- self . is_declaration = true ;
188-
189- self . transform_class ( class, ctx) ;
185+ self . transform_class ( class, true , ctx) ;
190186
191187 // TODO: Run other transforms on inserted statements. How?
192188
@@ -292,7 +288,12 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
292288 }
293289
294290 /// Main guts of the transform.
295- fn transform_class ( & mut self , class : & mut Class < ' a > , ctx : & mut TraverseCtx < ' a > ) {
291+ fn transform_class (
292+ & mut self ,
293+ class : & mut Class < ' a > ,
294+ is_declaration : bool ,
295+ ctx : & mut TraverseCtx < ' a > ,
296+ ) {
296297 // TODO(improve-on-babel): If outer scope is sloppy mode, all code which is moved to outside
297298 // the class should be wrapped in an IIFE with `'use strict'` directive. Babel doesn't do this.
298299
@@ -371,12 +372,12 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
371372 // temp var for class. Static prop in class declaration doesn't.
372373 let mut class_name_binding = class. id . as_ref ( ) . map ( BoundIdentifier :: from_binding_ident) ;
373374
374- let need_temp_var = has_static_prop && ( !self . is_declaration || class. id . is_none ( ) ) ;
375+ let need_temp_var = has_static_prop && ( !is_declaration || class. id . is_none ( ) ) ;
375376 self . temp_var_is_created = need_temp_var;
376377
377378 let class_temp_binding = if need_temp_var {
378379 let temp_binding = ClassBindings :: create_temp_binding ( class_name_binding. as_ref ( ) , ctx) ;
379- if self . is_declaration {
380+ if is_declaration {
380381 // Anonymous `export default class {}`. Set class name binding to temp var.
381382 // Actual class name will be set to this later.
382383 class_name_binding = Some ( temp_binding. clone ( ) ) ;
@@ -396,7 +397,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
396397
397398 // Add entry to `classes_stack`
398399 self . classes_stack . push ( ClassDetails {
399- is_declaration : self . is_declaration ,
400+ is_declaration,
400401 private_props : if private_props. is_empty ( ) { None } else { Some ( private_props) } ,
401402 bindings : class_bindings,
402403 } ) ;
@@ -511,7 +512,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
511512 expr : Expression < ' a > ,
512513 ctx : & mut TraverseCtx < ' a > ,
513514 ) {
514- if self . is_declaration {
515+ if self . current_class ( ) . is_declaration {
515516 self . insert_after_stmts . push ( ctx. ast . statement_expression ( SPAN , expr) ) ;
516517 } else {
517518 self . insert_after_exprs . push ( expr) ;
0 commit comments