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

build: Update `swc_core` to `v16.0.0` (#76414)

### What?

Update `swc_core` to `v16.0.0`. This is a Wasm-breaking change, and changelog is at https://github.com/swc-project/swc/compare/swc_core%40v14.0.1...swc_core%40v16.0.0

### Why?

To apply various fixes.
parent be051841
This diff is collapsed.
...@@ -299,21 +299,21 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" } ...@@ -299,21 +299,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 = "14.0.1", features = [ swc_core = { version = "16.0.0", features = [
"ecma_loader_lru", "ecma_loader_lru",
"ecma_loader_parking_lot", "ecma_loader_parking_lot",
] } ] }
testing = { version = "7.0.0" } testing = { version = "8.0.0" }
# Keep consistent with preset_env_base through swc_core # Keep consistent with preset_env_base through swc_core
browserslist-rs = { version = "0.17.0" } browserslist-rs = { version = "0.17.0" }
miette = { version = "5.10.0", features = ["fancy"] } miette = { version = "5.10.0", features = ["fancy"] }
mdxjs = "0.3" mdxjs = "0.3"
modularize_imports = { version = "0.77.0" } modularize_imports = { version = "0.79.0" }
styled_components = { version = "0.105.0" } styled_components = { version = "0.107.0" }
styled_jsx = { version = "0.81.0" } styled_jsx = { version = "0.83.0" }
swc_emotion = { version = "0.81.0" } swc_emotion = { version = "0.83.0" }
swc_relay = { version = "0.51.0" } swc_relay = { version = "0.53.0" }
# General Deps # General Deps
chromiumoxide = { version = "0.5.4", features = [ chromiumoxide = { version = "0.5.4", features = [
...@@ -435,4 +435,4 @@ wasmer-cache = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" } ...@@ -435,4 +435,4 @@ wasmer-cache = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" }
wasmer-compiler-cranelift = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" } wasmer-compiler-cranelift = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" }
wasmer-wasix = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" } wasmer-wasix = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" }
mdxjs={git="https://github.com/kdy1/mdxjs-rs.git",branch = "swc-core-14"} mdxjs = { git="https://github.com/kdy1/mdxjs-rs.git", branch = "swc-core-15" }
...@@ -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.31.0" react_remove_properties = "0.33.0"
remove_console = "0.32.0" remove_console = "0.34.0"
auto-hash-map = { workspace = true } auto-hash-map = { workspace = true }
......
use anyhow::Result; use anyhow::Result;
use async_trait::async_trait; use async_trait::async_trait;
use next_custom_transforms::transforms::fonts::*; use next_custom_transforms::transforms::fonts::*;
use swc_core::ecma::{ast::Program, atoms::JsWord, visit::VisitMutWith}; use swc_core::ecma::{ast::Program, atoms::Atom, visit::VisitMutWith};
use turbo_tasks::ResolvedVc; use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect}; use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext}; use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};
...@@ -33,7 +33,7 @@ pub fn get_next_font_transform_rule(enable_mdx_rs: bool) -> ModuleRule { ...@@ -33,7 +33,7 @@ pub fn get_next_font_transform_rule(enable_mdx_rs: bool) -> ModuleRule {
#[derive(Debug)] #[derive(Debug)]
struct NextJsFont { struct NextJsFont {
font_loaders: Vec<JsWord>, font_loaders: Vec<Atom>,
} }
#[async_trait] #[async_trait]
......
...@@ -60,8 +60,8 @@ swc_relay = { workspace = true } ...@@ -60,8 +60,8 @@ swc_relay = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true } turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
react_remove_properties = "0.31.0" react_remove_properties = "0.33.0"
remove_console = "0.32.0" remove_console = "0.34.0"
preset_env_base = "2.0.1" preset_env_base = "2.0.1"
[dev-dependencies] [dev-dependencies]
......
...@@ -3,7 +3,7 @@ use swc_core::ecma::{ ...@@ -3,7 +3,7 @@ use swc_core::ecma::{
Ident, IdentName, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement, Ident, IdentName, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement,
Pass, Pass,
}, },
atoms::JsWord, atoms::Atom,
visit::{fold_pass, Fold}, visit::{fold_pass, Fold},
}; };
...@@ -37,7 +37,7 @@ impl Fold for AmpAttributePatcher { ...@@ -37,7 +37,7 @@ impl Fold for AmpAttributePatcher {
if sym as &str == "className" { if sym as &str == "className" {
*i = JSXAttrOrSpread::JSXAttr(JSXAttr { *i = JSXAttrOrSpread::JSXAttr(JSXAttr {
name: JSXAttrName::Ident(IdentName { name: JSXAttrName::Ident(IdentName {
sym: JsWord::from("class"), sym: Atom::from("class"),
span: *s, span: *s,
}), }),
span: *span, span: *span,
......
...@@ -2,13 +2,13 @@ use swc_core::{ ...@@ -2,13 +2,13 @@ use swc_core::{
common::errors::HANDLER, common::errors::HANDLER,
ecma::{ ecma::{
ast::*, ast::*,
atoms::JsWord, atoms::Atom,
visit::{noop_visit_type, Visit}, visit::{noop_visit_type, Visit},
}, },
}; };
pub struct FontFunctionsCollector<'a> { pub struct FontFunctionsCollector<'a> {
pub font_loaders: &'a [JsWord], pub font_loaders: &'a [Atom],
pub state: &'a mut super::State, pub state: &'a mut super::State,
} }
......
...@@ -3,7 +3,7 @@ use swc_core::{ ...@@ -3,7 +3,7 @@ use swc_core::{
common::{errors::HANDLER, Spanned, DUMMY_SP}, common::{errors::HANDLER, Spanned, DUMMY_SP},
ecma::{ ecma::{
ast::*, ast::*,
atoms::JsWord, atoms::Atom,
visit::{noop_visit_type, Visit}, visit::{noop_visit_type, Visit},
}, },
}; };
...@@ -66,7 +66,7 @@ impl FontImportsGenerator<'_> { ...@@ -66,7 +66,7 @@ impl FontImportsGenerator<'_> {
return Some(ImportDecl { return Some(ImportDecl {
src: Box::new(Str { src: Box::new(Str {
value: JsWord::from(format!( value: Atom::from(format!(
"{}/target.css?{}", "{}/target.css?{}",
font_function.loader, query_json font_function.loader, query_json
)), )),
......
...@@ -4,7 +4,7 @@ use swc_core::{ ...@@ -4,7 +4,7 @@ use swc_core::{
common::{BytePos, Spanned}, common::{BytePos, Spanned},
ecma::{ ecma::{
ast::{Id, ModuleItem, Pass}, ast::{Id, ModuleItem, Pass},
atoms::JsWord, atoms::Atom,
visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitWith}, visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitWith},
}, },
}; };
...@@ -16,8 +16,8 @@ mod font_imports_generator; ...@@ -16,8 +16,8 @@ mod font_imports_generator;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")] #[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct Config { pub struct Config {
pub font_loaders: Vec<JsWord>, pub font_loaders: Vec<Atom>,
pub relative_file_path_from_root: JsWord, pub relative_file_path_from_root: Atom,
} }
pub fn next_font_loaders(config: Config) -> impl Pass + VisitMut { pub fn next_font_loaders(config: Config) -> impl Pass + VisitMut {
...@@ -31,8 +31,8 @@ pub fn next_font_loaders(config: Config) -> impl Pass + VisitMut { ...@@ -31,8 +31,8 @@ pub fn next_font_loaders(config: Config) -> impl Pass + VisitMut {
#[derive(Debug)] #[derive(Debug)]
pub struct FontFunction { pub struct FontFunction {
loader: JsWord, loader: Atom,
function_name: Option<JsWord>, function_name: Option<Atom>,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct State { pub struct State {
......
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{ use swc_core::{
atoms::JsWord, atoms::Atom,
ecma::{ ecma::{
ast::{ ast::{
Expr, Id, ImportDecl, ImportNamedSpecifier, ImportSpecifier, MemberExpr, MemberProp, Expr, Id, ImportDecl, ImportNamedSpecifier, ImportSpecifier, MemberExpr, MemberProp,
...@@ -13,16 +13,16 @@ use swc_core::{ ...@@ -13,16 +13,16 @@ use swc_core::{
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub(crate) struct ImportMap { pub(crate) struct ImportMap {
/// Map from module name to (module path, exported symbol) /// Map from module name to (module path, exported symbol)
imports: FxHashMap<Id, (JsWord, JsWord)>, imports: FxHashMap<Id, (Atom, Atom)>,
namespace_imports: FxHashMap<Id, JsWord>, namespace_imports: FxHashMap<Id, Atom>,
imported_modules: FxHashSet<JsWord>, imported_modules: FxHashSet<Atom>,
} }
#[allow(unused)] #[allow(unused)]
impl ImportMap { impl ImportMap {
pub fn is_module_imported(&mut self, module: &JsWord) -> bool { pub fn is_module_imported(&mut self, module: &Atom) -> bool {
self.imported_modules.contains(module) self.imported_modules.contains(module)
} }
...@@ -96,7 +96,7 @@ impl Visit for Analyzer<'_> { ...@@ -96,7 +96,7 @@ impl Visit for Analyzer<'_> {
} }
} }
fn orig_name(n: &ModuleExportName) -> JsWord { fn orig_name(n: &ModuleExportName) -> Atom {
match n { match n {
ModuleExportName::Ident(v) => v.sym.clone(), ModuleExportName::Ident(v) => v.sym.clone(),
ModuleExportName::Str(v) => v.value.clone(), ModuleExportName::Str(v) => v.value.clone(),
......
...@@ -3,7 +3,7 @@ use swc_core::{ ...@@ -3,7 +3,7 @@ use swc_core::{
common::Mark, common::Mark,
ecma::{ ecma::{
ast::*, ast::*,
atoms::{js_word, JsWord}, atoms::{atom, Atom},
transforms::optimization::simplify::dce::{dce, Config as DCEConfig}, transforms::optimization::simplify::dce::{dce, Config as DCEConfig},
visit::{fold_pass, Fold, FoldWith, VisitMutWith}, visit::{fold_pass, Fold, FoldWith, VisitMutWith},
}, },
...@@ -11,7 +11,7 @@ use swc_core::{ ...@@ -11,7 +11,7 @@ use swc_core::{
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
pub struct Config { pub struct Config {
pub ignore: Vec<JsWord>, pub ignore: Vec<Atom>,
} }
pub fn shake_exports(config: Config) -> impl Pass { pub fn shake_exports(config: Config) -> impl Pass {
...@@ -23,7 +23,7 @@ pub fn shake_exports(config: Config) -> impl Pass { ...@@ -23,7 +23,7 @@ pub fn shake_exports(config: Config) -> impl Pass {
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct ExportShaker { struct ExportShaker {
ignore: Vec<JsWord>, ignore: Vec<Atom>,
remove_export: bool, remove_export: bool,
} }
...@@ -108,14 +108,14 @@ impl Fold for ExportShaker { ...@@ -108,14 +108,14 @@ impl Fold for ExportShaker {
} }
fn fold_export_default_decl(&mut self, decl: ExportDefaultDecl) -> ExportDefaultDecl { fn fold_export_default_decl(&mut self, decl: ExportDefaultDecl) -> ExportDefaultDecl {
if !self.ignore.contains(&js_word!("default")) { if !self.ignore.contains(&atom!("default")) {
self.remove_export = true self.remove_export = true
} }
decl decl
} }
fn fold_export_default_expr(&mut self, expr: ExportDefaultExpr) -> ExportDefaultExpr { fn fold_export_default_expr(&mut self, expr: ExportDefaultExpr) -> ExportDefaultExpr {
if !self.ignore.contains(&js_word!("default")) { if !self.ignore.contains(&atom!("default")) {
self.remove_export = true self.remove_export = true
} }
expr expr
......
...@@ -2,7 +2,7 @@ use anyhow::Result; ...@@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait; use async_trait::async_trait;
use swc_core::{ use swc_core::{
common::comments::NoopComments, common::comments::NoopComments,
ecma::{ast::Program, atoms::JsWord}, ecma::{ast::Program, atoms::Atom},
}; };
use turbo_tasks::{ValueDefault, Vc}; use turbo_tasks::{ValueDefault, Vc};
use turbopack_ecmascript::{CustomTransformer, TransformContext}; use turbopack_ecmascript::{CustomTransformer, TransformContext};
...@@ -71,7 +71,7 @@ impl StyledComponentsTransformer { ...@@ -71,7 +71,7 @@ impl StyledComponentsTransformer {
if !top_level_import_paths.is_empty() { if !top_level_import_paths.is_empty() {
options.top_level_import_paths = top_level_import_paths options.top_level_import_paths = top_level_import_paths
.iter() .iter()
.map(|s| JsWord::from(s.clone())) .map(|s| Atom::from(s.clone()))
.collect(); .collect();
} }
let meaningless_file_names = &config.meaningless_file_names; let meaningless_file_names = &config.meaningless_file_names;
......
use std::mem::take; use std::mem::take;
use swc_core::ecma::atoms::js_word; use swc_core::ecma::atoms::atom;
use super::{ConstantNumber, ConstantValue, JsValue, LogicalOperator, LogicalProperty, ObjectPart}; use super::{ConstantNumber, ConstantValue, JsValue, LogicalOperator, LogicalProperty, ObjectPart};
use crate::analyzer::JsValueUrlKind; use crate::analyzer::JsValueUrlKind;
...@@ -303,7 +303,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool { ...@@ -303,7 +303,7 @@ pub fn replace_builtin(value: &mut JsValue) -> bool {
} }
} }
if potential_values.is_empty() { if potential_values.is_empty() {
*value = JsValue::FreeVar(js_word!("undefined")); *value = JsValue::FreeVar(atom!("undefined"));
} else { } else {
*value = potential_values_to_alternatives( *value = potential_values_to_alternatives(
potential_values, potential_values,
......
...@@ -9,7 +9,7 @@ use swc_core::{ ...@@ -9,7 +9,7 @@ use swc_core::{
common::{comments::Comments, pass::AstNodePath, Mark, Span, Spanned, SyntaxContext, GLOBALS}, common::{comments::Comments, pass::AstNodePath, Mark, Span, Spanned, SyntaxContext, GLOBALS},
ecma::{ ecma::{
ast::*, ast::*,
atoms::js_word, atoms::atom,
utils::contains_ident_ref, utils::contains_ident_ref,
visit::{fields::*, *}, visit::{fields::*, *},
}, },
...@@ -658,7 +658,7 @@ impl EvalContext { ...@@ -658,7 +658,7 @@ impl EvalContext {
} }
let args = args.iter().map(|arg| self.eval(&arg.expr)).collect(); let args = args.iter().map(|arg| self.eval(&arg.expr)).collect();
let callee = Box::new(JsValue::FreeVar(js_word!("import"))); let callee = Box::new(JsValue::FreeVar(atom!("import")));
JsValue::call(callee, args) JsValue::call(callee, args)
} }
...@@ -673,7 +673,7 @@ impl EvalContext { ...@@ -673,7 +673,7 @@ impl EvalContext {
.iter() .iter()
.map(|e| match e { .map(|e| match e {
Some(e) => self.eval(&e.expr), Some(e) => self.eval(&e.expr),
_ => JsValue::FreeVar(js_word!("undefined")), _ => JsValue::FreeVar(atom!("undefined")),
}) })
.collect(); .collect();
JsValue::array(arr) JsValue::array(arr)
...@@ -1127,7 +1127,7 @@ impl Analyzer<'_> { ...@@ -1127,7 +1127,7 @@ impl Analyzer<'_> {
match callee { match callee {
Callee::Import(_) => { Callee::Import(_) => {
self.add_effect(Effect::Call { self.add_effect(Effect::Call {
func: Box::new(JsValue::FreeVar(js_word!("import"))), func: Box::new(JsValue::FreeVar(atom!("import"))),
args, args,
ast_path: as_parent_path(ast_path), ast_path: as_parent_path(ast_path),
span, span,
...@@ -1213,7 +1213,7 @@ impl Analyzer<'_> { ...@@ -1213,7 +1213,7 @@ impl Analyzer<'_> {
let values = self.cur_fn_return_values.take().unwrap(); let values = self.cur_fn_return_values.take().unwrap();
Box::new(match values.len() { Box::new(match values.len() {
0 => JsValue::FreeVar(js_word!("undefined")), 0 => JsValue::FreeVar(atom!("undefined")),
1 => values.into_iter().next().unwrap(), 1 => values.into_iter().next().unwrap(),
_ => JsValue::alternatives(values), _ => JsValue::alternatives(values),
}) })
...@@ -1793,7 +1793,7 @@ impl VisitAstPath for Analyzer<'_> { ...@@ -1793,7 +1793,7 @@ impl VisitAstPath for Analyzer<'_> {
.arg .arg
.as_deref() .as_deref()
.map(|e| self.eval_context.eval(e)) .map(|e| self.eval_context.eval(e))
.unwrap_or(JsValue::FreeVar(js_word!("undefined"))); .unwrap_or(JsValue::FreeVar(atom!("undefined")));
values.push(return_value); values.push(return_value);
} }
......
...@@ -6,7 +6,7 @@ use swc_core::{ ...@@ -6,7 +6,7 @@ use swc_core::{
common::{comments::Comments, source_map::SmallPos, BytePos, Span, Spanned}, common::{comments::Comments, source_map::SmallPos, BytePos, Span, Spanned},
ecma::{ ecma::{
ast::*, ast::*,
atoms::{js_word, JsWord}, atoms::{atom, Atom},
visit::{Visit, VisitWith}, visit::{Visit, VisitWith},
}, },
}; };
...@@ -26,19 +26,19 @@ use crate::{ ...@@ -26,19 +26,19 @@ use crate::{
pub struct ImportAnnotations { pub struct ImportAnnotations {
// TODO store this in more structured way // TODO store this in more structured way
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
map: BTreeMap<JsWord, JsWord>, map: BTreeMap<Atom, Atom>,
} }
/// Enables a specified transition for the annotated import /// Enables a specified transition for the annotated import
static ANNOTATION_TRANSITION: Lazy<JsWord> = static ANNOTATION_TRANSITION: Lazy<Atom> =
Lazy::new(|| crate::annotations::ANNOTATION_TRANSITION.into()); Lazy::new(|| crate::annotations::ANNOTATION_TRANSITION.into());
/// Changes the chunking type for the annotated import /// Changes the chunking type for the annotated import
static ANNOTATION_CHUNKING_TYPE: Lazy<JsWord> = static ANNOTATION_CHUNKING_TYPE: Lazy<Atom> =
Lazy::new(|| crate::annotations::ANNOTATION_CHUNKING_TYPE.into()); Lazy::new(|| crate::annotations::ANNOTATION_CHUNKING_TYPE.into());
/// Changes the type of the resolved module (only "json" is supported currently) /// Changes the type of the resolved module (only "json" is supported currently)
static ATTRIBUTE_MODULE_TYPE: Lazy<JsWord> = Lazy::new(|| "type".into()); static ATTRIBUTE_MODULE_TYPE: Lazy<Atom> = Lazy::new(|| "type".into());
impl ImportAnnotations { impl ImportAnnotations {
pub fn parse(with: Option<&ObjectLit>) -> ImportAnnotations { pub fn parse(with: Option<&ObjectLit>) -> ImportAnnotations {
...@@ -113,7 +113,7 @@ impl ImportAnnotations { ...@@ -113,7 +113,7 @@ impl ImportAnnotations {
self.get(&ATTRIBUTE_MODULE_TYPE) self.get(&ATTRIBUTE_MODULE_TYPE)
} }
pub fn get(&self, key: &JsWord) -> Option<&str> { pub fn get(&self, key: &Atom) -> Option<&str> {
self.map.get(key).map(|w| w.as_str()) self.map.get(key).map(|w| w.as_str())
} }
} }
...@@ -136,8 +136,8 @@ impl Display for ImportAnnotations { ...@@ -136,8 +136,8 @@ impl Display for ImportAnnotations {
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum Reexport { pub(crate) enum Reexport {
Star, Star,
Namespace { exported: JsWord }, Namespace { exported: Atom },
Named { imported: JsWord, exported: JsWord }, Named { imported: Atom, exported: Atom },
} }
/// The storage for all kinds of imports. /// The storage for all kinds of imports.
...@@ -147,7 +147,7 @@ pub(crate) enum Reexport { ...@@ -147,7 +147,7 @@ pub(crate) enum Reexport {
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub(crate) struct ImportMap { pub(crate) struct ImportMap {
/// Map from identifier to (index in references, exported symbol) /// Map from identifier to (index in references, exported symbol)
imports: FxIndexMap<Id, (usize, JsWord)>, imports: FxIndexMap<Id, (usize, Atom)>,
/// Map from identifier to index in references /// Map from identifier to index in references
namespace_imports: FxIndexMap<Id, usize>, namespace_imports: FxIndexMap<Id, usize>,
...@@ -177,7 +177,7 @@ pub(crate) struct ImportMap { ...@@ -177,7 +177,7 @@ pub(crate) struct ImportMap {
/// The module specifiers of star imports that are accessed dynamically and should be imported /// The module specifiers of star imports that are accessed dynamically and should be imported
/// as a whole. /// as a whole.
full_star_imports: FxHashSet<JsWord>, full_star_imports: FxHashSet<Atom>,
} }
/// Represents a collection of [webpack-style "magic comments"][magic] that override import /// Represents a collection of [webpack-style "magic comments"][magic] that override import
...@@ -226,7 +226,7 @@ impl Default for &ImportAttributes { ...@@ -226,7 +226,7 @@ impl Default for &ImportAttributes {
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) enum ImportedSymbol { pub(crate) enum ImportedSymbol {
ModuleEvaluation, ModuleEvaluation,
Symbol(JsWord), Symbol(Atom),
Exports, Exports,
Part(u32), Part(u32),
PartEvaluation(u32), PartEvaluation(u32),
...@@ -234,7 +234,7 @@ pub(crate) enum ImportedSymbol { ...@@ -234,7 +234,7 @@ pub(crate) enum ImportedSymbol {
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct ImportMapReference { pub(crate) struct ImportMapReference {
pub module_path: JsWord, pub module_path: Atom,
pub imported_symbol: ImportedSymbol, pub imported_symbol: ImportedSymbol,
pub annotations: ImportAnnotations, pub annotations: ImportAnnotations,
pub issue_source: Option<IssueSource>, pub issue_source: Option<IssueSource>,
...@@ -353,8 +353,8 @@ impl ImportMap { ...@@ -353,8 +353,8 @@ impl ImportMap {
struct StarImportAnalyzer<'a> { struct StarImportAnalyzer<'a> {
/// The local identifiers of the star imports /// The local identifiers of the star imports
candidates: FxIndexMap<Id, JsWord>, candidates: FxIndexMap<Id, Atom>,
full_star_imports: &'a mut FxHashSet<JsWord>, full_star_imports: &'a mut FxHashSet<Atom>,
} }
impl Visit for StarImportAnalyzer<'_> { impl Visit for StarImportAnalyzer<'_> {
...@@ -420,7 +420,7 @@ impl Analyzer<'_> { ...@@ -420,7 +420,7 @@ impl Analyzer<'_> {
fn ensure_reference( fn ensure_reference(
&mut self, &mut self,
span: Span, span: Span,
module_path: JsWord, module_path: Atom,
imported_symbol: ImportedSymbol, imported_symbol: ImportedSymbol,
annotations: ImportAnnotations, annotations: ImportAnnotations,
) -> Option<usize> { ) -> Option<usize> {
...@@ -444,7 +444,7 @@ impl Analyzer<'_> { ...@@ -444,7 +444,7 @@ impl Analyzer<'_> {
} }
} }
fn to_word(name: &ModuleExportName) -> JsWord { fn to_word(name: &ModuleExportName) -> Atom {
match name { match name {
ModuleExportName::Ident(ident) => ident.sym.clone(), ModuleExportName::Ident(ident) => ident.sym.clone(),
ModuleExportName::Str(str) => str.value.clone(), ModuleExportName::Str(str) => str.value.clone(),
...@@ -580,7 +580,7 @@ impl Visit for Analyzer<'_> { ...@@ -580,7 +580,7 @@ impl Visit for Analyzer<'_> {
self.data.reexports.push(( self.data.reexports.push((
i, i,
Reexport::Named { Reexport::Named {
imported: js_word!("default"), imported: atom!("default"),
exported: d.exported.sym.clone(), exported: d.exported.sym.clone(),
}, },
)); ));
...@@ -718,7 +718,7 @@ fn parse_ignore_directive(comments: &dyn Comments, value: Option<&ExprOrSpread>) ...@@ -718,7 +718,7 @@ fn parse_ignore_directive(comments: &dyn Comments, value: Option<&ExprOrSpread>)
.next() .next()
} }
pub(crate) fn orig_name(n: &ModuleExportName) -> JsWord { pub(crate) fn orig_name(n: &ModuleExportName) -> Atom {
match n { match n {
ModuleExportName::Ident(v) => v.sym.clone(), ModuleExportName::Ident(v) => v.sym.clone(),
ModuleExportName::Str(v) => v.value.clone(), ModuleExportName::Str(v) => v.value.clone(),
...@@ -743,7 +743,7 @@ fn get_import_symbol_from_import(specifier: &ImportSpecifier) -> ImportedSymbol ...@@ -743,7 +743,7 @@ fn get_import_symbol_from_import(specifier: &ImportSpecifier) -> ImportedSymbol
Some(imported) => orig_name(imported), Some(imported) => orig_name(imported),
_ => local.sym.clone(), _ => local.sym.clone(),
}), }),
ImportSpecifier::Default(..) => ImportedSymbol::Symbol(js_word!("default")), ImportSpecifier::Default(..) => ImportedSymbol::Symbol(atom!("default")),
ImportSpecifier::Namespace(..) => ImportedSymbol::Exports, ImportSpecifier::Namespace(..) => ImportedSymbol::Exports,
} }
} }
...@@ -753,7 +753,7 @@ fn get_import_symbol_from_export(specifier: &ExportSpecifier) -> ImportedSymbol ...@@ -753,7 +753,7 @@ fn get_import_symbol_from_export(specifier: &ExportSpecifier) -> ImportedSymbol
ExportSpecifier::Named(ExportNamedSpecifier { orig, .. }) => { ExportSpecifier::Named(ExportNamedSpecifier { orig, .. }) => {
ImportedSymbol::Symbol(orig_name(orig)) ImportedSymbol::Symbol(orig_name(orig))
} }
ExportSpecifier::Default(..) => ImportedSymbol::Symbol(js_word!("default")), ExportSpecifier::Default(..) => ImportedSymbol::Symbol(atom!("default")),
ExportSpecifier::Namespace(..) => ImportedSymbol::Exports, ExportSpecifier::Namespace(..) => ImportedSymbol::Exports,
} }
} }
...@@ -22,7 +22,7 @@ use swc_core::{ ...@@ -22,7 +22,7 @@ use swc_core::{
common::Mark, common::Mark,
ecma::{ ecma::{
ast::{Id, Ident, Lit}, ast::{Id, Ident, Lit},
atoms::{Atom, JsWord}, atoms::Atom,
}, },
}; };
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -275,7 +275,7 @@ impl Display for ConstantValue { ...@@ -275,7 +275,7 @@ impl Display for ConstantValue {
#[derive(Debug, Clone, Hash, PartialEq, Eq)] #[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct ModuleValue { pub struct ModuleValue {
pub module: JsWord, pub module: Atom,
pub annotations: ImportAnnotations, pub annotations: ImportAnnotations,
} }
...@@ -500,9 +500,9 @@ pub enum JsValue { ...@@ -500,9 +500,9 @@ pub enum JsValue {
/// A reference to an function argument. /// A reference to an function argument.
/// (func_ident, arg_index) /// (func_ident, arg_index)
Argument(u32, usize), Argument(u32, usize),
// TODO no predefined kinds, only JsWord // TODO no predefined kinds, only Atom
/// A reference to a free variable. /// A reference to a free variable.
FreeVar(JsWord), FreeVar(Atom),
/// This is a reference to a imported module. /// This is a reference to a imported module.
Module(ModuleValue), Module(ModuleValue),
} }
...@@ -3799,9 +3799,9 @@ pub enum WellKnownFunctionKind { ...@@ -3799,9 +3799,9 @@ pub enum WellKnownFunctionKind {
RequireContextRequireKeys(RequireContextValue), RequireContextRequireKeys(RequireContextValue),
RequireContextRequireResolve(RequireContextValue), RequireContextRequireResolve(RequireContextValue),
Define, Define,
FsReadMethod(JsWord), FsReadMethod(Atom),
PathToFileUrl, PathToFileUrl,
ChildProcessSpawnMethod(JsWord), ChildProcessSpawnMethod(Atom),
ChildProcessFork, ChildProcessFork,
OsArch, OsArch,
OsPlatform, OsPlatform,
......
...@@ -32,7 +32,7 @@ use regex::Regex; ...@@ -32,7 +32,7 @@ use regex::Regex;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use swc_core::{ use swc_core::{
atoms::JsWord, atoms::Atom,
common::{ common::{
comments::{CommentKind, Comments}, comments::{CommentKind, Comments},
errors::{DiagnosticId, Handler, HANDLER}, errors::{DiagnosticId, Handler, HANDLER},
...@@ -3176,7 +3176,7 @@ impl VisitAstPath for ModuleReferencesVisitor<'_> { ...@@ -3176,7 +3176,7 @@ impl VisitAstPath for ModuleReferencesVisitor<'_> {
if export.src.is_none() { if export.src.is_none() {
for spec in export.specifiers.iter() { for spec in export.specifiers.iter() {
fn to_string(name: &ModuleExportName) -> &JsWord { fn to_string(name: &ModuleExportName) -> &Atom {
name.atom() name.atom()
} }
match spec { match spec {
...@@ -3445,7 +3445,7 @@ impl From<Vec<AstParentKind>> for AstPath { ...@@ -3445,7 +3445,7 @@ impl From<Vec<AstParentKind>> for AstPath {
} }
} }
pub static TURBOPACK_HELPER: Lazy<JsWord> = Lazy::new(|| "__turbopack-helper__".into()); pub static TURBOPACK_HELPER: Lazy<Atom> = Lazy::new(|| "__turbopack-helper__".into());
pub fn is_turbopack_helper_import(import: &ImportDecl) -> bool { pub fn is_turbopack_helper_import(import: &ImportDecl) -> bool {
let annotations = ImportAnnotations::parse(import.with.as_deref()); let annotations = ImportAnnotations::parse(import.with.as_deref());
......
...@@ -19,7 +19,7 @@ use swc_core::{ ...@@ -19,7 +19,7 @@ use swc_core::{
Lit, Module, ModuleDecl, ModuleExportName, ModuleItem, NamedExport, ObjectLit, Prop, Lit, Module, ModuleDecl, ModuleExportName, ModuleItem, NamedExport, ObjectLit, Prop,
PropName, PropOrSpread, Stmt, Str, VarDecl, VarDeclKind, VarDeclarator, PropName, PropOrSpread, Stmt, Str, VarDecl, VarDeclKind, VarDeclarator,
}, },
atoms::JsWord, atoms::Atom,
utils::{find_pat_ids, private_ident, quote_ident, ExprCtx, ExprExt}, utils::{find_pat_ids, private_ident, quote_ident, ExprCtx, ExprExt},
}, },
}; };
...@@ -46,7 +46,7 @@ pub(crate) enum ItemId { ...@@ -46,7 +46,7 @@ pub(crate) enum ItemId {
pub(crate) enum ItemIdGroupKind { pub(crate) enum ItemIdGroupKind {
ModuleEvaluation, ModuleEvaluation,
/// `(local, export_name)`` /// `(local, export_name)``
Export(Id, JsWord), Export(Id, Atom),
} }
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
...@@ -109,7 +109,7 @@ pub(crate) struct ItemData { ...@@ -109,7 +109,7 @@ pub(crate) struct ItemData {
pub content: ModuleItem, pub content: ModuleItem,
pub export: Option<JsWord>, pub export: Option<Atom>,
/// This value denotes the module specifier of the [ImportDecl] that declares this /// This value denotes the module specifier of the [ImportDecl] that declares this
/// [ItemId]. /// [ItemId].
...@@ -1642,7 +1642,7 @@ pub(crate) fn find_turbopack_part_id_in_asserts(asserts: &ObjectLit) -> Option<P ...@@ -1642,7 +1642,7 @@ pub(crate) fn find_turbopack_part_id_in_asserts(asserts: &ObjectLit) -> Option<P
} }
/// givin a number, return a base54 encoded string /// givin a number, return a base54 encoded string
/// `usize -> [a-zA-Z$_][a-zA-Z$_0-9]*` /// `usize -> [a-zA-Z$_][a-zA-Z$_0-9]*`
pub(crate) fn encode_base54(init: &mut usize, skip_reserved: bool) -> JsWord { pub(crate) fn encode_base54(init: &mut usize, skip_reserved: bool) -> Atom {
static BASE54_CHARS: &[u8; 64] = static BASE54_CHARS: &[u8; 64] =
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_"; b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
...@@ -1674,8 +1674,8 @@ pub(crate) fn encode_base54(init: &mut usize, skip_reserved: bool) -> JsWord { ...@@ -1674,8 +1674,8 @@ pub(crate) fn encode_base54(init: &mut usize, skip_reserved: bool) -> JsWord {
let s = unsafe { let s = unsafe {
// Safety: We are only using ascii characters // Safety: We are only using ascii characters
// Safety: The stack memory for ret is alive while creating JsWord // Safety: The stack memory for ret is alive while creating Atom
JsWord::from(std::str::from_utf8_unchecked(&ret)) Atom::from(std::str::from_utf8_unchecked(&ret))
}; };
if skip_reserved if skip_reserved
......
...@@ -2,7 +2,7 @@ use anyhow::Error; ...@@ -2,7 +2,7 @@ use anyhow::Error;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use swc_core::ecma::{ use swc_core::ecma::{
ast::{Module, ModuleDecl, ModuleItem}, ast::{Module, ModuleDecl, ModuleItem},
atoms::JsWord, atoms::Atom,
}; };
use super::{graph::find_turbopack_part_id_in_asserts, PartId}; use super::{graph::find_turbopack_part_id_in_asserts, PartId};
...@@ -22,7 +22,7 @@ where ...@@ -22,7 +22,7 @@ where
{ {
loader: L, loader: L,
done: FxHashSet<(JsWord, u32)>, done: FxHashSet<(Atom, u32)>,
} }
impl<L> Merger<L> impl<L> Merger<L>
......
...@@ -6,7 +6,7 @@ use swc_core::{ ...@@ -6,7 +6,7 @@ use swc_core::{
common::{comments::SingleThreadedComments, util::take::Take, Mark, SourceMap, SyntaxContext}, common::{comments::SingleThreadedComments, util::take::Take, Mark, SourceMap, SyntaxContext},
ecma::{ ecma::{
ast::{EsVersion, Id, Module}, ast::{EsVersion, Id, Module},
atoms::JsWord, atoms::Atom,
codegen::text_writer::JsWriter, codegen::text_writer::JsWriter,
parser::{parse_file_as_module, EsSyntax}, parser::{parse_file_as_module, EsSyntax},
visit::VisitMutWith, visit::VisitMutWith,
...@@ -176,7 +176,7 @@ fn run(input: PathBuf) { ...@@ -176,7 +176,7 @@ fn run(input: PathBuf) {
) )
.unwrap(); .unwrap();
let uri_of_module: JsWord = "entry.js".into(); let uri_of_module: Atom = "entry.js".into();
let mut describe = let mut describe =
|is_debug: bool, title: &str, entries: Vec<ItemIdGroupKind>, skip_parts: bool| { |is_debug: bool, title: &str, entries: Vec<ItemIdGroupKind>, skip_parts: bool| {
......
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