-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
packages/next-swc/crates/next-core/src/next_shared/transforms/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/next-swc/crates/next-core/src/next_shared/transforms/next_amp_attributes.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::amp_attributes::amp_attributes; | ||
use turbopack_binding::{ | ||
swc::core::{ | ||
common::util::take::Take, | ||
ecma::{ast::*, visit::FoldWith}, | ||
}, | ||
turbopack::ecmascript::{CustomTransformer, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextAmpAttributes {} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextAmpAttributes { | ||
async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> { | ||
let p = std::mem::replace(program, Program::Module(Module::dummy())); | ||
*program = p.fold_with(&mut amp_attributes()); | ||
Ok(()) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/next-swc/crates/next-core/src/next_shared/transforms/next_cjs_optimizer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::cjs_optimizer::{cjs_optimizer, Config}; | ||
use turbopack_binding::{ | ||
swc::core::{ | ||
common::SyntaxContext, | ||
ecma::{ast::*, visit::VisitMutWith}, | ||
}, | ||
turbopack::ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextCjsOptimizer { | ||
config: Config, | ||
} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextCjsOptimizer { | ||
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> { | ||
let mut visitor = cjs_optimizer( | ||
self.config.clone(), | ||
SyntaxContext::empty().apply_mark(ctx.unresolved_mark), | ||
); | ||
|
||
program.visit_mut_with(&mut visitor); | ||
Ok(()) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...xt-swc/crates/next-core/src/next_shared/transforms/next_disallow_re_export_all_in_page.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::disallow_re_export_all_in_page::disallow_re_export_all_in_page; | ||
use turbopack_binding::{ | ||
swc::core::{ | ||
common::util::take::Take, | ||
ecma::{ast::*, visit::FoldWith}, | ||
}, | ||
turbopack::ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextDisallowReExportAllInPage { | ||
is_page_file: bool, | ||
} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextDisallowReExportAllInPage { | ||
async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> { | ||
let p = std::mem::replace(program, Program::Module(Module::dummy())); | ||
*program = p.fold_with(&mut disallow_re_export_all_in_page(self.is_page_file)); | ||
Ok(()) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/next-swc/crates/next-core/src/next_shared/transforms/next_optimize_server_react.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::optimize_server_react::{optimize_server_react, Config}; | ||
use turbopack_binding::{ | ||
swc::core::{ | ||
common::util::take::Take, | ||
ecma::{ast::*, visit::FoldWith}, | ||
}, | ||
turbopack::ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextOptimizeServerReact { | ||
optimize_use_state: bool, | ||
} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextOptimizeServerReact { | ||
async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> { | ||
let p = std::mem::replace(program, Program::Module(Module::dummy())); | ||
|
||
*program = p.fold_with(&mut optimize_server_react(Config { | ||
optimize_use_state: self.optimize_use_state, | ||
})); | ||
Ok(()) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/next-swc/crates/next-core/src/next_shared/transforms/next_page_config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::page_config::page_config; | ||
use turbopack_binding::{ | ||
swc::core::{ | ||
common::util::take::Take, | ||
ecma::{ast::*, visit::FoldWith}, | ||
}, | ||
turbopack::ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextPageConfig { | ||
is_development: bool, | ||
is_page_file: bool, | ||
} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextPageConfig { | ||
async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> { | ||
let p = std::mem::replace(program, Program::Module(Module::dummy())); | ||
|
||
*program = p.fold_with(&mut page_config(self.is_development, self.is_page_file)); | ||
Ok(()) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/next-swc/crates/next-core/src/next_shared/transforms/next_pure.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::pure::pure_magic; | ||
use turbopack_binding::{ | ||
swc::core::ecma::{ast::*, visit::VisitMutWith}, | ||
turbopack::ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextPure {} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextPure { | ||
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> { | ||
program.visit_mut_with(&mut pure_magic(ctx.comments.clone())); | ||
Ok(()) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/next-swc/crates/next-core/src/next_shared/transforms/next_shake_exports.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use next_custom_transforms::transforms::shake_exports::{shake_exports, Config}; | ||
use turbopack_binding::{ | ||
swc::core::{ | ||
common::util::take::Take, | ||
ecma::{ast::*, visit::FoldWith}, | ||
}, | ||
turbopack::ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
struct NextShakeExports { | ||
ignore: Vec<String>, | ||
} | ||
|
||
#[async_trait] | ||
impl CustomTransformer for NextShakeExports { | ||
async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> { | ||
let p = std::mem::replace(program, Program::Module(Module::dummy())); | ||
|
||
*program = p.fold_with(&mut shake_exports(Config { | ||
ignore: self.ignore.iter().map(|s| s.clone().into()).collect(), | ||
})); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters