Skip to content

Commit

Permalink
Merge 246b33d into 10799c6
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Sep 18, 2023
2 parents 10799c6 + 246b33d commit 5aae0ce
Show file tree
Hide file tree
Showing 65 changed files with 411 additions and 847 deletions.
287 changes: 44 additions & 243 deletions Cargo.lock

Large diffs are not rendered by default.

59 changes: 4 additions & 55 deletions crates/turbopack-binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,9 @@ bench = false
[features]
__swc = []
__swc_core = ["__swc"]
__swc_core_next_core = [
"__swc_core",
"swc_core/common_concurrent",
"swc_core/ecma_ast",
"swc_core/ecma_visit",
"swc_core/ecma_loader_node",
"swc_core/ecma_loader_lru",
"swc_core/ecma_utils",
"swc_core/ecma_minifier",
"swc_core/ecma_transforms",
"swc_core/ecma_transforms_react",
"swc_core/ecma_transforms_typescript",
"swc_core/ecma_transforms_optimization",
"swc_core/ecma_parser",
"swc_core/ecma_parser_typescript",
"swc_core/cached",
"swc_core/base",
]
__swc_core_next_core = ["__swc_core"]

__swc_core_binding_napi = [
"__swc_core",
"swc_core/base_concurrent",
"swc_core/base_node",
"swc_core/common_concurrent",
"swc_core/ecma_ast",
"swc_core/ecma_loader_node",
"swc_core/ecma_loader_lru",
"swc_core/bundler",
"swc_core/bundler_concurrent",
"swc_core/ecma_codegen",
"swc_core/ecma_minifier",
"swc_core/ecma_parser",
"swc_core/ecma_parser_typescript",
"swc_core/ecma_transforms",
"swc_core/ecma_transforms_optimization",
"swc_core/ecma_transforms_react",
"swc_core/ecma_transforms_typescript",
"swc_core/ecma_utils",
"swc_core/ecma_visit",
]
__swc_core_binding_napi = ["__swc_core"]
__swc_core_binding_napi_plugin = [
"swc_core/plugin_transform_host_native",
"turbopack-ecmascript-plugins/swc_ecma_transform_plugin",
Expand All @@ -63,24 +26,10 @@ __swc_core_binding_napi_plugin_shared_runtime = [
]
__swc_core_binding_napi_allocator = ["swc_core/allocator_node"]

__swc_core_binding_wasm = [
"__swc_core",
"swc_core/common_concurrent",
"swc_core/binding_macro_wasm",
"swc_core/ecma_codegen",
"swc_core/ecma_minifier",
"swc_core/ecma_transforms",
"swc_core/ecma_transforms_typescript",
"swc_core/ecma_transforms_optimization",
"swc_core/ecma_transforms_react",
"swc_core/ecma_parser",
"swc_core/ecma_parser_typescript",
"swc_core/ecma_utils",
"swc_core/ecma_visit",
]
__swc_core_binding_wasm = ["__swc_core"]
__swc_core_binding_wasm_plugin = ["swc_core/plugin_transform_host_js"]

__swc_core_testing_transform = ["swc_core/testing_transform"]
__swc_core_testing_transform = []

__turbo = []
__turbo_tasks_malloc = ["__turbo", "turbo-tasks-malloc"]
Expand Down
14 changes: 10 additions & 4 deletions crates/turbopack-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ serde = { workspace = true }
serde_json = { workspace = true }
serde_qs = { workspace = true }
sourcemap = { workspace = true }
swc_core = { workspace = true, features = [
"__parser",
"ecma_minifier",
"ecma_minifier_concurrent",
swc = "0.266.0"
swc_atoms = "0.5.9"
swc_common = "0.32.1"
swc_ecma_ast = "0.109.1"
swc_ecma_codegen = "0.145.0"
swc_ecma_minifier = "0.187.0"
swc_ecma_parser = "0.140.0"
swc_ecma_transforms_base = { version = "0.133.0", features = [
"concurrent-renamer",
] }
swc_ecma_visit = "0.95.1"

turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
Expand Down
46 changes: 20 additions & 26 deletions crates/turbopack-build/src/ecmascript/minify.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
use std::{io::Write, sync::Arc};

use anyhow::{bail, Context, Result};
use swc_core::{
base::{try_with_handler, Compiler},
common::{
comments::{Comments, SingleThreadedComments},
BytePos, FileName, FilePathMapping, LineCol, Mark, SourceMap as SwcSourceMap, GLOBALS,
},
ecma::{
self,
ast::{EsVersion, Program},
codegen::{
text_writer::{self, JsWriter, WriteJs},
Emitter, Node,
},
minifier::option::{ExtraOptions, MinifyOptions},
parser::{lexer::Lexer, Parser, StringInput, Syntax},
visit::FoldWith,
},
use swc::{try_with_handler, Compiler};
use swc_common::{
comments::{Comments, SingleThreadedComments},
BytePos, FileName, FilePathMapping, LineCol, Mark, SourceMap as SwcSourceMap, GLOBALS,
};
use swc_ecma_ast::{EsVersion, Program};
use swc_ecma_codegen::{
text_writer::{self, JsWriter, WriteJs},
Emitter, Node,
};
use swc_ecma_minifier::option::{ExtraOptions, MinifyOptions};
use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax};
use swc_ecma_visit::FoldWith;
use turbo_tasks::Vc;
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
Expand Down Expand Up @@ -77,14 +72,13 @@ async fn perform_minify(path: Vc<FileSystemPath>, code_vc: Vc<Code>) -> Result<V
let top_level_mark = Mark::new();

Ok(compiler.run_transform(handler, false, || {
let mut program =
program.fold_with(&mut swc_core::ecma::transforms::base::resolver(
unresolved_mark,
top_level_mark,
false,
));
let mut program = program.fold_with(&mut swc_ecma_transforms_base::resolver(
unresolved_mark,
top_level_mark,
false,
));

program = swc_core::ecma::minifier::optimize(
program = swc_ecma_minifier::optimize(
program,
cm.clone(),
Some(&comments),
Expand All @@ -100,7 +94,7 @@ async fn perform_minify(path: Vc<FileSystemPath>, code_vc: Vc<Code>) -> Result<V
},
);

program.fold_with(&mut ecma::transforms::base::fixer::fixer(Some(
program.fold_with(&mut swc_ecma_transforms_base::fixer::fixer(Some(
&comments as &dyn Comments,
)))
}))
Expand Down Expand Up @@ -138,7 +132,7 @@ fn print_program(
)))) as Box<dyn WriteJs>;

let mut emitter = Emitter {
cfg: swc_core::ecma::codegen::Config::default().with_minify(true),
cfg: swc_ecma_codegen::Config::default().with_minify(true),
comments: None,
cm: cm.clone(),
wr,
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { workspace = true, features = ["rc"] }
serde_json = { workspace = true, features = ["preserve_order"] }
serde_qs = { workspace = true }
sourcemap = { workspace = true }
swc_core = { workspace = true, features = ["ecma_preset_env", "common"] }
swc_ecma_preset_env = "0.201.0"
tracing = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-env = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-core/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use anyhow::{anyhow, bail, Context, Result};
use serde::{Deserialize, Serialize};
use swc_core::ecma::preset_env::{Version, Versions};
use swc_ecma_preset_env::{Version, Versions};
use turbo_tasks::{Value, Vc};
use turbo_tasks_env::ProcessEnv;

Expand Down
23 changes: 8 additions & 15 deletions crates/turbopack-css/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,20 @@ indoc = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
swc_atoms = "0.5.9"
swc_common = "0.32.1"
swc_css_ast = { version = "0.139.1", features = ["serde", "serde-impl"] }
swc_css_codegen = "0.149.1"
swc_css_compat = "0.25.1"
swc_css_modules = "0.27.1"
swc_css_parser = "0.148.1"
swc_css_visit = { version = "0.138.1", features = ["path"] }
turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbopack-core = { workspace = true }
turbopack-ecmascript = { workspace = true }
turbopack-swc-utils = { workspace = true }

swc_core = { workspace = true, features = [
"ecma_ast",
"css_ast",
"css_ast_serde",
"css_codegen",
"css_parser",
"css_utils",
"css_visit",
"css_visit_path",
"css_compat",
"css_modules",
"common",
"common_concurrent",
] }

[build-dependencies]
turbo-tasks-build = { workspace = true }
12 changes: 4 additions & 8 deletions crates/turbopack-css/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use anyhow::Result;
use swc_core::{
common::{Globals, GLOBALS},
css::{
ast::{AtRule, AtRulePrelude, Rule},
codegen::{writer::basic::BasicCssWriter, CodeGenerator, Emit},
visit::{VisitMutWith, VisitMutWithPath},
},
};
use swc_common::{Globals, GLOBALS};
use swc_css_ast::{AtRule, AtRulePrelude, Rule};
use swc_css_codegen::{writer::basic::BasicCssWriter, CodeGenerator, Emit};
use swc_css_visit::{VisitMutWith, VisitMutWithPath};
use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
Expand Down
26 changes: 13 additions & 13 deletions crates/turbopack-css/src/code_gen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use swc_core::css::visit::{AstParentKind, VisitMut};
use swc_css_visit::{AstParentKind, VisitMut};
use turbo_tasks::Vc;
use turbopack_core::chunk::ChunkingContext;

Expand Down Expand Up @@ -55,62 +55,62 @@ macro_rules! create_visitor {
};
($ast_path:expr, $name:ident($arg:ident: &mut $ty:ident) $b:block) => {
$crate::create_visitor!(__ $crate::code_gen::path_to(&$ast_path, |n| {
matches!(n, swc_core::css::visit::AstParentKind::$ty(_))
matches!(n, swc_css_visit::AstParentKind::$ty(_))
}), $name($arg: &mut $ty) $b)
};
(__ $ast_path:expr, $name:ident($arg:ident: &mut $ty:ident) $b:block) => {{
struct Visitor<T: Fn(&mut swc_core::css::ast::$ty) + Send + Sync> {
struct Visitor<T: Fn(&mut swc_css_ast::$ty) + Send + Sync> {
$name: T,
}

impl<T: Fn(&mut swc_core::css::ast::$ty) + Send + Sync> $crate::code_gen::VisitorFactory
impl<T: Fn(&mut swc_css_ast::$ty) + Send + Sync> $crate::code_gen::VisitorFactory
for Box<Visitor<T>>
{
fn create<'a>(&'a self) -> Box<dyn swc_core::css::visit::VisitMut + Send + Sync + 'a> {
fn create<'a>(&'a self) -> Box<dyn swc_css_visit::VisitMut + Send + Sync + 'a> {
Box::new(&**self)
}
}

impl<'a, T: Fn(&mut swc_core::css::ast::$ty) + Send + Sync> swc_core::css::visit::VisitMut
impl<'a, T: Fn(&mut swc_css_ast::$ty) + Send + Sync> swc_css_visit::VisitMut
for &'a Visitor<T>
{
fn $name(&mut self, $arg: &mut swc_core::css::ast::$ty) {
fn $name(&mut self, $arg: &mut swc_css_ast::$ty) {
(self.$name)($arg);
}
}

(
$ast_path,
Box::new(Box::new(Visitor {
$name: move |$arg: &mut swc_core::css::ast::$ty| $b,
$name: move |$arg: &mut swc_css_ast::$ty| $b,
})) as Box<dyn $crate::code_gen::VisitorFactory>,
)
}};
(visit_mut_stylesheet($arg:ident: &mut Stylesheet) $b:block) => {{
struct Visitor<T: Fn(&mut swc_core::css::ast::Stylesheet) + Send + Sync> {
struct Visitor<T: Fn(&mut swc_css_ast::Stylesheet) + Send + Sync> {
visit_mut_stylesheet: T,
}

impl<T: Fn(&mut swc_core::css::ast::Stylesheet) + Send + Sync> $crate::code_gen::VisitorFactory
impl<T: Fn(&mut swc_css_ast::Stylesheet) + Send + Sync> $crate::code_gen::VisitorFactory
for Box<Visitor<T>>
{
fn create<'a>(&'a self) -> Box<dyn VisitMut + Send + Sync + 'a> {
Box::new(&**self)
}
}

impl<'a, T: Fn(&mut swc_core::css::ast::Stylesheet) + Send + Sync> swc_core::css::visit::VisitMut
impl<'a, T: Fn(&mut swc_css_ast::Stylesheet) + Send + Sync> swc_css_visit::VisitMut
for &'a Visitor<T>
{
fn visit_mut_stylesheet(&mut self, $arg: &mut swc_core::css::ast::Stylesheet) {
fn visit_mut_stylesheet(&mut self, $arg: &mut swc_css_ast::Stylesheet) {
(self.visit_mut_stylesheet)($arg);
}
}

(
Vec::new(),
Box::new(Box::new(Visitor {
visit_mut_stylesheet: move |$arg: &mut swc_core::css::ast::Stylesheet| $b,
visit_mut_stylesheet: move |$arg: &mut swc_css_ast::Stylesheet| $b,
})) as Box<dyn $crate::code_gen::VisitorFactory>,
)
}};
Expand Down
6 changes: 2 additions & 4 deletions crates/turbopack-css/src/module_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ use std::{fmt::Write, iter::once, sync::Arc};
use anyhow::{bail, Result};
use indexmap::IndexMap;
use indoc::formatdoc;
use swc_core::{
common::{BytePos, FileName, LineCol, SourceMap},
css::modules::CssClassName,
};
use swc_common::{BytePos, FileName, LineCol, SourceMap};
use swc_css_modules::CssClassName;
use turbo_tasks::{Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
Expand Down
20 changes: 8 additions & 12 deletions crates/turbopack-css/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ use anyhow::{Context, Result};
use indexmap::IndexMap;
use once_cell::sync::Lazy;
use regex::Regex;
use swc_core::{
common::{
errors::Handler, source_map::SourceMapGenConfig, BytePos, FileName, LineCol, SourceMap,
},
css::{
ast::Stylesheet,
modules::{CssClassName, TransformConfig},
parser::{parse_file, parser::ParserConfig},
},
ecma::atoms::JsWord,
use swc_atoms::JsWord;
use swc_common::{
errors::Handler, source_map::SourceMapGenConfig, BytePos, FileName, LineCol, SourceMap,
};
use swc_css_ast::Stylesheet;
use swc_css_modules::{CssClassName, TransformConfig};
use swc_css_parser::{parse_file, parser::ParserConfig};
use turbo_tasks::{ValueToString, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbopack_core::{
Expand Down Expand Up @@ -209,7 +205,7 @@ async fn parse_content(
let (imports, exports) = match ty {
CssModuleAssetType::Default => Default::default(),
CssModuleAssetType::Module => {
let imports = swc_core::css::modules::imports::analyze_imports(&parsed_stylesheet);
let imports = swc_css_modules::imports::analyze_imports(&parsed_stylesheet);
let basename = BASENAME_RE
.captures(fs_path.file_name())
.context("Must include basename preceding .")?
Expand All @@ -218,7 +214,7 @@ async fn parse_content(
.as_str();
// Truncate this as u32 so it's formated as 8-character hex in the suffic below
let path_hash = turbo_tasks_hash::hash_xxh3_hash64(ident_str) as u32;
let result = swc_core::css::modules::compile(
let result = swc_css_modules::compile(
&mut parsed_stylesheet,
// TODO swc_css_modules should take `impl TransformConfig + '_`
ModuleTransformConfig {
Expand Down
10 changes: 3 additions & 7 deletions crates/turbopack-css/src/path_visitor.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use std::{borrow::Cow, collections::HashMap};

use swc_core::{
common::pass::AstKindPath,
css::{
ast::*,
visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithPath},
},
};
use swc_common::pass::AstKindPath;
use swc_css_ast::*;
use swc_css_visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithPath};

use crate::code_gen::VisitorFactory;

Expand Down
Loading

0 comments on commit 5aae0ce

Please sign in to comment.