Skip to content

Commit

Permalink
Bump swc (#8686)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored Dec 14, 2022
1 parent 593c2bc commit 426852f
Show file tree
Hide file tree
Showing 9 changed files with 434 additions and 341 deletions.
697 changes: 394 additions & 303 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @jsx h */

const Boom = () => {
const littleBoom = ['hello', 'world']
return <div>{...littleBoom.map(el => el)}</div>
Expand Down
14 changes: 7 additions & 7 deletions packages/core/integration-tests/test/transpilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,20 @@ describe('transpilation', function () {
{
message: null,
start: {
column: 15,
line: 3,
column: 1,
line: 1,
},
end: {
column: 43,
line: 3,
column: 12,
line: 1,
},
},
],
filePath: source,
},
],
hints: null,
message: 'Spread children are not supported in React.',
message: 'pragma cannot be set when runtime is automatic',
origin: '@parcel/transformer-js',
},
{
Expand All @@ -435,11 +435,11 @@ describe('transpilation', function () {
message: null,
start: {
column: 4,
line: 7,
line: 9,
},
end: {
column: 4,
line: 7,
line: 9,
},
},
],
Expand Down
6 changes: 3 additions & 3 deletions packages/transformers/js/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ edition = "2018"
crate-type = ["rlib"]

[dependencies]
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"
swc_ecmascript = { version = "0.206.19", features = ["parser", "transforms", "module", "optimization", "react", "typescript", "utils", "visit", "codegen", "utils", "preset_env"] }
swc_common = { version = "0.29.23", features = ["tty-emitter", "sourcemap"] }
swc_atoms = "0.4.29"
indoc = "1.0.3"
serde = "1.0.123"
serde_bytes = "0.11.5"
Expand Down
18 changes: 9 additions & 9 deletions packages/transformers/js/core/src/dependency_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a> DependencyCollector<'a> {

fn rewrite_require_specifier(node: ast::CallExpr) -> ast::CallExpr {
if let Some(arg) = node.args.get(0) {
if let Some((value, _)) = match_str(&*arg.expr) {
if let Some((value, _)) = match_str(&arg.expr) {
if value.starts_with("node:") {
// create_require will take care of replacing the node: prefix...
return create_require(value);
Expand Down Expand Up @@ -474,7 +474,7 @@ impl<'a> Fold for DependencyCollector<'a> {
// Promise.resolve(require('foo'))
if match_member_expr(member, vec!["Promise", "resolve"], self.decls) {
if let Some(expr) = node.args.get(0) {
if match_require(&*expr.expr, self.decls, Mark::fresh(Mark::root())).is_some() {
if match_require(&expr.expr, self.decls, Mark::fresh(Mark::root())).is_some() {
self.in_promise = true;
let node = node.fold_children_with(self);
self.in_promise = was_in_promise;
Expand Down Expand Up @@ -580,7 +580,7 @@ impl<'a> Fold for DependencyCollector<'a> {
};
let mut node = node.clone();

let (specifier, span) = if let Some(s) = self.match_new_url(&*arg.expr, self.decls) {
let (specifier, span) = if let Some(s) = self.match_new_url(&arg.expr, self.decls) {
s
} else if let Lit(ast::Lit::Str(str_)) = &*arg.expr {
let (msg, docs) = if kind == DependencyKind::ServiceWorker {
Expand Down Expand Up @@ -626,7 +626,7 @@ impl<'a> Fold for DependencyCollector<'a> {
return node;
}

if let Some((specifier, span)) = match_str(&*arg.expr) {
if let Some((specifier, span)) = match_str(&arg.expr) {
// require() calls aren't allowed in scripts, flag as an error.
if kind == DependencyKind::Require && self.config.source_type == SourceType::Script {
self.add_script_error(node.span);
Expand Down Expand Up @@ -750,7 +750,7 @@ impl<'a> Fold for DependencyCollector<'a> {

if let Some(args) = &node.args {
if !args.is_empty() {
let (specifier, span) = if let Some(s) = self.match_new_url(&*args[0].expr, self.decls) {
let (specifier, span) = if let Some(s) = self.match_new_url(&args[0].expr, self.decls) {
s
} else if let Lit(ast::Lit::Str(str_)) = &*args[0].expr {
let constructor = match &*node.callee {
Expand Down Expand Up @@ -916,7 +916,7 @@ impl<'a> DependencyCollector<'a> {
if let ast::Expr::Ident(id) = &**callee {
if id.to_id() == resolve_id {
if let Some(arg) = call.args.get(0) {
if match_require(&*arg.expr, self.decls, Mark::fresh(Mark::root())).is_some() {
if match_require(&arg.expr, self.decls, Mark::fresh(Mark::root())).is_some() {
let was_in_promise = self.in_promise;
self.in_promise = true;
let node = node.fold_children_with(self);
Expand Down Expand Up @@ -1151,13 +1151,13 @@ impl<'a> DependencyCollector<'a> {

if let Some(args) = &new.args {
let (specifier, span) = if let Some(arg) = args.get(0) {
match_str(&*arg.expr)?
match_str(&arg.expr)?
} else {
return None;
};

if let Some(arg) = args.get(1) {
if self.is_import_meta_url(&*arg.expr) {
if self.is_import_meta_url(&arg.expr) {
return Some((specifier, span));
}
}
Expand Down Expand Up @@ -1363,7 +1363,7 @@ fn match_worker_type(expr: Option<&ast::ExprOrSpread>) -> (SourceType, Option<as
_ => return true,
};

let v = if let Some((v, _)) = match_str(&*kv.value) {
let v = if let Some((v, _)) = match_str(&kv.value) {
v
} else {
return true;
Expand Down
6 changes: 3 additions & 3 deletions packages/transformers/js/core/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<'a> Fold for InlineFS<'a> {
if let Some((source, specifier)) = self.match_module_reference(expr) {
if &source == "fs" && &specifier == "readFileSync" {
if let Some(arg) = call.args.get(0) {
if let Some(res) = self.evaluate_fs_arg(&*arg.expr, call.args.get(1), call.span) {
if let Some(res) = self.evaluate_fs_arg(&arg.expr, call.args.get(1), call.span) {
return res;
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a> InlineFS<'a> {
_ => return None,
};

if let Some(source) = self.collect.match_require(&*member.obj) {
if let Some(source) = self.collect.match_require(&member.obj) {
return Some((source, prop));
}

Expand Down Expand Up @@ -127,7 +127,7 @@ impl<'a> InlineFS<'a> {
Ok(path) => path,
Err(_err) => return None,
};
if !path.starts_with(&self.project_root) {
if !path.starts_with(self.project_root) {
return None;
}

Expand Down
20 changes: 10 additions & 10 deletions packages/transformers/js/core/src/hoist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ impl<'a> Fold for Hoist<'a> {
if let Expr::Member(member) = &**init {
// Match var x = require('foo').bar;
if let Some(source) =
match_require(&*member.obj, &self.collect.decls, self.collect.ignore_mark)
match_require(&member.obj, &self.collect.decls, self.collect.ignore_mark)
{
if !self.collect.non_static_requires.contains(&source) {
// If this is not the first declarator in the variable declaration, we need to
Expand Down Expand Up @@ -742,7 +742,7 @@ impl<'a> Fold for Hoist<'a> {
.enumerate()
.map(|(i, expr)| {
if i != len - 1
&& match_require(&*expr, &self.collect.decls, self.collect.ignore_mark).is_some()
&& match_require(&expr, &self.collect.decls, self.collect.ignore_mark).is_some()
{
return Box::new(Expr::Unary(UnaryExpr {
op: UnaryOp::Bang,
Expand Down Expand Up @@ -1346,7 +1346,7 @@ impl Visit for Collect {
}
Stmt::Expr(expr) => {
// Top-level require(). Do not traverse further so it is not marked as wrapped.
if let Some(_source) = self.match_require(&*expr.expr) {
if let Some(_source) = self.match_require(&expr.expr) {
return;
}

Expand Down Expand Up @@ -1844,7 +1844,7 @@ impl Visit for Collect {

match &**init {
Expr::Member(member) => {
if let Some(source) = self.match_require(&*member.obj) {
if let Some(source) = self.match_require(&member.obj) {
// Convert member expression on require to a destructuring assignment.
// const yx = require('y').x; -> const {x: yx} = require('x');
let key = match &member.prop {
Expand Down Expand Up @@ -1875,7 +1875,7 @@ impl Visit for Collect {
Expr::Await(await_exp) => {
// let x = await import('foo');
// let {x} = await import('foo');
if let Some(source) = match_import(&*await_exp.arg, self.ignore_mark) {
if let Some(source) = match_import(&await_exp.arg, self.ignore_mark) {
self.add_pat_imports(&node.name, &source, ImportKind::DynamicImport);
return;
}
Expand Down Expand Up @@ -1903,7 +1903,7 @@ impl Visit for Collect {
}
Expr::Member(member) => {
// import('foo').then(foo => ...);
if let Some(source) = match_import(&*member.obj, self.ignore_mark) {
if let Some(source) = match_import(&member.obj, self.ignore_mark) {
if match_property_name(member).map_or(false, |f| &*f.0 == "then") {
if let Some(ExprOrSpread { expr, .. }) = node.args.get(0) {
let param = match &**expr {
Expand Down Expand Up @@ -2078,15 +2078,15 @@ impl Collect {
for prop in &object.props {
match prop {
ObjectPatProp::KeyValue(kv) => {
self.get_non_const_binding_idents(&*kv.value, idents);
self.get_non_const_binding_idents(&kv.value, idents);
}
ObjectPatProp::Assign(assign) => {
if self.non_const_bindings.contains_key(&id!(assign.key)) {
idents.push(assign.key.clone());
}
}
ObjectPatProp::Rest(rest) => {
self.get_non_const_binding_idents(&*rest.arg, idents);
self.get_non_const_binding_idents(&rest.arg, idents);
}
}
}
Expand Down Expand Up @@ -2121,7 +2121,7 @@ fn has_binding_identifier(node: &Pat, sym: &JsWord, decls: &HashSet<Id>) -> bool
for prop in &object.props {
match prop {
ObjectPatProp::KeyValue(kv) => {
if has_binding_identifier(&*kv.value, sym, decls) {
if has_binding_identifier(&kv.value, sym, decls) {
return true;
}
}
Expand All @@ -2131,7 +2131,7 @@ fn has_binding_identifier(node: &Pat, sym: &JsWord, decls: &HashSet<Id>) -> bool
}
}
ObjectPatProp::Rest(rest) => {
if has_binding_identifier(&*rest.arg, sym, decls) {
if has_binding_identifier(&rest.arg, sym, decls) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/transformers/js/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,11 @@ pub fn transform(config: Config) -> Result<TransformResult, std::io::Error> {
result.diagnostics = Some(diagnostics);
}

let (buf, mut src_map_buf) =
let (buf, src_map_buf) =
emit(source_map.clone(), comments, &module, config.source_maps)?;
if config.source_maps
&& source_map
.build_source_map(&mut src_map_buf)
.build_source_map(&src_map_buf)
.to_writer(&mut map_buf)
.is_ok()
{
Expand Down
8 changes: 4 additions & 4 deletions packages/transformers/js/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn match_str(node: &ast::Expr) -> Option<(JsWord, Span)> {

pub fn match_property_name(node: &ast::MemberExpr) -> Option<(JsWord, Span)> {
match &node.prop {
ast::MemberProp::Computed(s) => match_str(&*s.expr),
ast::MemberProp::Computed(s) => match_str(&s.expr),
ast::MemberProp::Ident(id) => Some((id.sym.clone(), id.span)),
ast::MemberProp::PrivateName(_) => None,
}
Expand Down Expand Up @@ -126,7 +126,7 @@ pub fn match_require(node: &ast::Expr, decls: &HashSet<Id>, ignore_mark: Mark) -
&& !is_marked(ident.span, ignore_mark)
{
if let Some(arg) = call.args.get(0) {
return match_str(&*arg.expr).map(|(name, _)| name);
return match_str(&arg.expr).map(|(name, _)| name);
}
}

Expand All @@ -135,7 +135,7 @@ pub fn match_require(node: &ast::Expr, decls: &HashSet<Id>, ignore_mark: Mark) -
Expr::Member(member) => {
if match_member_expr(member, vec!["module", "require"], decls) {
if let Some(arg) = call.args.get(0) {
return match_str(&*arg.expr).map(|(name, _)| name);
return match_str(&arg.expr).map(|(name, _)| name);
}
}

Expand All @@ -156,7 +156,7 @@ pub fn match_import(node: &ast::Expr, ignore_mark: Mark) -> Option<JsWord> {
Expr::Call(call) => match &call.callee {
Callee::Import(ident) if !is_marked(ident.span, ignore_mark) => {
if let Some(arg) = call.args.get(0) {
return match_str(&*arg.expr).map(|(name, _)| name);
return match_str(&arg.expr).map(|(name, _)| name);
}
None
}
Expand Down

0 comments on commit 426852f

Please sign in to comment.