Unverified Commit 4c33361f authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

Revert "Update `swc_core` to `v0.100.6` (#68560)" (#68978)

### What?

Revert swc_core upgrade, as it has a bug related to `styled_jsx`
transform.

Wasm plugin version runs after the TypeScript pass so it works, but
custom transform (next-swc) runs before the typescript pass so it
breaks.

### Why?

It broke some apps.

### How?
parent 735deb6a
This diff is collapsed.
......@@ -84,21 +84,21 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" }
turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" }
# SWC crates
swc_core = { version = "0.100.6", features = [
swc_core = { version = "0.96.9", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
] }
testing = { version = "0.39.0" }
testing = { version = "0.36.0" }
# Keep consistent with preset_env_base through swc_core
browserslist-rs = { version = "0.16.0" }
miette = { version = "5.10.0", features = ["fancy"] }
mdxjs = "0.2.5"
modularize_imports = { version = "0.68.21" }
styled_components = { version = "0.96.20" }
styled_jsx = { version = "0.73.29" }
swc_emotion = { version = "0.72.19" }
swc_relay = { version = "0.44.22" }
modularize_imports = { version = "0.68.7" }
styled_components = { version = "0.96.6" }
styled_jsx = { version = "0.73.10" }
swc_emotion = { version = "0.72.6" }
swc_relay = { version = "0.44.5" }
# General Deps
......@@ -198,7 +198,7 @@ smallvec = { version = "1.13.1", features = [
"union",
"const_new",
] }
sourcemap = "9.0.0"
sourcemap = "8.0.1"
syn = "1.0.107"
tempfile = "3.3.0"
thiserror = "1.0.48"
......
......@@ -59,7 +59,7 @@ enum MinifyTarget {
impl MinifyTarget {
fn to_file(&self, cm: Lrc<SourceMap>) -> Lrc<SourceFile> {
match self {
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon.into(), code.clone()),
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon, code.clone()),
MinifyTarget::Map(codes) => {
assert_eq!(
codes.len(),
......@@ -69,7 +69,7 @@ impl MinifyTarget {
let (filename, code) = codes.iter().next().unwrap();
cm.new_source_file(FileName::Real(filename.clone().into()).into(), code.clone())
cm.new_source_file(FileName::Real(filename.clone().into()), code.clone())
}
}
}
......
......@@ -35,7 +35,7 @@ impl Task for ParseTask {
None
};
let fm =
c.cm.new_source_file(self.filename.clone().into(), self.src.clone());
c.cm.new_source_file(self.filename.clone(), self.src.clone());
let program = try_with_handler(
c.cm.clone(),
swc_core::base::HandlerOpts {
......
......@@ -105,7 +105,7 @@ impl Task for TransformTask {
FileName::Real(options.swc.filename.clone().into())
};
self.c.cm.new_source_file(filename.into(), src.to_string())
self.c.cm.new_source_file(filename, src.to_string())
}
Input::FromFilename => {
let filename = &options.swc.filename;
......@@ -114,7 +114,7 @@ impl Task for TransformTask {
}
self.c.cm.new_source_file(
FileName::Real(filename.into()).into(),
FileName::Real(filename.into()),
read_to_string(filename).with_context(|| {
format!("Failed to read source code from {}", filename)
})?,
......
......@@ -32,8 +32,8 @@ lazy_static = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
rustc-hash = { workspace = true }
react_remove_properties = "0.24.17"
remove_console = "0.25.17"
react_remove_properties = "0.24.15"
remove_console = "0.25.15"
auto-hash-map = { workspace = true }
......
......@@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use swc_core::{
common::{source_map::SmallPos, Span, Spanned, GLOBALS},
common::{source_map::Pos, Span, Spanned, GLOBALS},
ecma::ast::{Decl, Expr, FnExpr, Ident, Program},
};
use turbo_tasks::{trace::TraceRawVcs, RcStr, TryJoinIterExt, ValueDefault, Vc};
......
......@@ -57,7 +57,7 @@ impl CustomTransformer for NextJsDynamic {
self.is_react_server_layer,
self.is_app_dir,
NextDynamicMode::Webpack,
FileName::Real(ctx.file_path_str.into()).into(),
FileName::Real(ctx.file_path_str.into()),
None,
));
......
......@@ -56,8 +56,8 @@ swc_emotion = { workspace = true }
swc_relay = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true }
react_remove_properties = "0.24.17"
remove_console = "0.25.17"
react_remove_properties = "0.24.15"
remove_console = "0.25.15"
preset_env_base = "0.5.1"
[dev-dependencies]
......
......@@ -132,7 +132,7 @@ where
if let Some(config) = &opts.relay {
Either::Left(swc_relay::relay(
Arc::new(config.clone()),
(*file.name).clone(),
file.name.clone(),
std::env::current_dir().unwrap(),
opts.pages_dir.clone(),
None,
......@@ -160,7 +160,7 @@ where
let styled_jsx = if let Some(config) = opts.styled_jsx.to_option() {
Either::Left(styled_jsx::visitor::styled_jsx(
cm.clone(),
(*file.name).clone(),
file.name.clone(),
styled_jsx::visitor::Config {
use_lightningcss: config.use_lightningcss,
browsers: target_browsers,
......@@ -266,7 +266,7 @@ where
if !config.enabled.unwrap_or(false) {
return None;
}
if let FileName::Real(path) = &*file.name {
if let FileName::Real(path) = &file.name {
path.to_str().map(|_| {
Either::Left(swc_emotion::EmotionTransformer::new(
config.clone(),
......
use swc_core::ecma::{
ast::{
Ident, IdentName, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement,
},
ast::{Ident, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement},
atoms::JsWord,
visit::Fold,
};
......@@ -28,16 +26,22 @@ impl Fold for AmpAttributePatcher {
if sym.starts_with("amp-") {
for i in &mut attrs {
if let JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(IdentName { sym, span: s }),
name:
JSXAttrName::Ident(Ident {
sym,
span: s,
optional: o,
}),
span,
value,
}) = &i
{
if sym as &str == "className" {
*i = JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(IdentName {
name: JSXAttrName::Ident(Ident {
sym: JsWord::from("class"),
span: *s,
optional: *o,
}),
span: *span,
value: value.clone(),
......
......@@ -4,8 +4,8 @@ use swc_core::{
common::{util::take::Take, SyntaxContext, DUMMY_SP},
ecma::{
ast::{
CallExpr, Callee, Decl, Expr, Id, Ident, IdentName, Lit, MemberExpr, MemberProp,
Module, ModuleItem, Pat, Script, Stmt, VarDecl, VarDeclKind, VarDeclarator,
CallExpr, Callee, Decl, Expr, Id, Ident, Lit, MemberExpr, MemberProp, Module,
ModuleItem, Pat, Script, Stmt, VarDecl, VarDeclKind, VarDeclarator,
},
atoms::{Atom, JsWord},
utils::{prepend_stmts, private_ident, ExprFactory, IdentRenamer},
......@@ -114,19 +114,18 @@ impl VisitMut for CjsOptimizer {
span: DUMMY_SP,
callee: Ident::new(
"require".into(),
DUMMY_SP,
self.unresolved_ctxt,
DUMMY_SP.with_ctxt(self.unresolved_ctxt),
)
.as_callee(),
args: vec![Expr::Lit(Lit::Str(
renamed.clone().into(),
))
.as_arg()],
..Default::default()
type_args: None,
})),
prop: MemberProp::Ident(IdentName::new(
prop: MemberProp::Ident(Ident::new(
prop.sym.clone(),
DUMMY_SP,
DUMMY_SP.with_ctxt(self.unresolved_ctxt),
)),
}))),
definite: false,
......@@ -143,8 +142,8 @@ impl VisitMut for CjsOptimizer {
Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![var],
..Default::default()
}),
)));
}
......@@ -213,7 +212,7 @@ impl VisitMut for CjsOptimizer {
})) = n.init.as_deref()
{
if let Expr::Ident(ident) = &**callee {
if ident.ctxt == self.unresolved_ctxt && ident.sym == *"require" {
if ident.span.ctxt == self.unresolved_ctxt && ident.sym == *"require" {
if let Some(arg) = args.first() {
if let Expr::Lit(Lit::Str(v)) = &*arg.expr {
// TODO: Config
......
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use std::path::{Path, PathBuf};
use pathdiff::diff_paths;
use swc_core::{
......@@ -9,7 +6,7 @@ use swc_core::{
ecma::{
ast::{
op, ArrayLit, ArrowExpr, BinExpr, BlockStmt, BlockStmtOrExpr, Bool, CallExpr, Callee,
Expr, ExprOrSpread, ExprStmt, Id, Ident, IdentName, ImportDecl, ImportDefaultSpecifier,
Expr, ExprOrSpread, ExprStmt, Id, Ident, ImportDecl, ImportDefaultSpecifier,
ImportNamedSpecifier, ImportSpecifier, KeyValueProp, Lit, ModuleDecl, ModuleItem,
ObjectLit, Prop, PropName, PropOrSpread, Stmt, Str, Tpl, UnaryExpr, UnaryOp,
},
......@@ -30,7 +27,7 @@ pub fn next_dynamic(
is_react_server_layer: bool,
prefer_esm: bool,
mode: NextDynamicMode,
filename: Arc<FileName>,
filename: FileName,
pages_or_app_dir: Option<PathBuf>,
) -> impl Fold {
NextDynamicPatcher {
......@@ -84,7 +81,7 @@ struct NextDynamicPatcher {
is_react_server_layer: bool,
prefer_esm: bool,
pages_or_app_dir: Option<PathBuf>,
filename: Arc<FileName>,
filename: FileName,
dynamic_bindings: Vec<Id>,
is_next_dynamic_first_arg: bool,
dynamically_imported_specifier: Option<(String, Span)>,
......@@ -328,10 +325,7 @@ impl Fold for NextDynamicPatcher {
let mut props =
vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: PropName::Ident(IdentName::new(
"loadableGenerated".into(),
DUMMY_SP,
)),
key: PropName::Ident(Ident::new("loadableGenerated".into(), DUMMY_SP)),
value: generated,
})))];
......@@ -351,7 +345,11 @@ impl Fold for NextDynamicPatcher {
},
_ => None,
} {
if let Some(IdentName { sym, span: _ }) = match key {
if let Some(Ident {
sym,
span: _,
optional: _,
}) = match key {
PropName::Ident(ident) => Some(ident),
_ => None,
} {
......@@ -401,7 +399,7 @@ impl Fold for NextDynamicPatcher {
raw: None,
}))),
}],
..Default::default()
type_args: Default::default(),
});
let side_effect_free_loader_arg = Expr::Arrow(ArrowExpr {
......@@ -415,11 +413,11 @@ impl Fold for NextDynamicPatcher {
&require_resolve_weak_expr,
)),
})],
..Default::default()
})),
is_async: true,
is_generator: false,
..Default::default()
type_params: None,
return_type: None,
});
expr.args[0] = side_effect_free_loader_arg.as_arg();
......@@ -447,7 +445,7 @@ impl Fold for NextDynamicPatcher {
fn module_id_options(module_id: Expr) -> Vec<PropOrSpread> {
vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: PropName::Ident(IdentName::new("modules".into(), DUMMY_SP)),
key: PropName::Ident(Ident::new("modules".into(), DUMMY_SP)),
value: Box::new(Expr::Array(ArrayLit {
elems: vec![Some(ExprOrSpread {
expr: Box::new(module_id),
......@@ -460,7 +458,7 @@ fn module_id_options(module_id: Expr) -> Vec<PropOrSpread> {
fn webpack_options(module_id: Expr) -> Vec<PropOrSpread> {
vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: PropName::Ident(IdentName::new("webpack".into(), DUMMY_SP)),
key: PropName::Ident(Ident::new("webpack".into(), DUMMY_SP)),
value: Box::new(Expr::Arrow(ArrowExpr {
params: vec![],
body: Box::new(BlockStmtOrExpr::Expr(Box::new(Expr::Array(ArrayLit {
......@@ -473,7 +471,8 @@ fn webpack_options(module_id: Expr) -> Vec<PropOrSpread> {
is_async: false,
is_generator: false,
span: DUMMY_SP,
..Default::default()
return_type: None,
type_params: None,
})),
})))]
}
......@@ -507,10 +506,7 @@ impl NextDynamicPatcher {
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: chunks_ident,
imported: Some(
Ident::new("chunks".into(), DUMMY_SP, Default::default())
.into(),
),
imported: Some(Ident::new("chunks".into(), DUMMY_SP).into()),
is_type_only: false,
}),
],
......@@ -534,12 +530,7 @@ impl NextDynamicPatcher {
span: DUMMY_SP,
local: id_ident,
imported: Some(
Ident::new(
"__turbopack_module_id__".into(),
DUMMY_SP,
Default::default(),
)
.into(),
Ident::new("__turbopack_module_id__".into(), DUMMY_SP).into(),
),
is_type_only: false,
})],
......@@ -564,12 +555,7 @@ impl NextDynamicPatcher {
span: DUMMY_SP,
local: id_ident,
imported: Some(
Ident::new(
"__turbopack_module_id__".into(),
DUMMY_SP,
Default::default(),
)
.into(),
Ident::new("__turbopack_module_id__".into(), DUMMY_SP).into(),
),
is_type_only: false,
})],
......@@ -593,12 +579,7 @@ impl NextDynamicPatcher {
span: DUMMY_SP,
local: id_ident,
imported: Some(
Ident::new(
"__turbopack_module_id__".into(),
DUMMY_SP,
Default::default(),
)
.into(),
Ident::new("__turbopack_module_id__".into(), DUMMY_SP).into(),
),
is_type_only: false,
})],
......@@ -631,8 +612,9 @@ fn exec_expr_when_resolve_weak_available(expr: &Expr) -> Expr {
span: DUMMY_SP,
op: UnaryOp::TypeOf, // 'typeof' operator
arg: Box::new(Expr::Ident(Ident {
span: DUMMY_SP,
sym: quote_ident!("require.resolveWeak").sym,
..Default::default()
optional: false,
})),
});
......
......@@ -201,7 +201,7 @@ impl Fold for Analyzer<'_> {
tracing::trace!(
"ssg: Handling `{}{:?}`; in_data_fn = {:?}",
f.ident.sym,
f.ident.ctxt,
f.ident.span.ctxt,
self.in_data_fn
);
......@@ -392,7 +392,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping import `{}{:?}` because it should be removed",
local.sym,
local.ctxt
local.span.ctxt
);
self.state.should_run_again = true;
......@@ -466,7 +466,7 @@ impl Fold for NextSsg {
let mut var = Some(VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(
IdentName::new(
Ident::new(
if self.state.is_prerenderer {
"__N_SSG".into()
} else {
......@@ -498,8 +498,8 @@ impl Fold for NextSsg {
decl: Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: Default::default(),
decls: vec![var],
..Default::default()
})),
})))
}
......@@ -578,7 +578,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping var `{}{:?}` because it should be removed",
name.id.sym,
name.id.ctxt
name.id.span.ctxt
);
return Pat::Invalid(Invalid { span: DUMMY_SP });
......
......@@ -241,6 +241,7 @@ impl Fold for OptimizeBarrel {
decl: Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(BindingIdent {
......@@ -254,7 +255,6 @@ impl Fold for OptimizeBarrel {
})))),
definite: false,
}],
..Default::default()
})),
})));
......@@ -279,6 +279,7 @@ impl Fold for OptimizeBarrel {
decl: Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(BindingIdent {
......@@ -292,7 +293,6 @@ impl Fold for OptimizeBarrel {
})))),
definite: false,
}],
..Default::default()
})),
})));
}
......
......@@ -170,7 +170,8 @@ impl Fold for OptimizeServerReact {
is_async: false,
is_generator: false,
params: vec![],
..Default::default()
return_type: None,
type_params: None,
})
.into(),
),
......
......@@ -49,7 +49,8 @@ impl Fold for PageConfig {
name: Pat::Ident(BindingIdent {
id: Ident {
sym: STRING_LITERAL_DROP_BUNDLE.into(),
..Default::default()
span: DUMMY_SP,
optional: false,
},
type_ann: None,
}),
......@@ -63,7 +64,7 @@ impl Fold for PageConfig {
}],
span: DUMMY_SP,
kind: VarDeclKind::Const,
..Default::default()
declare: false,
}))))];
}
}
......
......@@ -263,7 +263,7 @@ mod tests {
};
let fm = c.cm.new_source_file(
swc_core::common::FileName::Real(PathBuf::from(file_path.to_string())).into(),
swc_core::common::FileName::Real(PathBuf::from(file_path.to_string())),
contents.to_string(),
);
......
use std::{collections::HashMap, path::PathBuf, rc::Rc, sync::Arc};
use std::{collections::HashMap, path::PathBuf, rc::Rc};
use regex::Regex;
use serde::Deserialize;
......@@ -161,11 +161,11 @@ impl<C: Comments> ReactServerComponents<C> {
span: DUMMY_SP,
callee: quote_ident!("require").as_callee(),
args: vec![quote_str!("private-next-rsc-mod-ref-proxy").as_arg()],
..Default::default()
type_args: Default::default(),
}))),
definite: false,
}],
..Default::default()
declare: false,
})))),
ModuleItem::Stmt(Stmt::Expr(ExprStmt {
span: DUMMY_SP,
......@@ -173,7 +173,7 @@ impl<C: Comments> ReactServerComponents<C> {
span: DUMMY_SP,
left: MemberExpr {
span: DUMMY_SP,
obj: Box::new(Expr::Ident(quote_ident!("module").into())),
obj: Box::new(Expr::Ident(quote_ident!("module"))),
prop: MemberProp::Ident(quote_ident!("exports")),
}
.into(),
......@@ -182,7 +182,7 @@ impl<C: Comments> ReactServerComponents<C> {
span: DUMMY_SP,
callee: quote_ident!("createProxy").as_callee(),
args: vec![filepath.as_arg()],
..Default::default()
type_args: Default::default(),
})),
})),
})),
......@@ -860,7 +860,7 @@ pub fn server_components_assert(
/// Runs react server component transform for the module proxy, as well as
/// running assertion.
pub fn server_components<C: Comments>(
filename: Arc<FileName>,
filename: FileName,
config: Config,
comments: C,
app_dir: Option<PathBuf>,
......@@ -872,7 +872,7 @@ pub fn server_components<C: Comments>(
as_folder(ReactServerComponents {
is_react_server_layer,
comments,
filepath: match &*filename {
filepath: match filename {
FileName::Custom(path) => format!("<{path}>"),
_ => filename.to_string(),
},
......
......@@ -600,15 +600,13 @@ impl NextSsg {
decl: Decl::Var(Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: Default::default(),
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Ident(
IdentName::new(data_marker.into(), DUMMY_SP).into(),
),
name: Pat::Ident(Ident::new(data_marker.into(), DUMMY_SP).into()),
init: Some(true.into()),
definite: Default::default(),
}],
..Default::default()
})),
})),
);
......@@ -738,7 +736,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping import `{}{:?}` because it should be removed",
local.sym,
local.ctxt
local.span.ctxt
);
self.state.should_run_again = true;
......@@ -927,7 +925,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping var `{}{:?}` because it should be removed",
name.id.sym,
name.id.ctxt
name.id.span.ctxt
);
return Pat::Invalid(Invalid { span: DUMMY_SP });
......@@ -981,7 +979,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping var `{}{:?}` because it should be removed",
name.id.sym,
name.id.ctxt
name.id.span.ctxt
);
return SimpleAssignTarget::Invalid(Invalid { span: DUMMY_SP });
......
......@@ -57,7 +57,7 @@ fn next_dynamic_errors(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -93,7 +93,7 @@ fn react_server_components_server_graph_errors(input: PathBuf) {
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/layout.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/layout.js")),
Config::WithOptions(Options {
is_react_server_layer: true,
}),
......@@ -118,7 +118,7 @@ fn react_server_components_client_graph_errors(input: PathBuf) {
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/page.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/page.js")),
Config::WithOptions(Options {
is_react_server_layer: false,
}),
......@@ -165,7 +165,7 @@ fn react_server_actions_server_errors(input: PathBuf) {
chain!(
resolver(Mark::new(), Mark::new(), false),
server_components(
FileName::Real(PathBuf::from("/app/item.js")).into(),
FileName::Real(PathBuf::from("/app/item.js")),
Config::WithOptions(Options {
is_react_server_layer: true
},),
......@@ -201,7 +201,7 @@ fn react_server_actions_client_errors(input: PathBuf) {
chain!(
resolver(Mark::new(), Mark::new(), false),
server_components(
FileName::Real(PathBuf::from("/app/item.js")).into(),
FileName::Real(PathBuf::from("/app/item.js")),
Config::WithOptions(Options {
is_react_server_layer: false
},),
......
......@@ -71,7 +71,7 @@ fn next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -88,7 +88,7 @@ fn next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -105,7 +105,7 @@ fn next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -133,7 +133,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -150,7 +150,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -167,7 +167,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -184,7 +184,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()),
)
},
......@@ -317,7 +317,7 @@ fn react_server_components_typescript(input: PathBuf) {
Syntax::Typescript(Default::default()),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Config::WithOptions(Options {
is_react_server_layer: true,
}),
......@@ -339,7 +339,7 @@ fn react_server_components_server_graph_fixture(input: PathBuf) {
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Config::WithOptions(Options {
is_react_server_layer: true,
}),
......@@ -361,7 +361,7 @@ fn react_server_components_client_graph_fixture(input: PathBuf) {
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Config::WithOptions(Options {
is_react_server_layer: false,
}),
......
......@@ -19,7 +19,7 @@ static COMPILER: Lazy<Arc<Compiler>> = Lazy::new(|| {
fn should_collect_estimated_third_part_packages() {
let eliminated_packages: Rc<RefCell<FxHashSet<String>>> = Default::default();
let fm = COMPILER.cm.new_source_file(
FileName::Real("fixture.js".into()).into(),
FileName::Real("fixture.js".into()),
r#"import http from 'http'
import { hash } from '@napi-rs/bcrypt'
......
......@@ -40,7 +40,7 @@ pub fn minify_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
},
|handler| {
GLOBALS.set(&Default::default(), || {
let fm = c.cm.new_source_file(FileName::Anon.into(), s.into());
let fm = c.cm.new_source_file(FileName::Anon, s.into());
let program = c
.minify(fm, handler, &opts)
.context("failed to minify file")?;
......@@ -84,9 +84,9 @@ pub fn transform_sync(s: JsValue, opts: JsValue) -> Result<JsValue, JsValue> {
Ok(s) => {
let fm = c.cm.new_source_file(
if opts.swc.filename.is_empty() {
FileName::Anon.into()
FileName::Anon
} else {
FileName::Real(opts.swc.filename.clone().into()).into()
FileName::Real(opts.swc.filename.clone().into())
},
s.into(),
);
......@@ -151,7 +151,7 @@ pub fn parse_sync(s: JsString, opts: JsValue) -> Result<JsValue, JsValue> {
|handler| {
c.run(|| {
GLOBALS.set(&Default::default(), || {
let fm = c.cm.new_source_file(FileName::Anon.into(), s.into());
let fm = c.cm.new_source_file(FileName::Anon, s.into());
let cmts = c.comments().clone();
let comments = if opts.comments {
......
......@@ -420,7 +420,7 @@ fn generate_minimal_source_map(filename: String, source: String) -> Vc<ParseResu
pos += line.len() as u32;
}
let sm: Arc<SourceMap> = Default::default();
sm.new_source_file(FileName::Custom(filename).into(), source);
sm.new_source_file(FileName::Custom(filename), source);
let map = ParseResultSourceMap::new(sm, mappings, OptionSourceMap::none());
map.cell()
}
......
......@@ -634,7 +634,7 @@ async fn process_content(
)),
);
let fm = cm.new_source_file(FileName::Custom(filename.to_string()).into(), code.clone());
let fm = cm.new_source_file(FileName::Custom(filename.to_string()), code.clone());
let mut errors = vec![];
let ss = swc_core::css::parser::parse_file(
......@@ -1144,10 +1144,7 @@ mod tests {
fn lint_swc(code: &str) -> Vec<CssError> {
let cm = swc_core::common::SourceMap::new(FilePathMapping::empty());
let fm = cm.new_source_file(
FileName::Custom("test.css".to_string()).into(),
code.to_string(),
);
let fm = cm.new_source_file(FileName::Custom("test.css".to_string()), code.to_string());
let ss: Stylesheet = swc_core::css::parser::parse_file(
&fm,
......
......@@ -95,7 +95,7 @@ impl CustomTransformer for StyledComponentsTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "styled_components", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
program.visit_mut_with(&mut styled_components::styled_components(
FileName::Real(PathBuf::from(ctx.file_path_str)).into(),
FileName::Real(PathBuf::from(ctx.file_path_str)),
ctx.file_name_hash,
self.config.clone(),
NoopComments,
......
......@@ -3,7 +3,7 @@ use std::{collections::BTreeMap, fmt::Display};
use indexmap::{IndexMap, IndexSet};
use once_cell::sync::Lazy;
use swc_core::{
common::{source_map::SmallPos, Span},
common::{source_map::Pos, Span},
ecma::{
ast::*,
atoms::{js_word, JsWord},
......
......@@ -3570,7 +3570,7 @@ impl WellKnownFunctionKind {
}
fn is_unresolved(i: &Ident, unresolved_mark: Mark) -> bool {
i.ctxt.outer() == unresolved_mark
i.span.ctxt.outer() == unresolved_mark
}
#[doc(hidden)]
......
......@@ -47,7 +47,7 @@ use swc_core::{
common::GLOBALS,
ecma::{
codegen::{text_writer::JsWriter, Emitter},
visit::{VisitMutWith, VisitMutWithAstPath},
visit::{VisitMutWith, VisitMutWithPath},
},
};
pub use transform::{
......@@ -831,7 +831,7 @@ async fn gen_content_with_visitors(
GLOBALS.set(globals, || {
if !visitors.is_empty() {
program.visit_mut_with_ast_path(
program.visit_mut_with_path(
&mut ApplyVisitors::new(visitors),
&mut Default::default(),
);
......
......@@ -38,7 +38,7 @@ pub async fn minify(path: Vc<FileSystemPath>, code: Vc<Code>) -> Result<Vc<Code>
let cm = Arc::new(SwcSourceMap::new(FilePathMapping::empty()));
let compiler = Arc::new(Compiler::new(cm.clone()));
let fm = compiler.cm.new_source_file(
FileName::Custom(path.path.to_string()).into(),
FileName::Custom(path.path.to_string()),
code.source_code().to_str()?.to_string(),
);
......
use std::{future::Future, sync::Arc};
use std::{borrow::Cow, future::Future, sync::Arc};
use anyhow::{anyhow, Context, Result};
use swc_core::{
......@@ -119,13 +119,13 @@ impl GenerateSourceMap for ParseResultSourceMap {
None
};
let input_map = if let Some(map) = original_src_map.as_ref() {
map.as_regular_source_map()
map.as_regular_source_map().map(Cow::into_owned)
} else {
None
};
let map = self.files_map.build_source_map_with_config(
&self.mappings,
input_map.as_deref(),
input_map,
InlineSourcesContentConfig {},
);
Ok(Vc::cell(Some(SourceMap::new_regular(map).cell())))
......@@ -275,11 +275,11 @@ async fn parse_content(
let parser_handler = Handler::with_emitter(true, false, emitter.clone());
let globals = Arc::new(Globals::new());
let globals_ref = &globals;
let helpers = GLOBALS.set(globals_ref, || Helpers::new(true));
let mut result = WrapFuture::new(
async {
let file_name = FileName::Custom(ident.to_string());
let fm = source_map.new_source_file(file_name.clone().into(), string);
let fm = source_map.new_source_file(file_name.clone(), string);
let comments = SwcComments::default();
......@@ -448,7 +448,7 @@ async fn parse_content(
},
|f, cx| {
GLOBALS.set(globals_ref, || {
HANDLER.set(&handler, || HELPERS.set(&Helpers::new(true), || f.poll(cx)))
HANDLER.set(&handler, || HELPERS.set(&helpers, || f.poll(cx)))
})
},
)
......
......@@ -4,7 +4,7 @@ use swc_core::{
common::pass::AstKindPath,
ecma::{
ast::*,
visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithAstPath},
visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithPath},
},
};
......@@ -80,7 +80,7 @@ impl<'a, 'b> ApplyVisitors<'a, 'b> {
fn visit_if_required<N>(&mut self, n: &mut N, ast_path: &mut AstKindPath<AstParentKind>)
where
N: for<'aa> VisitMutWith<dyn VisitMut + Send + Sync + 'aa>
+ for<'aa, 'bb> VisitMutWithAstPath<ApplyVisitors<'aa, 'bb>>,
+ for<'aa, 'bb> VisitMutWithPath<ApplyVisitors<'aa, 'bb>>,
{
let mut index = self.index;
let mut current_visitors = self.visitors.as_ref();
......@@ -99,7 +99,7 @@ impl<'a, 'b> ApplyVisitors<'a, 'b> {
if current {
// Potentially skip visiting this sub tree
if nested_visitors_start < visitors.len() {
n.visit_mut_children_with_ast_path(
n.visit_mut_children_with_path(
&mut ApplyVisitors {
// We only select visitors starting from `nested_visitors_start`
// which maintains the invariant.
......@@ -128,7 +128,7 @@ impl<'a, 'b> ApplyVisitors<'a, 'b> {
}
}
// Ast path is unchanged, just keep visiting
n.visit_mut_children_with_ast_path(self, ast_path);
n.visit_mut_children_with_path(self, ast_path);
}
}
......@@ -168,7 +168,7 @@ mod tests {
codegen::{text_writer::JsWriter, Emitter},
parser::parse_file_as_module,
transforms::base::resolver,
visit::{fields::*, AstParentKind, VisitMut, VisitMutWith, VisitMutWithAstPath},
visit::{fields::*, AstParentKind, VisitMut, VisitMutWith, VisitMutWithPath},
},
testing::run_test,
};
......@@ -232,7 +232,7 @@ mod tests {
#[test]
fn path_visitor() {
run_test(false, |cm, _handler| {
let fm = cm.new_source_file(FileName::Anon.into(), "('foo', 'bar', ['baz']);".into());
let fm = cm.new_source_file(FileName::Anon, "('foo', 'bar', ['baz']);".into());
let m = parse(&fm);
......@@ -263,7 +263,7 @@ mod tests {
let bar_replacer = replacer("bar", "bar-success");
let mut m = m.clone();
m.visit_mut_with_ast_path(
m.visit_mut_with_path(
&mut ApplyVisitors::new(vec![(&path, &bar_replacer)]),
&mut Default::default(),
);
......@@ -288,7 +288,7 @@ mod tests {
let bar_replacer = replacer("bar", "bar-success");
let mut m = m.clone();
m.visit_mut_with_ast_path(
m.visit_mut_with_path(
&mut ApplyVisitors::new(vec![(&wrong_path, &bar_replacer)]),
&mut Default::default(),
);
......
......@@ -244,7 +244,7 @@ fn transform_amd_factory(
args: deps,
callee: Callee::Expr(Box::new(Expr::Ident(f.clone()))),
span: DUMMY_SP,
..Default::default()
type_args: None,
});
*callee = Callee::Expr(quote_expr!(
"($f1, r = typeof $f2 !== \"function\" ? $f3 : $call_f) => r !== undefined && \
......@@ -268,7 +268,8 @@ fn transform_amd_factory(
expr: Box::new(Expr::Call(CallExpr {
args: deps,
callee: Callee::Expr(factory),
..Default::default()
span: DUMMY_SP,
type_args: None,
})),
spread: None,
});
......
......@@ -214,7 +214,7 @@ impl AsyncModule {
fn add_async_dependency_handler(program: &mut Program, idents: &IndexSet<String>) {
let idents = idents
.iter()
.map(|ident| Ident::new(ident.clone().into(), DUMMY_SP, Default::default()))
.map(|ident| Ident::new(ident.clone().into(), DUMMY_SP))
.collect::<Vec<_>>();
let stmt = quote!(
......
......@@ -309,7 +309,7 @@ impl CodeGenerateable for CjsRequireCacheAccess {
let path = &self.path.await?;
visitors.push(create_visitor!(path, visit_mut_expr(expr: &mut Expr) {
if let Expr::Member(_) = expr {
*expr = Expr::Ident(Ident::new("__turbopack_cache__".into(), DUMMY_SP, Default::default()));
*expr = Expr::Ident(Ident::new("__turbopack_cache__".into(), DUMMY_SP));
} else {
unreachable!("`CjsRequireCacheAccess` is only created from `MemberExpr`");
}
......
......@@ -255,7 +255,7 @@ impl CodeGenerateable for EsmAssetReference {
visitors.push(create_visitor!(visit_mut_program(program: &mut Program) {
let stmt = quote!(
"var $name = __turbopack_import__($id);" as Stmt,
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
name = Ident::new(ident.clone().into(), DUMMY_SP),
id: Expr = Expr::Lit(match &*id {
ModuleId::String(s) => s.clone().as_str().into(),
ModuleId::Number(n) => (*n as f64).into(),
......@@ -282,13 +282,13 @@ impl CodeGenerateable for EsmAssetReference {
let stmt = if import_externals {
quote!(
"var $name = __turbopack_external_import__($id);" as Stmt,
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
name = Ident::new(ident.clone().into(), DUMMY_SP),
id: Expr = Expr::Lit(request.to_string().into())
)
} else {
quote!(
"var $name = __turbopack_external_require__($id, true);" as Stmt,
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
name = Ident::new(ident.clone().into(), DUMMY_SP),
id: Expr = Expr::Lit(request.to_string().into())
)
};
......@@ -315,7 +315,7 @@ impl CodeGenerateable for EsmAssetReference {
visitors.push(create_visitor!(visit_mut_program(program: &mut Program) {
let stmt = quote!(
"var $name = __turbopack_external_require__($id, true);" as Stmt,
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
name = Ident::new(ident.clone().into(), DUMMY_SP),
id: Expr = Expr::Lit(request.to_string().into())
);
insert_hoisted_stmt(program, stmt);
......
use anyhow::Result;
use serde::{Deserialize, Serialize};
use swc_core::{
common::Span,
common::{Span, SyntaxContext},
ecma::{
ast::{
ComputedPropName, Expr, Ident, KeyValueProp, Lit, MemberExpr, MemberProp, Number, Prop,
......@@ -79,7 +79,7 @@ impl EsmBinding {
// TODO: Merge with the above condition when https://rust-lang.github.io/rfcs/2497-if-let-chains.html lands.
if let Some(imported_ident) = imported_module.as_deref() {
*prop = Prop::KeyValue(KeyValueProp {
key: PropName::Ident(ident.clone().into()),
key: PropName::Ident(ident.clone()),
value: Box::new(make_expr(imported_ident, item.export.as_deref(), ident.span, false))
});
}
......@@ -167,14 +167,11 @@ impl CodeGenerateable for EsmBindings {
}
fn make_expr(imported_module: &str, export: Option<&str>, span: Span, in_call: bool) -> Expr {
let span = span.with_ctxt(SyntaxContext::empty());
if let Some(export) = export {
let mut expr = Expr::Member(MemberExpr {
span,
obj: Box::new(Expr::Ident(Ident::new(
imported_module.into(),
span,
Default::default(),
))),
obj: Box::new(Expr::Ident(Ident::new(imported_module.into(), span))),
prop: MemberProp::Computed(ComputedPropName {
span,
expr: Box::new(Expr::Lit(Lit::Str(Str {
......@@ -199,6 +196,6 @@ fn make_expr(imported_module: &str, export: Option<&str>, span: Span, in_call: b
}
expr
} else {
Expr::Ident(Ident::new(imported_module.into(), span, Default::default()))
Expr::Ident(Ident::new(imported_module.into(), span))
}
}
......@@ -149,7 +149,7 @@ impl CodeGenerateable for EsmAsyncAssetReference {
expr: error,
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
});
});
......
......@@ -429,7 +429,7 @@ impl CodeGenerateable for EsmExports {
dynamic_exports.push(quote_expr!(
"__turbopack_dynamic__($arg)",
arg: Expr = Ident::new(ident.into(), DUMMY_SP, Default::default()).into()
arg: Expr = Ident::new(ident.into(), DUMMY_SP).into()
));
}
......@@ -443,17 +443,13 @@ impl CodeGenerateable for EsmExports {
if *mutable {
Some(quote!(
"([() => $local, ($new) => $local = $new])" as Expr,
local = Ident::new((name as &str).into(), DUMMY_SP, Default::default()),
new = Ident::new(
format!("{name}_new_value").into(),
DUMMY_SP,
Default::default()
),
local = Ident::new((name as &str).into(), DUMMY_SP),
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP),
))
} else {
Some(quote!(
"(() => $local)" as Expr,
local = Ident::new((name as &str).into(), DUMMY_SP, Default::default())
local = Ident::new((name as &str).into(), DUMMY_SP)
))
}
}
......@@ -463,7 +459,7 @@ impl CodeGenerateable for EsmExports {
referenced_asset.get_ident().await?.map(|ident| {
let expr = Expr::Member(MemberExpr {
span: DUMMY_SP,
obj: Box::new(Expr::Ident(Ident::new(ident.into(), DUMMY_SP, Default::default()))),
obj: Box::new(Expr::Ident(Ident::new(ident.into(), DUMMY_SP))),
prop: MemberProp::Computed(ComputedPropName {
span: DUMMY_SP,
expr: Box::new(Expr::Lit(Lit::Str(Str {
......@@ -477,7 +473,7 @@ impl CodeGenerateable for EsmExports {
quote!(
"([() => $expr, ($new) => $expr = $new])" as Expr,
expr: Expr = expr,
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP, Default::default()),
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP),
)
} else {
quote!(
......@@ -493,7 +489,7 @@ impl CodeGenerateable for EsmExports {
referenced_asset.get_ident().await?.map(|ident| {
quote!(
"(() => $imported)" as Expr,
imported = Ident::new(ident.into(), DUMMY_SP, Default::default())
imported = Ident::new(ident.into(), DUMMY_SP)
)
})
}
......
......@@ -146,11 +146,7 @@ fn encode_path(path: &'_ str) -> Cow<'_, str> {
}
fn meta_ident() -> Ident {
Ident::new(
magic_identifier::mangle("import.meta").into(),
DUMMY_SP,
Default::default(),
)
Ident::new(magic_identifier::mangle("import.meta").into(), DUMMY_SP)
}
#[cfg(test)]
......
......@@ -52,7 +52,7 @@ impl CodeGenerateable for EsmModuleItem {
match module_decl {
ModuleDecl::ExportDefaultExpr(ExportDefaultExpr { box expr, .. }) => {
let stmt = quote!("const $name = $expr;" as Stmt,
name = Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP, Default::default()),
name = Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP),
expr: Expr = expr
);
*module_item = ModuleItem::Stmt(stmt);
......@@ -61,14 +61,14 @@ impl CodeGenerateable for EsmModuleItem {
match decl {
DefaultDecl::Class(class) => {
*module_item = ModuleItem::Stmt(Stmt::Decl(Decl::Class(ClassDecl {
ident: class.ident.unwrap_or_else(|| Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP, Default::default())),
ident: class.ident.unwrap_or_else(|| Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP)),
declare: false,
class: class.class
})))
}
DefaultDecl::Fn(fn_expr) => {
*module_item = ModuleItem::Stmt(Stmt::Decl(Decl::Fn(FnDecl {
ident: fn_expr.ident.unwrap_or_else(|| Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP, Default::default())),
ident: fn_expr.ident.unwrap_or_else(|| Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP)),
declare: false,
function: fn_expr.function
})))
......
......@@ -40,14 +40,14 @@ use swc_core::{
comments::{CommentKind, Comments},
errors::{DiagnosticId, Handler, HANDLER},
pass::AstNodePath,
source_map::SmallPos,
source_map::Pos,
Globals, Span, Spanned, GLOBALS,
},
ecma::{
ast::*,
visit::{
fields::{AssignExprField, AssignTargetField, SimpleAssignTargetField},
AstParentKind, AstParentNodeRef, VisitAstPath, VisitWithAstPath,
AstParentKind, AstParentNodeRef, VisitAstPath, VisitWithPath,
},
},
};
......@@ -653,7 +653,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
}
}
program.visit_with_ast_path(&mut visitor, &mut Default::default());
program.visit_with_path(&mut visitor, &mut Default::default());
(
visitor.webpack_runtime,
......@@ -2628,7 +2628,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
) {
let path = Vc::cell(as_parent_path(ast_path));
self.analysis.add_code_gen(EsmModuleItem::new(path));
export.visit_children_with_ast_path(self, ast_path);
export.visit_children_with_path(self, ast_path);
}
fn visit_named_export<'ast: 'r, 'r>(
......@@ -2693,7 +2693,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
self.analysis.add_code_gen(EsmModuleItem::new(path));
export.visit_children_with_ast_path(self, ast_path);
export.visit_children_with_path(self, ast_path);
}
fn visit_export_decl<'ast: 'r, 'r>(
......@@ -2707,7 +2707,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
});
self.analysis
.add_code_gen(EsmModuleItem::new(Vc::cell(as_parent_path(ast_path))));
export.visit_children_with_ast_path(self, ast_path);
export.visit_children_with_path(self, ast_path);
}
fn visit_export_default_expr<'ast: 'r, 'r>(
......@@ -2721,7 +2721,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
);
self.analysis
.add_code_gen(EsmModuleItem::new(Vc::cell(as_parent_path(ast_path))));
export.visit_children_with_ast_path(self, ast_path);
export.visit_children_with_path(self, ast_path);
}
fn visit_export_default_decl<'ast: 'r, 'r>(
......@@ -2748,7 +2748,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
self.analysis
.add_code_gen(EsmModuleItem::new(Vc::cell(as_parent_path(ast_path))));
export.visit_children_with_ast_path(self, ast_path);
export.visit_children_with_path(self, ast_path);
}
fn visit_import_decl<'ast: 'r, 'r>(
......@@ -2758,7 +2758,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
) {
let path = Vc::cell(as_parent_path(ast_path));
let src = import.src.value.to_string();
import.visit_children_with_ast_path(self, ast_path);
import.visit_children_with_path(self, ast_path);
if import.type_only {
return;
}
......@@ -2821,7 +2821,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
}
}
decl.visit_children_with_ast_path(self, ast_path);
decl.visit_children_with_path(self, ast_path);
}
fn visit_call_expr<'ast: 'r, 'r>(
......@@ -2860,7 +2860,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
}
}
call.visit_children_with_ast_path(self, ast_path);
call.visit_children_with_path(self, ast_path);
}
}
......
......@@ -112,7 +112,7 @@ impl SinglePatternMapping {
expr: Box::new(self.create_id(key_expr)),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
}),
Self::External(request, ExternalType::CommonJs) => Expr::Call(CallExpr {
callee: Callee::Expr(quote_expr!("__turbopack_external_require__")),
......@@ -121,7 +121,7 @@ impl SinglePatternMapping {
expr: request.as_str().into(),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
}),
Self::External(request, ty) => throw_module_not_found_error_expr(
request,
......@@ -144,7 +144,7 @@ impl SinglePatternMapping {
expr: error,
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
})
}
Self::Unresolveable(_) => self.create_id(key_expr),
......@@ -157,7 +157,7 @@ impl SinglePatternMapping {
expr: Box::new(key_expr.into_owned()),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
})
} else {
Expr::Call(CallExpr {
......@@ -170,7 +170,7 @@ impl SinglePatternMapping {
),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
})
}
}
......@@ -184,7 +184,7 @@ impl SinglePatternMapping {
),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
}),
#[allow(unreachable_patterns)]
Self::External(request, ty) => throw_module_not_found_error_expr(
......@@ -204,7 +204,7 @@ impl SinglePatternMapping {
expr: quote_expr!("__turbopack_import__"),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
}),
Self::Ignored => {
quote!("Promise.resolve({})" as Expr)
......@@ -219,7 +219,7 @@ impl SinglePatternMapping {
),
}],
span: DUMMY_SP,
..Default::default()
type_args: None,
}),
}
}
......
......@@ -65,7 +65,6 @@ impl CodeGenerateable for Unreachable {
*stmt = Stmt::Block(BlockStmt {
span: stmt.span(),
stmts: replacement,
..Default::default()
});
}),
]
......@@ -140,7 +139,6 @@ impl<'a> VisitMut for ExtractDeclarations<'a> {
kind,
declare,
decls,
ctxt,
} = decl;
if self.in_nested_block_scope && !matches!(kind, VarDeclKind::Var) {
return;
......@@ -169,7 +167,6 @@ impl<'a> VisitMut for ExtractDeclarations<'a> {
span: *span,
kind: *kind,
declare: *declare,
ctxt: *ctxt,
decls,
}))));
}
......@@ -222,7 +219,6 @@ impl<'a> VisitMut for ExtractDeclarations<'a> {
definite: false,
}],
kind: VarDeclKind::Let,
..Default::default()
}))));
}
......
......@@ -6,7 +6,7 @@ use swc_core::{
ecma::{
ast::Program,
codegen::{text_writer::JsWriter, Emitter},
visit::{VisitMutWith, VisitMutWithAstPath},
visit::{VisitMutWith, VisitMutWithPath},
},
};
use turbo_tasks::{TryJoinIterExt, Vc};
......@@ -106,7 +106,7 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem {
let mut program = Program::Module(swc_core::ecma::ast::Module::dummy());
GLOBALS.set(&Globals::new(), || {
if !visitors.is_empty() {
program.visit_mut_with_ast_path(
program.visit_mut_with_path(
&mut ApplyVisitors::new(visitors),
&mut Default::default(),
);
......
......@@ -132,7 +132,7 @@ impl CodeGenerateable for EcmascriptModulePartReference {
visitors.push(create_visitor!(visit_mut_program(program: &mut Program) {
let stmt = quote!(
"var $name = __turbopack_import__($id);" as Stmt,
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
name = Ident::new(ident.clone().into(), DUMMY_SP),
id: Expr = Expr::Lit(match &*id {
ModuleId::String(s) => s.as_str().into(),
ModuleId::Number(n) => (*n as f64).into(),
......
......@@ -279,7 +279,7 @@ impl EcmascriptInputTransform {
} => {
use swc_core::ecma::transforms::typescript::typescript;
let config = Default::default();
program.visit_mut_with(&mut typescript(config, unresolved_mark, top_level_mark));
program.visit_mut_with(&mut typescript(config, unresolved_mark));
}
EcmascriptInputTransform::Decorators {
is_legacy,
......
......@@ -15,10 +15,10 @@ use swc_core::{
ecma::{
ast::{
op, ClassDecl, Decl, DefaultDecl, ExportAll, ExportDecl, ExportNamedSpecifier,
ExportSpecifier, Expr, ExprStmt, FnDecl, Id, Ident, IdentName, ImportDecl,
ImportNamedSpecifier, ImportSpecifier, ImportStarAsSpecifier, KeyValueProp, Lit,
Module, ModuleDecl, ModuleExportName, ModuleItem, NamedExport, ObjectLit, Prop,
PropName, PropOrSpread, Stmt, VarDecl, VarDeclKind, VarDeclarator,
ExportSpecifier, Expr, ExprStmt, FnDecl, Id, Ident, ImportDecl, ImportNamedSpecifier,
ImportSpecifier, ImportStarAsSpecifier, KeyValueProp, Lit, Module, ModuleDecl,
ModuleExportName, ModuleItem, NamedExport, ObjectLit, Prop, PropName, PropOrSpread,
Stmt, VarDecl, VarDeclKind, VarDeclarator,
},
atoms::JsWord,
utils::{find_pat_ids, private_ident, quote_ident},
......@@ -318,11 +318,7 @@ impl DepGraph {
let s = ExportSpecifier::Named(ExportNamedSpecifier {
span: DUMMY_SP,
orig: ModuleExportName::Ident(Ident::new(
export.clone(),
DUMMY_SP,
Default::default(),
)),
orig: ModuleExportName::Ident(Ident::new(export.clone(), DUMMY_SP)),
exported: None,
is_type_only: false,
});
......@@ -570,7 +566,7 @@ impl DepGraph {
Some(s.orig.clone()),
match &s.orig {
ModuleExportName::Ident(i) => i.clone(),
ModuleExportName::Str(..) => quote_ident!("_tmp").into(),
ModuleExportName::Str(..) => quote_ident!("_tmp"),
},
Some(s.exported.clone().unwrap_or_else(|| s.orig.clone())),
),
......@@ -578,16 +574,15 @@ impl DepGraph {
Some(ModuleExportName::Ident(Ident::new(
"default".into(),
DUMMY_SP,
Default::default(),
))),
quote_ident!("default").into(),
quote_ident!("default"),
Some(ModuleExportName::Ident(s.exported.clone())),
),
ExportSpecifier::Namespace(s) => (
None,
match &s.name {
ModuleExportName::Ident(i) => i.clone(),
ModuleExportName::Str(..) => quote_ident!("_tmp").into(),
ModuleExportName::Str(..) => quote_ident!("_tmp"),
},
Some(s.name.clone()),
),
......@@ -707,7 +702,7 @@ impl DepGraph {
exports.push((
default_var.to_id(),
Some(ModuleExportName::Ident(quote_ident!("default").into())),
Some(ModuleExportName::Ident(quote_ident!("default"))),
));
}
ModuleDecl::ExportDefaultExpr(export) => {
......@@ -744,13 +739,13 @@ impl DepGraph {
VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: default_var.clone().into(),
init: Some(export.expr.clone()),
definite: false,
}],
..Default::default()
},
)))),
..Default::default()
......@@ -769,7 +764,7 @@ impl DepGraph {
exports.push((
default_var.to_id(),
Some(ModuleExportName::Ident(quote_ident!("default").into())),
Some(ModuleExportName::Ident(quote_ident!("default"))),
));
}
}
......@@ -1160,7 +1155,7 @@ pub(crate) fn create_turbopack_part_id_assert(dep: PartId) -> ObjectLit {
ObjectLit {
span: DUMMY_SP,
props: vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: PropName::Ident(IdentName::new(ASSERT_CHUNK_KEY.into(), DUMMY_SP)),
key: PropName::Ident(Ident::new(ASSERT_CHUNK_KEY.into(), DUMMY_SP)),
value: match dep {
PartId::ModuleEvaluation => "module evaluation".into(),
PartId::Exports => "exports".into(),
......
......@@ -597,7 +597,6 @@ pub(super) async fn part_of_module(
orig: ModuleExportName::Ident(Ident::new(
export_name.as_str().into(),
DUMMY_SP,
Default::default(),
)),
exported: None,
is_type_only: false,
......@@ -678,7 +677,6 @@ pub(super) async fn part_of_module(
orig: ModuleExportName::Ident(Ident::new(
export_name.as_str().into(),
DUMMY_SP,
Default::default(),
)),
exported: None,
is_type_only: false,
......
......@@ -112,16 +112,16 @@ impl Visit for IdentUsageCollector<'_> {
return;
}
if n.ctxt == self.unresolved {
if n.span.ctxt == self.unresolved {
self.vars.found_unresolved = true;
return;
}
// We allow SyntaxContext::empty() because Some built-in files do not go into
// resolver()
if n.ctxt != self.unresolved
&& n.ctxt != self.top_level
&& n.ctxt != SyntaxContext::empty()
if n.span.ctxt != self.unresolved
&& n.span.ctxt != self.top_level
&& n.span.ctxt != SyntaxContext::empty()
&& !self.top_level_vars.contains(&n.to_id())
{
return;
......
......@@ -54,7 +54,7 @@
Ident,
),
],
span: 54..61,
span: 54..61#1,
in_try: false,
},
Call {
......@@ -113,7 +113,7 @@
Call,
),
],
span: 54..64,
span: 54..64#0,
in_try: false,
},
]
......@@ -63,7 +63,7 @@
Member,
),
],
span: 53..87,
span: 53..87#0,
in_try: false,
},
MemberCall {
......@@ -235,7 +235,7 @@
Call,
),
],
span: 53..123,
span: 53..123#0,
in_try: false,
},
Member {
......@@ -302,7 +302,7 @@
Member,
),
],
span: 135..169,
span: 135..169#0,
in_try: false,
},
MemberCall {
......@@ -474,7 +474,7 @@
Call,
),
],
span: 135..207,
span: 135..207#0,
in_try: false,
},
Member {
......@@ -541,7 +541,7 @@
Member,
),
],
span: 219..253,
span: 219..253#0,
in_try: false,
},
MemberCall {
......@@ -660,7 +660,7 @@
Member,
),
],
span: 281..296,
span: 281..296#0,
in_try: false,
},
FreeVar {
......@@ -740,7 +740,7 @@
Ident,
),
],
span: 281..288,
span: 281..288#1,
in_try: false,
},
MemberCall {
......@@ -822,7 +822,7 @@
Call,
),
],
span: 281..302,
span: 281..302#0,
in_try: false,
},
Unreachable {
......@@ -956,7 +956,7 @@
Call,
),
],
span: 219..306,
span: 219..306#0,
in_try: false,
},
Member {
......@@ -1015,7 +1015,7 @@
Member,
),
],
span: 339..354,
span: 339..354#0,
in_try: false,
},
FreeVar {
......@@ -1073,7 +1073,7 @@
Ident,
),
],
span: 339..346,
span: 339..346#1,
in_try: false,
},
MemberCall {
......@@ -1133,7 +1133,7 @@
Call,
),
],
span: 339..360,
span: 339..360#0,
in_try: false,
},
Unreachable {
......
......@@ -60,7 +60,7 @@
Member,
),
],
span: 39..63,
span: 39..63#0,
in_try: false,
},
Member {
......@@ -113,7 +113,7 @@
Member,
),
],
span: 50..62,
span: 50..62#0,
in_try: false,
},
FreeVar {
......@@ -165,7 +165,7 @@
Ident,
),
],
span: 50..56,
span: 50..56#1,
in_try: false,
},
Member {
......@@ -215,7 +215,7 @@
Member,
),
],
span: 100..116,
span: 100..116#0,
in_try: false,
},
Member {
......@@ -268,7 +268,7 @@
Member,
),
],
span: 103..115,
span: 103..115#0,
in_try: false,
},
FreeVar {
......@@ -320,7 +320,7 @@
Ident,
),
],
span: 103..109,
span: 103..109#1,
in_try: false,
},
Member {
......@@ -364,7 +364,7 @@
Member,
),
],
span: 129..134,
span: 129..134#0,
in_try: false,
},
Member {
......@@ -408,7 +408,7 @@
Member,
),
],
span: 147..152,
span: 147..152#0,
in_try: false,
},
]
......@@ -113,7 +113,7 @@
Ident,
),
],
span: 152..157,
span: 152..157#2,
in_try: false,
},
Call {
......@@ -214,7 +214,7 @@
Call,
),
],
span: 152..159,
span: 152..159#0,
in_try: false,
},
],
......@@ -334,7 +334,7 @@
Call,
),
],
span: 132..167,
span: 132..167#0,
in_try: false,
},
]
......@@ -147,7 +147,7 @@
Test,
),
],
span: 18..34,
span: 18..34#0,
in_try: false,
},
Call {
......@@ -195,7 +195,7 @@
Call,
),
],
span: 11..35,
span: 11..35#0,
in_try: false,
},
Member {
......@@ -272,7 +272,7 @@
Member,
),
],
span: 57..81,
span: 57..81#0,
in_try: false,
},
Member {
......@@ -345,7 +345,7 @@
Member,
),
],
span: 57..68,
span: 57..68#0,
in_try: false,
},
FreeVar {
......@@ -417,7 +417,7 @@
Ident,
),
],
span: 57..64,
span: 57..64#1,
in_try: false,
},
Conditional {
......@@ -599,7 +599,7 @@
Test,
),
],
span: 57..196,
span: 57..196#0,
in_try: false,
},
Call {
......@@ -691,7 +691,7 @@
Call,
),
],
span: 47..198,
span: 47..198#0,
in_try: false,
},
Conditional {
......@@ -758,7 +758,7 @@
Call,
),
],
span: 226..237,
span: 226..237#0,
in_try: false,
},
],
......@@ -843,7 +843,7 @@
Call,
),
],
span: 254..265,
span: 254..265#0,
in_try: false,
},
],
......@@ -889,7 +889,7 @@
Test,
),
],
span: 208..268,
span: 208..268#0,
in_try: false,
},
Conditional {
......@@ -940,7 +940,7 @@
Ident,
),
],
span: 354..355,
span: 354..355#2,
in_try: false,
},
],
......@@ -1009,7 +1009,7 @@
Ident,
),
],
span: 368..369,
span: 368..369#2,
in_try: false,
},
],
......@@ -1055,7 +1055,7 @@
Test,
),
],
span: 340..372,
span: 340..372#0,
in_try: false,
},
Conditional {
......@@ -1229,7 +1229,7 @@
Test,
),
],
span: 399..434,
span: 399..434#0,
in_try: false,
},
Call {
......@@ -1286,7 +1286,7 @@
Call,
),
],
span: 438..449,
span: 438..449#0,
in_try: false,
},
ImportedBinding {
......@@ -1333,7 +1333,7 @@
Ident,
),
],
span: 453..454,
span: 453..454#2,
in_try: false,
},
]
......@@ -30,7 +30,7 @@
Ident,
),
],
span: 166..167,
span: 166..167#1,
in_try: false,
},
]
......@@ -56,7 +56,7 @@
Ident,
),
],
span: 117..122,
span: 117..122#2,
in_try: false,
},
Unreachable {
......@@ -157,7 +157,7 @@
Ident,
),
],
span: 62..67,
span: 62..67#2,
in_try: false,
},
Unreachable {
......
......@@ -34,7 +34,7 @@
Call,
),
],
span: 598..615,
span: 598..615#0,
in_try: false,
},
FreeVar {
......@@ -77,7 +77,7 @@
Ident,
),
],
span: 12..19,
span: 12..19#1,
in_try: false,
},
Call {
......@@ -122,7 +122,7 @@
Call,
),
],
span: 12..27,
span: 12..27#0,
in_try: false,
},
FreeVar {
......@@ -165,7 +165,7 @@
Ident,
),
],
span: 41..48,
span: 41..48#1,
in_try: false,
},
Call {
......@@ -210,7 +210,7 @@
Call,
),
],
span: 41..56,
span: 41..56#0,
in_try: false,
},
Member {
......@@ -265,7 +265,7 @@
Member,
),
],
span: 296..329,
span: 296..329#0,
in_try: false,
},
FreeVar {
......@@ -326,7 +326,7 @@
Ident,
),
],
span: 317..328,
span: 317..328#1,
in_try: false,
},
Unreachable {
......@@ -413,7 +413,7 @@
Call,
),
],
span: 443..476,
span: 443..476#0,
in_try: false,
},
Member {
......@@ -489,7 +489,7 @@
Member,
),
],
span: 515..530,
span: 515..530#0,
in_try: true,
},
FreeVar {
......@@ -564,7 +564,7 @@
Ident,
),
],
span: 515..522,
span: 515..522#1,
in_try: true,
},
MemberCall {
......@@ -659,7 +659,7 @@
Call,
),
],
span: 515..551,
span: 515..551#0,
in_try: true,
},
Unreachable {
......
......@@ -53,7 +53,7 @@
Call,
),
],
span: 72..83,
span: 72..83#0,
in_try: false,
},
Unreachable {
......
......@@ -53,7 +53,7 @@
Call,
),
],
span: 59..70,
span: 59..70#0,
in_try: false,
},
Unreachable {
......
......@@ -46,7 +46,7 @@
Member,
),
],
span: 13..24,
span: 13..24#0,
in_try: false,
},
FreeVar {
......@@ -95,7 +95,7 @@
Ident,
),
],
span: 13..19,
span: 13..19#1,
in_try: false,
},
MemberCall {
......@@ -147,7 +147,7 @@
Call,
),
],
span: 13..39,
span: 13..39#0,
in_try: false,
},
]
......@@ -28,7 +28,7 @@ fn main() -> Result<()> {
stdin().read_line(&mut contents)?;
let sm = Arc::new(SourceMap::default());
let file = sm.new_source_file(FileName::Anon.into(), contents);
let file = sm.new_source_file(FileName::Anon, contents);
let target = EsVersion::latest();
let syntax = Syntax::Typescript(TsSyntax {
tsx: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment