Skip to content

Commit

Permalink
Merge pull request #26 from stormslowly/feat/update_swc_core_0.100
Browse files Browse the repository at this point in the history
chore: ⬆️ update swc_core to 0.100.x
  • Loading branch information
SyMind authored Sep 19, 2024
2 parents 5d83cb9 + 666222c commit a5d487f
Show file tree
Hide file tree
Showing 19 changed files with 1,507 additions and 1,192 deletions.
2,304 changes: 1,236 additions & 1,068 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"crates/core",
"crates/binding"
"crates/core",
"crates/binding",
]
resolver = "2"
3 changes: 2 additions & 1 deletion binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export interface TransformOutput {
code: string
map?: string
output?: string
}
export interface Caller {
name?: string
Expand All @@ -24,4 +25,4 @@ export interface State {
*/
caller?: Caller
}
export function transform(code: string, config: Buffer, state?: State | undefined | null): Promise<string>
export declare function transform(code: string, config: Buffer, state?: State | undefined | null): Promise<string>
66 changes: 62 additions & 4 deletions binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process').execSync('which ldd').toString().trim();
const lddPath = require('child_process').execSync('which ldd').toString().trim()
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
Expand Down Expand Up @@ -224,14 +224,72 @@ switch (platform) {
}
break
case 'arm':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'svgr-rs.linux-arm-musleabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./svgr-rs.linux-arm-musleabihf.node')
} else {
nativeBinding = require('@svgr-rs/core-linux-arm-musleabihf')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'svgr-rs.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./svgr-rs.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('@svgr-rs/core-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'svgr-rs.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./svgr-rs.linux-riscv64-musl.node')
} else {
nativeBinding = require('@svgr-rs/core-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'svgr-rs.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./svgr-rs.linux-riscv64-gnu.node')
} else {
nativeBinding = require('@svgr-rs/core-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'svgr-rs.linux-arm-gnueabihf.node')
join(__dirname, 'svgr-rs.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./svgr-rs.linux-arm-gnueabihf.node')
nativeBinding = require('./svgr-rs.linux-s390x-gnu.node')
} else {
nativeBinding = require('@svgr-rs/core-linux-arm-gnueabihf')
nativeBinding = require('@svgr-rs/core-linux-s390x-gnu')
}
} catch (e) {
loadError = e
Expand Down
2 changes: 1 addition & 1 deletion crates/binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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", "async"] }
napi-derive = { version = "2.12.2" }
swc_core = { version = "0.74.2", features = ["base_node"] }
swc_core = { version = "0.100.1", features = ["base_node"] }
svgr-rs = { path = "../core", features = ["node"] }

[build-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ napi-derive = { version = "2.12.2", optional = true }
clap = { version = "4.2.0", features = ["derive"] }
regex = "1.7.3"
serde = { version = "1", features = ["derive"] }
swc_xml = "0.10.3"
swc_core = { version = "0.74.2", features = [
swc_xml = "0.17.0"
swc_core = { version = "0.100.1", features = [
"ecma_ast",
"ecma_ast_serde",
"common_concurrent",
Expand All @@ -28,7 +28,7 @@ swc_core = { version = "0.74.2", features = [
"ecma_transforms",
"ecma_visit",
"ecma_codegen",
"__parser",
"ecma_parser",
] }
thiserror = "1.0.56"
linked-hash-map = { version = "0.5.6", features = ["serde_impl"] }
Expand Down
18 changes: 9 additions & 9 deletions crates/core/src/add_jsx_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use swc_core::common::SyntaxContext;
use swc_core::{
common::DUMMY_SP,
ecma::{ast::*, visit::VisitMut},
Expand Down Expand Up @@ -163,16 +164,16 @@ fn get_attr(spread: bool, name: &str, value: Option<&String>, literal: bool) ->
expr: Box::new(Expr::Ident(Ident {
sym: name.to_string().into(),
span: DUMMY_SP,
ctxt: SyntaxContext::empty(),
optional: false,
})),
})
} else {
JSXAttrOrSpread::JSXAttr(JSXAttr {
span: DUMMY_SP,
name: JSXAttrName::Ident(Ident {
name: JSXAttrName::Ident(IdentName {
sym: name.to_string().into(),
span: DUMMY_SP,
optional: false,
}),
value: get_attr_value(literal, value),
})
Expand All @@ -188,6 +189,7 @@ fn get_attr_value(literal: bool, attr_value: Option<&String>) -> Option<JSXAttrV
expr: JSXExpr::Expr(Box::new(Expr::Ident(Ident {
sym: value.to_string().into(),
span: DUMMY_SP,
ctxt: SyntaxContext::empty(),
optional: false,
}))),
}))
Expand Down Expand Up @@ -226,8 +228,8 @@ mod tests {
common::{FileName, SourceMap},
ecma::{
ast::*,
codegen::{text_writer::JsWriter, Config, Emitter},
parser::{lexer::Lexer, EsConfig, Parser, StringInput, Syntax},
codegen::{text_writer::JsWriter, Emitter},
parser::{lexer::Lexer, EsSyntax, Parser, StringInput, Syntax},
visit::{as_folder, FoldWith},
},
};
Expand All @@ -241,10 +243,10 @@ mod tests {

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

let lexer = Lexer::new(
Syntax::Es(EsConfig {
Syntax::Es(EsSyntax {
decorators: true,
jsx: true,
..Default::default()
Expand All @@ -264,9 +266,7 @@ mod tests {

let mut buf = vec![];
let mut emitter = Emitter {
cfg: Config {
..Default::default()
},
cfg: Default::default(),
cm: cm.clone(),
comments: None,
wr: JsWriter::new(cm, "", &mut buf, None),
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/core/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct Config {

#[derive(Debug)]
pub struct InternalConfig {
#[allow(dead_code)]
pub file_path: Option<String>,
pub component_name: String,
pub caller: Option<Caller>,
Expand Down
25 changes: 16 additions & 9 deletions crates/core/src/hast_to_swc_ast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;

use regex::{Captures, Regex};
use swc_core::common::SyntaxContext;
use swc_core::{
common::DUMMY_SP,
ecma::{ast::*, atoms::JsWord},
Expand Down Expand Up @@ -109,13 +110,17 @@ impl HastVisitor {
let value = attr.value.clone().map(|v| get_value(&attr.name, &v));
JSXAttrOrSpread::JSXAttr(JSXAttr {
span: DUMMY_SP,
name: JSXAttrName::Ident(self.get_key(&attr.name, &n.tag_name)),
name: JSXAttrName::Ident(self.get_key(&attr.name, &n.tag_name).into()),
value,
})
})
.collect::<Vec<JSXAttrOrSpread>>();

let name = JSXElementName::Ident(Ident::new(n.tag_name.clone(), DUMMY_SP));
let name = JSXElementName::Ident(Ident::new(
n.tag_name.clone(),
DUMMY_SP,
SyntaxContext::empty(),
));
let children = self.all(&n.children);

let opening = JSXOpeningElement {
Expand Down Expand Up @@ -177,6 +182,7 @@ impl HastVisitor {
if let Some(k) = rc_key {
return Ident {
span: DUMMY_SP,
ctxt: SyntaxContext::empty(),
sym: k.into(),
optional: false,
};
Expand All @@ -186,6 +192,7 @@ impl HastVisitor {
if let Some(k) = mapped_attr {
return Ident {
span: DUMMY_SP,
ctxt: SyntaxContext::empty(),
sym: JsWord::from(*k),
optional: false,
};
Expand All @@ -196,6 +203,7 @@ impl HastVisitor {
if kebab_key.starts_with("aria-") {
return Ident {
span: DUMMY_SP,
ctxt: SyntaxContext::empty(),
sym: convert_aria_attribute(attr_name).into(),
optional: false,
};
Expand All @@ -204,14 +212,16 @@ impl HastVisitor {
if kebab_key.starts_with("data-") {
return Ident {
span: DUMMY_SP,
sym: attr_name.clone().into(),
ctxt: SyntaxContext::empty(),
sym: attr_name.into(),
optional: false,
};
}

Ident {
span: DUMMY_SP,
sym: attr_name.clone().into(),
ctxt: SyntaxContext::empty(),
sym: attr_name.into(),
optional: false,
}
}
Expand Down Expand Up @@ -255,10 +265,7 @@ mod tests {
false => "\n",
};
let mut emitter = Emitter {
cfg: Config {
minify,
..Default::default()
},
cfg: Config::default().with_minify(minify),
cm: cm.clone(),
comments: None,
wr: JsWriter::new(cm, new_line, &mut buf, None),
Expand Down Expand Up @@ -289,7 +296,7 @@ mod tests {

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

let res = transform(cm, fm, true);

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/hast_to_swc_ast/string_to_object_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn format_key(key: &str) -> PropName {
key = key[1..].into();
}

PropName::Ident(Ident::new(hyphen_to_camel_case(&key).into(), DUMMY_SP))
PropName::Ident(IdentName::new(hyphen_to_camel_case(&key).into(), DUMMY_SP))
}

fn is_convertible_pixel_value(s: &str) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn transform(code: String, config: Config, state: State) -> Result<String, S
let state = core::state::expand_state(&state);

let cm = Arc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon, code);
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)
Expand Down
15 changes: 7 additions & 8 deletions crates/core/src/remove_jsx_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ impl VisitMut for Visitor {

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

use swc_core::{
common::{FileName, SourceMap},
ecma::{
ast::*,
codegen::{text_writer::JsWriter, Config, Emitter},
parser::{lexer::Lexer, EsConfig, Parser, StringInput, Syntax},
codegen::{text_writer::JsWriter, Emitter},
parser::{lexer::Lexer, EsSyntax, Parser, StringInput, Syntax},
visit::{as_folder, FoldWith},
},
};
Expand All @@ -71,11 +72,11 @@ mod tests {
}

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

let lexer = Lexer::new(
Syntax::Es(EsConfig {
Syntax::Es(EsSyntax {
decorators: true,
jsx: true,
..Default::default()
Expand All @@ -95,9 +96,7 @@ mod tests {

let mut buf = vec![];
let mut emitter = Emitter {
cfg: Config {
..Default::default()
},
cfg: Default::default(),
cm: cm.clone(),
comments: None,
wr: JsWriter::new(cm, "", &mut buf, None),
Expand Down
Loading

0 comments on commit a5d487f

Please sign in to comment.