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

Bump swc #8537

Merged
merged 4 commits into from Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
169 changes: 102 additions & 67 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/javascript.js
Expand Up @@ -5703,7 +5703,7 @@ describe('javascript', function () {
},
{
message:
'External dependency "@swc/helpers" does not satisfy required semver range "^0.4.2".',
'External dependency "@swc/helpers" does not satisfy required semver range "^0.4.12".',
origin: '@parcel/resolver-default',
codeFrames: [
{
Expand All @@ -5726,7 +5726,7 @@ describe('javascript', function () {
},
],
hints: [
'Update the dependency on "@swc/helpers" to satisfy "^0.4.2".',
'Update the dependency on "@swc/helpers" to satisfy "^0.4.12".',
],
},
],
Expand Down
6 changes: 3 additions & 3 deletions packages/transformers/js/core/Cargo.toml
Expand Up @@ -8,9 +8,9 @@ edition = "2018"
crate-type = ["rlib"]

[dependencies]
swc_ecmascript = { version = "0.192.0", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils", "preset_env"] }
swc_common = { version = "0.27.13", features = ["tty-emitter", "sourcemap"] }
swc_atoms = "0.4.8"
swc_ecmascript = { version = "0.205.17", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils", "preset_env"] }
swc_common = { version = "0.29.8", features = ["tty-emitter", "sourcemap"] }
swc_atoms = "0.4.21"
indoc = "1.0.3"
serde = "1.0.123"
serde_bytes = "0.11.5"
Expand Down
8 changes: 4 additions & 4 deletions packages/transformers/js/core/src/dependency_collector.rs
Expand Up @@ -247,7 +247,7 @@ impl<'a> Fold for DependencyCollector<'a> {
if let Some(decl) = self.import_meta.take() {
res.body.insert(
0,
ast::ModuleItem::Stmt(ast::Stmt::Decl(ast::Decl::Var(decl))),
ast::ModuleItem::Stmt(ast::Stmt::Decl(ast::Decl::Var(Box::new(decl)))),
);
}
res
Expand Down Expand Up @@ -1004,7 +1004,7 @@ fn build_promise_chain(node: ast::CallExpr, require_node: ast::CallExpr) -> ast:
args: vec![ast::ExprOrSpread {
expr: Box::new(ast::Expr::Fn(ast::FnExpr {
ident: None,
function: ast::Function {
function: Box::new(ast::Function {
body: Some(ast::BlockStmt {
span: DUMMY_SP,
stmts: vec![ast::Stmt::Return(ast::ReturnStmt {
Expand All @@ -1019,7 +1019,7 @@ fn build_promise_chain(node: ast::CallExpr, require_node: ast::CallExpr) -> ast:
return_type: None,
type_params: None,
span: DUMMY_SP,
},
}),
})),
spread: None,
}],
Expand Down Expand Up @@ -1203,7 +1203,7 @@ impl<'a> DependencyCollector<'a> {
..
}) => {
// Match "file:" + __filename
let left = match_str(&*left);
let left = match_str(left);
match (left, &**right) {
(Some((left, _)), Expr::Ident(Ident { sym: right, .. })) => {
&left == "file:" && right == "__filename"
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/js/core/src/fs.rs
Expand Up @@ -254,7 +254,7 @@ impl<'a> Fold for Evaluator<'a> {
},
Expr::Call(call) => {
let callee = match &call.callee {
Callee::Expr(expr) => &*expr,
Callee::Expr(expr) => expr,
_ => return node,
};

Expand Down
56 changes: 31 additions & 25 deletions packages/transformers/js/core/src/hoist.rs
Expand Up @@ -148,7 +148,9 @@ impl<'a> Fold for Hoist<'a> {
specifiers: vec![],
asserts: None,
span: DUMMY_SP,
src: format!("{}:{}:{}", self.module_id, import.src.value, "esm").into(),
src: Box::new(
format!("{}:{}:{}", self.module_id, import.src.value, "esm").into(),
),
type_only: false,
})));
// Ensure that all import specifiers are constant.
Expand Down Expand Up @@ -193,11 +195,11 @@ impl<'a> Fold for Hoist<'a> {
specifiers: vec![],
asserts: None,
span: DUMMY_SP,
src: Str {
src: Box::new(Str {
value: format!("{}:{}:{}", self.module_id, src.value, "esm").into(),
span: DUMMY_SP,
raw: None,
},
}),
type_only: false,
})));

Expand Down Expand Up @@ -286,7 +288,9 @@ impl<'a> Fold for Hoist<'a> {
specifiers: vec![],
asserts: None,
span: DUMMY_SP,
src: format!("{}:{}:{}", self.module_id, export.src.value, "esm").into(),
src: Box::new(
format!("{}:{}:{}", self.module_id, export.src.value, "esm").into(),
),
type_only: false,
})));
self.re_exports.push(ImportedSymbol {
Expand All @@ -302,7 +306,7 @@ impl<'a> Fold for Hoist<'a> {
let init = export.expr.fold_with(self);
self
.module_items
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
declare: false,
kind: VarDeclKind::Var,
span: DUMMY_SP,
Expand All @@ -312,7 +316,7 @@ impl<'a> Fold for Hoist<'a> {
name: Pat::Ident(BindingIdent::from(ident)),
init: Some(init),
}],
}))));
})))));
}
ModuleDecl::ExportDefaultDecl(export) => {
let decl = match export.decl {
Expand Down Expand Up @@ -380,7 +384,7 @@ impl<'a> Fold for Hoist<'a> {
};
self
.module_items
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(var))));
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(var)))));
}

