Skip to content
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

feat/upgrade swc #1444

Merged
merged 96 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
c08e0a9
🚧
stormslowly Jul 23, 2024
c2c086c
🚧 a basic working version
stormslowly Jul 24, 2024
ee880a9
chore: 🚨 lint happy
stormslowly Jul 24, 2024
f462f2d
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Jul 24, 2024
6cd9a0e
refactor: 🎨 adjust to new swc
stormslowly Jul 24, 2024
3ac7a58
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Jul 29, 2024
7234ad3
refactor: 🎨 remove deprecated methods
stormslowly Jul 29, 2024
1138d0d
chore: 🚨 lint happy
stormslowly Jul 29, 2024
3ffa4f7
feat: ✨ update swc emotion
stormslowly Jul 29, 2024
38f29a4
chore: 🔧 remove useless profile in sub crate
stormslowly Jul 29, 2024
7c90a2e
chore: 🔧 add back emotion plugin
stormslowly Jul 29, 2024
b019acc
refactor: 🎨 add back merge source map
stormslowly Jul 30, 2024
f6ad12f
test: ✅ hot update js file served by hyper static, it use text/javasc…
stormslowly Jul 30, 2024
4999c74
chore: 🔧 lock update
stormslowly Jul 30, 2024
e653291
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 1, 2024
7d35042
chore: 🔧 clean up swc core feature
stormslowly Aug 1, 2024
ac36b4f
refactor: 🎨 fix breaking change of ctxt of span
stormslowly Aug 2, 2024
a8b8c0f
fix: 🐛 ctxt apply mark
stormslowly Aug 2, 2024
5890fd1
refactor: 🎨 use DUMMY CTXT instead of SyntaxContext::empty()
stormslowly Aug 2, 2024
d042ab9
chore: ⬆️ temperal use mdxjs from kdy branch
stormslowly Aug 3, 2024
4804b61
feat: ✨ re-enable mdxjs
stormslowly Aug 3, 2024
70a4b27
feat: ✨ swc_core 0.100.1
stormslowly Aug 6, 2024
aa3b063
chore: 🙈 ignore fmt in fixtures
stormslowly Aug 6, 2024
f0a01c1
chore: 🚨 lint happy
stormslowly Aug 6, 2024
d88c5b3
chore: ⬆️ swc_common
stormslowly Aug 6, 2024
83efd80
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 7, 2024
6a1de11
chore: ✏️ typo
stormslowly Aug 7, 2024
6e11a11
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 7, 2024
e097ed7
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 8, 2024
bf8205e
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 9, 2024
040ef88
release: @umijs/[email protected]
stormslowly Aug 12, 2024
81a3b94
chore: [email protected]
stormslowly Aug 12, 2024
e3b5032
chore: ⬆️ swc_core 0.100.6
stormslowly Aug 13, 2024
47d44c5
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 13, 2024
ad4f211
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 14, 2024
9005c84
release: @umijs/[email protected]
stormslowly Aug 14, 2024
bd59d9e
chore: [email protected]
stormslowly Aug 14, 2024
116bebd
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 16, 2024
47d623d
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 19, 2024
1ea6050
chore: 🚨 lint happy
stormslowly Aug 19, 2024
a9b4b79
chore: 🔧 CI build bindings
stormslowly Aug 20, 2024
ec76b7b
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 20, 2024
182ff17
chore: 🔧 fix build docker
stormslowly Aug 20, 2024
08091e9
refactor: 🔥 remove aarch64-unknown-linux-gnu
stormslowly Aug 20, 2024
82f2b66
chore: 🔧 create tar
stormslowly Aug 20, 2024
3cbc14b
chore: 🙈
stormslowly Aug 20, 2024
813fb05
release: @umijs/[email protected]
stormslowly Aug 20, 2024
fa39267
chore: [email protected]
stormslowly Aug 20, 2024
1a92861
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 20, 2024
a0737d8
chore: 🔧 wrong donwload param
stormslowly Aug 20, 2024
8698e6a
chore: 🔧 upload download actions should be same version
stormslowly Aug 20, 2024
90aafa0
chore: 🔧 try codecov in ci
stormslowly Aug 20, 2024
85ac122
refactor: 🔥 remove unnecessary target
stormslowly Aug 21, 2024
5413b2b
refactor: 🎨 use swc comments
stormslowly Aug 22, 2024
2818dcd
fix: 🐛 after upgrade to swc_core it should remove paren before minifiy
stormslowly Aug 22, 2024
0f31d48
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 22, 2024
6997dd6
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 22, 2024
3477f81
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 22, 2024
2dec42a
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 26, 2024
770214a
refactor: 🎨 move dummy ctxt defintion to ast mod
stormslowly Aug 26, 2024
6b4b3c1
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Aug 29, 2024
c041491
chore: 🚨 lint happy
stormslowly Aug 29, 2024
6557211
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 2, 2024
509be77
release: @umijs/[email protected]
stormslowly Sep 2, 2024
0ecd456
chore: [email protected]
stormslowly Sep 2, 2024
cef7aa9
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 3, 2024
10b0ec3
release: @umijs/[email protected]
stormslowly Sep 3, 2024
073b801
chore: [email protected]
stormslowly Sep 3, 2024
4f0429e
refactor: 🎨 use VisitMut + Fold code style
stormslowly Sep 3, 2024
5a7a51d
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 5, 2024
1cc9e22
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 5, 2024
e750180
chore: ⬆️ update pnpm-lock
stormslowly Sep 5, 2024
e428feb
chore: 🙈
stormslowly Sep 5, 2024
8904f1f
revert: ⏪ delete musl bindin
stormslowly Sep 5, 2024
022702b
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 9, 2024
90fab94
release: @umijs/[email protected]
stormslowly Sep 9, 2024
450c3ae
chore: [email protected]
stormslowly Sep 9, 2024
c1497ef
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 10, 2024
1ca67f6
release: @umijs/[email protected]
stormslowly Sep 10, 2024
21ad3ee
chore: [email protected]
stormslowly Sep 10, 2024
a285995
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 10, 2024
ee28ca6
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 12, 2024
166741c
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 14, 2024
5e52a54
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 14, 2024
843c1e6
fix: 🐛 use chars() instead of bytes()
stormslowly Sep 18, 2024
aebe68f
fix: 🐛 unescape html entity by html escape crate
stormslowly Sep 18, 2024
a1bb3f0
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 19, 2024
1d7ac53
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 23, 2024
6445297
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 23, 2024
98ee3c9
release: @umijs/[email protected]
stormslowly Sep 24, 2024
f93d46f
chore: [email protected]
stormslowly Sep 24, 2024
3b76180
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Sep 26, 2024
f2f2cc5
release: @umijs/[email protected]
stormslowly Sep 27, 2024
5da9cda
chore: [email protected]
stormslowly Sep 27, 2024
9d219f5
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Oct 10, 2024
c8153ef
Merge remote-tracking branch 'origin/master' into feat/upgrade_swc
stormslowly Oct 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,743 changes: 2,034 additions & 1,709 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ resolver = "2"

