Skip to content

Commit

Permalink
refactor(es/decorator): Remove unsafe code (#8839)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Apr 11, 2024
1 parent 62cd932 commit e8c6344
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
collections::VecDeque,
iter::once,
mem::{take, transmute},
};
use std::{collections::VecDeque, iter::once, mem::take};

use rustc_hash::FxHashMap;
use swc_atoms::JsWord;
Expand Down Expand Up @@ -278,15 +274,17 @@ impl Decorator202203 {

fn ensure_constructor<'a>(&mut self, c: &'a mut Class) -> &'a mut Constructor {
let mut insert_index = 0;
for (i, member) in c.body.iter_mut().enumerate() {
for (i, member) in c.body.iter().enumerate() {
if let ClassMember::Constructor(constructor) = member {
insert_index = i + 1;
// decorators occur before typescript's type strip, so skip ctor overloads
if constructor.body.is_some() {
return unsafe {
// Safety: We need polonius
transmute::<&mut Constructor, &'a mut Constructor>(constructor)
};
if let Some(ClassMember::Constructor(c)) = c.body.get_mut(i) {
return c;
} else {
unreachable!()
}
} else {
insert_index = i + 1;
}
}
}
Expand All @@ -305,15 +303,17 @@ impl Decorator202203 {

fn ensure_identity_constructor<'a>(&mut self, c: &'a mut Class) -> &'a mut Constructor {
let mut insert_index = 0;
for (i, member) in c.body.iter_mut().enumerate() {
for (i, member) in c.body.iter().enumerate() {
if let ClassMember::Constructor(constructor) = member {
insert_index = i + 1;
// decorators occur before typescript's type strip, so skip ctor overloads
if constructor.body.is_some() {
return unsafe {
// Safety: We need polonius
transmute::<&mut Constructor, &'a mut Constructor>(constructor)
};
if let Some(ClassMember::Constructor(c)) = c.body.get_mut(i) {
return c;
} else {
unreachable!()
}
} else {
insert_index = i + 1;
}
}
}
Expand Down

0 comments on commit e8c6344

Please sign in to comment.