From ab0896a5c2ae1b4bce7772afc1a2a22e6c911fbe Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Fri, 15 Apr 2022 13:17:33 -0700 Subject: [PATCH] refactor(next-swc/ssg): consolidate repeated constants --- packages/next-swc/crates/core/src/next_ssg.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/next-swc/crates/core/src/next_ssg.rs b/packages/next-swc/crates/core/src/next_ssg.rs index dde7155f6ccd796..2f8987ed2139614 100644 --- a/packages/next-swc/crates/core/src/next_ssg.rs +++ b/packages/next-swc/crates/core/src/next_ssg.rs @@ -13,6 +13,8 @@ use swc_ecmascript::{ visit::{noop_fold_type, Fold}, }; +static SSG_EXPORTS: &[&str; 3] = &["getStaticProps", "getStaticPaths", "getServerSideProps"]; + /// Note: This paths requires running `resolver` **before** running this. pub fn next_ssg(eliminated_packages: Rc>>) -> impl Fold { Repeat::new(NextSsg { @@ -55,9 +57,7 @@ struct State { impl State { #[allow(clippy::wrong_self_convention)] fn is_data_identifier(&mut self, i: &Ident) -> Result { - let ssg_exports = &["getStaticProps", "getStaticPaths", "getServerSideProps"]; - - if ssg_exports.contains(&&*i.sym) { + if SSG_EXPORTS.contains(&&*i.sym) { if &*i.sym == "getServerSideProps" { if self.is_prerenderer { HANDLER.with(|handler| { @@ -132,9 +132,7 @@ impl Fold for Analyzer<'_> { fn fold_export_named_specifier(&mut self, s: ExportNamedSpecifier) -> ExportNamedSpecifier { if let ModuleExportName::Ident(id) = &s.orig { - let ssg_exports = &["getStaticProps", "getStaticPaths", "getServerSideProps"]; - - if !ssg_exports.contains(&&*id.sym) { + if !SSG_EXPORTS.contains(&&*id.sym) { self.add_ref(id.to_id()); } } @@ -149,9 +147,7 @@ impl Fold for Analyzer<'_> { } if let Pat::Ident(id) = &d.decls[0].name { - let ssg_exports = &["getStaticProps", "getStaticPaths", "getServerSideProps"]; - - if !ssg_exports.contains(&&*id.id.sym) { + if !SSG_EXPORTS.contains(&&*id.id.sym) { self.add_ref(id.to_id()); } }