self
Expand All @@ -389,11 +393,11 @@ impl<'a> Fold for Hoist<'a> {
specifiers: vec![],
asserts: None,
span: DUMMY_SP,
src: Str {
src: Box::new(Str {
value: format!("{}:{}", self.module_id, source).into(),
span: DUMMY_SP,
raw: None,
},
}),
type_only: false,
})));

Expand Down Expand Up @@ -422,19 +426,19 @@ impl<'a> Fold for Hoist<'a> {
};
self
.module_items
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(var))));
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(var)))));
}
self
.module_items
.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
specifiers: vec![],
asserts: None,
span: DUMMY_SP,
src: Str {
src: Box::new(Str {
value: format!("{}:{}", self.module_id, source,).into(),
span: DUMMY_SP,
raw: None,
},
}),
type_only: false,
})));

Expand All @@ -460,9 +464,10 @@ impl<'a> Fold for Hoist<'a> {
declare: var.declare,
decls: std::mem::take(&mut decls),
};
self
.module_items
.insert(items_len, ModuleItem::Stmt(Stmt::Decl(Decl::Var(var))));
self.module_items.insert(
items_len,
ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(var)))),
);
}
decls.push(d);
}
Expand All @@ -477,7 +482,7 @@ impl<'a> Fold for Hoist<'a> {
};
self
.module_items
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(var))))
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(var)))))
}
}
item => {
Expand Down Expand Up @@ -897,7 +902,7 @@ impl<'a> Fold for Hoist<'a> {
if self.collect.static_cjs_exports && self.export_decls.insert(ident.id.sym.clone()) {
self
.hoisted_imports
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
declare: false,
kind: VarDeclKind::Var,
span: node.span,
Expand All @@ -910,7 +915,7 @@ impl<'a> Fold for Hoist<'a> {
))),
init: None,
}],
}))));
})))));
}

return AssignExpr {
Expand Down Expand Up @@ -986,7 +991,7 @@ impl<'a> Hoist<'a> {
specifiers: vec![],
asserts: None,
span: DUMMY_SP,
src: src.into(),
src: Box::new(src.into()),
type_only: false,
})));
}
Expand Down Expand Up @@ -1025,10 +1030,10 @@ impl<'a> Hoist<'a> {
}

fn get_require_ident(&self, local: &JsWord) -> Ident {
return Ident::new(
Ident::new(
format!("${}$require${}", self.module_id, local).into(),
DUMMY_SP,
);
)
}

fn get_export_ident(&mut self, span: Span, exported: &JsWord) -> Ident {
Expand Down Expand Up @@ -1074,7 +1079,7 @@ impl<'a> Hoist<'a> {
);
self
.module_items
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
.push(ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
declare: false,
kind: VarDeclKind::Var,
span: DUMMY_SP,
Expand All @@ -1084,7 +1089,7 @@ impl<'a> Hoist<'a> {
name: Pat::Ident(BindingIdent::from(require_id)),
init: Some(Box::new(Expr::Ident(import_id))),
}],
}))));
})))));
}
}
}
Expand All @@ -1104,7 +1109,7 @@ macro_rules! collect_visit_fn {
};
}

