Skip to content

Commit

Permalink
refactor(next-swc/ssg): consolidate repeated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Apr 15, 2022
1 parent f83ea07 commit 3d3b061
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/next-swc/crates/core/src/next_ssg.rs
Expand Up @@ -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<RefCell<FxHashSet<String>>>) -> impl Fold {
Repeat::new(NextSsg {
Expand Down Expand Up @@ -55,9 +57,7 @@ struct State {
impl State {
#[allow(clippy::wrong_self_convention)]
fn is_data_identifier(&mut self, i: &Ident) -> Result<bool, Error> {
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| {
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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());
}
}
Expand Down

0 comments on commit 3d3b061

Please sign in to comment.