Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Jun 28, 2023
1 parent e1633e9 commit 26a4160
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions packages/next-swc/crates/core/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,14 @@ impl VisitMut for ClosureReplacer<'_> {
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct Name(Id, Vec<(JsWord, bool)>);
struct NamePart {
prop: JsWord,
is_member: bool,
optional: bool,
}

#[derive(Debug, Clone, PartialEq, Eq)]
struct Name(Id, Vec<NamePart>);

impl From<&'_ Ident> for Name {
fn from(value: &Ident) -> Self {
Expand Down Expand Up @@ -1539,7 +1546,11 @@ impl TryFrom<&'_ MemberExpr> for Name {
match &value.prop {
MemberProp::Ident(prop) => {
let mut obj: Name = value.obj.as_ref().try_into()?;
obj.1.push((prop.sym.clone(), true));
obj.1.push(NamePart {
prop: prop.sym.clone(),
is_member: true,
optional: false,
});
Ok(obj)
}
_ => Err(()),
Expand All @@ -1552,10 +1563,14 @@ impl TryFrom<&'_ OptChainExpr> for Name {

fn try_from(value: &OptChainExpr) -> Result<Self, Self::Error> {
match &*value.base {
OptChainBase::Member(value) => match &value.prop {
OptChainBase::Member(m) => match &m.prop {
MemberProp::Ident(prop) => {
let mut obj: Name = value.obj.as_ref().try_into()?;
obj.1.push((prop.sym.clone(), false));
let mut obj: Name = m.obj.as_ref().try_into()?;
obj.1.push(NamePart {
prop: prop.sym.clone(),
is_member: false,
optional: value.optional,
});
Ok(obj)
}
_ => Err(()),
Expand All @@ -1569,7 +1584,12 @@ impl From<Name> for Expr {
fn from(value: Name) -> Self {
let mut expr = Expr::Ident(value.0.into());

for (prop, is_member) in value.1.into_iter() {
for NamePart {
prop,
is_member,
optional,
} in value.1.into_iter()
{
if is_member {
expr = Expr::Member(MemberExpr {
span: DUMMY_SP,
Expand All @@ -1579,12 +1599,12 @@ impl From<Name> for Expr {
} else {
expr = Expr::OptChain(OptChainExpr {
span: DUMMY_SP,
question_dot_token: DUMMY_SP,
base: Box::new(OptChainBase::Member(MemberExpr {
span: DUMMY_SP,
obj: expr.into(),
prop: MemberProp::Ident(Ident::new(prop, DUMMY_SP)),
})),
optional,
});
}
}
Expand Down

0 comments on commit 26a4160

Please sign in to comment.