#[derive(Debug, Deserialize, PartialEq, Clone, Copy, Serialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy, Serialize)]
pub enum ImportKind {
Require,
Import,
Expand All @@ -1119,7 +1124,7 @@ pub struct Import {
pub loc: SourceLocation,
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Export {
pub source: Option<JsWord>,
pub specifier: JsWord,
Expand Down Expand Up @@ -2225,6 +2230,7 @@ mod tests {
minify: false,
ascii_only: false,
target: swc_ecmascript::ast::EsVersion::Es5,
omit_last_semi: false,
};
let mut emitter = swc_ecmascript::codegen::Emitter {
cfg: config,
Expand Down
1 change: 1 addition & 0 deletions packages/transformers/js/core/src/lib.rs
Expand Up @@ -573,6 +573,7 @@ fn emit(
minify: false,
ascii_only: false,
target: swc_ecmascript::ast::EsVersion::Es5,
omit_last_semi: false,
};
let mut emitter = swc_ecmascript::codegen::Emitter {
cfg: config,
Expand Down
16 changes: 8 additions & 8 deletions packages/transformers/js/core/src/modules.rs
Expand Up @@ -89,7 +89,7 @@ impl ESMFold {
}

let ident = self.get_require_name(&src, DUMMY_SP);
let require = ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
let require = ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
span,
kind: VarDeclKind::Var,
decls: vec![VarDeclarator {
Expand All @@ -99,7 +99,7 @@ impl ESMFold {
definite: false,
}],
declare: false,
})));
}))));

self.requires.push(require)
}
Expand All @@ -111,7 +111,7 @@ impl ESMFold {

let local = self.get_require_name(&src, DUMMY_SP);
let ident = self.get_interop_default_name(&src);
let interop = ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
let interop = ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
decls: vec![VarDeclarator {
Expand All @@ -125,7 +125,7 @@ impl ESMFold {
definite: false,
}],
declare: false,
})));
}))));

self.requires.push(interop);
self.interops.insert(src);
Expand Down Expand Up @@ -168,7 +168,7 @@ impl ESMFold {
if matches!(self.versions, Some(versions) if Feature::ArrowFunctions.should_enable(versions, true, false)) {
Expr::Fn(FnExpr {
ident: None,
function: Function {
function: Box::new(Function {
body: Some(BlockStmt {
span: DUMMY_SP,
stmts: vec![Stmt::Return({
Expand All @@ -185,7 +185,7 @@ impl ESMFold {
span: DUMMY_SP,
return_type: None,
type_params: None,
},
}),
})
} else {
Expr::Arrow(ArrowExpr {
Expand Down Expand Up @@ -534,7 +534,7 @@ impl Fold for ESMFold {
if self.needs_helpers {
items.insert(
0,
ModuleItem::Stmt(Stmt::Decl(Decl::Var(VarDecl {
ModuleItem::Stmt(Stmt::Decl(Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
decls: vec![VarDeclarator {
Expand All @@ -548,7 +548,7 @@ impl Fold for ESMFold {
definite: false,
}],
declare: false,
}))),
})))),
)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/transformers/js/core/src/utils.rs
Expand Up @@ -177,7 +177,7 @@ pub fn create_global_decl_stmt(
let span = DUMMY_SP.apply_mark(global_mark);

(
ast::Stmt::Decl(ast::Decl::Var(ast::VarDecl {
ast::Stmt::Decl(ast::Decl::Var(Box::new(ast::VarDecl {
kind: ast::VarDeclKind::Var,
declare: false,
span: DUMMY_SP,
Expand All @@ -187,7 +187,7 @@ pub fn create_global_decl_stmt(
definite: false,
init: Some(Box::new(init)),
}],
})),
}))),
span.ctxt,
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/transformers/js/package.json
Expand Up @@ -35,7 +35,7 @@
"@parcel/source-map": "^2.0.0",
"@parcel/utils": "2.7.0",
"@parcel/workers": "2.7.0",
"@swc/helpers": "^0.4.2",
"@swc/helpers": "^0.4.12",
"browserslist": "^4.6.6",
"detect-libc": "^1.0.3",
"nullthrows": "^1.1.1",
Expand Down