Skip to content
Closed
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
1,122 changes: 543 additions & 579 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 10 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ opt-level = "s"
[profile.release.package.swc_ecma_transforms_typescript]
opt-level = 3

[profile.release.package.swc_css_prefixer]
opt-level = "s"

[profile.release.package.zstd-sys]
opt-level = 3

Expand Down Expand Up @@ -337,24 +334,24 @@ 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 = "46.0.2", 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 = "4.0.0" }
testing = "17.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"
modularize_imports = "0.100.0"
styled_components = "0.128.0"
styled_jsx = "0.104.0"
swc_emotion = "0.104.0"
swc_relay = "0.74.0"
react_remove_properties = "0.54.0"
remove_console = "0.55.0"
preset_env_base = "5.0.0"


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 @@ -48,9 +48,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 @@ -59,7 +59,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
24 changes: 13 additions & 11 deletions crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use swc_core::{
common::comments::Comments,
ecma::{
ast::{
Decl, ExportSpecifier, Id, ModuleDecl, ModuleItem, ObjectLit, Program,
PropOrSpread::Prop,
Decl, ExportSpecifier, Id, ModuleDecl, ModuleExportName, ModuleItem, ObjectLit,
Program, PropOrSpread::Prop,
},
utils::find_pat_ids,
},
Expand Down Expand Up @@ -366,20 +366,15 @@ fn all_export_names(program: &Program) -> Vec<Atom> {
for s in decl.specifiers.iter() {
match s {
ExportSpecifier::Named(named) => {
exports.push(
named
.exported
.as_ref()
.unwrap_or(&named.orig)
.atom()
.clone(),
);
exports.push(module_export_name_to_atom(
named.exported.as_ref().unwrap_or(&named.orig),
));
}
ExportSpecifier::Default(_) => {
exports.push(atom!("default"));
}
ExportSpecifier::Namespace(e) => {
exports.push(e.name.atom().clone());
exports.push(module_export_name_to_atom(&e.name));
}
}
}
Expand Down Expand Up @@ -416,6 +411,13 @@ fn is_turbopack_internal_var(with: &Option<Box<ObjectLit>>) -> bool {
.unwrap_or(false)
}

fn module_export_name_to_atom(name: &ModuleExportName) -> Atom {
match name {
ModuleExportName::Ident(ident) => ident.sym.clone(),
ModuleExportName::Str(s) => s.value.to_atom_lossy().into_owned(),
}
}

type HashToLayerNameModule = Vec<(String, (ActionLayer, String, ResolvedVc<Box<dyn Module>>))>;

/// A mapping of every module which exports a Server Action, with the hashed id
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
7 changes: 5 additions & 2 deletions crates/next-core/src/segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,11 @@ 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) => &*ident.sym,
ModuleExportName::Str(s) => &*s
.value
.as_str()
.expect("unpaired unicode surrgate in export name"),
},
None,
specifier.span(),
Expand Down
1 change: 1 addition & 0 deletions crates/next-custom-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ swc_relay = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbo-rcstr = { workspace = true }
urlencoding = { workspace = true }
swc_atoms = "8.0.1"

react_remove_properties = { workspace = true }
remove_console = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions crates/next-custom-transforms/src/chain_transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
let file = file.clone();

fn_pass(move |program| {
if let Some(config) = opts.styled_jsx.to_option() {
if let Some(..) = opts.styled_jsx.to_option() {

Check failure on line 163 in crates/next-custom-transforms/src/chain_transforms.rs

View workflow job for this annotation

GitHub Actions / rust check / build

redundant pattern matching, consider using `is_some()`
let target_browsers = opts
.css_env
.as_ref()
Expand All @@ -174,7 +174,6 @@
cm.clone(),
&file.name,
&styled_jsx::visitor::Config {
use_lightningcss: config.use_lightningcss,
browsers: *target_browsers,
},
&styled_jsx::visitor::NativeConfig { process_css: None },
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: "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
9 changes: 5 additions & 4 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,8 +17,8 @@ mod font_imports_generator;
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct Config {
pub font_loaders: Vec<Atom>,
pub relative_file_path_from_root: Atom,
pub font_loaders: Vec<Wtf8Atom>,
pub relative_file_path_from_root: Wtf8Atom,
}

pub fn next_font_loaders(config: Config) -> impl Pass + VisitMut {
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 Expand Up @@ -63,7 +64,7 @@ impl VisitMut for NextFontLoaders {
// Generate imports from font function calls
let mut import_generator = font_imports_generator::FontImportsGenerator {
state: &mut self.state,
relative_path: &self.config.relative_file_path_from_root,
relative_path: &self.config.relative_file_path_from_root.to_string_lossy(),
};
items.visit_with(&mut import_generator);

Expand Down
12 changes: 6 additions & 6 deletions crates/next-custom-transforms/src/transforms/import_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{
atoms::{atom, Atom},
atoms::{atom, Atom, Wtf8Atom},
ecma::{
ast::{
Expr, Id, ImportDecl, ImportNamedSpecifier, ImportSpecifier, MemberExpr, MemberProp,
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 @@ -99,6 +99,6 @@ impl Visit for Analyzer<'_> {
fn orig_name(n: &ModuleExportName) -> Atom {
match n {
ModuleExportName::Ident(v) => v.sym.clone(),
ModuleExportName::Str(v) => v.value.clone(),
ModuleExportName::Str(v) => v.value.clone().to_atom_lossy().into_owned(),
}
}
Loading
Loading