Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Swap swc_css out #5737

Closed
wants to merge 193 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
50719e5
Disable swc_css
kdy1 Aug 14, 2023
e70be50
Deps
kdy1 Aug 16, 2023
831a62e
srcmap
kdy1 Aug 21, 2023
4968bad
more
kdy1 Aug 21, 2023
a0ae878
Dep
kdy1 Aug 21, 2023
aaff75f
More
kdy1 Aug 21, 2023
d827579
more
kdy1 Aug 22, 2023
726fb0b
remove needless
kdy1 Aug 22, 2023
3df5aed
remove needless
kdy1 Aug 22, 2023
f09c083
TODO
kdy1 Aug 22, 2023
3025f62
imports
kdy1 Aug 22, 2023
5253be3
types
kdy1 Aug 22, 2023
40de136
more fix
kdy1 Aug 22, 2023
47fa8d1
More type fix
kdy1 Aug 22, 2023
84fc00c
Replace codegen
kdy1 Aug 22, 2023
2007971
hmm
kdy1 Aug 26, 2023
bfac189
Fix
kdy1 Aug 27, 2023
7bb2433
Remove `swc_core::css::ast::`
kdy1 Aug 28, 2023
0069a22
Fix more
kdy1 Aug 28, 2023
9ba2fac
Replace trait path
kdy1 Aug 28, 2023
64b8719
trait
kdy1 Aug 28, 2023
507f81a
More work
kdy1 Aug 28, 2023
2861661
More work
kdy1 Aug 28, 2023
11b5df6
fixup
kdy1 Aug 28, 2023
df75797
Fix more
kdy1 Aug 28, 2023
119335c
Fix more
kdy1 Aug 28, 2023
6967918
Visitor
kdy1 Aug 28, 2023
59df005
okay
kdy1 Aug 28, 2023
7b01e98
More typedef
kdy1 Aug 29, 2023
c90ed37
traits
kdy1 Aug 29, 2023
17a0bc0
More fix
kdy1 Aug 29, 2023
c874df4
Hmm
kdy1 Aug 29, 2023
40bc3fb
More
kdy1 Aug 29, 2023
01f26e0
'_
kdy1 Aug 29, 2023
a3c7faf
More fix
kdy1 Aug 29, 2023
acf77b1
More work
kdy1 Aug 29, 2023
e0ab551
visit_import
kdy1 Aug 29, 2023
69ce003
More fix
kdy1 Aug 29, 2023
a1b1a07
Remove exports
kdy1 Aug 29, 2023
5338646
flatten
kdy1 Aug 29, 2023
be6f07d
patch
kdy1 Aug 31, 2023
d30479d
Hmm
kdy1 Aug 31, 2023
e376b5a
`VisitorLike`
kdy1 Sep 1, 2023
65a0aa5
Use it
kdy1 Sep 1, 2023
bc5aad7
$crate::code_gen::VisitorLike<'a>
kdy1 Sep 1, 2023
cc0ddde
`visit()`
kdy1 Sep 1, 2023
8eecd94
more
kdy1 Sep 3, 2023
e422924
WIP
kdy1 Sep 3, 2023
3b96f7b
`Visitor`
kdy1 Sep 3, 2023
a0fef96
Dep
kdy1 Sep 3, 2023
d8573df
More fix
kdy1 Sep 3, 2023
a87aaf1
More traits
kdy1 Sep 3, 2023
4d174d4
visitor retutn type
kdy1 Sep 3, 2023
8d51e14
serde
kdy1 Sep 3, 2023
c066ac6
More fix
kdy1 Sep 3, 2023
814d756
More
kdy1 Sep 3, 2023
a3e30c2
Dep
kdy1 Sep 3, 2023
460cd19
More
kdy1 Sep 3, 2023
53f9cab
Remove patch
kdy1 Sep 3, 2023
ae7e5f1
`TYPES`
kdy1 Sep 3, 2023
81c2f27
More
kdy1 Sep 3, 2023
a6b89d2
Remove `visit_if_required`
kdy1 Sep 3, 2023
03724f8
More
kdy1 Sep 3, 2023
86afd8e
Visitor
kdy1 Sep 3, 2023
4a47fc5
`process_css`
kdy1 Sep 5, 2023
65fce13
`process_content`
kdy1 Sep 5, 2023
c5b9ec2
Remove `parse_css`
kdy1 Sep 5, 2023
73765dd
More work for removal
kdy1 Sep 5, 2023
b53b25e
More work for removal
kdy1 Sep 5, 2023
c3423e7
Hmm
kdy1 Sep 5, 2023
1de6d6f
`ProcessCss`
kdy1 Sep 5, 2023
8e3e4af
`classes`
kdy1 Sep 5, 2023
9b407a2
Process
kdy1 Sep 5, 2023
793b6ba
Fix `classes()`
kdy1 Sep 5, 2023
c10999b
Remove unused
kdy1 Sep 5, 2023
2205335
More fix
kdy1 Sep 5, 2023
5eb2986
TODOx
kdy1 Sep 5, 2023
5ea0311
More
kdy1 Sep 5, 2023
68afaa6
ParseCssResultSourceMap
kdy1 Sep 5, 2023
3f6a586
DependencyOptions
kdy1 Sep 5, 2023
9ce02e6
`ProcessCssResultSourceMap`
kdy1 Sep 5, 2023
17af54a
fix
kdy1 Sep 5, 2023
4fc6a9c
`soruce_map`
kdy1 Sep 5, 2023
8f9e9f4
USe `Vc`
kdy1 Sep 5, 2023
056bac8
More fix
kdy1 Sep 5, 2023
5bb5350
More fix
kdy1 Sep 5, 2023
3e0543c
More fix
kdy1 Sep 5, 2023
490a0bf
More
kdy1 Sep 5, 2023
ce39930
Move
kdy1 Sep 5, 2023
7c248d8
CssModuleReference
kdy1 Sep 5, 2023
db3857d
Hmm
kdy1 Sep 5, 2023
6b7db4c
`module_references`
kdy1 Sep 5, 2023
56f857f
Fix
kdy1 Sep 5, 2023
7d3414d
fix
kdy1 Sep 5, 2023
da8945c
`analyze_references`
kdy1 Sep 5, 2023
223c727
Well, restore
kdy1 Sep 5, 2023
ab006c3
Remove visitors
kdy1 Sep 5, 2023
1127c06
more
kdy1 Sep 5, 2023
8f8a54a
fix
kdy1 Sep 5, 2023
b425c0b
Vec<T>
kdy1 Sep 5, 2023
2c22042
More
kdy1 Sep 5, 2023
7ced556
More fix
kdy1 Sep 5, 2023
57123b5
typo
kdy1 Sep 5, 2023
37c7d1b
more fix
kdy1 Sep 5, 2023
fddece6
`stylesheet_into_static`
kdy1 Sep 5, 2023
cc26e2c
more
kdy1 Sep 5, 2023
6997610
eq
kdy1 Sep 6, 2023
9caaf3f
Fix import attr
kdy1 Sep 6, 2023
bf10679
Some fix
kdy1 Sep 6, 2023
d41f4bd
More work
kdy1 Sep 6, 2023
c99dd59
Remove AstPath
kdy1 Sep 6, 2023
e75141a
Vec<(String, Vc<Box<dyn ModuleReference>>)>
kdy1 Sep 6, 2023
e634c1a
`analyze_references`
kdy1 Sep 6, 2023
5afb48d
Mroe
kdy1 Sep 6, 2023
97b27c0
almost
kdy1 Sep 6, 2023
86c01e1
Split
kdy1 Sep 6, 2023
d1843ba
More
kdy1 Sep 6, 2023
e559ac8
`finalize_css`
kdy1 Sep 6, 2023
b28e9ff
More
kdy1 Sep 6, 2023
f284cd7
`IssueSource`
kdy1 Sep 6, 2023
9b0ac63
`IssueSource::new`
kdy1 Sep 6, 2023
56b46fc
More
kdy1 Sep 6, 2023
d60efc9
Use chunking contextx
kdy1 Sep 6, 2023
f04158e
Really...
kdy1 Sep 6, 2023
29b56e2
Rename
kdy1 Sep 6, 2023
1e24ec4
Rename
kdy1 Sep 6, 2023
32aa885
Rename
kdy1 Sep 6, 2023
64f8f3f
`get_css_with_placeholder`
kdy1 Sep 19, 2023
c737b4a
Use `get_css_with_placeholder`
kdy1 Sep 19, 2023
6a3b5c7
Fix types
kdy1 Sep 19, 2023
53e7b4d
fixup
kdy1 Sep 19, 2023
7f4936d
raw
kdy1 Sep 19, 2023
9bef1c8
fix
kdy1 Sep 19, 2023
9c55e49
`CssWithPlaceholderResult`
kdy1 Sep 19, 2023
a7c7561
Fix compilation
kdy1 Sep 19, 2023
bce7a2c
disable serde
kdy1 Sep 19, 2023
501bc32
fmt
kdy1 Sep 21, 2023
b4651c8
More work
kdy1 Sep 21, 2023
b8c0c08
More work
kdy1 Sep 21, 2023
46a93bf
More work
kdy1 Sep 21, 2023
65aef76
More work
kdy1 Sep 21, 2023
af5b498
Lints
kdy1 Sep 21, 2023
637441e
fix
kdy1 Oct 6, 2023
5e33847
Reexport
kdy1 Oct 6, 2023
58c338b
WIP: lifetime
kdy1 Oct 6, 2023
21b05d5
Update lightningcss
kdy1 Oct 13, 2023
750c888
fix
kdy1 Oct 13, 2023
3216cde
cleanup
kdy1 Oct 13, 2023
f8d4d8e
into_owned
kdy1 Oct 13, 2023
e88f70e
fix
kdy1 Oct 16, 2023
41dc8e9
`__turbopack_placeholder__`
kdy1 Oct 16, 2023
631c011
Fix panic
kdy1 Oct 16, 2023
9f4c72d
imports
kdy1 Oct 16, 2023
da3f333
remove useles fieldx
kdy1 Oct 16, 2023
a014d92
url refs
kdy1 Oct 16, 2023
c609f2c
ㅑㅈ
kdy1 Oct 17, 2023
8f9f4bf
Use mutated
kdy1 Oct 17, 2023
76ee96b
Remove one dbg
kdy1 Oct 17, 2023
c2f4d4e
Preserve ParserOption
kdy1 Oct 17, 2023
582f67b
sources
kdy1 Oct 17, 2023
e5e9374
process nesting
kdy1 Oct 17, 2023
a285be9
Remove `@`
kdy1 Oct 18, 2023
67edcd3
fixup
kdy1 Oct 18, 2023
fb34c08
class name
kdy1 Oct 18, 2023
04c6583
Remove `dbg!`
kdy1 Oct 19, 2023
b5a71e4
deterministic
kdy1 Oct 19, 2023
31d8919
clippy --fix
kdy1 Oct 19, 2023
ab68679
clippy
kdy1 Oct 19, 2023
2db3163
expose more
kdy1 Oct 22, 2023
f255b22
nessage
kdy1 Oct 22, 2023
d2ae67b
Add dbg
kdy1 Oct 25, 2023
c8e46df
Add dbg
kdy1 Oct 25, 2023
fe094b9
Add dbg
kdy1 Oct 25, 2023
6532f78
Add dbg
kdy1 Oct 25, 2023
b2881cb
[WIP] Make visitor work
kdy1 Oct 25, 2023
8992065
Add dbg
kdy1 Oct 25, 2023
dfedc4b
Remove transmute
kdy1 Oct 25, 2023
c74474a
Add dbg
kdy1 Oct 25, 2023
aabc9fc
Remove leak
kdy1 Oct 25, 2023
f107d77
Make it end with local
kdy1 Oct 25, 2023
133e173
Remove dbg!
kdy1 Oct 25, 2023
3c14e72
Patch lightningcss
kdy1 Oct 25, 2023
59655de
cargo lockfile
kdy1 Oct 25, 2023
1e075f3
Renove dbg!
kdy1 Oct 25, 2023
82575a5
Remove unused
kdy1 Oct 25, 2023
1ce86cb
Add dbg
kdy1 Oct 25, 2023
7cd2f28
Remove vdbg
kdy1 Oct 30, 2023
6ca8450
Remove patch
kdy1 Oct 30, 2023
4925639
Add dbg
kdy1 Oct 31, 2023
22f12d3
Add dbg
kdy1 Oct 31, 2023
df47b0c
Update swc crates
kdy1 Nov 15, 2023
43ae669
cargo lockfile
kdy1 Nov 15, 2023
0412a5f
fixup for rebase
kdy1 Nov 15, 2023
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
338 changes: 150 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ lto = "off"
[workspace.dependencies]
async-recursion = "1.0.2"
# Keep consistent with preset_env_base through swc_core
browserslist-rs = { version = "0.12.2" }
browserslist-rs = { version = "0.13.0" }

mdxjs = "0.1.19"
modularize_imports = { version = "0.55.0" }
styled_components = { version = "0.82.0" }
styled_jsx = { version = "0.59.0" }
swc_core = { version = "0.86.40", features = [
modularize_imports = { version = "0.56.0" }
styled_components = { version = "0.83.0" }
styled_jsx = { version = "0.60.0" }
swc_core = { version = "0.86.60", features = [
"ecma_loader_lru",
"ecma_loader_parking_lot",
] }
swc_emotion = { version = "0.58.0" }
swc_relay = { version = "0.30.0" }
testing = { version = "0.35.7" }
swc_emotion = { version = "0.59.0" }
swc_relay = { version = "0.31.0" }
testing = { version = "0.35.10" }

auto-hash-map = { path = "crates/turbo-tasks-auto-hash-map" }
node-file-trace = { path = "crates/node-file-trace", default-features = false }
Expand Down Expand Up @@ -246,3 +246,4 @@ url = "2.2.2"
urlencoding = "2.1.2"
webbrowser = "0.8.7"
which = "4.4.0"

12 changes: 12 additions & 0 deletions crates/turbopack-core/src/issue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ impl IssueSource {
})
}

#[turbo_tasks::function]
pub fn from_line_col(
source: Vc<Box<dyn Source>>,
start: SourcePos,
end: SourcePos,
) -> Vc<Self> {
Self::cell(IssueSource {
source,
range: Some(SourceRange::LineColumn(start, end).cell()),
})
}

/// Create a [`IssueSource`] from byte offsets given by an swc ast node
/// span.
///
Expand Down
3 changes: 2 additions & 1 deletion crates/turbopack-core/src/source_pos.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use turbo_tasks::trace::TraceRawVcs;
use turbo_tasks::{trace::TraceRawVcs, TaskInput};
use turbo_tasks_hash::DeterministicHash;

/// LINE FEED (LF), one of the basic JS line terminators.
Expand All @@ -16,6 +16,7 @@ const U8_CR: u8 = 0x0D;
Clone,
PartialOrd,
Ord,
TaskInput,
TraceRawVcs,
Serialize,
Deserialize,
Expand Down
17 changes: 8 additions & 9 deletions crates/turbopack-css/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
lightningcss = { version = "1.0.0-alpha.50", features = [
"serde",
"visitor",
"into_owned",
] }
once_cell = { workspace = true }
parcel_selectors = "0.26.0"
regex = { workspace = true }
serde = { workspace = true }
turbo-tasks = { workspace = true }
Expand All @@ -24,17 +30,10 @@ turbopack-core = { workspace = true }
turbopack-ecmascript = { workspace = true }
turbopack-swc-utils = { workspace = true }

parcel_sourcemap = "2.1.1"
smallvec = "1.11.0"
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",
] }
Expand Down
124 changes: 45 additions & 79 deletions crates/turbopack-css/src/asset.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
use anyhow::Result;
use swc_core::{
common::{Globals, GLOBALS},
css::{
ast::{AtRule, AtRulePrelude, Rule},
codegen::{writer::basic::BasicCssWriter, CodeGenerator, Emit},
visit::{VisitMutWith, VisitMutWithPath},
},
};
use turbo_tasks::{TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
Expand All @@ -23,12 +15,11 @@ use turbopack_core::{
use crate::{
chunk::{CssChunkItem, CssChunkItemContent, CssChunkPlaceable, CssChunkType, CssImport},
code_gen::CodeGenerateable,
parse::{parse_css, ParseCss, ParseCssResult, ParseCssResultSourceMap},
path_visitor::ApplyVisitors,
references::{
analyze_css_stylesheet, compose::CssModuleComposeReference, import::ImportAssetReference,
process::{
finalize_css, parse_css, process_css_with_placeholder, CssWithPlaceholderResult,
FinalCssResult, ParseCss, ParseCssResult, ProcessCss,
},
transform::CssInputTransforms,
references::{compose::CssModuleComposeReference, import::ImportAssetReference},
CssModuleAssetType,
};

Expand All @@ -42,7 +33,6 @@ fn modifier() -> Vc<String> {
pub struct CssModuleAsset {
source: Vc<Box<dyn Source>>,
asset_context: Vc<Box<dyn AssetContext>>,
transforms: Vc<CssInputTransforms>,
ty: CssModuleAssetType,
}

Expand All @@ -53,13 +43,11 @@ impl CssModuleAsset {
pub fn new(
source: Vc<Box<dyn Source>>,
asset_context: Vc<Box<dyn AssetContext>>,
transforms: Vc<CssInputTransforms>,
ty: CssModuleAssetType,
) -> Vc<Self> {
Self::cell(CssModuleAsset {
source,
asset_context,
transforms,
ty,
})
}
Expand All @@ -74,8 +62,34 @@ impl CssModuleAsset {
#[turbo_tasks::value_impl]
impl ParseCss for CssModuleAsset {
#[turbo_tasks::function]
fn parse_css(&self) -> Vc<ParseCssResult> {
parse_css(self.source, self.ty, self.transforms)
async fn parse_css(self: Vc<Self>) -> Result<Vc<ParseCssResult>> {
let this = self.await?;

Ok(parse_css(this.source, Vc::upcast(self), this.ty))
}
}

#[turbo_tasks::value_impl]
impl ProcessCss for CssModuleAsset {
#[turbo_tasks::function]
async fn get_css_with_placeholder(self: Vc<Self>) -> Result<Vc<CssWithPlaceholderResult>> {
let parse_result = self.parse_css();

dbg!("CssModuleAsset::get_css_with_placeholder");

Ok(process_css_with_placeholder(parse_result))
}

#[turbo_tasks::function]
async fn finalize_css(
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<FinalCssResult>> {
let process_result = self.get_css_with_placeholder();

dbg!("CssModuleAsset::finalize_css");

Ok(finalize_css(process_result, chunking_context))
}
}

Expand All @@ -91,14 +105,14 @@ impl Module for CssModuleAsset {

#[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let this = self.await?;
let result = self.parse_css().await?;
// TODO: include CSS source map
Ok(analyze_css_stylesheet(
this.source,
Vc::upcast(self),
this.ty,
this.transforms,
))

match &*result {
ParseCssResult::Ok { references, .. } => Ok(*references),
ParseCssResult::Unparseable => Ok(ModuleReferences::empty()),
ParseCssResult::NotFound => Ok(ModuleReferences::empty()),
}
}
}

Expand Down Expand Up @@ -238,72 +252,24 @@ impl CssChunkItem for CssModuleChunkItem {
let code_gens = code_gens.into_iter().try_join().await?;
let code_gens = code_gens.iter().map(|cg| &**cg).collect::<Vec<_>>();
// TOOD use interval tree with references into "code_gens"
let mut visitors = Vec::new();
let mut root_visitors = Vec::new();
for code_gen in code_gens {
for import in &code_gen.imports {
imports.push(import.clone());
}

for (path, visitor) in code_gen.visitors.iter() {
if path.is_empty() {
root_visitors.push(&**visitor);
} else {
visitors.push((path, &**visitor));
}
}
}

let parsed = self.module.parse_css().await?;
let result = self.module.finalize_css(chunking_context).await?;

if let ParseCssResult::Ok {
stylesheet,
if let FinalCssResult::Ok {
output_code,
source_map,
..
} = &*parsed
} = &*result
{
let mut stylesheet = stylesheet.clone();

let globals = Globals::new();
GLOBALS.set(&globals, || {
if !visitors.is_empty() {
stylesheet.visit_mut_with_path(
&mut ApplyVisitors::new(visitors),
&mut Default::default(),
);
}
for visitor in root_visitors {
stylesheet.visit_mut_with(&mut visitor.create());
}
});

// remove imports
stylesheet.rules.retain(|r| {
!matches!(
r,
&Rule::AtRule(box AtRule {
prelude: Some(box AtRulePrelude::ImportPrelude(_)),
..
})
)
});

let mut code_string = String::new();
let mut srcmap = vec![];

let mut code_gen = CodeGenerator::new(
BasicCssWriter::new(&mut code_string, Some(&mut srcmap), Default::default()),
Default::default(),
);

code_gen.emit(&stylesheet)?;

let srcmap = ParseCssResultSourceMap::new(source_map.clone(), srcmap).cell();

Ok(CssChunkItemContent {
inner_code: code_string.into(),
inner_code: output_code.to_owned().into(),
imports,
source_map: Some(srcmap),
source_map: Some(*source_map),
}
.into())
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use turbopack_core::{
use writer::expand_imports;

use self::{single_item_chunk::chunk::SingleItemCssChunk, source_map::CssChunkSourceMapAsset};
use crate::{parse::ParseCssResultSourceMap, util::stringify_js, ImportAssetReference};
use crate::{process::ParseCssResultSourceMap, util::stringify_js, ImportAssetReference};

#[turbo_tasks::value]
pub struct CssChunk {
Expand Down
Loading
Loading