Skip to content

Commit 642d85f

Browse files
chore: bump swc to 27.0.4 (#10660)
* Update SWC dependencies to latest compatible versions in Cargo.toml * fix: remove TODO comment in JavaScriptTransformer implementation * Remove unnecessary iterator conversion in JavaScriptCompiler
1 parent ec15322 commit 642d85f

File tree

9 files changed

+203
-267
lines changed

9 files changed

+203
-267
lines changed

Cargo.lock

Lines changed: 163 additions & 253 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ rkyv = { version = "=0.8.8" }
100100

101101
# Must be pinned with the same swc versions
102102
pnp = { version = "0.9.0" }
103-
swc = { version = "=25.0.0" }
104-
swc_config = { version = "=3.0.0" }
105-
swc_core = { version = "=26.3.4", default-features = false, features = ["parallel_rayon"] }
106-
swc_ecma_lexer = { version = "=14.0.4" }
107-
swc_ecma_minifier = { version = "=20.0.3", default-features = false }
108-
swc_error_reporters = { version = "=13.0.0" }
109-
swc_html = { version = "=20.0.0" }
110-
swc_html_minifier = { version = "=20.0.0", default-features = false }
111-
swc_node_comments = { version = "=11.0.0" }
103+
swc = { version = "=26.0.0" }
104+
swc_config = { version = "=3.1.1" }
105+
swc_core = { version = "=27.0.4", default-features = false, features = ["parallel_rayon"] }
106+
swc_ecma_lexer = { version = "=15.0.1" }
107+
swc_ecma_minifier = { version = "=21.0.3", default-features = false }
108+
swc_error_reporters = { version = "=14.0.0" }
109+
swc_html = { version = "=21.0.0" }
110+
swc_html_minifier = { version = "=21.0.0", default-features = false }
111+
swc_node_comments = { version = "=12.0.0" }
112112

113113
rspack_dojang = { version = "0.1.11" }
114114

crates/rspack_core/src/concatenated_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ impl ConcatenatedModule {
18631863
"{}",
18641864
self.readable_identifier(&compilation.options.context),
18651865
))),
1866-
source_code.into(),
1866+
source_code.to_string(),
18671867
);
18681868
let comments = SwcComments::default();
18691869
let mut module_info = concatenation_scope.current_module;

crates/rspack_error/src/error.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ impl TraceableError {
127127
title: String,
128128
message: String,
129129
) -> Self {
130-
Self::from_arc_string(Some(source_file.src.clone()), start, end, title, message)
130+
Self::from_arc_string(
131+
Some(source_file.src.clone().into_string().into()),
132+
start,
133+
end,
134+
title,
135+
message,
136+
)
131137
}
132138

133139
pub fn from_file(

crates/rspack_javascript_compiler/src/compiler/parse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn parse_with_lexer(
129129
IsModule::Bool(true) => parser.parse_module().map(SwcProgram::Module),
130130
IsModule::Bool(false) => parser.parse_script().map(SwcProgram::Script),
131131
IsModule::Unknown => parser.parse_program(),
132+
IsModule::CommonJS => parser.parse_commonjs().map(SwcProgram::Script),
132133
};
133134
let mut errors = parser.take_errors();
134135
// Using combinator will let rustc unhappy.

crates/rspack_javascript_compiler/src/compiler/stringify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl JavaScriptCompiler {
195195
.collect::<Vec<_>>(),
196196
combined_source_map
197197
.source_contents()
198-
.map(Option::unwrap_or_default)
198+
.flatten()
199199
.map(ToString::to_string)
200200
.collect::<Vec<_>>(),
201201
combined_source_map

crates/rspack_javascript_compiler/src/compiler/transform.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ use swc_core::{
3636
},
3737
ecma::{
3838
ast::{EsVersion, Pass, Program},
39-
parser::{parse_file_as_module, parse_file_as_program, parse_file_as_script, Syntax},
39+
parser::{
40+
parse_file_as_commonjs, parse_file_as_module, parse_file_as_program, parse_file_as_script,
41+
Syntax,
42+
},
4043
transforms::base::helpers::{self, Helpers},
4144
},
4245
};
@@ -356,6 +359,9 @@ impl<'a> JavaScriptTransformer<'a> {
356359
parse_file_as_script(&fm, syntax, target, comments, &mut errors).map(Program::Script)
357360
}
358361
IsModule::Unknown => parse_file_as_program(&fm, syntax, target, comments, &mut errors),
362+
IsModule::CommonJS => {
363+
parse_file_as_commonjs(&fm, syntax, target, comments, &mut errors).map(Program::Script)
364+
}
359365
};
360366

361367
for e in errors {
@@ -477,6 +483,7 @@ impl<'a> JavaScriptTransformer<'a> {
477483
BoolOr::Bool(true) | BoolOr::Data(JsMinifyCommentOption::PreserveAllComments) => true,
478484
BoolOr::Data(JsMinifyCommentOption::PreserveSomeComments) => false,
479485
BoolOr::Bool(false) => false,
486+
BoolOr::Data(JsMinifyCommentOption::PreserveRegexComments { .. }) => false,
480487
};
481488

482489
minify_file_comments(

crates/rspack_plugin_javascript/src/utils/eval/eval_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn eval_source<T: Display>(
3838
span.lo.0.saturating_sub(1) as usize,
3939
span.hi.0.saturating_sub(1) as usize,
4040
format!("{error_title} warning"),
41-
format!("failed to parse {}", json!(fm.src.as_ref())),
41+
format!("failed to parse {}", json!(fm.src.as_str())),
4242
)
4343
.with_severity(Severity::Warning),
4444
));

crates/rspack_util/src/swc.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,17 @@ pub fn minify_file_comments(
8080
l.clear();
8181
t.clear();
8282
}
83+
BoolOr::Data(JsMinifyCommentOption::PreserveRegexComments { regex }) => {
84+
let preserve_excl = |_: &BytePos, vc: &mut std::vec::Vec<Comment>| -> bool {
85+
// Preserve comments that match the regex
86+
//
87+
// See https://github.com/terser/terser/blob/798135e04baddd94fea403cfaab4ba8b22b1b524/lib/output.js#L286
88+
vc.retain(|c: &Comment| regex.find(&c.text).is_some());
89+
!vc.is_empty()
90+
};
91+
let (mut l, mut t) = comments.borrow_all_mut();
92+
l.retain(preserve_excl);
93+
t.retain(preserve_excl);
94+
}
8395
}
8496
}

0 commit comments

Comments
 (0)