Skip to content

Commit

Permalink
refactor(turbopack): Merge Atom and JsWord variant of `ConstantSt…
Browse files Browse the repository at this point in the history
…ring` (#74967)

### What?

Merge two variants as those are exactly the same.

### Why?

`JsWord` is an alias of `Atom`.
  • Loading branch information
kdy1 authored Jan 16, 2025
1 parent 262a08d commit 0cfa5f4
Show file tree
Hide file tree
Showing 53 changed files with 239 additions and 241 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
),
Constant(
Str(
Word(
Atom(
".js",
),
),
Expand All @@ -70,14 +70,14 @@
values: [
Constant(
Str(
Word(
Atom(
"hello",
),
),
),
Constant(
Str(
Word(
Atom(
"world",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -72,14 +72,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -245,14 +245,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -312,14 +312,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -485,14 +485,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -552,14 +552,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand All @@ -91,14 +91,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -132,14 +132,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down Expand Up @@ -173,14 +173,14 @@
items: [
Constant(
Str(
Word(
Atom(
"../lib/a.js",
),
),
),
Constant(
Str(
Word(
Atom(
"../lib/b.js",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
),
Constant(
Str(
Word(
Atom(
"foo",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"b",
Constant(
Str(
Word(
Atom(
"foo",
),
),
Expand All @@ -35,7 +35,7 @@
),
Constant(
Str(
Word(
Atom(
"foo",
),
),
Expand Down Expand Up @@ -72,7 +72,7 @@
),
Constant(
Str(
Word(
Atom(
"foo",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
values: [
Constant(
Str(
Word(
Atom(
"",
),
),
Expand All @@ -22,7 +22,7 @@
),
Constant(
Str(
Word(
Atom(
"x",
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
Value(
Constant(
Str(
Word(
Atom(
"a",
),
),
Expand Down Expand Up @@ -450,7 +450,7 @@
StrictEqual,
Constant(
Str(
Word(
Atom(
"edge",
),
),
Expand Down Expand Up @@ -639,22 +639,22 @@
StrictEqual,
Constant(
Str(
Word(
Atom(
"edge",
),
),
),
),
Constant(
Str(
Word(
Atom(
"next/dist/compiled/@vercel/og/index.edge.js",
),
),
),
Constant(
Str(
Word(
Atom(
"next/dist/compiled/@vercel/og/index.node.js",
),
),
Expand Down Expand Up @@ -711,7 +711,7 @@
Value(
Constant(
Str(
Word(
Atom(
"a",
),
),
Expand Down Expand Up @@ -797,7 +797,7 @@
Value(
Constant(
Str(
Word(
Atom(
"b",
),
),
Expand Down Expand Up @@ -1244,7 +1244,7 @@
Value(
Constant(
Str(
Word(
Atom(
"c",
),
),
Expand Down
Loading

0 comments on commit 0cfa5f4

Please sign in to comment.