Skip to content

Commit

Permalink
perf: remove swc unused features (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind authored Sep 21, 2024
1 parent 7d1f617 commit 5cb0506
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 1,284 deletions.
1,335 changes: 85 additions & 1,250 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crates/binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ crate-type = ["cdylib"]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.12.0", default-features = false, features = ["napi4"] }
napi-derive = { version = "2.12.2" }
swc_core = { version = "0.100.1", features = ["base_node"] }
svgr-rs = { path = "../core" }

[build-dependencies]
Expand Down
5 changes: 1 addition & 4 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ version = "0.1.3"
regex = "1.7.3"
swc_xml = "0.17.0"
swc_core = { version = "0.100.1", features = [
"__common",
"ecma_ast",
"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 @@ -223,7 +223,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 @@ -243,7 +243,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 @@ -248,7 +248,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 @@ -259,7 +259,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 @@ -291,7 +291,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 @@ -302,7 +302,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
6 changes: 3 additions & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(path_file_prefix)]
#![deny(clippy::all)]

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

use swc_core::{
common::{comments::SingleThreadedComments, FileName, SourceMap},
Expand Down Expand Up @@ -54,11 +54,11 @@ 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![];
let document = parse_file_as_document(fm.borrow(), Default::default(), &mut errors)
let document = parse_file_as_document(fm.as_ref(), Default::default(), &mut errors)
.map_err(|e| SvgrError::Parse(e.message().to_string()))?;

let jsx_element = hast_to_swc_ast::to_swc_ast(document);
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 @@ -64,7 +64,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 @@ -79,7 +79,7 @@ mod tests {
use super::*;

fn code_test(input: &str, replace_attr_values: HashMap<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
7 changes: 3 additions & 4 deletions crates/core/src/transform_react_native_svg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{cell::RefCell, collections::HashMap, rc::Rc};
use std::rc::Rc;
use std::{cell::RefCell, collections::HashMap};

use linked_hash_set::LinkedHashSet;
use swc_core::common::SyntaxContext;
Expand Down Expand Up @@ -249,8 +250,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 +263,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
6 changes: 3 additions & 3 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::rc::Rc;

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -147,12 +147,12 @@ 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![];
let expr = parser::parse_file_as_expr(
fm.borrow(),
fm.as_ref(),
parser::Syntax::Es(parser::EsSyntax {
jsx: true,
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/transform_svg_component/variables.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Borrow, sync::Arc};
use std::rc::Rc;

use swc_core::common::SyntaxContext;
use swc_core::{
Expand Down Expand Up @@ -323,12 +323,12 @@ pub fn get_variables(

if let Some(caller) = &state.caller {
if let Some(previous_export) = caller.previous_export.clone() {
let cm = Arc::<SourceMap>::default();
let cm = Rc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), previous_export);

let mut recovered_errors = vec![];
let module = parser::parse_file_as_module(
fm.borrow(),
fm.as_ref(),
parser::Syntax::Es(parser::EsSyntax {
jsx: true,
..Default::default()
Expand Down

0 comments on commit 5cb0506

Please sign in to comment.