Skip to content

Commit 684b164

Browse files
authored
Bump SWC to 0.106 (#9967)
1 parent 5b639af commit 684b164

22 files changed

+744
-509
lines changed

Cargo.lock

+490-323
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ napi = ["dep:napi", "dep:napi-derive", "dep:crossbeam-channel"]
99

1010
[dependencies]
1111
indexmap = "1.9.2"
12-
swc_core = { version = "0.96", features = [
12+
swc_core = { version = "0.106", features = [
1313
"common",
1414
"common_ahash",
1515
"common_sourcemap",

crates/macros/src/lib.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use swc_core::ecma::utils::stack_size::maybe_grow_default;
88

99
use indexmap::IndexMap;
1010
use swc_core::{
11-
common::{util::take::Take, SourceMap, Span, DUMMY_SP},
11+
common::{sync::Lrc, util::take::Take, SourceMap, Span, DUMMY_SP},
1212
ecma::{
1313
ast::*,
1414
atoms::{js_word, JsWord},
@@ -332,7 +332,9 @@ fn is_macro(with: &ObjectLit) -> bool {
332332
if let PropOrSpread::Prop(prop) = &prop {
333333
if let Prop::KeyValue(kv) = &**prop {
334334
let k = match &kv.key {
335-
PropName::Ident(Ident { sym, .. }) | PropName::Str(Str { value: sym, .. }) => sym.clone(),
335+
PropName::Ident(IdentName { sym, .. }) | PropName::Str(Str { value: sym, .. }) => {
336+
sym.clone()
337+
}
336338
_ => continue,
337339
};
338340
if &k == "type"
@@ -443,9 +445,8 @@ impl<'a> Macros<'a> {
443445
Prop::KeyValue(kv) => {
444446
let v = self.eval(&*kv.value)?;
445447
let k = match &kv.key {
446-
PropName::Ident(Ident { sym, .. }) | PropName::Str(Str { value: sym, .. }) => {
447-
sym.to_string()
448-
}
448+
PropName::Ident(IdentName { sym, .. })
449+
| PropName::Str(Str { value: sym, .. }) => sym.to_string(),
449450
PropName::Num(n) => n.value.to_string(),
450451
PropName::Computed(c) => match self.eval(&*c.expr) {
451452
Err(e) => return Err(e),
@@ -682,7 +683,7 @@ impl<'a> Macros<'a> {
682683
fn value_to_expr(&self, value: JsValue) -> Result<Expr, MacroError> {
683684
Ok(match value {
684685
JsValue::Null => Expr::Lit(Lit::Null(Null::dummy())),
685-
JsValue::Undefined => Expr::Ident(Ident::new(js_word!("undefined"), DUMMY_SP)),
686+
JsValue::Undefined => Expr::Ident(Ident::new_no_ctxt(js_word!("undefined"), DUMMY_SP)),
686687
JsValue::Bool(b) => Expr::Lit(Lit::Bool(Bool {
687688
value: b,
688689
span: DUMMY_SP,
@@ -721,7 +722,7 @@ impl<'a> Macros<'a> {
721722
.map(|(k, v)| -> Result<_, MacroError> {
722723
Ok(PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
723724
key: if Ident::verify_symbol(&k).is_ok() {
724-
PropName::Ident(Ident::new(k.into(), DUMMY_SP))
725+
PropName::Ident(IdentName::new(k.into(), DUMMY_SP))
725726
} else {
726727
PropName::Str(Str {
727728
value: k.into(),
@@ -735,9 +736,10 @@ impl<'a> Macros<'a> {
735736
.collect::<Result<Vec<_>, MacroError>>()?,
736737
}),
737738
JsValue::Function(source) => {
738-
let source_file = self
739-
.source_map
740-
.new_source_file(swc_core::common::FileName::MacroExpansion, source.into());
739+
let source_file = self.source_map.new_source_file(
740+
Lrc::new(swc_core::common::FileName::MacroExpansion),
741+
source.into(),
742+
);
741743
let lexer = Lexer::new(
742744
Default::default(),
743745
Default::default(),

packages/core/integration-tests/test/macros.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ describe('macros', function () {
583583
});
584584

585585
let res = await overlayFS.readFile(b.getBundles()[0].filePath, 'utf8');
586-
let match = res.match(/output=(\d+)/);
586+
let match = res.match(/output=(.*);/);
587587
assert(match);
588588

589589
b = await bundle(path.join(dir, '/index.js'), {
@@ -593,7 +593,7 @@ describe('macros', function () {
593593
});
594594

595595
res = await overlayFS.readFile(b.getBundles()[0].filePath, 'utf8');
596-
let match2 = res.match(/output=(\d+)/);
596+
let match2 = res.match(/output=(.*);/);
597597
assert(match2);
598598
assert.notEqual(match[1], match2[1]);
599599
});

packages/core/integration-tests/test/transpilation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ describe('transpilation', function () {
434434
{
435435
message: undefined,
436436
start: {
437-
column: 4,
437+
column: 3,
438438
line: 9,
439439
},
440440
end: {

packages/core/package-manager/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@parcel/types": "2.12.0",
5151
"@parcel/utils": "2.12.0",
5252
"@parcel/workers": "2.12.0",
53-
"@swc/core": "^1.3.36",
53+
"@swc/core": "^1.7.26",
5454
"semver": "^7.5.2"
5555
},
5656
"devDependencies": {

packages/optimizers/inline-requires/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@parcel/plugin": "2.12.0",
2424
"@parcel/source-map": "^2.1.1",
2525
"@parcel/types": "2.12.0",
26-
"@swc/core": "^1.3.36",
26+
"@swc/core": "^1.7.26",
2727
"nullthrows": "^1.1.1"
2828
}
2929
}

packages/optimizers/swc/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@parcel/plugin": "2.12.0",
2525
"@parcel/source-map": "^2.1.1",
2626
"@parcel/utils": "2.12.0",
27-
"@swc/core": "^1.3.36",
27+
"@swc/core": "^1.7.26",
2828
"nullthrows": "^1.1.1"
2929
}
3030
}

packages/transformers/js/core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
crate-type = ["rlib"]
99

1010
[dependencies]
11-
swc_core = { version = "0.96", features = [
11+
swc_core = { version = "0.106", features = [
1212
"common",
1313
"common_ahash",
1414
"common_sourcemap",

packages/transformers/js/core/src/collect.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct Collect {
6767
pub should_wrap: bool,
6868
/// local variable binding -> descriptor
6969
pub imports: HashMap<Id, Import>,
70-
pub this_exprs: HashMap<Id, (Ident, Span)>,
70+
pub this_exprs: HashMap<JsWord, Span>,
7171
/// exported name -> descriptor
7272
pub exports: HashMap<JsWord, Export>,
7373
/// local variable binding -> exported name
@@ -260,8 +260,8 @@ impl Visit for Collect {
260260
}
261261
self.in_module_this = false;
262262

263-
for (_key, (ident, span)) in std::mem::take(&mut self.this_exprs) {
264-
if self.exports.contains_key(&ident.sym) {
263+
for (key, span) in std::mem::take(&mut self.this_exprs) {
264+
if self.exports.contains_key(&key) {
265265
self.should_wrap = true;
266266
self.add_bailout(span, BailoutReason::ThisInExport);
267267
}
@@ -601,7 +601,7 @@ impl Visit for Collect {
601601
.or_insert_with(|| node.id.sym.clone());
602602
}
603603

604-
if self.in_assign && node.id.span.has_mark(self.global_mark) {
604+
if self.in_assign && node.id.ctxt.has_mark(self.global_mark) {
605605
self
606606
.non_const_bindings
607607
.entry(id!(node.id))
@@ -627,7 +627,7 @@ impl Visit for Collect {
627627
.or_insert_with(|| node.key.sym.clone());
628628
}
629629

630-
if self.in_assign && node.key.span.has_mark(self.global_mark) {
630+
if self.in_assign && node.key.ctxt.has_mark(self.global_mark) {
631631
self
632632
.non_const_bindings
633633
.entry(id!(node.key))
@@ -712,7 +712,7 @@ impl Visit for Collect {
712712
}
713713
} else if !self.in_class {
714714
if let MemberProp::Ident(prop) = &node.prop {
715-
self.this_exprs.insert(id!(prop), (prop.clone(), node.span));
715+
self.this_exprs.insert(prop.sym.clone(), node.span);
716716
}
717717
}
718718
return;
@@ -750,7 +750,7 @@ impl Visit for Collect {
750750
self.add_bailout(span, BailoutReason::NonTopLevelRequire);
751751
}
752752

753-
if let Some(source) = match_import(node, self.ignore_mark) {
753+
if let Some(source) = match_import(node) {
754754
self.non_static_requires.insert(source.clone());
755755
self.wrapped_requires.insert(source.to_string());
756756
let span = match node {
@@ -901,7 +901,7 @@ impl Visit for Collect {
901901
Expr::Await(await_exp) => {
902902
// let x = await import('foo');
903903
// let {x} = await import('foo');
904-
if let Some(source) = match_import(&await_exp.arg, self.ignore_mark) {
904+
if let Some(source) = match_import(&await_exp.arg) {
905905
self.add_pat_imports(&node.name, &source, ImportKind::DynamicImport);
906906
return;
907907
}
@@ -929,7 +929,7 @@ impl Visit for Collect {
929929
}
930930
Expr::Member(member) => {
931931
// import('foo').then(foo => ...);
932-
if let Some(source) = match_import(&member.obj, self.ignore_mark) {
932+
if let Some(source) = match_import(&member.obj) {
933933
if match_property_name(member).map_or(false, |f| &*f.0 == "then") {
934934
if let Some(ExprOrSpread { expr, .. }) = node.args.first() {
935935
let param = match &**expr {

packages/transformers/js/core/src/constant_module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ mod tests {
164164

165165
fn is_constant_module(code: &str) -> bool {
166166
let source_map = Lrc::new(SourceMap::default());
167-
let source_file = source_map.new_source_file(FileName::Anon, code.into());
167+
let source_file = source_map.new_source_file(Lrc::new(FileName::Anon), code.into());
168168

169169
let comments = SingleThreadedComments::default();
170170
let lexer = Lexer::new(

0 commit comments

Comments
 (0)