diff --git a/crates/oxc_transformer/src/es2022/class_properties.rs b/crates/oxc_transformer/src/es2022/class_properties.rs index 1c5bcf8f75785c..0acfa05b7b3b5a 100644 --- a/crates/oxc_transformer/src/es2022/class_properties.rs +++ b/crates/oxc_transformer/src/es2022/class_properties.rs @@ -70,7 +70,10 @@ //! * //! * Class properties TC39 proposal: -use rustc_hash::FxHashMap; +use std::hash::BuildHasherDefault; + +use indexmap::IndexMap; +use rustc_hash::FxHasher; use serde::Deserialize; use oxc_allocator::{Address, Box as ArenaBox, GetAddress}; @@ -89,6 +92,8 @@ use crate::{common::helper_loader::Helper, CompilerAssumptions, TransformCtx}; use super::ClassStaticBlock; +type FxIndexMap = IndexMap>; + #[derive(Debug, Default, Clone, Copy, Deserialize)] #[serde(default, rename_all = "camelCase")] pub struct ClassPropertiesOptions { @@ -113,7 +118,8 @@ pub struct ClassProperties<'a, 'ctx> { // then stack will get out of sync. // TODO: Should push to the stack only when entering class body, because `#x` in class `extends` // clause resolves to `#x` in *outer* class, not the current class. - private_props_stack: SparseStack, PrivateProp<'a>>>, + // TODO(improve-on-babel): Order that temp vars are created in is not important. Use `FxHashMap` instead. + private_props_stack: SparseStack, PrivateProp<'a>>>, /// Addresses of class expressions being processed, to prevent same class being visited twice. /// Have to use a stack because the revisit doesn't necessarily happen straight after the first visit. /// e.g. `c = class C { [class D {}] = 1; }` -> `c = (_D = class D {}, class C { ... })` @@ -455,8 +461,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { // Check if class has any properties and get index and `ScopeId` of constructor (if class has one) let mut instance_prop_count = 0; let mut has_static_prop_or_static_block = false; - // TODO: Store `FxHashMap`s in a pool and re-use them - let mut private_props = FxHashMap::default(); + // TODO: Store `FxIndexMap`s in a pool and re-use them + let mut private_props = FxIndexMap::default(); let mut constructor = None; let mut index_not_including_removed = 0; for element in &class.body.body {