Unverified Commit 0a3fa759 authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

build: Update `swc_core` to `v0.101.3` (#69039)

This reverts commit 4c33361f.


### What?

 - Reverts https://github.com/vercel/next.js/pull/68978
 - Re-apply https://github.com/vercel/next.js/pull/68560

### Why?

The bug of `Evaluator` is fixed.

### How?
parent cc484b99
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.96.9", features = [
swc_core = { version = "0.101.3", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
] }
testing = { version = "0.36.0" }
testing = { version = "0.39.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.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" }
mdxjs = "0.2.7"
modularize_imports = { version = "0.68.22" }
styled_components = { version = "0.96.21" }
styled_jsx = { version = "0.73.30" }
swc_emotion = { version = "0.72.20" }
swc_relay = { version = "0.44.23" }
# General Deps
......@@ -198,7 +198,7 @@ smallvec = { version = "1.13.1", features = [
"union",
"const_new",
] }
sourcemap = "8.0.1"
sourcemap = "9.0.0"
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, code.clone()),
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon.into(), 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()), code.clone())
cm.new_source_file(FileName::Real(filename.clone().into()).into(), code.clone())
}
}
}
......
......@@ -35,7 +35,7 @@ impl Task for ParseTask {
None
};
let fm =
c.cm.new_source_file(self.filename.clone(), self.src.clone());
c.cm.new_source_file(self.filename.clone().into(), 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, src.to_string())
self.c.cm.new_source_file(filename.into(), 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()),
FileName::Real(filename.into()).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.15"
remove_console = "0.25.15"
react_remove_properties = "0.24.18"
remove_console = "0.25.18"
auto-hash-map = { workspace = true }
......
......@@ -5,7 +5,7 @@ use async_recursion::async_recursion;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use swc_core::{
common::{source_map::Pos, Span, Spanned, GLOBALS},
common::{source_map::SmallPos, 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()),
FileName::Real(ctx.file_path_str.into()).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.15"
remove_console = "0.25.15"
react_remove_properties = "0.24.18"
remove_console = "0.25.18"
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, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement},
ast::{
Ident, IdentName, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement,
},
atoms::JsWord,
visit::Fold,
};
......@@ -26,22 +28,16 @@ impl Fold for AmpAttributePatcher {
if sym.starts_with("amp-") {
for i in &mut attrs {
if let JSXAttrOrSpread::JSXAttr(JSXAttr {
name:
JSXAttrName::Ident(Ident {
sym,
span: s,
optional: o,
}),
name: JSXAttrName::Ident(IdentName { sym, span: s }),
span,
value,
}) = &i
{
if sym as &str == "className" {
*i = JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(Ident {
name: JSXAttrName::Ident(IdentName {
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, Lit, MemberExpr, MemberProp, Module,
ModuleItem, Pat, Script, Stmt, VarDecl, VarDeclKind, VarDeclarator,
CallExpr, Callee, Decl, Expr, Id, Ident, IdentName, Lit, MemberExpr, MemberProp,
Module, ModuleItem, Pat, Script, Stmt, VarDecl, VarDeclKind, VarDeclarator,
},
atoms::{Atom, JsWord},
utils::{prepend_stmts, private_ident, ExprFactory, IdentRenamer},
......@@ -114,18 +114,19 @@ impl VisitMut for CjsOptimizer {
span: DUMMY_SP,
callee: Ident::new(
"require".into(),
DUMMY_SP.with_ctxt(self.unresolved_ctxt),
DUMMY_SP,
self.unresolved_ctxt,
)
.as_callee(),
args: vec![Expr::Lit(Lit::Str(
renamed.clone().into(),
))
.as_arg()],
type_args: None,
..Default::default()
})),
prop: MemberProp::Ident(Ident::new(
prop: MemberProp::Ident(IdentName::new(
prop.sym.clone(),
DUMMY_SP.with_ctxt(self.unresolved_ctxt),
DUMMY_SP,
)),
}))),
definite: false,
......@@ -142,8 +143,8 @@ impl VisitMut for CjsOptimizer {
Box::new(VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
decls: vec![var],
..Default::default()
}),
)));
}
......@@ -212,7 +213,7 @@ impl VisitMut for CjsOptimizer {
})) = n.init.as_deref()
{
if let Expr::Ident(ident) = &**callee {
if ident.span.ctxt == self.unresolved_ctxt && ident.sym == *"require" {
if ident.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};
use std::{
path::{Path, PathBuf},
sync::Arc,
};
use pathdiff::diff_paths;
use swc_core::{
......@@ -6,7 +9,7 @@ use swc_core::{
ecma::{
ast::{
op, ArrayLit, ArrowExpr, BinExpr, BlockStmt, BlockStmtOrExpr, Bool, CallExpr, Callee,
Expr, ExprOrSpread, ExprStmt, Id, Ident, ImportDecl, ImportDefaultSpecifier,
Expr, ExprOrSpread, ExprStmt, Id, Ident, IdentName, ImportDecl, ImportDefaultSpecifier,
ImportNamedSpecifier, ImportSpecifier, KeyValueProp, Lit, ModuleDecl, ModuleItem,
ObjectLit, Prop, PropName, PropOrSpread, Stmt, Str, Tpl, UnaryExpr, UnaryOp,
},
......@@ -27,7 +30,7 @@ pub fn next_dynamic(
is_react_server_layer: bool,
prefer_esm: bool,
mode: NextDynamicMode,
filename: FileName,
filename: Arc<FileName>,
pages_or_app_dir: Option<PathBuf>,
) -> impl Fold {
NextDynamicPatcher {
......@@ -81,7 +84,7 @@ struct NextDynamicPatcher {
is_react_server_layer: bool,
prefer_esm: bool,
pages_or_app_dir: Option<PathBuf>,
filename: FileName,
filename: Arc<FileName>,
dynamic_bindings: Vec<Id>,
is_next_dynamic_first_arg: bool,
dynamically_imported_specifier: Option<(String, Span)>,
......@@ -325,7 +328,10 @@ impl Fold for NextDynamicPatcher {
let mut props =
vec![PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
key: PropName::Ident(Ident::new("loadableGenerated".into(), DUMMY_SP)),
key: PropName::Ident(IdentName::new(
"loadableGenerated".into(),
DUMMY_SP,
)),
value: generated,
})))];
......@@ -345,11 +351,7 @@ impl Fold for NextDynamicPatcher {
},
_ => None,
} {
if let Some(Ident {
sym,
span: _,
optional: _,
}) = match key {
if let Some(IdentName { sym, span: _ }) = match key {
PropName::Ident(ident) => Some(ident),
_ => None,
} {
......@@ -399,7 +401,7 @@ impl Fold for NextDynamicPatcher {
raw: None,
}))),
}],
type_args: Default::default(),
..Default::default()
});
let side_effect_free_loader_arg = Expr::Arrow(ArrowExpr {
......@@ -413,11 +415,11 @@ impl Fold for NextDynamicPatcher {
&require_resolve_weak_expr,
)),
})],
..Default::default()
})),
is_async: true,
is_generator: false,
type_params: None,
return_type: None,
..Default::default()
});
expr.args[0] = side_effect_free_loader_arg.as_arg();
......@@ -445,7 +447,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(Ident::new("modules".into(), DUMMY_SP)),
key: PropName::Ident(IdentName::new("modules".into(), DUMMY_SP)),
value: Box::new(Expr::Array(ArrayLit {
elems: vec![Some(ExprOrSpread {
expr: Box::new(module_id),
......@@ -458,7 +460,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(Ident::new("webpack".into(), DUMMY_SP)),
key: PropName::Ident(IdentName::new("webpack".into(), DUMMY_SP)),
value: Box::new(Expr::Arrow(ArrowExpr {
params: vec![],
body: Box::new(BlockStmtOrExpr::Expr(Box::new(Expr::Array(ArrayLit {
......@@ -471,8 +473,7 @@ fn webpack_options(module_id: Expr) -> Vec<PropOrSpread> {
is_async: false,
is_generator: false,
span: DUMMY_SP,
return_type: None,
type_params: None,
..Default::default()
})),
})))]
}
......@@ -506,7 +507,10 @@ impl NextDynamicPatcher {
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: chunks_ident,
imported: Some(Ident::new("chunks".into(), DUMMY_SP).into()),
imported: Some(
Ident::new("chunks".into(), DUMMY_SP, Default::default())
.into(),
),
is_type_only: false,
}),
],
......@@ -530,7 +534,12 @@ impl NextDynamicPatcher {
span: DUMMY_SP,
local: id_ident,
imported: Some(
Ident::new("__turbopack_module_id__".into(), DUMMY_SP).into(),
Ident::new(
"__turbopack_module_id__".into(),
DUMMY_SP,
Default::default(),
)
.into(),
),
is_type_only: false,
})],
......@@ -555,7 +564,12 @@ impl NextDynamicPatcher {
span: DUMMY_SP,
local: id_ident,
imported: Some(
Ident::new("__turbopack_module_id__".into(), DUMMY_SP).into(),
Ident::new(
"__turbopack_module_id__".into(),
DUMMY_SP,
Default::default(),
)
.into(),
),
is_type_only: false,
})],
......@@ -579,7 +593,12 @@ impl NextDynamicPatcher {
span: DUMMY_SP,
local: id_ident,
imported: Some(
Ident::new("__turbopack_module_id__".into(), DUMMY_SP).into(),
Ident::new(
"__turbopack_module_id__".into(),
DUMMY_SP,
Default::default(),
)
.into(),
),
is_type_only: false,
})],
......@@ -612,9 +631,8 @@ 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,
optional: false,
..Default::default()
})),
});
......
......@@ -201,7 +201,7 @@ impl Fold for Analyzer<'_> {
tracing::trace!(
"ssg: Handling `{}{:?}`; in_data_fn = {:?}",
f.ident.sym,
f.ident.span.ctxt,
f.ident.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.span.ctxt
local.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(
Ident::new(
IdentName::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.span.ctxt
name.id.ctxt
);
return Pat::Invalid(Invalid { span: DUMMY_SP });
......
......@@ -241,7 +241,6 @@ 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 {
......@@ -255,6 +254,7 @@ impl Fold for OptimizeBarrel {
})))),
definite: false,
}],
..Default::default()
})),
})));
......@@ -279,7 +279,6 @@ 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 {
......@@ -293,6 +292,7 @@ impl Fold for OptimizeBarrel {
})))),
definite: false,
}],
..Default::default()
})),
})));
}
......
......@@ -170,8 +170,7 @@ impl Fold for OptimizeServerReact {
is_async: false,
is_generator: false,
params: vec![],
return_type: None,
type_params: None,
..Default::default()
})
.into(),
),
......
......@@ -49,8 +49,7 @@ impl Fold for PageConfig {
name: Pat::Ident(BindingIdent {
id: Ident {
sym: STRING_LITERAL_DROP_BUNDLE.into(),
span: DUMMY_SP,
optional: false,
..Default::default()
},
type_ann: None,
}),
......@@ -64,7 +63,7 @@ impl Fold for PageConfig {
}],
span: DUMMY_SP,
kind: VarDeclKind::Const,
declare: false,
..Default::default()
}))))];
}
}
......
......@@ -263,7 +263,7 @@ mod tests {
};
let fm = c.cm.new_source_file(
swc_core::common::FileName::Real(PathBuf::from(file_path.to_string())),
swc_core::common::FileName::Real(PathBuf::from(file_path.to_string())).into(),
contents.to_string(),
);
......
use std::{collections::HashMap, path::PathBuf, rc::Rc};
use std::{collections::HashMap, path::PathBuf, rc::Rc, sync::Arc};
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()],
type_args: Default::default(),
..Default::default()
}))),
definite: false,
}],
declare: false,
..Default::default()
})))),
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"))),
obj: Box::new(Expr::Ident(quote_ident!("module").into())),
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()],
type_args: Default::default(),
..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: FileName,
filename: Arc<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,13 +600,15 @@ 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(Ident::new(data_marker.into(), DUMMY_SP).into()),
name: Pat::Ident(
IdentName::new(data_marker.into(), DUMMY_SP).into(),
),
init: Some(true.into()),
definite: Default::default(),
}],
..Default::default()
})),
})),
);
......@@ -736,7 +738,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping import `{}{:?}` because it should be removed",
local.sym,
local.span.ctxt
local.ctxt
);
self.state.should_run_again = true;
......@@ -925,7 +927,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping var `{}{:?}` because it should be removed",
name.id.sym,
name.id.span.ctxt
name.id.ctxt
);
return Pat::Invalid(Invalid { span: DUMMY_SP });
......@@ -979,7 +981,7 @@ impl Fold for NextSsg {
tracing::trace!(
"Dropping var `{}{:?}` because it should be removed",
name.id.sym,
name.id.span.ctxt
name.id.ctxt
);
return SimpleAssignTarget::Invalid(Invalid { span: DUMMY_SP });
......
......@@ -3,7 +3,7 @@ use std::sync::Arc;
use swc_core::{
common::{errors::HANDLER, SourceMap, Span},
ecma::{
ast::{Expr, Ident, MemberExpr, MemberProp},
ast::{Expr, IdentName, MemberExpr, MemberProp},
utils::{ExprCtx, ExprExt},
visit::{Visit, VisitWith},
},
......@@ -64,7 +64,7 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime",loc.line+1);
true
}
fn warn_for_unsupported_process_api(&self, span: Span, prop: &Ident) {
fn warn_for_unsupported_process_api(&self, span: Span, prop: &IdentName) {
if !self.is_in_middleware_layer() || prop.sym == "env" {
return;
}
......@@ -87,7 +87,7 @@ impl Visit for WarnForEdgeRuntime {
fn visit_expr(&mut self, n: &Expr) {
if let Expr::Ident(ident) = n {
if ident.span.ctxt == self.ctx.unresolved_ctxt {
if ident.ctxt == self.ctx.unresolved_ctxt {
for api in EDGE_UNSUPPORTED_NODE_APIS {
if self.is_in_middleware_layer() && ident.sym == *api {
self.build_unsupported_api_error(ident.span, api);
......
......@@ -57,7 +57,7 @@ fn next_dynamic_errors(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
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")),
FileName::Real(PathBuf::from("/some-project/src/layout.js")).into(),
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")),
FileName::Real(PathBuf::from("/some-project/src/page.js")).into(),
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")),
FileName::Real(PathBuf::from("/app/item.js")).into(),
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")),
FileName::Real(PathBuf::from("/app/item.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: false
},),
......
......@@ -72,7 +72,7 @@ fn next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -89,7 +89,7 @@ fn next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -106,7 +106,7 @@ fn next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -134,7 +134,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -151,7 +151,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -168,7 +168,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -185,7 +185,7 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
false,
false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Some("/some-project/src".into()),
)
},
......@@ -318,7 +318,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")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: true,
}),
......@@ -340,7 +340,7 @@ fn react_server_components_server_graph_fixture(input: PathBuf) {
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: true,
}),
......@@ -362,7 +362,7 @@ fn react_server_components_client_graph_fixture(input: PathBuf) {
syntax(),
&|tr| {
server_components(
FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
FileName::Real(PathBuf::from("/some-project/src/some-file.js")).into(),
Config::WithOptions(Options {
is_react_server_layer: false,
}),
......
......@@ -4,5 +4,5 @@ import r from 'other';
e(r, 1)[0];
export var __N_SSG = !0;
export default function t() {
return React.createElement("div", null);
return /*#__PURE__*/ React.createElement("div", null);
}
......@@ -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()),
FileName::Real("fixture.js".into()).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, s.into());
let fm = c.cm.new_source_file(FileName::Anon.into(), 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
FileName::Anon.into()
} else {
FileName::Real(opts.swc.filename.clone().into())
FileName::Real(opts.swc.filename.clone().into()).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, s.into());
let fm = c.cm.new_source_file(FileName::Anon.into(), 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), source);
sm.new_source_file(FileName::Custom(filename).into(), 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()), code.clone());
let fm = cm.new_source_file(FileName::Custom(filename.to_string()).into(), code.clone());
let mut errors = vec![];
let ss = swc_core::css::parser::parse_file(
......@@ -1144,7 +1144,10 @@ 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()), code.to_string());
let fm = cm.new_source_file(
FileName::Custom("test.css".to_string()).into(),
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)),
FileName::Real(PathBuf::from(ctx.file_path_str)).into(),
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::Pos, Span},
common::{source_map::SmallPos, Span},
ecma::{
ast::*,
atoms::{js_word, JsWord},
......
......@@ -3667,7 +3667,7 @@ impl WellKnownFunctionKind {
}
fn is_unresolved(i: &Ident, unresolved_mark: Mark) -> bool {
i.span.ctxt.outer() == unresolved_mark
i.ctxt.outer() == unresolved_mark
}
fn is_unresolved_id(i: &Id, unresolved_mark: Mark) -> bool {
......
......@@ -47,7 +47,7 @@ use swc_core::{
common::GLOBALS,
ecma::{
codegen::{text_writer::JsWriter, Emitter},
visit::{VisitMutWith, VisitMutWithPath},
visit::{VisitMutWith, VisitMutWithAstPath},
},
};
pub use transform::{
......@@ -831,7 +831,7 @@ async fn gen_content_with_visitors(
GLOBALS.set(globals, || {
if !visitors.is_empty() {
program.visit_mut_with_path(
program.visit_mut_with_ast_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()),
FileName::Custom(path.path.to_string()).into(),
code.source_code().to_str()?.to_string(),
);
......
use std::{borrow::Cow, future::Future, sync::Arc};
use std::{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(Cow::into_owned)
map.as_regular_source_map()
} else {
None
};
let map = self.files_map.build_source_map_with_config(
&self.mappings,
input_map,
input_map.as_deref(),
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(), string);
let fm = source_map.new_source_file(file_name.clone().into(), 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, || f.poll(cx)))
HANDLER.set(&handler, || HELPERS.set(&Helpers::new(true), || f.poll(cx)))
})
},
)
......
......@@ -4,7 +4,7 @@ use swc_core::{
common::pass::AstKindPath,
ecma::{
ast::*,
visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithPath},
visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithAstPath},
},
};
......@@ -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> VisitMutWithPath<ApplyVisitors<'aa, 'bb>>,
+ for<'aa, 'bb> VisitMutWithAstPath<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_path(
n.visit_mut_children_with_ast_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_path(self, ast_path);
n.visit_mut_children_with_ast_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, VisitMutWithPath},
visit::{fields::*, AstParentKind, VisitMut, VisitMutWith, VisitMutWithAstPath},
},
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, "('foo', 'bar', ['baz']);".into());
let fm = cm.new_source_file(FileName::Anon.into(), "('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_path(
m.visit_mut_with_ast_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_path(
m.visit_mut_with_ast_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,
type_args: None,
..Default::default()
});
*callee = Callee::Expr(quote_expr!(
"($f1, r = typeof $f2 !== \"function\" ? $f3 : $call_f) => r !== undefined && \
......@@ -268,8 +268,7 @@ fn transform_amd_factory(
expr: Box::new(Expr::Call(CallExpr {
args: deps,
callee: Callee::Expr(factory),
span: DUMMY_SP,
type_args: None,
..Default::default()
})),
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))
.map(|ident| Ident::new(ident.clone().into(), DUMMY_SP, Default::default()))
.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));
*expr = Expr::Ident(Ident::new("__turbopack_cache__".into(), DUMMY_SP, Default::default()));
} 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),
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
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),
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
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),
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
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),
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
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, SyntaxContext},
common::Span,
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()),
key: PropName::Ident(ident.clone().into()),
value: Box::new(make_expr(imported_ident, item.export.as_deref(), ident.span, false))
});
}
......@@ -167,11 +167,14 @@ 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))),
obj: Box::new(Expr::Ident(Ident::new(
imported_module.into(),
span,
Default::default(),
))),
prop: MemberProp::Computed(ComputedPropName {
span,
expr: Box::new(Expr::Lit(Lit::Str(Str {
......@@ -196,6 +199,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))
Expr::Ident(Ident::new(imported_module.into(), span, Default::default()))
}
}
......@@ -149,7 +149,7 @@ impl CodeGenerateable for EsmAsyncAssetReference {
expr: error,
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
});
});
......
......@@ -429,7 +429,7 @@ impl CodeGenerateable for EsmExports {
dynamic_exports.push(quote_expr!(
"__turbopack_dynamic__($arg)",
arg: Expr = Ident::new(ident.into(), DUMMY_SP).into()
arg: Expr = Ident::new(ident.into(), DUMMY_SP, Default::default()).into()
));
}
......@@ -443,13 +443,17 @@ impl CodeGenerateable for EsmExports {
if *mutable {
Some(quote!(
"([() => $local, ($new) => $local = $new])" as Expr,
local = Ident::new((name as &str).into(), DUMMY_SP),
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP),
local = Ident::new((name as &str).into(), DUMMY_SP, Default::default()),
new = Ident::new(
format!("{name}_new_value").into(),
DUMMY_SP,
Default::default()
),
))
} else {
Some(quote!(
"(() => $local)" as Expr,
local = Ident::new((name as &str).into(), DUMMY_SP)
local = Ident::new((name as &str).into(), DUMMY_SP, Default::default())
))
}
}
......@@ -459,7 +463,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))),
obj: Box::new(Expr::Ident(Ident::new(ident.into(), DUMMY_SP, Default::default()))),
prop: MemberProp::Computed(ComputedPropName {
span: DUMMY_SP,
expr: Box::new(Expr::Lit(Lit::Str(Str {
......@@ -473,7 +477,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),
new = Ident::new(format!("{name}_new_value").into(), DUMMY_SP, Default::default()),
)
} else {
quote!(
......@@ -489,7 +493,7 @@ impl CodeGenerateable for EsmExports {
referenced_asset.get_ident().await?.map(|ident| {
quote!(
"(() => $imported)" as Expr,
imported = Ident::new(ident.into(), DUMMY_SP)
imported = Ident::new(ident.into(), DUMMY_SP, Default::default())
)
})
}
......
......@@ -146,7 +146,11 @@ fn encode_path(path: &'_ str) -> Cow<'_, str> {
}
fn meta_ident() -> Ident {
Ident::new(magic_identifier::mangle("import.meta").into(), DUMMY_SP)
Ident::new(
magic_identifier::mangle("import.meta").into(),
DUMMY_SP,
Default::default(),
)
}
#[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),
name = Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP, Default::default()),
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)),
ident: class.ident.unwrap_or_else(|| Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP, Default::default())),
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)),
ident: fn_expr.ident.unwrap_or_else(|| Ident::new(magic_identifier::mangle("default export").into(), DUMMY_SP, Default::default())),
declare: false,
function: fn_expr.function
})))
......
......@@ -40,14 +40,14 @@ use swc_core::{
comments::{CommentKind, Comments},
errors::{DiagnosticId, Handler, HANDLER},
pass::AstNodePath,
source_map::Pos,
source_map::SmallPos,
Globals, Span, Spanned, GLOBALS,
},
ecma::{
ast::*,
visit::{
fields::{AssignExprField, AssignTargetField, SimpleAssignTargetField},
AstParentKind, AstParentNodeRef, VisitAstPath, VisitWithPath,
AstParentKind, AstParentNodeRef, VisitAstPath, VisitWithAstPath,
},
},
};
......@@ -697,7 +697,7 @@ pub(crate) async fn analyse_ecmascript_module_internal(
}
}
program.visit_with_path(&mut visitor, &mut Default::default());
program.visit_with_ast_path(&mut visitor, &mut Default::default());
(
visitor.webpack_runtime,
......@@ -2705,7 +2705,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_path(self, ast_path);
export.visit_children_with_ast_path(self, ast_path);
}
fn visit_named_export<'ast: 'r, 'r>(
......@@ -2770,7 +2770,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
self.analysis.add_code_gen(EsmModuleItem::new(path));
export.visit_children_with_path(self, ast_path);
export.visit_children_with_ast_path(self, ast_path);
}
fn visit_export_decl<'ast: 'r, 'r>(
......@@ -2784,7 +2784,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_path(self, ast_path);
export.visit_children_with_ast_path(self, ast_path);
}
fn visit_export_default_expr<'ast: 'r, 'r>(
......@@ -2798,7 +2798,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_path(self, ast_path);
export.visit_children_with_ast_path(self, ast_path);
}
fn visit_export_default_decl<'ast: 'r, 'r>(
......@@ -2825,7 +2825,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_path(self, ast_path);
export.visit_children_with_ast_path(self, ast_path);
}
fn visit_import_decl<'ast: 'r, 'r>(
......@@ -2835,7 +2835,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_path(self, ast_path);
import.visit_children_with_ast_path(self, ast_path);
if import.type_only {
return;
}
......@@ -2898,7 +2898,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
}
}
decl.visit_children_with_path(self, ast_path);
decl.visit_children_with_ast_path(self, ast_path);
}
fn visit_call_expr<'ast: 'r, 'r>(
......@@ -2937,7 +2937,7 @@ impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> {
}
}
}
call.visit_children_with_path(self, ast_path);
call.visit_children_with_ast_path(self, ast_path);
}
}
......
......@@ -112,7 +112,7 @@ impl SinglePatternMapping {
expr: Box::new(self.create_id(key_expr)),
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
}),
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,
type_args: None,
..Default::default()
}),
Self::External(request, ty) => throw_module_not_found_error_expr(
request,
......@@ -144,7 +144,7 @@ impl SinglePatternMapping {
expr: error,
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
})
}
Self::Unresolveable(_) => self.create_id(key_expr),
......@@ -157,7 +157,7 @@ impl SinglePatternMapping {
expr: Box::new(key_expr.into_owned()),
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
})
} else {
Expr::Call(CallExpr {
......@@ -170,7 +170,7 @@ impl SinglePatternMapping {
),
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
})
}
}
......@@ -184,7 +184,7 @@ impl SinglePatternMapping {
),
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
}),
#[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,
type_args: None,
..Default::default()
}),
Self::Ignored => {
quote!("Promise.resolve({})" as Expr)
......@@ -219,7 +219,7 @@ impl SinglePatternMapping {
),
}],
span: DUMMY_SP,
type_args: None,
..Default::default()
}),
}
}
......
......@@ -65,6 +65,7 @@ impl CodeGenerateable for Unreachable {
*stmt = Stmt::Block(BlockStmt {
span: stmt.span(),
stmts: replacement,
..Default::default()
});
}),
]
......@@ -139,6 +140,7 @@ impl<'a> VisitMut for ExtractDeclarations<'a> {
kind,
declare,
decls,
ctxt,
} = decl;
if self.in_nested_block_scope && !matches!(kind, VarDeclKind::Var) {
return;
......@@ -167,6 +169,7 @@ impl<'a> VisitMut for ExtractDeclarations<'a> {
span: *span,
kind: *kind,
declare: *declare,
ctxt: *ctxt,
decls,
}))));
}
......@@ -219,6 +222,7 @@ 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, VisitMutWithPath},
visit::{VisitMutWith, VisitMutWithAstPath},
},
};
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_path(
program.visit_mut_with_ast_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),
name = Ident::new(ident.clone().into(), DUMMY_SP, Default::default()),
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));
program.visit_mut_with(&mut typescript(config, unresolved_mark, top_level_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, 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, IdentName, 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,7 +318,11 @@ impl DepGraph {
let s = ExportSpecifier::Named(ExportNamedSpecifier {
span: DUMMY_SP,
orig: ModuleExportName::Ident(Ident::new(export.clone(), DUMMY_SP)),
orig: ModuleExportName::Ident(Ident::new(
export.clone(),
DUMMY_SP,
Default::default(),
)),
exported: None,
is_type_only: false,
});
......@@ -566,7 +570,7 @@ impl DepGraph {
Some(s.orig.clone()),
match &s.orig {
ModuleExportName::Ident(i) => i.clone(),
ModuleExportName::Str(..) => quote_ident!("_tmp"),
ModuleExportName::Str(..) => quote_ident!("_tmp").into(),
},
Some(s.exported.clone().unwrap_or_else(|| s.orig.clone())),
),
......@@ -574,15 +578,16 @@ impl DepGraph {
Some(ModuleExportName::Ident(Ident::new(
"default".into(),
DUMMY_SP,
Default::default(),
))),
quote_ident!("default"),
quote_ident!("default").into(),
Some(ModuleExportName::Ident(s.exported.clone())),
),
ExportSpecifier::Namespace(s) => (
None,
match &s.name {
ModuleExportName::Ident(i) => i.clone(),
ModuleExportName::Str(..) => quote_ident!("_tmp"),
ModuleExportName::Str(..) => quote_ident!("_tmp").into(),
},
Some(s.name.clone()),
),
......@@ -702,7 +707,7 @@ impl DepGraph {
exports.push((
default_var.to_id(),
Some(ModuleExportName::Ident(quote_ident!("default"))),
Some(ModuleExportName::Ident(quote_ident!("default").into())),
));
}
ModuleDecl::ExportDefaultExpr(export) => {
......@@ -739,13 +744,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()
......@@ -764,7 +769,7 @@ impl DepGraph {
exports.push((
default_var.to_id(),
Some(ModuleExportName::Ident(quote_ident!("default"))),
Some(ModuleExportName::Ident(quote_ident!("default").into())),
));
}
}
......@@ -1155,7 +1160,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(Ident::new(ASSERT_CHUNK_KEY.into(), DUMMY_SP)),
key: PropName::Ident(IdentName::new(ASSERT_CHUNK_KEY.into(), DUMMY_SP)),
value: match dep {
PartId::ModuleEvaluation => "module evaluation".into(),
PartId::Exports => "exports".into(),
......
......@@ -597,6 +597,7 @@ 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,
......@@ -677,6 +678,7 @@ 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.span.ctxt == self.unresolved {
if n.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.span.ctxt != self.unresolved
&& n.span.ctxt != self.top_level
&& n.span.ctxt != SyntaxContext::empty()
if n.ctxt != self.unresolved
&& n.ctxt != self.top_level
&& n.ctxt != SyntaxContext::empty()
&& !self.top_level_vars.contains(&n.to_id())
{
return;
......
......@@ -54,7 +54,7 @@
Ident,
),
],
span: 54..61#1,
span: 54..61,
in_try: false,
},
Call {
......@@ -113,7 +113,7 @@
Call,
),
],
span: 54..64#0,
span: 54..64,
in_try: false,
},
]
......@@ -63,7 +63,7 @@
Member,
),
],
span: 53..87#0,
span: 53..87,
in_try: false,
},
MemberCall {
......@@ -235,7 +235,7 @@
Call,
),
],
span: 53..123#0,
span: 53..123,
in_try: false,
},
Member {
......@@ -302,7 +302,7 @@
Member,
),
],
span: 135..169#0,
span: 135..169,
in_try: false,
},
MemberCall {
......@@ -474,7 +474,7 @@
Call,
),
],
span: 135..207#0,
span: 135..207,
in_try: false,
},
Member {
......@@ -541,7 +541,7 @@
Member,
),
],
span: 219..253#0,
span: 219..253,
in_try: false,
},
MemberCall {
......@@ -660,7 +660,7 @@
Member,
),
],
span: 281..296#0,
span: 281..296,
in_try: false,
},
FreeVar {
......@@ -740,7 +740,7 @@
Ident,
),
],
span: 281..288#1,
span: 281..288,
in_try: false,
},
MemberCall {
......@@ -822,7 +822,7 @@
Call,
),
],
span: 281..302#0,
span: 281..302,
in_try: false,
},
Unreachable {
......@@ -956,7 +956,7 @@
Call,
),
],
span: 219..306#0,
span: 219..306,
in_try: false,
},
Member {
......@@ -1015,7 +1015,7 @@
Member,
),
],
span: 339..354#0,
span: 339..354,
in_try: false,
},
FreeVar {
......@@ -1073,7 +1073,7 @@
Ident,
),
],
span: 339..346#1,
span: 339..346,
in_try: false,
},
MemberCall {
......@@ -1133,7 +1133,7 @@
Call,
),
],
span: 339..360#0,
span: 339..360,
in_try: false,
},
Unreachable {
......
......@@ -60,7 +60,7 @@
Member,
),
],
span: 39..63#0,
span: 39..63,
in_try: false,
},
Member {
......@@ -113,7 +113,7 @@
Member,
),
],
span: 50..62#0,
span: 50..62,
in_try: false,
},
FreeVar {
......@@ -165,7 +165,7 @@
Ident,
),
],
span: 50..56#1,
span: 50..56,
in_try: false,
},
Member {
......@@ -215,7 +215,7 @@
Member,
),
],
span: 100..116#0,
span: 100..116,
in_try: false,
},
Member {
......@@ -268,7 +268,7 @@
Member,
),
],
span: 103..115#0,
span: 103..115,
in_try: false,
},
FreeVar {
......@@ -320,7 +320,7 @@
Ident,
),
],
span: 103..109#1,
span: 103..109,
in_try: false,
},
Member {
......@@ -364,7 +364,7 @@
Member,
),
],
span: 129..134#0,
span: 129..134,
in_try: false,
},
Member {
......@@ -408,7 +408,7 @@
Member,
),
],
span: 147..152#0,
span: 147..152,
in_try: false,
},
]
......@@ -113,7 +113,7 @@
Ident,
),
],
span: 152..157#2,
span: 152..157,
in_try: false,
},
Call {
......@@ -214,7 +214,7 @@
Call,
),
],
span: 152..159#0,
span: 152..159,
in_try: false,
},
],
......@@ -334,7 +334,7 @@
Call,
),
],
span: 132..167#0,
span: 132..167,
in_try: false,
},
]
......@@ -147,7 +147,7 @@
Test,
),
],
span: 18..34#0,
span: 18..34,
in_try: false,
},
Call {
......@@ -195,7 +195,7 @@
Call,
),
],
span: 11..35#0,
span: 11..35,
in_try: false,
},
Member {
......@@ -272,7 +272,7 @@
Member,
),
],
span: 57..81#0,
span: 57..81,
in_try: false,
},
Member {
......@@ -345,7 +345,7 @@
Member,
),
],
span: 57..68#0,
span: 57..68,
in_try: false,
},
FreeVar {
......@@ -417,7 +417,7 @@
Ident,
),
],
span: 57..64#1,
span: 57..64,
in_try: false,
},
Conditional {
......@@ -599,7 +599,7 @@
Test,
),
],
span: 57..196#0,
span: 57..196,
in_try: false,
},
Call {
......@@ -691,7 +691,7 @@
Call,
),
],
span: 47..198#0,
span: 47..198,
in_try: false,
},
Conditional {
......@@ -758,7 +758,7 @@
Call,
),
],
span: 226..237#0,
span: 226..237,
in_try: false,
},
],
......@@ -843,7 +843,7 @@
Call,
),
],
span: 254..265#0,
span: 254..265,
in_try: false,
},
],
......@@ -889,7 +889,7 @@
Test,
),
],
span: 208..268#0,
span: 208..268,
in_try: false,
},
Conditional {
......@@ -940,7 +940,7 @@
Ident,
),
],
span: 354..355#2,
span: 354..355,
in_try: false,
},
],
......@@ -1009,7 +1009,7 @@
Ident,
),
],
span: 368..369#2,
span: 368..369,
in_try: false,
},
],
......@@ -1055,7 +1055,7 @@
Test,
),
],
span: 340..372#0,
span: 340..372,
in_try: false,
},
Conditional {
......@@ -1229,7 +1229,7 @@
Test,
),
],
span: 399..434#0,
span: 399..434,
in_try: false,
},
Call {
......@@ -1286,7 +1286,7 @@
Call,
),
],
span: 438..449#0,
span: 438..449,
in_try: false,
},
ImportedBinding {
......@@ -1333,7 +1333,7 @@
Ident,
),
],
span: 453..454#2,
span: 453..454,
in_try: false,
},
]
......@@ -30,7 +30,7 @@
Ident,
),
],
span: 166..167#1,
span: 166..167,
in_try: false,
},
]
......@@ -56,7 +56,7 @@
Ident,
),
],
span: 117..122#2,
span: 117..122,
in_try: false,
},
Unreachable {
......@@ -157,7 +157,7 @@
Ident,
),
],
span: 62..67#2,
span: 62..67,
in_try: false,
},
Unreachable {
......
......@@ -53,7 +53,7 @@
Call,
),
],
span: 72..83#0,
span: 72..83,
in_try: false,
},
Unreachable {
......
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