Skip to content

Commit

Permalink
Fix: Store private props in FxIndexMap
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 18, 2024
1 parent c798471 commit 83249dd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/oxc_transformer/src/es2022/class_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
//! * <https://github.com/babel/babel/blob/v7.26.2/packages/babel-helper-create-class-features-plugin/src/fields.ts>
//! * Class properties TC39 proposal: <https://github.com/tc39/proposal-class-fields>

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};
Expand All @@ -89,6 +92,8 @@ use crate::{common::helper_loader::Helper, CompilerAssumptions, TransformCtx};

use super::ClassStaticBlock;

type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;

#[derive(Debug, Default, Clone, Copy, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct ClassPropertiesOptions {
Expand All @@ -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<FxHashMap<Atom<'a>, PrivateProp<'a>>>,
// TODO(improve-on-babel): Order that temp vars are created in is not important. Use `FxHashMap` instead.
private_props_stack: SparseStack<FxIndexMap<Atom<'a>, 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 { ... })`
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 83249dd

Please sign in to comment.