[workspace.dependencies]
cached = "0.46.1"
clap = "4.3.11"
mimalloc-rust = { version = "=0.2.1" }
serde = { version = "1.0.171", features = ["derive"] }
regex = "1.9.3"
serde = "1.0.171"
serde_json = "1.0.100"
swc_core = { version = "=0.83.22", default-features = false }
swc_core = { version = "0.101.4", default-features = false }
tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tls"] }

[profile.release]
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"./tmp/**",
"./.pnpm-store/**",
"./packages/*/dist/**",
"**/package.json"
"**/package.json",
"./crates/svgr-rs/__fixture__/**"
]
},
"formatter": {
Expand Down
1 change: 1 addition & 0 deletions crates/binding/src/tsfn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct JsHooks {
}

pub struct TsFnHooks {
#[allow(dead_code)]
pub name: String,
pub build_start: Option<threadsafe_function::ThreadsafeFunction<ReadMessage<(), ()>>>,
pub generate_end:
Expand Down
25 changes: 9 additions & 16 deletions crates/mako/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ test = false
bitflags = { version = "2.4.2", features = ["serde"] }
cached = { workspace = true }
dashmap = "4.0.1"
delegate = "0.12.0"
fixedbitset = "0.4.2"
get_if_addrs = "0.5.3"
glob-match = "0.2.1"
Expand All @@ -30,13 +29,6 @@ serde_json = { workspace = true }
url = { version = "2.5.0" }

swc_core = { workspace = true, features = [
"__ecma",
"__ecma_plugin_transform",
"__ecma_transforms",
"__parser",
"__testing_transform",
"__utils",
"__visit",
"base",
"common_concurrent",
"common_sourcemap",
Expand All @@ -50,11 +42,11 @@ swc_core = { workspace = true, features = [
"css_prefixer",
"css_utils",
"css_visit",
"css_visit_path",
"ecma_ast",
"ecma_codegen",
"ecma_minifier",
"ecma_minifier_concurrent",
"ecma_parser",
"ecma_preset_env",
"ecma_quote",
"ecma_transforms_compat",
Expand All @@ -63,18 +55,19 @@ swc_core = { workspace = true, features = [
"ecma_transforms_proposal",
"ecma_transforms_react",
"ecma_transforms_typescript",
"ecma_utils",
"ecma_visit_path",
"swc_ecma_quote_macros",
] }

swc_emotion = "0.51.0"
swc_error_reporters = "0.16.1"
swc_node_comments = "0.19.1"
swc_emotion = "0.72.19"
swc_error_reporters = "0.21.0"
swc_node_comments = "0.24.0"

anyhow = "1.0.71"
base64 = "0.21.2"
chrono = "0.4.38"
clap = { version = "4.3.11", features = ["derive"] }
clap = { workspace = true, features = ["derive"] }
colored = "2"
config = "0.13.3"
convert_case = "0.6.0"
Expand All @@ -89,7 +82,7 @@ hyper-tungstenite = "0.10.0"
indexmap = "2.0.0"
indicatif = "0.17.8"
md5 = "0.7.0"
mdxjs = "0.1.14"
mdxjs = "0.2.6"
mime_guess = "2.0.4"
nohash-hasher = "0.2.0"
notify = { version = "6.1.1", default-features = false, features = ["macos_kqueue"] }
Expand All @@ -101,11 +94,11 @@ petgraph = "0.6.3"
puffin = { version = "0.16.0", optional = true }
puffin_egui = { version = "0.22.0", optional = true }
rayon = "1.7.0"
regex = "1.9.3"
regex = { workspace = true }
sailfish = "0.8.3"
serde-xml-rs = "0.6.0"
serde_yaml = "0.9.22"
svgr-rs = "0.1.3"
svgr-rs = { path = "../svgr-rs" }
thiserror = "1.0.43"
tokio = { version = "1", features = ["rt-multi-thread", "sync"] }
tokio-tungstenite = "0.19.0"
Expand Down
40 changes: 2 additions & 38 deletions crates/mako/src/ast/comments.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use delegate::delegate;
use swc_core::common;
use swc_core::common::comments::{Comment, Comments as CommentsTrait};
use swc_core::common::{BytePos, Span};
use swc_node_comments::SwcComments;

#[derive(Default)]
pub struct Comments(MakoComments);
pub struct Comments(SwcComments);

impl Comments {
pub fn get_swc_comments(&self) -> &MakoComments {
pub fn get_swc_comments(&self) -> &SwcComments {
&self.0
}

Expand Down Expand Up @@ -85,38 +84,3 @@ impl Comments {
found
}
}

#[derive(Clone, Default)]
pub struct MakoComments(SwcComments);

impl CommentsTrait for MakoComments {
fn add_pure_comment(&self, pos: BytePos) {
//ref: https://github.com/swc-project/swc/pull/8172
if pos.is_dummy() {
#[cfg(debug_assertions)]
{
use tracing::warn;
warn!("still got pure comments at dummy pos! UPGRADE SWC!!!");
}
return;
}
self.0.add_pure_comment(pos);
}

delegate! {
to self.0 {
fn add_leading(&self, pos: BytePos, cmt: Comment);
fn add_leading_comments(&self, pos: BytePos, comments: Vec<Comment>);
fn has_leading(&self, pos: BytePos) -> bool;
fn move_leading(&self, from: BytePos, to: BytePos);
fn take_leading(&self, pos: BytePos) -> Option<Vec<Comment>>;
fn get_leading(&self, pos: BytePos) -> Option<Vec<Comment>>;
fn add_trailing(&self, pos: BytePos, cmt: Comment);
fn add_trailing_comments(&self, pos: BytePos, comments: Vec<Comment>);
fn has_trailing(&self, pos: BytePos) -> bool;
fn move_trailing(&self, from: BytePos, to: BytePos);
fn take_trailing(&self, pos: BytePos) -> Option<Vec<Comment>>;
fn get_trailing(&self, pos: BytePos) -> Option<Vec<Comment>>;
}
}
}
7 changes: 5 additions & 2 deletions crates/mako/src/ast/css_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ impl fmt::Debug for CssAst {
impl CssAst {
pub fn new(file: &File, context: Arc<Context>, css_modules: bool) -> Result<Self> {
let fm = context.meta.css.cm.new_source_file(
FileName::Real(file.relative_path.clone()),
FileName::Real(file.relative_path.clone()).into(),
file.get_content_raw(),
);
let config = parser::parser::ParserConfig {
css_modules,
legacy_ie: true,
..Default::default()
};
let lexer = parser::lexer::Lexer::new(StringInput::from(&*fm), config);

let comments = context.meta.css.comments.clone();

let lexer = parser::lexer::Lexer::new(StringInput::from(&*fm), Some(&comments), config);
let mut parser = parser::parser::Parser::new(lexer, config);
let parse_result = parser.parse_all();
let mut ast_errors = parser.take_errors();
Expand Down
8 changes: 4 additions & 4 deletions crates/mako/src/ast/js_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use swc_core::ecma::codegen::text_writer::JsWriter;
use swc_core::ecma::codegen::{Config as JsCodegenConfig, Emitter};
use swc_core::ecma::parser::error::SyntaxError;
use swc_core::ecma::parser::lexer::Lexer;
use swc_core::ecma::parser::{EsConfig, Parser, StringInput, Syntax, TsConfig};
use swc_core::ecma::parser::{EsSyntax, Parser, StringInput, Syntax, TsSyntax};
use swc_core::ecma::transforms::base::helpers::{inject_helpers, Helpers, HELPERS};
use swc_core::ecma::utils::contains_top_level_await;
use swc_core::ecma::visit;
Expand Down Expand Up @@ -45,13 +45,13 @@ impl fmt::Debug for JsAst {
impl JsAst {
pub fn new(file: &File, context: Arc<Context>) -> Result<Self> {
let fm = context.meta.script.cm.new_source_file(
FileName::Real(file.relative_path.to_path_buf()),
FileName::Real(file.relative_path.to_path_buf()).into(),
file.get_content_raw(),
);
let comments = context.meta.script.origin_comments.read().unwrap();
let extname = &file.extname;
let syntax = if extname == "ts" || extname == "tsx" {
Syntax::Typescript(TsConfig {
Syntax::Typescript(TsSyntax {
tsx: extname == "tsx",
decorators: true,
..Default::default()
Expand All @@ -60,7 +60,7 @@ impl JsAst {
let jsx = file.is_content_jsx()
|| extname == "jsx"
|| (extname == "js" && !file.is_under_node_modules);
Syntax::Es(EsConfig {
Syntax::Es(EsSyntax {
jsx,
decorators: true,
decorators_before_export: true,
Expand Down
20 changes: 16 additions & 4 deletions crates/mako/src/ast/sourcemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@
impl From<RawSourceMap> for swc_sourcemap::SourceMap {
fn from(rsm: RawSourceMap) -> Self {
Self::new(
rsm.file,
rsm.file.map(|f| f.into_boxed_str().into()),
rsm.tokens,
rsm.names,
rsm.sources,
Some(rsm.sources_content),
rsm.names
.into_iter()
.map(|n| n.into_boxed_str().into())

Check warning on line 75 in crates/mako/src/ast/sourcemap.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/ast/sourcemap.rs#L75

Added line #L75 was not covered by tests
.collect(),
rsm.sources
.into_iter()
.map(|n| n.into_boxed_str().into())
.collect(),
Some(
rsm.sources_content
.into_iter()
.map(|op_string| op_string.map(|s| s.into_boxed_str().into()))
.collect(),
),
)
}
}
Expand Down Expand Up @@ -122,6 +133,7 @@
final_token.get_src_col(),
replaced_source.as_deref(),
final_token.get_name(),
false,
);

// add source centent
Expand Down
15 changes: 8 additions & 7 deletions crates/mako/src/ast/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use base64::engine::general_purpose;
use base64::Engine;
use swc_core::common::{Mark, DUMMY_SP};
use swc_core::ecma::ast::{
CallExpr, Callee, Expr, ExprOrSpread, Ident, Import, Lit, MemberExpr, MemberProp, MetaPropExpr,
MetaPropKind, Module, ModuleItem,
CallExpr, Callee, Expr, ExprOrSpread, Ident, IdentName, Import, Lit, MemberExpr, MemberProp,
MetaPropExpr, MetaPropKind, Module, ModuleItem,
};

pub fn base64_encode<T: AsRef<[u8]>>(raw: T) -> String {
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn get_call_expr_ident(call_expr: &CallExpr) -> Option<&Ident> {
}

pub fn is_ident_undefined(ident: &Ident, sym: &str, unresolved_mark: &Mark) -> bool {
ident.sym == *sym && ident.span.ctxt.outer() == *unresolved_mark
ident.sym == *sym && ident.ctxt.outer() == *unresolved_mark
}

pub fn get_first_str_arg(call_expr: &CallExpr) -> Option<String> {
Expand All @@ -98,7 +98,7 @@ pub fn is_import_meta_url(expr: &Expr) -> bool {
..
}),
prop:
MemberProp::Ident(Ident {
MemberProp::Ident(IdentName {
sym,
..
}),
Expand All @@ -109,16 +109,16 @@ pub fn is_import_meta_url(expr: &Expr) -> bool {

pub fn id(s: &str) -> Ident {
Ident {
ctxt: Default::default(),
span: DUMMY_SP,
sym: s.into(),
optional: false,
}
}
pub fn member_prop(s: &str) -> MemberProp {
MemberProp::Ident(Ident {
MemberProp::Ident(IdentName {
span: DUMMY_SP,
sym: s.into(),
optional: false,
})
}

Expand All @@ -133,6 +133,7 @@ pub fn promise_all(promises: ExprOrSpread) -> Expr {
pub fn member_call(obj: Expr, member_prop: MemberProp, args: Vec<ExprOrSpread>) -> Expr {
Expr::Call(CallExpr {
span: DUMMY_SP,
ctxt: Default::default(),
callee: Callee::Expr(Box::new(Expr::Member(MemberExpr {
span: DUMMY_SP,
obj: Box::new(obj),
Expand All @@ -146,7 +147,7 @@ pub fn member_call(obj: Expr, member_prop: MemberProp, args: Vec<ExprOrSpread>)
pub fn require_ensure(source: String) -> Expr {
member_call(
Expr::Ident(id("__mako_require__")),
MemberProp::Ident(id("ensure")),
MemberProp::Ident(id("ensure").into()),
vec![ExprOrSpread {
spread: None,
expr: Box::new(Expr::Lit(Lit::Str(source.into()))),
Expand Down
2 changes: 1 addition & 1 deletion crates/mako/src/build/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
Err(reason) => {
return Err(anyhow!(LoadError::CompileMdError {
path: file.path.to_string_lossy().to_string(),
reason,
reason: reason.to_string(),

Check warning on line 136 in crates/mako/src/build/load.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/build/load.rs#L136

Added line #L136 was not covered by tests
}));
}
};
Expand Down
3 changes: 2 additions & 1 deletion crates/mako/src/build/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ impl Transform {
cm.clone(),
context.clone(),
top_level_mark,
unresolved_mark,
)))
}
// strip should be ts only
// since when use this in js, it will remove all unused imports
// which is not expected as what webpack does
if is_ts {
visitors.push(Box::new(ts_strip(top_level_mark)))
visitors.push(Box::new(ts_strip(unresolved_mark, top_level_mark)));
}
// named default export
if context.args.watch && !file.is_under_node_modules && is_jsx {
Expand Down
4 changes: 4 additions & 0 deletions crates/mako/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use regex::Regex;
use swc_core::common::sync::Lrc;
use swc_core::common::{Globals, SourceMap, DUMMY_SP};
use swc_core::ecma::ast::Ident;
use swc_node_comments::SwcComments;
use tracing::debug;

use crate::ast::comments::Comments;
Expand Down Expand Up @@ -174,6 +175,7 @@ impl ScriptMeta {

fn build_ident(ident: &str) -> Ident {
Ident {
ctxt: Default::default(),
span: DUMMY_SP,
sym: ident.into(),
optional: false,
Expand All @@ -183,13 +185,15 @@ fn build_ident(ident: &str) -> Ident {
pub struct CssMeta {
pub cm: Lrc<SourceMap>,
pub globals: Globals,
pub comments: SwcComments,
}

impl CssMeta {
fn new() -> Self {
Self {
cm: Default::default(),
globals: Globals::default(),
comments: Default::default(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/mako/src/features/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
impl VisitMut for MockFilenameAndDirname {
fn visit_mut_expr(&mut self, expr: &mut Expr) {
if let Expr::Ident(ident) = expr
&& ident.span.ctxt.outer() == self.unresolved_mark
&& ident.ctxt.outer() == self.unresolved_mark

Check warning on line 142 in crates/mako/src/features/node.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/features/node.rs#L142

Added line #L142 was not covered by tests
{
let is_filename = ident.sym.to_string() == "__filename";
let is_dirname = ident.sym.to_string() == "__dirname";
let is_filename = ident.sym == "__filename";
let is_dirname = ident.sym == "__dirname";

Check warning on line 145 in crates/mako/src/features/node.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/features/node.rs#L144-L145

Added lines #L144 - L145 were not covered by tests
if is_filename || is_dirname {
let path = diff_paths(&self.current_path, &self.context.root).unwrap_or("".into());
let value = if is_filename {
Expand Down
Loading
Loading