-
Notifications
You must be signed in to change notification settings - Fork 110
refactor: extract swc_plugin_snapshot & swc_plugin_list
#1819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
|
|
||
| --- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
packages/react/transform/crates/swc_plugin_list/Cargo.toml
This file contains hidden or 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,12 @@ | ||
| [package] | ||
| name = "swc_plugin_list" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| path = "lib.rs" | ||
|
|
||
| [dependencies] | ||
| swc_core = { workspace = true, features = ["base", "ecma_codegen", "ecma_parser", "ecma_minifier", "ecma_transforms_typescript", "ecma_utils", "ecma_quote", "ecma_transforms_react", "ecma_transforms_optimization", "css_parser", "css_ast", "css_visit", "css_codegen", "__visit", "__testing_transform"] } | ||
| swc_plugin_snapshot = { path = "../swc_plugin_snapshot" } | ||
| swc_plugins_shared = { path = "../swc_plugins_shared" } |
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
packages/react/transform/crates/swc_plugin_snapshot/Cargo.toml
This file contains hidden or 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,20 @@ | ||
| [package] | ||
| name = "swc_plugin_snapshot" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| path = "lib.rs" | ||
|
|
||
| [dependencies] | ||
| convert_case = { workspace = true } | ||
| hex = { workspace = true } | ||
| napi = { workspace = true } | ||
| napi-derive = { workspace = true } | ||
| once_cell = { workspace = true } | ||
| regex = { workspace = true } | ||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json = { workspace = true, features = ["preserve_order"] } | ||
| sha-1 = { workspace = true } | ||
| swc_core = { workspace = true, features = ["base", "ecma_codegen", "ecma_parser", "ecma_minifier", "ecma_transforms_typescript", "ecma_utils", "ecma_quote", "ecma_transforms_react", "ecma_transforms_optimization"] } | ||
| swc_plugins_shared = { path = "../swc_plugins_shared" } |
File renamed without changes.
This file contains hidden or 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
108 changes: 108 additions & 0 deletions
108
packages/react/transform/crates/swc_plugin_snapshot/napi.rs
This file contains hidden or 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,108 @@ | ||
| use napi_derive::napi; | ||
| use swc_core::{ | ||
| common::comments::Comments, | ||
| ecma::{ast::*, visit::VisitMut}, | ||
| }; | ||
| use swc_plugins_shared::{target_napi::TransformTarget, transform_mode_napi::TransformMode}; | ||
|
|
||
| use crate::{ | ||
| JSXTransformer as CoreJSXTransformer, JSXTransformerConfig as CoreJSXTransformerConfig, | ||
| }; | ||
|
|
||
| /// @internal | ||
| #[napi(object)] | ||
| #[derive(Clone, Debug)] | ||
| pub struct JSXTransformerConfig { | ||
| /// @internal | ||
| pub preserve_jsx: bool, | ||
| /// @internal | ||
| pub runtime_pkg: String, | ||
| /// @internal | ||
| pub jsx_import_source: Option<String>, | ||
| /// @internal | ||
| pub filename: String, | ||
| /// @internal | ||
| #[napi(ts_type = "'LEPUS' | 'JS' | 'MIXED'")] | ||
| pub target: TransformTarget, | ||
| /// @internal | ||
| pub is_dynamic_component: Option<bool>, | ||
| } | ||
|
|
||
| impl Default for JSXTransformerConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| preserve_jsx: false, | ||
| runtime_pkg: "@lynx-js/react".into(), | ||
| jsx_import_source: Some("@lynx-js/react".into()), | ||
| filename: Default::default(), | ||
| target: TransformTarget::LEPUS, | ||
| is_dynamic_component: Some(false), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<JSXTransformerConfig> for CoreJSXTransformerConfig { | ||
| fn from(val: JSXTransformerConfig) -> Self { | ||
| Self { | ||
| preserve_jsx: val.preserve_jsx, | ||
| runtime_pkg: val.runtime_pkg, | ||
| jsx_import_source: val.jsx_import_source, | ||
| filename: val.filename, | ||
| target: val.target.into(), | ||
| is_dynamic_component: val.is_dynamic_component, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<CoreJSXTransformerConfig> for JSXTransformerConfig { | ||
| fn from(val: CoreJSXTransformerConfig) -> Self { | ||
| Self { | ||
| preserve_jsx: val.preserve_jsx, | ||
| runtime_pkg: val.runtime_pkg, | ||
| jsx_import_source: val.jsx_import_source, | ||
| filename: val.filename, | ||
| target: val.target.into(), | ||
| is_dynamic_component: val.is_dynamic_component, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct JSXTransformer<C> | ||
| where | ||
| C: Comments + Clone, | ||
| { | ||
| inner: CoreJSXTransformer<C>, | ||
| } | ||
|
|
||
| impl<C> JSXTransformer<C> | ||
| where | ||
| C: Comments + Clone, | ||
| { | ||
| pub fn with_content_hash(mut self, content_hash: String) -> Self { | ||
| self.inner.content_hash = content_hash; | ||
| self | ||
| } | ||
|
|
||
| pub fn new(cfg: JSXTransformerConfig, comments: Option<C>, mode: TransformMode) -> Self { | ||
| Self { | ||
| inner: CoreJSXTransformer::new(cfg.into(), comments, mode.into()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<C> VisitMut for JSXTransformer<C> | ||
| where | ||
| C: Comments + Clone, | ||
| { | ||
| fn visit_mut_jsx_element(&mut self, node: &mut JSXElement) { | ||
| self.inner.visit_mut_jsx_element(node) | ||
| } | ||
|
|
||
| fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) { | ||
| self.inner.visit_mut_module_items(n) | ||
| } | ||
|
|
||
| fn visit_mut_module(&mut self, n: &mut Module) { | ||
| self.inner.visit_mut_module(n) | ||
| } | ||
| } | ||
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,4 +1,5 @@ | ||
| pub mod css; | ||
| pub mod jsx_helpers; | ||
| pub mod target; | ||
| pub mod target_napi; | ||
| pub mod transform_mode; | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.