Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
380 changes: 186 additions & 194 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,25 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" }
turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" }

# SWC crates
swc_core = { version = "45.0.1", features = [
swc_core = { version = "48.0.1", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
"parallel_rayon",
] }
swc_plugin_backend_wasmer = { version = "3.0.0" }
testing = "16.0.0"
swc_plugin_backend_wasmer = { version = "5.0.0" }
testing = "18.0.0"

# Keep consistent with preset_env_base through swc_core
browserslist-rs = "0.19.0"
mdxjs = "1.0.3"
modularize_imports = "0.99.0"
styled_components = "0.127.0"
styled_jsx = "0.103.0"
swc_emotion = "0.103.0"
swc_relay = "0.73.0"
react_remove_properties = "0.53.0"
remove_console = "0.54.0"
preset_env_base = "5.0.0"
modularize_imports = "0.102.0"
styled_components = "0.130.0"
styled_jsx = "0.105.1"
swc_emotion = "0.106.0"
swc_relay = "0.76.0"
react_remove_properties = "0.56.0"
remove_console = "0.57.0"
preset_env_base = "6.0.0"


# General Deps
Expand Down
6 changes: 3 additions & 3 deletions crates/napi/src/rspack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl Visit for Finder {

fn visit_export_named_specifier(&mut self, node: &swc_core::ecma::ast::ExportNamedSpecifier) {
let named_export = if let Some(exported) = &node.exported {
exported.atom().clone()
exported.atom().into_owned()
} else {
node.orig.atom().clone()
node.orig.atom().into_owned()
};
self.named_exports.push(named_export);
}
Expand All @@ -60,7 +60,7 @@ impl Visit for Finder {
&mut self,
node: &swc_core::ecma::ast::ExportNamespaceSpecifier,
) {
self.named_exports.push(node.name.atom().clone());
self.named_exports.push(node.name.atom().into_owned());
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ fn all_export_names(program: &Program) -> Vec<Atom> {
.as_ref()
.unwrap_or(&named.orig)
.atom()
.clone(),
.into_owned(),
);
}
ExportSpecifier::Default(_) => {
exports.push(atom!("default"));
}
ExportSpecifier::Namespace(e) => {
exports.push(e.name.atom().clone());
exports.push(e.name.atom().into_owned());
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/next-core/src/next_shared/transforms/next_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::fonts::*;
use swc_core::{
atoms::atom,
ecma::{ast::Program, atoms::Atom, visit::VisitMutWith},
atoms::{Wtf8Atom, atom},
ecma::{ast::Program, visit::VisitMutWith},
};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
Expand All @@ -14,10 +14,10 @@ use super::module_rule_match_js_no_url;
/// Returns a rule which applies the Next.js font transform.
pub fn get_next_font_transform_rule(enable_mdx_rs: bool) -> ModuleRule {
let font_loaders = vec![
atom!("next/font/google"),
atom!("@next/font/google"),
atom!("next/font/local"),
atom!("@next/font/local"),
atom!("next/font/google").into(),
atom!("@next/font/google").into(),
atom!("next/font/local").into(),
atom!("@next/font/local").into(),
];

let transformer =
Expand All @@ -37,7 +37,7 @@ pub fn get_next_font_transform_rule(enable_mdx_rs: bool) -> ModuleRule {

#[derive(Debug)]
struct NextJsFont {
font_loaders: Vec<Atom>,
font_loaders: Vec<Wtf8Atom>,
}

#[async_trait]
Expand Down
16 changes: 9 additions & 7 deletions crates/next-core/src/segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ pub async fn parse_segment_config_from_source(
ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(decl)) => match &decl.decl {
Decl::Class(decl) => {
parse(
&decl.ident.sym,
Cow::Borrowed(decl.ident.sym.as_str()),
Some(Cow::Owned(Expr::Class(ClassExpr {
ident: None,
class: decl.class.clone(),
Expand All @@ -428,7 +428,7 @@ pub async fn parse_segment_config_from_source(
}
Decl::Fn(decl) => {
parse(
&decl.ident.sym,
Cow::Borrowed(decl.ident.sym.as_str()),
Some(Cow::Owned(Expr::Fn(FnExpr {
ident: None,
function: decl.function.clone(),
Expand All @@ -446,7 +446,7 @@ pub async fn parse_segment_config_from_source(
let key = &ident.id.sym;

parse(
key,
Cow::Borrowed(key.as_str()),
Some(
decl.init.as_deref().map(Cow::Borrowed).unwrap_or_else(
|| Cow::Owned(*Expr::undefined(DUMMY_SP)),
Expand All @@ -470,8 +470,10 @@ pub async fn parse_segment_config_from_source(
if let ExportSpecifier::Named(named) = specifier {
parse(
match named.exported.as_ref().unwrap_or(&named.orig) {
ModuleExportName::Ident(ident) => &ident.sym,
ModuleExportName::Str(s) => &*s.value,
ModuleExportName::Ident(ident) => {
Cow::Borrowed(ident.sym.as_str())
}
ModuleExportName::Str(s) => s.value.to_string_lossy(),
},
None,
specifier.span(),
Expand Down Expand Up @@ -560,7 +562,7 @@ async fn parse_config_value(
mode: ParseSegmentMode,
config: &mut NextSegmentConfig,
eval_context: &EvalContext,
key: &str,
key: Cow<'_, str>,
init: Option<Cow<'_, Expr>>,
span: Span,
) -> Result<()> {
Expand All @@ -586,7 +588,7 @@ async fn parse_config_value(
})
};

match key {
match &*key {
"config" => {
let Some(value) = get_value() else {
return invalid_config(
Expand Down
8 changes: 4 additions & 4 deletions crates/next-custom-transforms/src/transforms/cjs_optimizer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_hash::{FxHashMap, FxHashSet};
use serde::Deserialize;
use swc_core::{
atoms::atom,
atoms::{atom, Wtf8Atom},
common::{util::take::Take, SyntaxContext, DUMMY_SP},
ecma::{
ast::{
Expand Down Expand Up @@ -47,7 +47,7 @@ struct State {
imports: FxHashMap<Id, ImportRecord>,

/// `(module_specifier, property): (identifier)`
replaced: FxHashMap<(Atom, Atom), Id>,
replaced: FxHashMap<(Wtf8Atom, Atom), Id>,

extra_stmts: Vec<Stmt>,

Expand All @@ -61,11 +61,11 @@ struct State {

#[derive(Debug)]
struct ImportRecord {
module_specifier: Atom,
module_specifier: Wtf8Atom,
}

impl CjsOptimizer {
fn should_rewrite(&self, module_specifier: &Atom) -> Option<&FxHashMap<Atom, Atom>> {
fn should_rewrite(&self, module_specifier: &Wtf8Atom) -> Option<&FxHashMap<Atom, Atom>> {
self.packages.get(module_specifier).map(|v| &v.transforms)
}
}
Expand Down
13 changes: 8 additions & 5 deletions crates/next-custom-transforms/src/transforms/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use pathdiff::diff_paths;
use swc_core::{
atoms::{atom, Atom},
atoms::{atom, Atom, Wtf8Atom},
common::{errors::HANDLER, FileName, Span, DUMMY_SP},
ecma::{
ast::{
Expand Down Expand Up @@ -91,7 +91,7 @@ struct NextDynamicPatcher {
filename: Arc<FileName>,
dynamic_bindings: Vec<Id>,
is_next_dynamic_first_arg: bool,
dynamically_imported_specifier: Option<(Atom, Span)>,
dynamically_imported_specifier: Option<(Wtf8Atom, Span)>,
state: NextDynamicPatcherState,
}

Expand All @@ -111,7 +111,10 @@ enum NextDynamicPatcherState {
#[derive(Debug, Clone, Eq, PartialEq)]
enum TurbopackImport {
// TODO do we need more variants? server vs client vs dev vs prod?
Import { id_ident: Ident, specifier: Atom },
Import {
id_ident: Ident,
specifier: Wtf8Atom,
},
}

impl Fold for NextDynamicPatcher {
Expand Down Expand Up @@ -149,7 +152,7 @@ impl Fold for NextDynamicPatcher {
}
Expr::Tpl(Tpl { exprs, quasis, .. }) if exprs.is_empty() => {
self.dynamically_imported_specifier =
Some((quasis[0].raw.clone(), quasis[0].span));
Some((quasis[0].raw.clone().into(), quasis[0].span));
}
_ => {}
}
Expand Down Expand Up @@ -541,7 +544,7 @@ impl NextDynamicPatcher {
fn exec_expr_when_resolve_weak_available(expr: &Expr) -> Expr {
let undefined_str_literal = Expr::Lit(Lit::Str(Str {
span: DUMMY_SP,
value: atom!("undefined"),
value: atom!("undefined").into(),
raw: None,
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use swc_core::{
atoms::Wtf8Atom,
common::errors::HANDLER,
ecma::{
ast::*,
atoms::Atom,
visit::{noop_visit_type, Visit},
},
};

pub struct FontFunctionsCollector<'a> {
pub font_loaders: &'a [Atom],
pub font_loaders: &'a [Wtf8Atom],
pub state: &'a mut super::State,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde_json::Value;
use swc_core::{
atoms::Wtf8Atom,
common::{errors::HANDLER, Spanned, DUMMY_SP},
ecma::{
ast::*,
atoms::Atom,
visit::{noop_visit_type, Visit},
},
};
Expand Down Expand Up @@ -66,9 +66,10 @@ impl FontImportsGenerator<'_> {

return Some(ImportDecl {
src: Box::new(Str {
value: Atom::from(format!(
value: Wtf8Atom::from(format!(
"{}/target.css?{}",
font_function.loader, query_json
font_function.loader.to_string_lossy(),
query_json
)),
raw: None,
span: DUMMY_SP,
Expand Down Expand Up @@ -223,7 +224,7 @@ fn object_lit_to_json(object_lit: &ObjectLit) -> Value {

fn expr_to_json(expr: &Expr) -> Result<Value, ()> {
match expr {
Expr::Lit(Lit::Str(str)) => Ok(Value::String(String::from(&*str.value))),
Expr::Lit(Lit::Str(str)) => Ok(Value::String(str.value.to_string_lossy().into_owned())),
Expr::Lit(Lit::Bool(Bool { value, .. })) => Ok(Value::Bool(*value)),
Expr::Lit(Lit::Num(Number { value, .. })) => {
Ok(Value::Number(serde_json::Number::from_f64(*value).unwrap()))
Expand Down
5 changes: 3 additions & 2 deletions crates/next-custom-transforms/src/transforms/fonts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc_hash::{FxHashMap, FxHashSet};
use serde::Deserialize;
use swc_core::{
atoms::Wtf8Atom,
common::{BytePos, Spanned},
ecma::{
ast::{Id, ModuleItem, Pass},
Expand All @@ -16,7 +17,7 @@ mod font_imports_generator;
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct Config {
pub font_loaders: Vec<Atom>,
pub font_loaders: Vec<Wtf8Atom>,
pub relative_file_path_from_root: Atom,
}

Expand All @@ -31,7 +32,7 @@ pub fn next_font_loaders(config: Config) -> impl Pass + VisitMut {

#[derive(Debug)]
pub struct FontFunction {
loader: Atom,
loader: Wtf8Atom,
function_name: Option<Atom>,
}
#[derive(Debug, Default)]
Expand Down
21 changes: 7 additions & 14 deletions crates/next-custom-transforms/src/transforms/import_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{
atoms::{atom, Atom},
atoms::{atom, Atom, Wtf8Atom},
ecma::{
ast::{
Expr, Id, ImportDecl, ImportNamedSpecifier, ImportSpecifier, MemberExpr, MemberProp,
Module, ModuleExportName,
Module,
},
visit::{noop_visit_type, Visit, VisitWith},
},
Expand All @@ -13,16 +13,16 @@ use swc_core::{
#[derive(Debug, Default)]
pub(crate) struct ImportMap {
/// Map from module name to (module path, exported symbol)
imports: FxHashMap<Id, (Atom, Atom)>,
imports: FxHashMap<Id, (Wtf8Atom, Atom)>,

namespace_imports: FxHashMap<Id, Atom>,
namespace_imports: FxHashMap<Id, Wtf8Atom>,

imported_modules: FxHashSet<Atom>,
imported_modules: FxHashSet<Wtf8Atom>,
}

#[allow(unused)]
impl ImportMap {
pub fn is_module_imported(&mut self, module: &Atom) -> bool {
pub fn is_module_imported(&mut self, module: &Wtf8Atom) -> bool {
self.imported_modules.contains(module)
}

Expand Down Expand Up @@ -77,7 +77,7 @@ impl Visit for Analyzer<'_> {
ImportSpecifier::Named(ImportNamedSpecifier {
local, imported, ..
}) => match imported {
Some(imported) => (local.to_id(), orig_name(imported)),
Some(imported) => (local.to_id(), imported.atom().into_owned()),
_ => (local.to_id(), local.sym.clone()),
},
ImportSpecifier::Default(s) => (s.local.to_id(), atom!("default")),
Expand All @@ -95,10 +95,3 @@ impl Visit for Analyzer<'_> {
}
}
}

fn orig_name(n: &ModuleExportName) -> Atom {
match n {
ModuleExportName::Ident(v) => v.sym.clone(),
ModuleExportName::Str(v) => v.value.clone(),
}
}
Loading
Loading