Skip to content

Commit 3df8b44

Browse files
authoredJan 13, 2025··
refactor(atoms): Rename FastAtom to UnsafeAtom (#9873)
**Description:** `UnsafeAtom` is the correct name of the type.
1 parent 50a0b42 commit 3df8b44

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed
 

‎.changeset/swift-experts-dance.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_atoms: patch
3+
swc_ecma_utils: patch
4+
---
5+
6+
refactor(atoms): Rename `FastAtom` to `UnsafeAtom`

‎crates/swc_ecma_ast/src/ident.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ impl From<IdentName> for BindingIdent {
465465
}
466466
}
467467

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

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

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

‎crates/swc_ecma_ast/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub use self::{
2323
expr::*,
2424
function::{Function, Param, ParamOrTsParamProp},
2525
ident::{
26-
fast_id, fast_id_from_ident, BindingIdent, EsReserved, FastId, Id, Ident, IdentName,
27-
PrivateName,
26+
unsafe_id, unsafe_id_from_ident, BindingIdent, EsReserved, Id, Ident, IdentName,
27+
PrivateName, UnsafeId,
2828
},
2929
jsx::{
3030
JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue, JSXClosingElement, JSXClosingFragment,

‎crates/swc_ecma_utils/src/ident.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use swc_atoms::JsWord;
22
use swc_common::SyntaxContext;
3-
use swc_ecma_ast::{fast_id, BindingIdent, FastId, Id, Ident};
3+
use swc_ecma_ast::{unsafe_id_from_ident, BindingIdent, Id, Ident, UnsafeId};
44

55
pub trait IdentLike: Sized + Send + Sync + 'static {
66
fn from_ident(i: &Ident) -> Self;
@@ -70,17 +70,17 @@ impl IdentLike for Ident {
7070
}
7171
}
7272

73-
impl IdentLike for FastId {
73+
impl IdentLike for UnsafeId {
7474
fn from_ident(i: &Ident) -> Self {
75-
unsafe { fast_id(&i.to_id()) }
75+
unsafe { unsafe_id_from_ident(i) }
7676
}
7777

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

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

0 commit comments

Comments
 (0)