Skip to content

Commit

Permalink
refactor(turbopack): Atom and JsWord is same type
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 16, 2025
1 parent 0cdb3e5 commit 1b55219
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions turbopack/crates/turbopack-ecmascript/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,13 @@ impl Eq for ConstantNumber {}

#[derive(Debug, Clone)]
pub enum ConstantString {
Word(JsWord),
Atom(Atom),
RcStr(RcStr),
}

impl ConstantString {
pub fn as_str(&self) -> &str {
match self {
Self::Word(s) => s,
Self::Atom(s) => s,
Self::RcStr(s) => s,
}
Expand Down Expand Up @@ -146,7 +144,7 @@ impl From<Atom> for ConstantString {

impl From<&'static str> for ConstantString {
fn from(v: &'static str) -> Self {
ConstantString::Word(v.into())
ConstantString::Atom(v.into())
}
}

Expand Down Expand Up @@ -236,14 +234,14 @@ impl From<bool> for ConstantValue {

impl From<&'_ str> for ConstantValue {
fn from(v: &str) -> Self {
ConstantValue::Str(ConstantString::Word(v.into()))
ConstantValue::Str(ConstantString::Atom(v.into()))
}
}

impl From<Lit> for ConstantValue {
fn from(v: Lit) -> Self {
match v {
Lit::Str(v) => ConstantValue::Str(ConstantString::Word(v.value)),
Lit::Str(v) => ConstantValue::Str(ConstantString::Atom(v.value)),
Lit::Bool(v) => {
if v.value {
ConstantValue::True
Expand Down Expand Up @@ -511,7 +509,7 @@ pub enum JsValue {

impl From<&'_ str> for JsValue {
fn from(v: &str) -> Self {
ConstantValue::Str(ConstantString::Word(v.into())).into()
ConstantValue::Str(ConstantString::Atom(v.into())).into()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3381,7 +3381,7 @@ fn is_invoking_node_process_eval(args: &[JsValue]) -> bool {
{
// Is `-e` one of the arguments passed to the program?
if items.iter().any(|e| {
if let JsValue::Constant(JsConstantValue::Str(ConstantString::Word(arg))) =
if let JsValue::Constant(JsConstantValue::Str(ConstantString::Atom(arg))) =
e
{
arg == "-e"
Expand Down

0 comments on commit 1b55219

Please sign in to comment.