Skip to content

Commit

Permalink
perf: remove swc unused features
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 20, 2024
1 parent fd2be5b commit 41ceec9
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 89 deletions.
61 changes: 0 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ regex = "1.7.3"
serde = { version = "1", features = ["derive"] }
swc_xml = "0.17.0"
swc_core = { version = "0.100.1", features = [
"__common",
"ecma_ast",
"ecma_ast_serde",
"common_concurrent",
"bundler",
"ecma_loader",
"ecma_transforms",
"ecma_visit",
"ecma_codegen",
"ecma_parser",
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/add_jsx_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn svg_prop_to_attr(key: &str, value: &str) -> Attribute {

#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::rc::Rc;

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -242,7 +242,7 @@ mod tests {
}

fn code_test(input: &str, opts: Options, expected: &str) {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let lexer = Lexer::new(
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/hast_to_swc_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub fn to_swc_ast(hast: swc_xml::ast::Document) -> Option<JSXElement> {

#[cfg(test)]
mod tests {
use std::{borrow::Borrow, path::PathBuf, sync::Arc};
use std::{borrow::Borrow, path::PathBuf, rc::Rc};

use swc_core::{
common::{FileName, SourceFile, SourceMap},
Expand All @@ -252,7 +252,7 @@ mod tests {

use super::*;

fn transform(cm: Arc<SourceMap>, fm: Arc<SourceFile>, minify: bool) -> String {
fn transform(cm: Rc<SourceMap>, fm: Rc<SourceFile>, minify: bool) -> String {
let mut errors = vec![];
let doc = parse_file_as_document(fm.borrow(), Default::default(), &mut errors).unwrap();

Expand Down Expand Up @@ -284,7 +284,7 @@ mod tests {
fn document_test(input: PathBuf) {
let jsx_path = input.parent().unwrap().join("output.jsx");

let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.load_file(&input).expect("failed to load fixture file");

let res = transform(cm, fm, false);
Expand All @@ -295,7 +295,7 @@ mod tests {
}

fn code_test(input: &str, expected: &str) {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let res = transform(cm, fm, true);
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#[macro_use]
extern crate napi_derive;

use std::{borrow::Borrow, sync::Arc};
use std::{borrow::Borrow, rc::Rc};

use swc_core::{
common::{comments::SingleThreadedComments, FileName, SourceMap},
Expand Down Expand Up @@ -56,7 +56,7 @@ pub use self::core::state::{Caller, Config as State};
pub fn transform(code: String, config: Config, state: State) -> Result<String, SvgrError> {
let state = core::state::expand_state(&state);

let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), code);

let mut errors = vec![];
Expand Down
5 changes: 2 additions & 3 deletions crates/core/src/remove_jsx_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl VisitMut for Visitor {

#[cfg(test)]
mod tests {
use std::default::Default;
use std::sync::Arc;
use std::{default::Default, rc::Rc};

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -72,7 +71,7 @@ mod tests {
}

fn code_test(input: &str, opts: Options, expected: &str) {
let cm = Arc::new(SourceMap::default());
let cm = Rc::new(SourceMap::default());
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let lexer = Lexer::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/replace_jsx_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn get_attr_value(new: &str) -> JSXAttrValue {

#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::rc::Rc;

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -78,7 +78,7 @@ mod tests {
use super::*;

fn code_test(input: &str, replace_attr_values: LinkedHashMap<String, String>, expected: &str) {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let lexer = Lexer::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/svg_dynamic_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl VisitMut for Visitor {

#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::rc::Rc;

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -234,7 +234,7 @@ mod tests {
use super::*;

fn code_test(input: &str, tag: String, expected: &str) {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let lexer = Lexer::new(
Expand Down
5 changes: 2 additions & 3 deletions crates/core/src/svg_em_dimensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ fn get_value(raw: Option<&Size>) -> JSXAttrValue {

#[cfg(test)]
mod tests {
use std::default::Default;
use std::sync::Arc;
use std::{default::Default, rc::Rc};

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -153,7 +152,7 @@ mod tests {
}

fn code_test(input: &str, opts: Options, expected: &str) {
let cm = Arc::new(SourceMap::default());
let cm = Rc::new(SourceMap::default());
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let lexer = Lexer::new(
Expand Down
4 changes: 1 addition & 3 deletions crates/core/src/transform_react_native_svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ impl VisitMut for ImportDeclVisitor {

#[cfg(test)]
mod tests {
use std::sync::Arc;

use swc_core::{
common::{comments::SingleThreadedComments, FileName, SourceMap},
ecma::{
Expand All @@ -264,7 +262,7 @@ mod tests {
use super::*;

fn code_test(input: &str, expected: &str) {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let lexer = Lexer::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/transform_svg_component/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn transform(

#[cfg(test)]
mod tests {
use std::{borrow::Borrow, sync::Arc};
use std::{borrow::Borrow, rc::Rc};

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -147,7 +147,7 @@ mod tests {
state: &core::state::InternalConfig,
expected: &str,
) {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

let mut recovered_errors = vec![];
Expand Down

0 comments on commit 41ceec9

Please sign in to comment.