Skip to content

Commit

Permalink
refactor(atoms): Rename FastAtom to UnsafeAtom (#9873)
Browse files Browse the repository at this point in the history
**Description:**

`UnsafeAtom` is the correct name of the type.
  • Loading branch information
kdy1 authored Jan 13, 2025
1 parent 50a0b42 commit 3df8b44
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .changeset/swift-experts-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_atoms: patch
swc_ecma_utils: patch
---

refactor(atoms): Rename `FastAtom` to `UnsafeAtom`
8 changes: 4 additions & 4 deletions crates/swc_ecma_ast/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,14 @@ impl From<IdentName> for BindingIdent {
}
}

/// FastId is a wrapper around [Id] that does not allocate, but extremely
/// UnsafeId is a wrapper around [Id] that does not allocate, but extremely
/// unsafe.
///
/// Do not use this unless you know what you are doing.
///
/// **Currently, it's considered as a unstable API and may be changed in the
/// future without a semver bump.**
pub type FastId = (FastAtom, SyntaxContext);
pub type UnsafeId = (FastAtom, SyntaxContext);

/// This is extremely unsafe so don't use it unless you know what you are doing.
///
Expand All @@ -482,7 +482,7 @@ pub type FastId = (FastAtom, SyntaxContext);
///
/// **Currently, it's considered as a unstable API and may be changed in the
/// future without a semver bump.**
pub unsafe fn fast_id(id: &Id) -> FastId {
pub unsafe fn unsafe_id(id: &Id) -> UnsafeId {
(FastAtom::new(&id.0), id.1)
}

Expand All @@ -494,7 +494,7 @@ pub unsafe fn fast_id(id: &Id) -> FastId {
///
/// **Currently, it's considered as a unstable API and may be changed in the
/// future without a semver bump.**
pub unsafe fn fast_id_from_ident(id: &Ident) -> FastId {
pub unsafe fn unsafe_id_from_ident(id: &Ident) -> UnsafeId {
(FastAtom::new(&id.sym), id.ctxt)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub use self::{
expr::*,
function::{Function, Param, ParamOrTsParamProp},
ident::{
fast_id, fast_id_from_ident, BindingIdent, EsReserved, FastId, Id, Ident, IdentName,
PrivateName,
unsafe_id, unsafe_id_from_ident, BindingIdent, EsReserved, Id, Ident, IdentName,
PrivateName, UnsafeId,
},
jsx::{
JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXClosingElement, JSXClosingFragment,
Expand Down
10 changes: 5 additions & 5 deletions crates/swc_ecma_utils/src/ident.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use swc_atoms::JsWord;
use swc_common::SyntaxContext;
use swc_ecma_ast::{fast_id, BindingIdent, FastId, Id, Ident};
use swc_ecma_ast::{unsafe_id_from_ident, BindingIdent, Id, Ident, UnsafeId};

pub trait IdentLike: Sized + Send + Sync + 'static {
fn from_ident(i: &Ident) -> Self;
Expand Down Expand Up @@ -70,17 +70,17 @@ impl IdentLike for Ident {
}
}

impl IdentLike for FastId {
impl IdentLike for UnsafeId {
fn from_ident(i: &Ident) -> Self {
unsafe { fast_id(&i.to_id()) }
unsafe { unsafe_id_from_ident(i) }
}

fn to_id(&self) -> Id {
unreachable!("FastId.to_id() is not allowed because it is very likely to be unsafe")
unreachable!("UnsafeId.to_id() is not allowed because it is very likely to be unsafe")
}

fn into_id(self) -> Id {
unreachable!("FastId.into_id() is not allowed because it is very likely to be unsafe")
unreachable!("UnsafeId.into_id() is not allowed because it is very likely to be unsafe")
}
}

Expand Down

0 comments on commit 3df8b44

Please sign in to comment.