Skip to content

Commit

Permalink
feat: remove unused swc_core features
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 21, 2024
1 parent 359f5a4 commit 0f1ea2e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 1,141 deletions.
1,125 changes: 10 additions & 1,115 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", default-features = false, features = ["base_node"] }
svgr-rs = { path = "../core" }

[build-dependencies]
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
4 changes: 2 additions & 2 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::sync::Arc;
use std::rc::Rc;

use swc_core::{
common::{comments::SingleThreadedComments, FileName, SourceMap},
Expand Down Expand Up @@ -54,7 +54,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
4 changes: 2 additions & 2 deletions crates/core/src/remove_jsx_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl VisitMut for Visitor {

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

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -71,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
4 changes: 2 additions & 2 deletions crates/core/src/svg_em_dimensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn get_value(raw: Option<&Size>) -> JSXAttrValue {

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

use swc_core::{
common::{FileName, SourceMap},
Expand All @@ -152,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 @@ -250,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 @@ -265,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 0f1ea2e

Please sign in to comment.