-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
14 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
crates/swc_plugin_compile_mode_pre_process/src/utils/constant.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,3 @@ | ||
pub const COMPILE_MODE: &str = "compileMode"; | ||
pub const DEFAULT_COMPONENT: &str = "Default_Component"; | ||
pub const COMPILE_MODE_SUB_COMPONENT: &str = "compileModeSubComponent"; |
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,3 @@ | ||
pub mod constant; | ||
pub mod react_component; | ||
pub mod render_fn; |
38 changes: 38 additions & 0 deletions
38
crates/swc_plugin_compile_mode_pre_process/src/utils/react_component.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,38 @@ | ||
use swc_core::ecma::{ast::BlockStmt, visit::VisitMutWith}; | ||
|
||
use crate::visitors::is_compile_mode_component::IsCompileModeVisitor; | ||
|
||
pub struct ReactComponent { | ||
pub name: String, | ||
pub block_stmt: Option<BlockStmt>, | ||
} | ||
|
||
impl Clone for ReactComponent { | ||
fn clone(&self) -> Self { | ||
ReactComponent { | ||
name: self.name.clone(), | ||
block_stmt: self.block_stmt.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl ReactComponent { | ||
pub fn new(name: String, block_stmt: Option<BlockStmt>) -> Self { | ||
ReactComponent { name, block_stmt } | ||
} | ||
|
||
pub fn get_name(&self) -> String { | ||
self.name.clone() | ||
} | ||
|
||
pub fn is_valid(&mut self) -> bool { | ||
// 1. 名称是否是大写字母开头 | ||
let is_first_char_uppercase = self.get_name().chars().next().unwrap().is_uppercase(); | ||
// 2. 返回的 JSX 里面有没有 compilerMode | ||
let mut is_compile_mode_component: IsCompileModeVisitor = IsCompileModeVisitor::new(); | ||
if let Some(block_stmt) = &mut self.block_stmt { | ||
block_stmt.visit_mut_with(&mut is_compile_mode_component); | ||
} | ||
is_first_char_uppercase && is_compile_mode_component.valid | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
crates/swc_plugin_compile_mode_pre_process/src/utils/render_fn.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 swc_core::ecma::ast::*; | ||
|
||
pub struct RenderFn { | ||
pub params: Vec<Pat>, | ||
pub jsx_element: JSXElement, | ||
} | ||
|
||
impl RenderFn { | ||
pub fn new(params: Vec<Pat>, jsx_element: JSXElement) -> Self { | ||
RenderFn { | ||
params, | ||
jsx_element, | ||
} | ||
} | ||
} | ||
|
||
impl Clone for RenderFn { | ||
fn clone(&self) -> Self { | ||
RenderFn { | ||
params: self.params.clone(), | ||
jsx_element: self.jsx_element.clone(), | ||
} | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
crates/swc_plugin_compile_mode_pre_process/src/visitors/collect_render_fn.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
7 changes: 5 additions & 2 deletions
7
crates/swc_plugin_compile_mode_pre_process/src/visitors/entry.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
2 changes: 1 addition & 1 deletion
2
crates/swc_plugin_compile_mode_pre_process/src/visitors/find_react_component.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
pub mod collect_render_fn; | ||
pub mod common; | ||
pub mod entry; | ||
pub mod find_react_component; | ||
pub mod generate_deps; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
tab_spaces = 2 | ||
|
||
edition = "2021" |