Unverified Commit 5639c4ec authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Use `swc_core::ecma::utils::prop_name_eq` for a couple of the…

Turbopack: Use `swc_core::ecma::utils::prop_name_eq` for a couple of the `next-custom-transforms` (#96035)

Found this helper while looking through one of @sampoder's PRs, noticed
that these places could benefit from it.
parent b2144ddb
...@@ -14,7 +14,7 @@ use swc_core::{ ...@@ -14,7 +14,7 @@ use swc_core::{
ImportSpecifier, KeyValueProp, Lit, ModuleDecl, ModuleItem, ObjectLit, Pass, Prop, ImportSpecifier, KeyValueProp, Lit, ModuleDecl, ModuleItem, ObjectLit, Pass, Prop,
PropName, PropOrSpread, Stmt, Str, Tpl, UnaryExpr, UnaryOp, op, PropName, PropOrSpread, Stmt, Str, Tpl, UnaryExpr, UnaryOp, op,
}, },
utils::{ExprFactory, private_ident, quote_ident}, utils::{ExprFactory, private_ident, prop_name_eq, quote_ident},
visit::{VisitMut, VisitMutWith, visit_mut_pass}, visit::{VisitMut, VisitMutWith, visit_mut_pass},
}, },
quote, quote,
...@@ -275,10 +275,7 @@ impl VisitMut for NextDynamicPatcher { ...@@ -275,10 +275,7 @@ impl VisitMut for NextDynamicPatcher {
_ => None, _ => None,
}, },
_ => None, _ => None,
} && let Some(IdentName { sym, span: _ }) = match key { } && prop_name_eq(key, "ssr")
PropName::Ident(ident) => Some(ident),
_ => None,
} && sym == "ssr"
&& let Some(Lit::Bool(Bool { && let Some(Lit::Bool(Bool {
value: false, value: false,
span: _, span: _,
......
...@@ -31,7 +31,7 @@ use swc_core::{ ...@@ -31,7 +31,7 @@ use swc_core::{
}, },
ecma::{ ecma::{
ast::*, ast::*,
utils::{ExprFactory, prepend_stmts, quote_ident, quote_str}, utils::{ExprFactory, prepend_stmts, prop_name_eq, quote_ident, quote_str},
visit::{ visit::{
Visit, VisitMut, VisitMutWith, VisitWith, noop_visit_mut_type, noop_visit_type, Visit, VisitMut, VisitMutWith, VisitWith, noop_visit_mut_type, noop_visit_type,
visit_mut_pass, visit_mut_pass,
...@@ -1086,13 +1086,7 @@ impl ReactServerComponentValidator { ...@@ -1086,13 +1086,7 @@ impl ReactServerComponentValidator {
let obj = ssr_arg.expr.as_object()?; let obj = ssr_arg.expr.as_object()?;
for prop in obj.props.iter().filter_map(|v| v.as_prop()?.as_key_value()) { for prop in obj.props.iter().filter_map(|v| v.as_prop()?.as_key_value()) {
let is_ssr = match &prop.key { if prop_name_eq(&prop.key, "ssr") {
PropName::Ident(IdentName { sym, .. }) => sym == "ssr",
PropName::Str(s) => s.value == "ssr",
_ => false,
};
if is_ssr {
let value = prop.value.as_lit()?; let value = prop.value.as_lit()?;
if let Lit::Bool(Bool { value: false, .. }) = value { if let Lit::Bool(Bool { value: false, .. }) = value {
report_error( report_error(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment