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