diff --git a/Cargo.lock b/Cargo.lock index 3313e875d7133..2c195a0a840c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -770,9 +770,9 @@ dependencies = [ [[package]] name = "binding_macros" -version = "0.60.40" +version = "0.60.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc6d576fb61191dccafc3c5c69fcfe579606c6e64b71f3b57865040a8eff6ad" +checksum = "6fdde7535e3cb901527bb60f69b10958215f8dafde044f2c57fd9fd7cb02e49b" dependencies = [ "anyhow", "console_error_panic_hook", @@ -867,27 +867,23 @@ dependencies = [ [[package]] name = "browserslist-rs" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bda9b4595376bf255f68dafb5dcc5b0e2842b38dc2a7b52c4e0bfe9fd1c651" +checksum = "e33066f72a558361eeb1077b0aff0f1dce1ac75bdc20b38a642f155f767b2824" dependencies = [ "ahash 0.8.6", "anyhow", "chrono", "either", - "getrandom", "itertools", - "js-sys", "nom", "once_cell", "quote", "serde", - "serde-wasm-bindgen", "serde_json", "string_cache", "string_cache_codegen", "thiserror", - "wasm-bindgen", ] [[package]] @@ -1909,7 +1905,8 @@ dependencies = [ "cssparser-macros", "dtoa-short", "itoa", - "phf 0.10.1", + "phf 0.11.2", + "serde", "smallvec", ] @@ -3224,9 +3221,9 @@ dependencies = [ [[package]] name = "hstr" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f8eaaa1bccc114f3ed94b7b66f0195cbf48151402d3efc27f7f6e362042416" +checksum = "de90d3db62411eb62eddabe402d706ac4970f7ac8d088c05f11069cad9be9857" dependencies = [ "new_debug_unreachable", "once_cell", @@ -4078,9 +4075,9 @@ dependencies = [ [[package]] name = "lightningcss" -version = "1.0.0-alpha.49" +version = "1.0.0-alpha.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06476660ee1e593a2672e4a342a1289708fd9936dcdf3e74433ad078145e9e3d" +checksum = "c2999490cc10a59ad8a87d731791a5d438d2d025e3f137aa7d4c23e1827985b0" dependencies = [ "ahash 0.7.6", "bitflags 2.4.0", @@ -4503,9 +4500,9 @@ dependencies = [ [[package]] name = "modularize_imports" -version = "0.55.0" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b7185e6577ae96612f3ad16f77e26631f1a3227a7baff75c2113e336a28111" +checksum = "b938c4ffaa1180f64186fd52f51dac5998e68c8c29f3ce4a0da952b873ebe021" dependencies = [ "convert_case 0.5.0", "handlebars", @@ -5077,9 +5074,9 @@ dependencies = [ [[package]] name = "parcel_selectors" -version = "0.26.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f000cdd23df6cebe999cf2b02a3bf40d55758f74883d7fd43a33690565618c8" +checksum = "05d74befe2d076330d9a58bf9ca2da424568724ab278adf15fb5718253133887" dependencies = [ "bitflags 2.4.0", "cssparser", @@ -5088,6 +5085,7 @@ dependencies = [ "phf 0.10.1", "phf_codegen", "precomputed-hash", + "serde", "smallvec", "static-self", ] @@ -5611,9 +5609,9 @@ dependencies = [ [[package]] name = "preset_env_base" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a83fddb10b466da126eaf6bf444c878141f691b23c2de6004bf1ef83c38e8e6" +checksum = "3277c43d5ab99ddc71f4a301686c50a1a155339feb0cbe41492aabc211ef474f" dependencies = [ "ahash 0.8.6", "anyhow", @@ -7027,9 +7025,9 @@ dependencies = [ [[package]] name = "static-self" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2978fa810a31711d7162d0bb843df1f36d84e393e335ce31ec2c485b2464c44" +checksum = "253e76c8c993a7b1b201b0539228b334582153cd4364292822d2c30776d469c7" dependencies = [ "smallvec", "static-self-derive", @@ -7037,9 +7035,9 @@ dependencies = [ [[package]] name = "static-self-derive" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc53c080b79432d9babd26457df68fb4b002cc7d2ce36a1a5195091cf9fecc14" +checksum = "5268c96d4b907c558a9a52d8492522d6c7b559651a5e1d8f2d551e461b9425d5" dependencies = [ "proc-macro2", "quote", @@ -7166,9 +7164,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.82.0" +version = "0.83.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27e27c25eeaa8ddea7f9094187417251cdedcd6e31a97404c964f724bf5fbaf0" +checksum = "97aa75a37e4afde897446c920d4569ff18fbf32d2f8f3d9d0f109da674a9cb15" dependencies = [ "Inflector", "once_cell", @@ -7184,13 +7182,14 @@ dependencies = [ [[package]] name = "styled_jsx" -version = "0.59.0" +version = "0.60.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7aa926750af235c32342376eaf5f997595b381f4202908e40a71bf3708c284" +checksum = "0d5d705b3f746558b25d9badb4e2af0d106688880a7a7efd7cc41b4af7d42fd4" dependencies = [ "easy-error", "lightningcss", "parcel_selectors", + "preset_env_base", "serde", "swc_common", "swc_css_ast", @@ -7257,9 +7256,9 @@ dependencies = [ [[package]] name = "swc" -version = "0.269.35" +version = "0.269.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fa4c765e8d643246054b4f4ad83bcf9cb7a7715e094c3f54c5c51754901c24" +checksum = "05849a2ce200bb82aec323cb672d9ecb9e9029316e3d44a0a7d510572d5e5501" dependencies = [ "anyhow", "base64 0.13.1", @@ -7320,9 +7319,9 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.6.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad769aeefe4cf20c3ec29e714c91870fa89307faa4280a644c4c65b5cc692" +checksum = "b8a9e1b6d97f27b6abe5571f8fe3bdbd2fa987299fc2126450c7cde6214896ef" dependencies = [ "bytecheck", "hstr", @@ -7334,9 +7333,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.222.31" +version = "0.222.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a8e4c2e870949ef919693a16a7bae57e30b75bec662e0e40bba131b5884c3fb" +checksum = "cdab096f62e461d4524ddf65978e69393db703356a97f4b558f2a4f212a1b7dd" dependencies = [ "anyhow", "crc", @@ -7380,9 +7379,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.33.5" +version = "0.33.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b33eb74d42276b5f37ac78ed470dd206ece8a2687cfe3a681444f66c29a061f" +checksum = "49fba1ce1d44f142b9e8212a6360fc7818e2c99c7f5ebe8b4fa4061c5764e48e" dependencies = [ "ahash 0.8.6", "anyhow", @@ -7414,9 +7413,9 @@ dependencies = [ [[package]] name = "swc_compiler_base" -version = "0.3.37" +version = "0.3.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5aa27756be34b2dcba6e632ac35e1416aefaef7aa1cf9e32c54bdd482a8b5ab" +checksum = "4ccb251385a0ab21b4470b2e9088c3d992f4cb3c9a3a80a46ee802e4f6b22dbb" dependencies = [ "anyhow", "base64 0.13.1", @@ -7463,9 +7462,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.86.40" +version = "0.86.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22da79427085d5ba7ea5ec14f104f8af66bf479655475cd901d292e87b7b3a73" +checksum = "f718c699aac95c69bad3ba5e81e554407c4195ff339e61b96686abab4bfed40c" dependencies = [ "binding_macros", "swc", @@ -7473,13 +7472,6 @@ dependencies = [ "swc_bundler", "swc_cached", "swc_common", - "swc_css_ast", - "swc_css_codegen", - "swc_css_compat", - "swc_css_modules", - "swc_css_parser", - "swc_css_utils", - "swc_css_visit", "swc_ecma_ast", "swc_ecma_codegen", "swc_ecma_loader", @@ -7496,7 +7488,7 @@ dependencies = [ "swc_ecma_transforms_typescript", "swc_ecma_utils", "swc_ecma_visit", - "swc_node_base", + "swc_malloc", "swc_nodejs_common", "swc_plugin_proxy", "swc_plugin_runner", @@ -7506,12 +7498,11 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.140.6" +version = "0.140.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec6ea3b519c6e44a16f680036f5faadcfd31d6bdad0762f19d4f15c2e6d013a" +checksum = "24e33aed6900a6478ec9bffa7cdf5249ea79b55fcc86b34872212800086504fa" dependencies = [ "is-macro", - "serde", "string_enum", "swc_atoms", "swc_common", @@ -7519,9 +7510,9 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.151.9" +version = "0.151.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0b313c0ca16ddb367288d17dd77d491c7c6ad62eb297448a0ce0ae1c3767592" +checksum = "71a04ac7b5672d740340ae09a6bcedad753d45ae9d4ec3b935617c20dce90094" dependencies = [ "auto_impl", "bitflags 2.4.0", @@ -7547,28 +7538,11 @@ dependencies = [ "syn 2.0.32", ] -[[package]] -name = "swc_css_compat" -version = "0.27.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8448e5731f3d2d2d91b28f11ca2c1ff0d92e7f8f687e3bba20857b0b85abc2fb" -dependencies = [ - "bitflags 2.4.0", - "once_cell", - "serde", - "serde_json", - "swc_atoms", - "swc_common", - "swc_css_ast", - "swc_css_utils", - "swc_css_visit", -] - [[package]] name = "swc_css_minifier" -version = "0.116.9" +version = "0.116.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfe9803a0b7562ac8e0baebca15fc228fdd3dbc3c88d4fc5e85545b5f1f9597f" +checksum = "f758a030c634a2dfd78c44ebefbb64c9155e086a72d15784ad3ee91c1fa66485" dependencies = [ "serde", "swc_atoms", @@ -7578,27 +7552,11 @@ dependencies = [ "swc_css_visit", ] -[[package]] -name = "swc_css_modules" -version = "0.29.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064878840d63575702f64e4f22e7c7866e5d61e3aa026237d5acd7f3b6ce547e" -dependencies = [ - "rustc-hash", - "serde", - "swc_atoms", - "swc_common", - "swc_css_ast", - "swc_css_codegen", - "swc_css_parser", - "swc_css_visit", -] - [[package]] name = "swc_css_parser" -version = "0.150.9" +version = "0.150.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7ae34661b2c08cb60947e05735d8d6db255b5ee2484d2ebdbc5d7de0f14b121" +checksum = "5a3a21dc7405cbb2f7c923e0759bc3ab4a561780b638e9e79c96675341fd89d0" dependencies = [ "lexical", "serde", @@ -7609,9 +7567,9 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.153.10" +version = "0.153.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28769f899a6c6dc208221c0272b58576b6c8cbe8988395efae913eeba5e4834e" +checksum = "18ee513d43dca0debd04de9f2df55292778f982ec27d02bc503203bb644e409d" dependencies = [ "once_cell", "preset_env_base", @@ -7626,9 +7584,9 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.137.6" +version = "0.137.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4e64f7d7de2158bbedd12b309089f8bb94ce60fc45dde37fa0447da8b6fa624" +checksum = "24fec9a00252d393ca43383109f38a68d64c326ca967b40ec35499ef0c57a7dc" dependencies = [ "once_cell", "serde", @@ -7641,9 +7599,9 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.139.6" +version = "0.139.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a1b09ebb933e50d23d5d583e783bf35c678b7ad7072a6d5f8f47e72aceeb6b5" +checksum = "5f4827e116e4e417a5f7f995ef3e2ef83ddef034418667c5e1ed169f072053c2" dependencies = [ "serde", "swc_atoms", @@ -7654,9 +7612,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.110.6" +version = "0.110.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f902ec313c3c442bfbb5e999326582fccfb83b7db6c171819495b485f4057f01" +checksum = "4cefcc1c71bf00e48da7b65801d1fccf7eed2b7fa1fc5c4848ed09801bfe2403" dependencies = [ "bitflags 2.4.0", "bytecheck", @@ -7674,9 +7632,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.146.16" +version = "0.146.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6c8efbcee4acb346c15e6d9470f47b94053a3d61f1677d5b7d677c8a79e6a6f" +checksum = "c45a0beb1293372354b57bbafa06bf5ca6c3fab4bfd157b54d65db96612232eb" dependencies = [ "memchr", "num-bigint", @@ -7706,9 +7664,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_bugfixes" -version = "0.1.24" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7475da4769ed5be961cd86a4cb0a0629ff55d11ff044a366732a64e02119d3cb" +checksum = "5521b96f87e13fd10f2a7c3bf4f8f80ed2cc3a532a4c9b6625a724d8e3083e85" dependencies = [ "swc_atoms", "swc_common", @@ -7723,9 +7681,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_common" -version = "0.1.16" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46ea85927ab506fb1f42a9c0c2cac73d8f0a4a28f2ec7aace836aba0ebfd62f6" +checksum = "c1889c73fde0612659b59359a0f4e42be73b623cba895fd88957b60471559d04" dependencies = [ "swc_common", "swc_ecma_ast", @@ -7736,9 +7694,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2015" -version = "0.1.24" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0904f4a35212c021e40745c6aa71b44c0bb2827ecdd836e4064d34db5cc6437" +checksum = "ea1c8835b35efa6b3264cf3330e5ecd3abde691e3037fac724fe73cf26fb4a9f" dependencies = [ "arrayvec 0.7.4", "indexmap 1.9.3", @@ -7762,9 +7720,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2016" -version = "0.1.22" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "587dad924fc00d268899771ae942a84c87c493dadc1a024d831eb464dcf330f9" +checksum = "58265ca3e2bbeefe595c3a77cbca10d44d877cf006429529ee6a7245122a7f84" dependencies = [ "swc_atoms", "swc_common", @@ -7779,9 +7737,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2017" -version = "0.1.22" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10bf1d18316b202f2a75dcd364f49c3bd6406d58f1c2cf308388c782773bbc66" +checksum = "590e3ea46d074bd8ebd57d0f45d3c8dcbafacf18e58704abd034ebcf73f120ad" dependencies = [ "serde", "swc_atoms", @@ -7797,9 +7755,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2018" -version = "0.1.22" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62266ecd18493c9440413731606ca8d46f76d32a1df3474f20b5863a6175c9bc" +checksum = "8e8ba03ae7d980a7a09c425b8be7ef56775f7ee703cceee82cf6f6712899cfe6" dependencies = [ "serde", "swc_atoms", @@ -7816,9 +7774,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2019" -version = "0.1.22" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49646a589d7c4594b452b4133e833060fe894efc16929bdb6b7040261601e845" +checksum = "7c034b8ea66e47552fafdef3d904c53597761c91ca51174c2576c04706e38687" dependencies = [ "swc_atoms", "swc_common", @@ -7832,9 +7790,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2020" -version = "0.1.21" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53da0baf19e324757527733d3b37615bfebc2d136ee3d989c0e930c5636e090" +checksum = "5d43af0631e13dbfccf67c42105b3e07dfc620d43226128c3a0cd478b57e87de" dependencies = [ "serde", "swc_atoms", @@ -7850,9 +7808,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2021" -version = "0.1.20" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c67a4db9e67f6ff3afc5629091cf672703966d69956dcdd88aa3e859f992008" +checksum = "4623f933fea8df5e8d8be0d511b9c441c30f0601f9161b6a6660fc0f6a54aea9" dependencies = [ "swc_atoms", "swc_common", @@ -7866,9 +7824,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es2022" -version = "0.1.22" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088b968df343c7d2d5dc05dbe72124a7745126c0febe4ce201eeb0f78c10c3be" +checksum = "9e041d062041ca30fea5cb0f9c590edff6e99f3fc117c0470f12dbe5abe5412d" dependencies = [ "swc_atoms", "swc_common", @@ -7885,9 +7843,9 @@ dependencies = [ [[package]] name = "swc_ecma_compat_es3" -version = "0.1.21" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54548c16bc5198c152ab61cb62167f2c883f96cae8ec3346182f7e05235598d8" +checksum = "6102f7c0c339ed21d5be4a197332ec9b4886d0b28fd4ca15905a9ce6eec4ea83" dependencies = [ "swc_common", "swc_ecma_ast", @@ -7900,9 +7858,9 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "0.110.19" +version = "0.110.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4b20acb54ee2c48784efa3f27995c648a6f44cb58c166e0538b92075c54e10" +checksum = "04c4614dca2e8561024be8906f9a095777ad1f39a3b2b426111b96c03465af8d" dependencies = [ "phf 0.10.1", "swc_atoms", @@ -7914,9 +7872,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.89.22" +version = "0.89.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c3900597328e9e84f903dd1ba0c5d1c82a304b4ac60fa71891f221c15d0cfb" +checksum = "c783cf4cf1a5887de0e7b5fc25fab6f7bdcf7268eca671fe2fb4ff654e6b1006" dependencies = [ "auto_impl", "dashmap", @@ -7934,9 +7892,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.45.6" +version = "0.45.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a550d167cef210e34ea7ad223a3243969257c3fe0efcdbe605b390065afc4a3" +checksum = "cc83806e30310943718eef1209c388f375417bcc3e499df8820c189d92ecf05f" dependencies = [ "anyhow", "dashmap", @@ -7955,9 +7913,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.189.32" +version = "0.189.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b07fc3067a5ed6ded17b4133765b1cde0a8e8a1c30c39388e0b864e97ad27" +checksum = "1d50fedc759df341016d49a100b389cb6c1b7574e4cc65367487d5d3afc22e9e" dependencies = [ "arrayvec 0.7.4", "indexmap 1.9.3", @@ -7990,9 +7948,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.141.14" +version = "0.141.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17e2c91d688f8853ed6be8ba5ee3bdec2230b60a58b22338f3174792646c9c8" +checksum = "acfad502c2e0579e09e216da1c627d583fdbc6c8a08f2c8bd0160f9119d4246d" dependencies = [ "either", "new_debug_unreachable", @@ -8012,9 +7970,9 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.203.29" +version = "0.203.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9b8ca7733d321438e15eee673bc435cacdd4b92fd71e0b441a5cd72b0ba5d35" +checksum = "652c066e316cd2acf9bc39a151456188925a5f01e5bb00018b9bf468ee0fd734" dependencies = [ "anyhow", "dashmap", @@ -8037,9 +7995,9 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.52.14" +version = "0.52.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725e83abdb92bac059ea9a90e41710e28dc8a892141bf79a2ca836c5c562d3d8" +checksum = "51c6de18105523ee7c930178406cd324c272ae21bc549e53593105b345969e18" dependencies = [ "anyhow", "pmutil", @@ -8055,9 +8013,9 @@ dependencies = [ [[package]] name = "swc_ecma_testing" -version = "0.22.7" +version = "0.22.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea1698f37105c753803166f415569edcf34a2b82f41c9aee125d5462af40d13" +checksum = "62dc3d273ef4f7fe39b670b7f1fdd2dd33518f5de987e7f7fe9d1b44e650e891" dependencies = [ "anyhow", "hex", @@ -8068,9 +8026,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.226.29" +version = "0.226.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "529ea35a5ad6ee8add3ef15380a8e5e5a1da4cfd04e0d070f2efc4c8c2266823" +checksum = "5b020aef371703583047e8e41468c17790e5f3caf9cf1cb53b7fb91d7a8d8a70" dependencies = [ "swc_atoms", "swc_common", @@ -8088,9 +8046,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.134.22" +version = "0.134.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b27038edff04dc41a41b1976670df93470a4a88c1dc5b17e996326978b76e8c" +checksum = "1cea2778aaa7152bacc2877ce900a78f815c64630102ec8d824a8ec543ac5ef5" dependencies = [ "better_scoped_tls", "bitflags 2.4.0", @@ -8112,9 +8070,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.123.23" +version = "0.123.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76e8bf4894b46f56b37657c942529d3478224260e576ab38c641c508b805d0bb" +checksum = "75a2a98541dffaffbfecb6aaccf8d910c8e9e54576a785e431d8eb2d2c56b80a" dependencies = [ "swc_atoms", "swc_common", @@ -8126,9 +8084,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.160.28" +version = "0.160.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "407f66ce3dd22fd2bcc00876d2007aefa73183e39bbca6e19da2a083235b001a" +checksum = "2be5f5f7b7e62cd94ae24f51bf42fc33a25a3ea5a401e3da313538bfa682bdf7" dependencies = [ "arrayvec 0.7.4", "indexmap 1.9.3", @@ -8176,9 +8134,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.177.30" +version = "0.177.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a7827f522465f597d1dfd93ec8b3e389799c3d351058d0f4a272bce15c1e1a" +checksum = "ee2323576600e67365ba75f6db9fa38d18d2227921cd5cec907a2bc5f3e8a51b" dependencies = [ "Inflector", "anyhow", @@ -8203,9 +8161,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.195.29" +version = "0.195.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a1cce15248d51fd3a1b4c8a638fda8e67ffab269a6ea2a53fb3e6a05d1ff2" +checksum = "eb488266e2ed474b1315fee62396217fc62a505adfe4a29a65aa9985026e9d24" dependencies = [ "dashmap", "indexmap 1.9.3", @@ -8228,9 +8186,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.168.30" +version = "0.168.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42afc0f6df25e37c46241fe86619a561ece47bb75317ff540da04ceba81ed707" +checksum = "fa5d747160aca89b0496d0f3e5a3c7961e6f31d3b4f75a1ab52e050d894d0e12" dependencies = [ "either", "rustc-hash", @@ -8248,9 +8206,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.180.31" +version = "0.180.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7ccd4ed6b3272dff18fb088b3030215c3dd1fdc44b0b3cac96dfcd459b67af" +checksum = "21876e623cb894ca2d020c29003c8e5f619e7d345f6188eb53e39c2ce6dea783" dependencies = [ "base64 0.13.1", "dashmap", @@ -8273,9 +8231,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_testing" -version = "0.137.24" +version = "0.137.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3929c8c9820a4277b801ac796f03deddc25134bd2e34a6973a00828c87aa8bdc" +checksum = "1633020e7f46dd994e1f39c9365b852f25384cab56e527cbde645ba6742dba65" dependencies = [ "ansi_term", "anyhow", @@ -8299,9 +8257,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.185.28" +version = "0.185.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74cfc6095f0e141595aa12845d6d2f93a73108c7eacc88f0e4dd472b74e41e58" +checksum = "e64b6cf5505e05f4a3a9ef2fcb13bcd5147e16ce642a8a06f76270eb5a240434" dependencies = [ "ryu-js", "serde", @@ -8316,9 +8274,9 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.20.20" +version = "0.20.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82cab9cbafaf2d28e1b45bad1e07bf97ab230f2cdc7cb4d494908b432f79cd1b" +checksum = "e5fd3bb4cdb8813a7045eb569388386ab9a13317f5bef4a334cfe2e7018bbc29" dependencies = [ "indexmap 1.9.3", "rustc-hash", @@ -8333,9 +8291,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.124.19" +version = "0.124.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "055737e1189b2bac57aac998699b339ab839945058134ed28b7611c950e34071" +checksum = "10584648054df1b174b0ce48070f1567996141c2549906eebd12467019752c00" dependencies = [ "indexmap 1.9.3", "num_cpus", @@ -8352,9 +8310,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.96.6" +version = "0.96.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c97d88354947ba36b21b355fccb75b5fba2a2db36f00bf8327a6728257662e4f" +checksum = "21305b130986e771206c9f447c8040f9b3be47c9fbbb1f659904e223b8e1c007" dependencies = [ "num-bigint", "serde", @@ -8367,9 +8325,9 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.58.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d123bc6ff6aff8724f43542964ee726801fc205137bbf0de7f822a2f8b15f204" +checksum = "708a605ff7a722d169e800dbbb0328a82db38811d3b07cbb8ca87db27d7b3e9c" dependencies = [ "base64 0.13.1", "byteorder", @@ -8403,9 +8361,9 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.17.5" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bbfad2ff99154d20b5dd9246290f162114c836cfe8532d8d0d4c116f49ee6ce" +checksum = "4a80f674bef7baf65c979f684bbe9fa8f4e275e3b61589b62d6dc260331a102b" dependencies = [ "anyhow", "miette 4.7.1", @@ -8416,9 +8374,9 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.21.5" +version = "0.21.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175c7dced501083242106790d72119bebe84233bc24c26b59a70172967dc8231" +checksum = "392047ce047ab6f9c02ef17e7e19627c0050fe6dbb0bccd2350a92664a859c62" dependencies = [ "indexmap 1.9.3", "petgraph", @@ -8428,9 +8386,9 @@ dependencies = [ [[package]] name = "swc_graph_analyzer" -version = "0.22.7" +version = "0.22.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7090c8d9faba1e3ff6ed8f88662ac89ce410cb70f87e940fe29a06099a07c83" +checksum = "ebb1843242b0ee38517116da75576e13bcdcc8e08af288537e8745d480c31cfc" dependencies = [ "auto_impl", "petgraph", @@ -8452,10 +8410,10 @@ dependencies = [ ] [[package]] -name = "swc_node_base" -version = "0.5.9" +name = "swc_malloc" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04959e1f4b183fd193e90203e1068b5b9903b6f143362c98e6392ac238fb0345" +checksum = "675984eeb1ba9a8a712a6a442e8176dfd159727a0fa2715e43d08650d7c9b711" dependencies = [ "mimalloc-rust", "tikv-jemallocator", @@ -8463,9 +8421,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.20.5" +version = "0.20.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779d8f8597eeb98dbcc7571af50bfa664d68b192a0e07c7b52643a3bfa720806" +checksum = "249c6c5935bcea54025c5c767f33d89d650293288837b50113ac9c437e546450" dependencies = [ "dashmap", "swc_atoms", @@ -8499,9 +8457,9 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" -version = "0.39.6" +version = "0.39.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2004e74d75a7bbbf5d6b89f2348e000825cb7eaf87d51966793729aa1bc56690" +checksum = "e73aa3453e0026b009f35462b77f7dbc2e1b9a91cd92fae6f517802f3b6f4561" dependencies = [ "better_scoped_tls", "rkyv", @@ -8513,9 +8471,9 @@ dependencies = [ [[package]] name = "swc_plugin_runner" -version = "0.104.14" +version = "0.104.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1604548ed056f29dcc3dafa6dd131ac00fc752f4fc812a02ac34a448133a4e6" +checksum = "b1ef2eb955ba87377bda7b17b7bb511b62d3c8e7b56c9481598f7821438df5e0" dependencies = [ "anyhow", "enumset", @@ -8537,9 +8495,9 @@ dependencies = [ [[package]] name = "swc_relay" -version = "0.30.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffdcdf1fd127262323ba54a1ab97a6dc0f5ba937e5d3fca8aa79935ded1a151" +checksum = "9a144781f2f2de3e7ccc22f7381a7f24383ac36168a4afefdbb029f78c1aa973" dependencies = [ "once_cell", "regex", @@ -8555,9 +8513,9 @@ dependencies = [ [[package]] name = "swc_timer" -version = "0.21.7" +version = "0.21.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90c333bce29a3bc3ee694976cce0b08927f0939c494bb0e1650bfce3dba214" +checksum = "388d9d8a67d907c9a5f69250a32134b80fa01c2c03b7fbfcdbb9e8d4ed18b3ed" dependencies = [ "tracing", ] @@ -8857,9 +8815,9 @@ dependencies = [ [[package]] name = "testing" -version = "0.35.7" +version = "0.35.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "272f2b6de45b9ad1444af11a54077d9b2ec439357c44086da60ad8369db1b87e" +checksum = "94fa85c2c4605cd16c3b358b125a23b36e01fe04a0ef687d22df97baa4b25fa8" dependencies = [ "ansi_term", "cargo_metadata", @@ -10024,9 +9982,13 @@ dependencies = [ "async-trait", "indexmap 1.9.3", "indoc", + "lightningcss", "once_cell", + "parcel_selectors", + "parcel_sourcemap", "regex", "serde", + "smallvec", "swc_core", "turbo-tasks", "turbo-tasks-build", @@ -10804,8 +10766,8 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", - "rand 0.4.6", + "cfg-if 1.0.0", + "rand 0.8.5", "static_assertions", ] diff --git a/Cargo.toml b/Cargo.toml index a4d18e512f2fa..733a29a231a84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } @@ -246,3 +246,4 @@ url = "2.2.2" urlencoding = "2.1.2" webbrowser = "0.8.7" which = "4.4.0" + diff --git a/crates/turbopack-core/src/issue/mod.rs b/crates/turbopack-core/src/issue/mod.rs index 2bd0fa69857d5..82045fce82854 100644 --- a/crates/turbopack-core/src/issue/mod.rs +++ b/crates/turbopack-core/src/issue/mod.rs @@ -457,6 +457,18 @@ impl IssueSource { }) } + #[turbo_tasks::function] + pub fn from_line_col( + source: Vc>, + start: SourcePos, + end: SourcePos, + ) -> Vc { + Self::cell(IssueSource { + source, + range: Some(SourceRange::LineColumn(start, end).cell()), + }) + } + /// Create a [`IssueSource`] from byte offsets given by an swc ast node /// span. /// diff --git a/crates/turbopack-core/src/source_pos.rs b/crates/turbopack-core/src/source_pos.rs index 85ce66757b72e..98f19f0e83bf6 100644 --- a/crates/turbopack-core/src/source_pos.rs +++ b/crates/turbopack-core/src/source_pos.rs @@ -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. @@ -16,6 +16,7 @@ const U8_CR: u8 = 0x0D; Clone, PartialOrd, Ord, + TaskInput, TraceRawVcs, Serialize, Deserialize, diff --git a/crates/turbopack-css/Cargo.toml b/crates/turbopack-css/Cargo.toml index ab70130faaa53..672d8b049a89c 100644 --- a/crates/turbopack-css/Cargo.toml +++ b/crates/turbopack-css/Cargo.toml @@ -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 } @@ -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", ] } diff --git a/crates/turbopack-css/src/asset.rs b/crates/turbopack-css/src/asset.rs index 8bb59eb278018..6b9673a8c6949 100644 --- a/crates/turbopack-css/src/asset.rs +++ b/crates/turbopack-css/src/asset.rs @@ -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::{ @@ -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, }; @@ -42,7 +33,6 @@ fn modifier() -> Vc { pub struct CssModuleAsset { source: Vc>, asset_context: Vc>, - transforms: Vc, ty: CssModuleAssetType, } @@ -53,13 +43,11 @@ impl CssModuleAsset { pub fn new( source: Vc>, asset_context: Vc>, - transforms: Vc, ty: CssModuleAssetType, ) -> Vc { Self::cell(CssModuleAsset { source, asset_context, - transforms, ty, }) } @@ -74,8 +62,34 @@ impl CssModuleAsset { #[turbo_tasks::value_impl] impl ParseCss for CssModuleAsset { #[turbo_tasks::function] - fn parse_css(&self) -> Vc { - parse_css(self.source, self.ty, self.transforms) + async fn parse_css(self: Vc) -> Result> { + 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) -> Result> { + 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, + chunking_context: Vc>, + ) -> Result> { + let process_result = self.get_css_with_placeholder(); + + dbg!("CssModuleAsset::finalize_css"); + + Ok(finalize_css(process_result, chunking_context)) } } @@ -91,14 +105,14 @@ impl Module for CssModuleAsset { #[turbo_tasks::function] async fn references(self: Vc) -> Result> { - 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()), + } } } @@ -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::>(); // 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 { diff --git a/crates/turbopack-css/src/chunk/mod.rs b/crates/turbopack-css/src/chunk/mod.rs index fc44b2651d831..4535ae8cb58cc 100644 --- a/crates/turbopack-css/src/chunk/mod.rs +++ b/crates/turbopack-css/src/chunk/mod.rs @@ -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 { diff --git a/crates/turbopack-css/src/code_gen.rs b/crates/turbopack-css/src/code_gen.rs index 55391294d3586..20855e79a1597 100644 --- a/crates/turbopack-css/src/code_gen.rs +++ b/crates/turbopack-css/src/code_gen.rs @@ -1,4 +1,3 @@ -use swc_core::css::visit::{AstParentKind, VisitMut}; use turbo_tasks::Vc; use turbopack_core::chunk::ChunkingContext; @@ -14,17 +13,10 @@ use crate::chunk::CssImport; cell = "new" )] pub struct CodeGeneration { - /// ast nodes matching the span will be visitor by the visitor - #[turbo_tasks(debug_ignore, trace_ignore)] - pub visitors: Vec<(Vec, Box)>, #[turbo_tasks(debug_ignore, trace_ignore)] pub imports: Vec, } -pub trait VisitorFactory: Send + Sync { - fn create<'a>(&'a self) -> Box; -} - #[turbo_tasks::value_trait] pub trait CodeGenerateable { fn code_generation( @@ -35,83 +27,3 @@ pub trait CodeGenerateable { #[turbo_tasks::value(transparent)] pub struct CodeGenerateables(Vec>>); - -pub fn path_to( - path: &[AstParentKind], - f: impl FnMut(&AstParentKind) -> bool, -) -> Vec { - if let Some(pos) = path.iter().rev().position(f) { - let index = path.len() - pos - 1; - path[..index].to_vec() - } else { - path.to_vec() - } -} - -#[macro_export] -macro_rules! create_visitor { - (exact $ast_path:expr, $name:ident($arg:ident: &mut $ty:ident) $b:block) => { - $crate::create_visitor!(__ $ast_path.to_vec(), $name($arg: &mut $ty) $b) - }; - ($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(_)) - }), $name($arg: &mut $ty) $b) - }; - (__ $ast_path:expr, $name:ident($arg:ident: &mut $ty:ident) $b:block) => {{ - struct Visitor { - $name: T, - } - - impl $crate::code_gen::VisitorFactory - for Box> - { - fn create<'a>(&'a self) -> Box { - Box::new(&**self) - } - } - - impl<'a, T: Fn(&mut swc_core::css::ast::$ty) + Send + Sync> swc_core::css::visit::VisitMut - for &'a Visitor - { - fn $name(&mut self, $arg: &mut swc_core::css::ast::$ty) { - (self.$name)($arg); - } - } - - ( - $ast_path, - Box::new(Box::new(Visitor { - $name: move |$arg: &mut swc_core::css::ast::$ty| $b, - })) as Box, - ) - }}; - (visit_mut_stylesheet($arg:ident: &mut Stylesheet) $b:block) => {{ - struct Visitor { - visit_mut_stylesheet: T, - } - - impl $crate::code_gen::VisitorFactory - for Box> - { - fn create<'a>(&'a self) -> Box { - Box::new(&**self) - } - } - - impl<'a, T: Fn(&mut swc_core::css::ast::Stylesheet) + Send + Sync> swc_core::css::visit::VisitMut - for &'a Visitor - { - fn visit_mut_stylesheet(&mut self, $arg: &mut swc_core::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, - })) as Box, - ) - }}; -} diff --git a/crates/turbopack-css/src/lib.rs b/crates/turbopack-css/src/lib.rs index 77a8f45f063c6..3f1fbaa297ac1 100644 --- a/crates/turbopack-css/src/lib.rs +++ b/crates/turbopack-css/src/lib.rs @@ -10,21 +10,20 @@ pub mod chunk; mod code_gen; pub mod embed; mod global_asset; +mod lifetime_util; mod module_asset; pub(crate) mod parse; -mod path_visitor; +pub(crate) mod process; pub(crate) mod references; -pub(crate) mod transform; pub(crate) mod util; pub use asset::CssModuleAsset; pub use global_asset::GlobalCssAsset; pub use module_asset::ModuleCssAsset; -pub use parse::{ParseCss, ParseCssResult}; use serde::{Deserialize, Serialize}; -pub use transform::{CssInputTransform, CssInputTransforms}; use turbo_tasks::{trace::TraceRawVcs, TaskInput}; +pub use self::process::*; use crate::references::import::ImportAssetReference; #[derive( diff --git a/crates/turbopack-css/src/lifetime_util.rs b/crates/turbopack-css/src/lifetime_util.rs new file mode 100644 index 0000000000000..38aade884bb6b --- /dev/null +++ b/crates/turbopack-css/src/lifetime_util.rs @@ -0,0 +1,16 @@ +use lightningcss::{ + stylesheet::{ParserOptions, StyleSheet}, + traits::IntoOwned, +}; + +pub fn stylesheet_into_static<'i, 'o>( + ss: &StyleSheet, + options: ParserOptions<'o, 'i>, +) -> StyleSheet<'i, 'o> { + let sources = ss.sources.clone(); + let rules = ss.rules.clone().into_owned(); + + // + + StyleSheet::new(sources, rules, options) +} diff --git a/crates/turbopack-css/src/module_asset.rs b/crates/turbopack-css/src/module_asset.rs index 1120794e35ce2..7b30d42e4773a 100644 --- a/crates/turbopack-css/src/module_asset.rs +++ b/crates/turbopack-css/src/module_asset.rs @@ -3,10 +3,8 @@ use std::{fmt::Write, iter::once, sync::Arc}; use anyhow::{bail, Context, Result}; use indexmap::IndexMap; use indoc::formatdoc; -use swc_core::{ - common::{BytePos, FileName, LineCol, SourceMap}, - css::modules::CssClassName, -}; +use lightningcss::css_modules::CssModuleReference; +use swc_core::common::{BytePos, FileName, LineCol, SourceMap}; use turbo_tasks::{Value, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ @@ -31,8 +29,9 @@ use turbopack_ecmascript::{ }; use crate::{ - parse::{ParseCss, ParseCssResult}, + process::{CssWithPlaceholderResult, ProcessCss}, references::{compose::CssModuleComposeReference, internal::InternalCssAssetReference}, + ParseCss, }; #[turbo_tasks::function] @@ -153,32 +152,42 @@ impl ModuleCssAsset { async fn classes(self: Vc) -> Result> { let inner = self.inner(); - let Some(inner) = Vc::try_resolve_sidecast::>(inner).await? else { - bail!("inner asset should be CSS parseable"); + let Some(inner) = Vc::try_resolve_sidecast::>(inner).await? else { + bail!("inner asset should be CSS processable"); }; - let parse_result = inner.parse_css().await?; + let result = inner.get_css_with_placeholder().await?; let mut classes = IndexMap::default(); // TODO(alexkirsz) Should we report an error on parse error here? - if let ParseCssResult::Ok { exports, .. } = &*parse_result { + if let CssWithPlaceholderResult::Ok { + exports: Some(exports), + .. + } = &*result + { for (class_name, export_class_names) in exports { let mut export = Vec::default(); - for export_class_name in export_class_names { + export.push(ModuleCssClass::Local { + name: export_class_names.name.clone(), + }); + + for export_class_name in &export_class_names.composes { export.push(match export_class_name { - CssClassName::Import { from, name } => ModuleCssClass::Import { - original: name.value.to_string(), - from: CssModuleComposeReference::new( - Vc::upcast(self), - Request::parse(Value::new(from.to_string().into())), - ), - }, - CssClassName::Local { name } => ModuleCssClass::Local { - name: name.value.to_string(), + CssModuleReference::Dependency { specifier, name } => { + ModuleCssClass::Import { + original: name.to_string(), + from: CssModuleComposeReference::new( + Vc::upcast(self), + Request::parse(Value::new(specifier.to_string().into())), + ), + } + } + CssModuleReference::Local { name } => ModuleCssClass::Local { + name: name.to_string(), }, - CssClassName::Global { name } => ModuleCssClass::Global { - name: name.value.to_string(), + CssModuleReference::Global { name } => ModuleCssClass::Global { + name: name.to_string(), }, }) } diff --git a/crates/turbopack-css/src/parse.rs b/crates/turbopack-css/src/parse.rs index 25b9556782a3c..a50431ade028d 100644 --- a/crates/turbopack-css/src/parse.rs +++ b/crates/turbopack-css/src/parse.rs @@ -1,103 +1,9 @@ -use std::sync::Arc; +use swc_core::common::{source_map::SourceMapGenConfig, FileName}; +use turbopack_core::SOURCE_MAP_ROOT_NAME; -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 turbo_tasks::{ValueToString, Vc}; -use turbo_tasks_fs::{FileContent, FileSystemPath}; -use turbopack_core::{ - asset::{Asset, AssetContent}, - source::Source, - source_map::{GenerateSourceMap, OptionSourceMap}, - SOURCE_MAP_ROOT_NAME, -}; -use turbopack_swc_utils::emitter::IssueEmitter; - -use crate::{ - transform::{CssInputTransform, CssInputTransforms, TransformContext}, - CssModuleAssetType, -}; - -// Capture up until the first "." -static BASENAME_RE: Lazy = Lazy::new(|| Regex::new(r"^[^.]*").unwrap()); - -#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] -pub enum ParseCssResult { - Ok { - #[turbo_tasks(trace_ignore)] - stylesheet: Stylesheet, - #[turbo_tasks(debug_ignore, trace_ignore)] - source_map: Arc, - #[turbo_tasks(debug_ignore, trace_ignore)] - imports: Vec, - #[turbo_tasks(debug_ignore, trace_ignore)] - exports: IndexMap>, - }, - Unparseable, - NotFound, -} - -impl PartialEq for ParseCssResult { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Ok { .. }, Self::Ok { .. }) => false, - _ => core::mem::discriminant(self) == core::mem::discriminant(other), - } - } -} - -#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] -pub struct ParseCssResultSourceMap { - #[turbo_tasks(debug_ignore, trace_ignore)] - source_map: Arc, - - /// The position mappings that can generate a real source map given a (SWC) - /// SourceMap. - #[turbo_tasks(debug_ignore, trace_ignore)] - mappings: Vec<(BytePos, LineCol)>, -} - -impl PartialEq for ParseCssResultSourceMap { - fn eq(&self, other: &Self) -> bool { - Arc::ptr_eq(&self.source_map, &other.source_map) && self.mappings == other.mappings - } -} - -impl ParseCssResultSourceMap { - pub fn new(source_map: Arc, mappings: Vec<(BytePos, LineCol)>) -> Self { - ParseCssResultSourceMap { - source_map, - mappings, - } - } -} - -#[turbo_tasks::value_impl] -impl GenerateSourceMap for ParseCssResultSourceMap { - #[turbo_tasks::function] - fn generate_source_map(&self) -> Vc { - let map = self.source_map.build_source_map_with_config( - &self.mappings, - None, - InlineSourcesContentConfig {}, - ); - Vc::cell(Some( - turbopack_core::source_map::SourceMap::new_regular(map).cell(), - )) - } -} +// // Capture up until the first "." +// static BASENAME_RE: Lazy = Lazy::new(|| +// Regex::new(r"^[^.]*").unwrap()); /// A config to generate a source map which includes the source content of every /// source file. SWC doesn't inline sources content by default when generating a @@ -116,146 +22,3 @@ impl SourceMapGenConfig for InlineSourcesContentConfig { true } } - -#[turbo_tasks::function] -pub async fn parse_css( - source: Vc>, - ty: CssModuleAssetType, - transforms: Vc, -) -> Result> { - let content = source.content(); - let fs_path = &*source.ident().path().await?; - let ident_str = &*source.ident().to_string().await?; - Ok(match &*content.await? { - AssetContent::Redirect { .. } => ParseCssResult::Unparseable.cell(), - AssetContent::File(file) => match &*file.await? { - FileContent::NotFound => ParseCssResult::NotFound.cell(), - FileContent::Content(file) => match file.content().to_str() { - Err(_err) => ParseCssResult::Unparseable.cell(), - Ok(string) => { - let transforms = &*transforms.await?; - parse_content( - string.into_owned(), - fs_path, - ident_str, - source, - ty, - transforms, - ) - .await? - } - }, - }, - }) -} - -async fn parse_content( - string: String, - fs_path: &FileSystemPath, - ident_str: &str, - source: Vc>, - ty: CssModuleAssetType, - transforms: &[CssInputTransform], -) -> Result> { - let source_map: Arc = Default::default(); - let handler = Handler::with_emitter( - true, - false, - Box::new(IssueEmitter { - source, - source_map: source_map.clone(), - title: Some("Parsing css source code failed".to_string()), - }), - ); - - let fm = source_map.new_source_file(FileName::Custom(ident_str.to_string()), string); - - let config = ParserConfig { - css_modules: matches!(ty, CssModuleAssetType::Module), - legacy_nesting: true, - legacy_ie: true, - ..Default::default() - }; - - let mut errors = Vec::new(); - let mut parsed_stylesheet = match parse_file::(&fm, None, config, &mut errors) { - Ok(stylesheet) => stylesheet, - Err(e) => { - // TODO report in in a stream - e.to_diagnostics(&handler).emit(); - return Ok(ParseCssResult::Unparseable.into()); - } - }; - - let mut has_errors = false; - for e in errors { - e.to_diagnostics(&handler).emit(); - has_errors = true - } - - if has_errors { - return Ok(ParseCssResult::Unparseable.into()); - } - - let transform_context = TransformContext { - source_map: &source_map, - }; - for transform in transforms.iter() { - transform - .apply(&mut parsed_stylesheet, &transform_context) - .await?; - } - - let (imports, exports) = match ty { - CssModuleAssetType::Default => Default::default(), - CssModuleAssetType::Module => { - let imports = swc_core::css::modules::imports::analyze_imports(&parsed_stylesheet); - let basename = BASENAME_RE - .captures(fs_path.file_name()) - .context("Must include basename preceding .")? - .get(0) - .context("Must include basename preceding .")? - .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( - &mut parsed_stylesheet, - // TODO swc_css_modules should take `impl TransformConfig + '_` - ModuleTransformConfig { - suffix: format!("__{}__{:x}", basename, path_hash), - }, - ); - let mut exports = result.renamed.into_iter().collect::>(); - // exports should be reported deterministically - // TODO(sokra) report in order of occurrence within swc_css_modules using an - // IndexMap - exports.sort_keys(); - (imports, exports) - } - }; - - Ok(ParseCssResult::Ok { - stylesheet: parsed_stylesheet, - source_map, - imports, - exports, - } - .into()) -} - -struct ModuleTransformConfig { - suffix: String, -} - -impl TransformConfig for ModuleTransformConfig { - fn new_name_for(&self, local: &JsWord) -> JsWord { - format!("{}{}", *local, self.suffix).into() - } -} - -/// Trait to be implemented by assets which can be parsed as CSS. -#[turbo_tasks::value_trait] -pub trait ParseCss { - /// Returns the parsed css. - fn parse_css(self: Vc) -> Vc; -} diff --git a/crates/turbopack-css/src/path_visitor.rs b/crates/turbopack-css/src/path_visitor.rs deleted file mode 100644 index 7ef2f904f8ae7..0000000000000 --- a/crates/turbopack-css/src/path_visitor.rs +++ /dev/null @@ -1,109 +0,0 @@ -use std::{borrow::Cow, collections::HashMap}; - -use swc_core::{ - common::pass::AstKindPath, - css::{ - ast::*, - visit::{AstParentKind, VisitMut, VisitMutAstPath, VisitMutWith, VisitMutWithPath}, - }, -}; - -use crate::code_gen::VisitorFactory; - -pub type AstPath = Vec; - -pub struct ApplyVisitors<'a> { - /// `VisitMut` should be shallow. In other words, it should not visit - /// children of the node. - visitors: HashMap>, - - index: usize, -} - -impl<'a> ApplyVisitors<'a> { - pub fn new(visitors: Vec<(&'a AstPath, &'a dyn VisitorFactory)>) -> Self { - let mut map = HashMap::>::new(); - for (path, visitor) in visitors { - if let Some(span) = path.first() { - map.entry(*span).or_default().push((path, visitor)); - } - } - Self { - visitors: map, - index: 0, - } - } - - fn visit_if_required(&mut self, n: &mut N, ast_path: &mut AstKindPath) - where - N: for<'aa> VisitMutWith - + for<'aa> VisitMutWithPath>, - { - let mut index = self.index; - let mut current_visitors_map = Cow::Borrowed(&self.visitors); - while index < ast_path.len() { - let current = index == ast_path.len() - 1; - let kind = ast_path[index]; - if let Some(visitors) = current_visitors_map.get(&kind) { - let mut visitors_map = HashMap::<_, Vec<_>>::with_capacity(visitors.len()); - - index += 1; - - let mut active_visitors = Vec::new(); - for (path, visitor) in visitors.iter() { - if index == path.len() { - if current { - active_visitors.push(*visitor); - } - } else { - debug_assert!(index < path.len()); - - let span = path[index]; - visitors_map - .entry(span) - .or_default() - .push((*path, *visitor)); - } - } - - if current { - // Potentially skip visiting this sub tree - if !visitors_map.is_empty() { - n.visit_mut_children_with_path( - &mut ApplyVisitors { - visitors: visitors_map, - index, - }, - ast_path, - ); - } - for visitor in active_visitors { - n.visit_mut_with(&mut visitor.create()); - } - return; - } else { - current_visitors_map = Cow::Owned(visitors_map); - } - } else { - // Skip visiting this sub tree - return; - } - } - // Ast path is unchanged, just keep visiting - n.visit_mut_children_with_path(self, ast_path); - } -} - -macro_rules! method { - ($name:ident,$T:ty) => { - fn $name(&mut self, n: &mut $T, ast_path: &mut AstKindPath) { - self.visit_if_required(n, ast_path); - } - }; -} - -impl VisitMutAstPath for ApplyVisitors<'_> { - // TODO: we need a macro to apply that for all methods - method!(visit_mut_url_value, UrlValue); - method!(visit_mut_url, Url); -} diff --git a/crates/turbopack-css/src/process.rs b/crates/turbopack-css/src/process.rs new file mode 100644 index 0000000000000..4abeb27b3407e --- /dev/null +++ b/crates/turbopack-css/src/process.rs @@ -0,0 +1,386 @@ +use std::{collections::HashMap, mem::transmute}; + +use anyhow::Result; +use indexmap::IndexMap; +use lightningcss::{ + css_modules::{CssModuleExport, CssModuleExports, Pattern, Segment}, + dependencies::{Dependency, DependencyOptions}, + stylesheet::{ParserOptions, PrinterOptions, StyleSheet}, + targets::{Features, Targets}, + values::url::Url, +}; +use smallvec::smallvec; +use swc_core::base::sourcemap::SourceMapBuilder; +use turbo_tasks::{ValueToString, Vc}; +use turbo_tasks_fs::{FileContent, FileSystemPath}; +use turbopack_core::{ + asset::{Asset, AssetContent}, + chunk::ChunkingContext, + reference::ModuleReferences, + resolve::origin::ResolveOrigin, + source::Source, + source_map::{GenerateSourceMap, OptionSourceMap}, +}; + +use crate::{ + lifetime_util::stylesheet_into_static, + references::{ + analyze_references, + url::{replace_url_references, resolve_url_reference, UrlAssetReference}, + }, + CssModuleAssetType, +}; + +/// Multiple [ModuleReference]s +#[turbo_tasks::value(transparent)] +pub struct UnresolvedUrlReferences(pub Vec<(String, Vc)>); + +#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] +pub enum ParseCssResult { + Ok { + #[turbo_tasks(trace_ignore)] + stylesheet: StyleSheet<'static, 'static>, + + references: Vc, + + url_references: Vc, + + #[turbo_tasks(trace_ignore)] + options: ParserOptions<'static, 'static>, + }, + Unparseable, + NotFound, +} + +impl PartialEq for ParseCssResult { + fn eq(&self, _: &Self) -> bool { + false + } +} + +#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] +pub enum CssWithPlaceholderResult { + Ok { + #[turbo_tasks(trace_ignore)] + stylesheet: StyleSheet<'static, 'static>, + + references: Vc, + + url_references: Vc, + + #[turbo_tasks(trace_ignore)] + exports: Option>, + + #[turbo_tasks(trace_ignore)] + placeholders: HashMap>, + + #[turbo_tasks(trace_ignore)] + options: ParserOptions<'static, 'static>, + }, + Unparseable, + NotFound, +} + +impl PartialEq for CssWithPlaceholderResult { + fn eq(&self, _: &Self) -> bool { + false + } +} + +#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] +pub enum FinalCssResult { + Ok { + #[turbo_tasks(trace_ignore)] + output_code: String, + + #[turbo_tasks(trace_ignore)] + exports: Option, + + source_map: Vc, + }, + Unparseable, + NotFound, +} + +impl PartialEq for FinalCssResult { + fn eq(&self, _: &Self) -> bool { + false + } +} + +#[turbo_tasks::function] +pub async fn process_css_with_placeholder( + result: Vc, +) -> Result> { + let result = result.await?; + + match &*result { + ParseCssResult::Ok { + stylesheet, + references, + url_references, + options, + } => { + dbg!("process_css_with_placeholder => start"); + + let stylesheet = stylesheet_into_static(stylesheet, options.clone()); + + dbg!("process_css_with_placeholder => after stylesheet_into_static"); + + let result = stylesheet.to_css(PrinterOptions { + analyze_dependencies: Some(DependencyOptions { + ..Default::default() + }), + ..Default::default() + })?; + + dbg!("process_css_with_placeholder => after StyleSheet::to_css"); + + let exports = result.exports.map(|exports| { + let mut exports = exports.into_iter().collect::>(); + + exports.sort_keys(); + + exports + }); + + dbg!("process_css_with_placeholder => after sorting exports"); + + Ok(CssWithPlaceholderResult::Ok { + exports, + references: *references, + url_references: *url_references, + placeholders: HashMap::new(), + stylesheet, + options: options.clone(), + } + .into()) + } + ParseCssResult::Unparseable => Ok(CssWithPlaceholderResult::Unparseable.into()), + ParseCssResult::NotFound => Ok(CssWithPlaceholderResult::NotFound.into()), + } +} + +#[turbo_tasks::function] +pub async fn finalize_css( + result: Vc, + chunking_context: Vc>, +) -> Result> { + let result = result.await?; + match &*result { + CssWithPlaceholderResult::Ok { + stylesheet, + url_references, + options, + .. + } => { + dbg!("finalize_css => start"); + + let mut stylesheet = stylesheet_into_static(stylesheet, options.clone()); + + dbg!("finalize_css => after stylesheet_into_static"); + + let url_references = *url_references; + + let mut url_map = HashMap::new(); + + for (src, reference) in (*url_references.await?).iter() { + let resolved = resolve_url_reference(*reference, chunking_context).await?; + if let Some(v) = resolved.as_ref().cloned() { + url_map.insert(src.to_string(), v); + } + } + + replace_url_references(&mut stylesheet, &url_map); + dbg!("finalize_css => after replacing url refs"); + + let mut srcmap = parcel_sourcemap::SourceMap::new(""); + let result = stylesheet.to_css(PrinterOptions { + source_map: Some(&mut srcmap), + analyze_dependencies: Some(DependencyOptions { + remove_imports: true, + }), + targets: Targets { + include: Features::Nesting, + ..Default::default() + }, + ..Default::default() + })?; + + dbg!("finalize_css => after StyleSheet::to_css"); + + srcmap.add_sources(stylesheet.sources.clone()); + + Ok(FinalCssResult::Ok { + output_code: result.code, + exports: result.exports, + source_map: ParseCssResultSourceMap::new(srcmap).cell(), + } + .into()) + } + CssWithPlaceholderResult::Unparseable => Ok(FinalCssResult::Unparseable.into()), + CssWithPlaceholderResult::NotFound => Ok(FinalCssResult::NotFound.into()), + } +} + +#[turbo_tasks::value_trait] +pub trait ParseCss { + async fn parse_css(self: Vc) -> Result>; +} + +#[turbo_tasks::value_trait] +pub trait ProcessCss: ParseCss { + async fn get_css_with_placeholder(self: Vc) -> Result>; + + async fn finalize_css( + self: Vc, + chunking_context: Vc>, + ) -> Result>; +} + +#[turbo_tasks::function] +pub async fn parse_css( + source: Vc>, + origin: Vc>, + ty: CssModuleAssetType, +) -> Result> { + let content = source.content(); + let fs_path = &*source.ident().path().await?; + let ident_str = &*source.ident().to_string().await?; + Ok(match &*content.await? { + AssetContent::Redirect { .. } => ParseCssResult::Unparseable.cell(), + AssetContent::File(file) => match &*file.await? { + FileContent::NotFound => ParseCssResult::NotFound.cell(), + FileContent::Content(file) => match file.content().to_str() { + Err(_err) => ParseCssResult::Unparseable.cell(), + Ok(string) => { + process_content(string.into_owned(), fs_path, ident_str, source, origin, ty) + .await? + } + }, + }, + }) +} + +async fn process_content( + code: String, + _fs_path: &FileSystemPath, + ident_str: &str, + source: Vc>, + origin: Vc>, + ty: CssModuleAssetType, +) -> Result> { + let config = ParserOptions { + css_modules: match ty { + CssModuleAssetType::Module => Some(lightningcss::css_modules::Config { + pattern: Pattern { + segments: smallvec![ + Segment::Name, + Segment::Literal("__"), + Segment::Hash, + Segment::Literal("__"), + Segment::Local, + ], + }, + dashed_idents: false, + }), + + _ => None, + }, + filename: ident_str.to_string(), + ..Default::default() + }; + + let stylesheet = match StyleSheet::parse(&code, config.clone()) { + Ok(stylesheet) => stylesheet, + Err(_e) => { + // TODO(kdy1): Report errors + // e.to_diagnostics(&handler).emit(); + return Ok(ParseCssResult::Unparseable.into()); + } + }; + + fn clone_options(config: ParserOptions) -> ParserOptions<'static, 'static> { + ParserOptions { + filename: config.filename, + css_modules: config + .css_modules + .clone() + .map(|v| lightningcss::css_modules::Config { + pattern: Pattern { + segments: unsafe { + // Safety: It's actually static (two `__``) + transmute(v.pattern.segments.clone()) + }, + }, + dashed_idents: v.dashed_idents, + }), + source_index: config.source_index, + error_recovery: config.error_recovery, + warnings: None, + flags: config.flags, + } + } + + let config = clone_options(config); + let mut stylesheet = stylesheet_into_static(&stylesheet, config.clone()); + + let (references, url_references) = analyze_references(&mut stylesheet, source, origin)?; + + Ok(ParseCssResult::Ok { + stylesheet, + references: Vc::cell(references), + url_references: Vc::cell(url_references), + options: config, + } + .into()) +} + +#[turbo_tasks::value(shared, serialization = "none", eq = "manual")] +pub struct ParseCssResultSourceMap { + #[turbo_tasks(debug_ignore, trace_ignore)] + source_map: parcel_sourcemap::SourceMap, +} + +impl PartialEq for ParseCssResultSourceMap { + fn eq(&self, _: &Self) -> bool { + false + } +} + +impl ParseCssResultSourceMap { + pub fn new(source_map: parcel_sourcemap::SourceMap) -> Self { + ParseCssResultSourceMap { source_map } + } +} + +#[turbo_tasks::value_impl] +impl GenerateSourceMap for ParseCssResultSourceMap { + #[turbo_tasks::function] + fn generate_source_map(&self) -> Vc { + let mut builder = SourceMapBuilder::new(None); + + for src in self.source_map.get_sources() { + builder.add_source(src); + } + + for (idx, content) in self.source_map.get_sources_content().iter().enumerate() { + builder.set_source_contents(idx as _, Some(content)); + } + + for m in self.source_map.get_mappings() { + builder.add( + m.generated_line, + m.generated_column, + m.original.map(|v| v.original_line).unwrap_or_default(), + m.original.map(|v| v.original_column).unwrap_or_default(), + None, + None, + ); + } + + Vc::cell(Some( + turbopack_core::source_map::SourceMap::new_regular(builder.into_sourcemap()).cell(), + )) + } +} diff --git a/crates/turbopack-css/src/references/import.rs b/crates/turbopack-css/src/references/import.rs index e8d253712246a..f3e2d2a332a75 100644 --- a/crates/turbopack-css/src/references/import.rs +++ b/crates/turbopack-css/src/references/import.rs @@ -1,13 +1,18 @@ use anyhow::Result; -use swc_core::{ - common::DUMMY_SP, - css::{ - ast::*, - codegen::{ - writer::basic::{BasicCssWriter, BasicCssWriterConfig}, - CodeGenerator, Emit, - }, +use lightningcss::{ + media_query::MediaList, + printer::Printer, + properties::custom::TokenList, + rules::{ + import::ImportRule, + layer::{LayerBlockRule, LayerName}, + media::MediaRule, + supports::{SupportsCondition, SupportsRule}, + unknown::UnknownAtRule, + CssRule, CssRuleList, Location, }, + stylesheet::PrinterOptions, + traits::ToCss, }; use turbo_tasks::{Value, ValueToString, Vc}; use turbopack_core::{ @@ -21,74 +26,32 @@ use turbopack_core::{ use crate::{ chunk::CssImport, code_gen::{CodeGenerateable, CodeGeneration}, - references::{css_resolve, AstPath}, + references::css_resolve, }; -#[turbo_tasks::value(into = "new")] +#[turbo_tasks::value(into = "new", eq = "manual", serialization = "none")] pub struct ImportAttributes { #[turbo_tasks(trace_ignore)] - pub layer_name: Option, + pub layer_name: Option>, #[turbo_tasks(trace_ignore)] - pub supports: Option, + pub supports: Option>, #[turbo_tasks(trace_ignore)] - pub media: Option>, + pub media: MediaList<'static>, } -impl ImportAttributes { - pub fn new_from_prelude(prelude: &ImportPrelude) -> Self { - let layer_name = prelude.layer_name.as_ref().map(|l| match l { - box ImportLayerName::Ident(_) => LayerName { - span: DUMMY_SP, - name: vec![], - }, - box ImportLayerName::Function(f) => { - assert_eq!(f.value.len(), 1); - assert!(matches!(&f.value[0], ComponentValue::LayerName(_))); - if let ComponentValue::LayerName(layer_name) = &f.value[0] { - *layer_name.clone() - } else { - unreachable!() - } - } - }); - - let (supports, media) = prelude - .import_conditions - .as_ref() - .map(|c| { - let supports = if let Some(supports) = &c.supports { - let v = supports.value.iter().find(|v| { - matches!( - v, - ComponentValue::SupportsCondition(..) | ComponentValue::Declaration(..) - ) - }); +impl PartialEq for ImportAttributes { + fn eq(&self, _: &Self) -> bool { + false + } +} - if let Some(supports) = v { - match &supports { - ComponentValue::SupportsCondition(s) => Some(*s.clone()), - ComponentValue::Declaration(d) => Some(SupportsCondition { - span: DUMMY_SP, - conditions: vec![SupportsConditionType::SupportsInParens( - SupportsInParens::Feature(SupportsFeature::Declaration( - d.clone(), - )), - )], - }), - _ => None, - } - } else { - None - } - } else { - None - }; +impl ImportAttributes { + pub fn new_from_prelude(prelude: &ImportRule<'static>) -> Self { + let layer_name = prelude.layer.clone().flatten(); - let media = c.media.as_ref().map(|m| m.queries.clone()); + let supports = prelude.supports.clone(); - (supports, media) - }) - .unwrap_or_else(|| (None, None)); + let media = prelude.media.clone(); Self { layer_name, @@ -98,82 +61,59 @@ impl ImportAttributes { } pub fn print_block(&self) -> Result<(String, String)> { - fn token(token: Token) -> TokenAndSpan { - TokenAndSpan { - span: DUMMY_SP, - token, - } - } - // something random that's never gonna be in real css - let mut rule = Rule::ListOfComponentValues(Box::new(ListOfComponentValues { - span: DUMMY_SP, - children: vec![ComponentValue::PreservedToken(Box::new(token( - Token::String { - value: Default::default(), - raw: r#""""__turbopack_placeholder__""""#.into(), - }, - )))], - })); + // Box::new(ListOfComponentValues { + // span: DUMMY_SP, + // children: vec![ComponentValue::PreservedToken(Box::new(token( + // Token::String { + // value: Default::default(), + // raw: r#""""__turbopack_placeholder__""""#.into(), + // }, + // )))], + // }) + + let default_loc = Location { + source_index: 0, + line: 0, + column: 0, + }; + + let mut rule: CssRule = CssRule::Unknown(UnknownAtRule { + name: r#""""__turbopack_placeholder__""""#.into(), + prelude: TokenList(vec![]), + block: None, + loc: default_loc, + }); - fn at_rule(name: &str, prelude: AtRulePrelude, inner_rule: Rule) -> Rule { - Rule::AtRule(Box::new(AtRule { - span: DUMMY_SP, - name: AtRuleName::Ident(Ident { - span: DUMMY_SP, - value: name.into(), - raw: None, - }), - prelude: Some(Box::new(prelude)), - block: Some(SimpleBlock { - span: DUMMY_SP, - name: token(Token::LBrace), - value: vec![ComponentValue::from(inner_rule)], - }), - })) + if !self.media.media_queries.is_empty() { + rule = CssRule::Media(MediaRule { + query: self.media.clone(), + rules: CssRuleList(vec![rule]), + loc: default_loc, + }) } - if let Some(media) = &self.media { - rule = at_rule( - "media", - AtRulePrelude::MediaPrelude(MediaQueryList { - span: DUMMY_SP, - queries: media.clone(), - }), - rule, - ); - } if let Some(supports) = &self.supports { - rule = at_rule( - "supports", - AtRulePrelude::SupportsPrelude(supports.clone()), - rule, - ); + rule = CssRule::Supports(SupportsRule { + condition: supports.clone(), + rules: CssRuleList(vec![rule]), + loc: default_loc, + }) } if let Some(layer_name) = &self.layer_name { - rule = at_rule( - "layer", - AtRulePrelude::LayerPrelude(LayerPrelude::Name(layer_name.clone())), - rule, - ); + rule = CssRule::LayerBlock(LayerBlockRule { + loc: default_loc, + name: Some(layer_name.clone()), + rules: CssRuleList(vec![rule]), + }); } let mut output = String::new(); - let mut code_gen = CodeGenerator::new( - BasicCssWriter::new( - &mut output, - None, - BasicCssWriterConfig { - indent_width: 0, - ..Default::default() - }, - ), - Default::default(), - ); - code_gen.emit(&rule)?; + let mut printer = Printer::new(&mut output, PrinterOptions::default()); + rule.to_css(&mut printer)?; let (open, close) = output - .split_once(r#""""__turbopack_placeholder__""""#) + .split_once(r#"@"""__turbopack_placeholder__""""#) .unwrap(); Ok((open.trim().into(), close.trim().into())) @@ -185,7 +125,6 @@ impl ImportAttributes { pub struct ImportAssetReference { pub origin: Vc>, pub request: Vc, - pub path: Vc, pub attributes: Vc, pub issue_source: Vc, } @@ -196,14 +135,12 @@ impl ImportAssetReference { pub fn new( origin: Vc>, request: Vc, - path: Vc, attributes: Vc, issue_source: Vc, ) -> Vc { Self::cell(ImportAssetReference { origin, request, - path, attributes, issue_source, }) @@ -254,11 +191,7 @@ impl CodeGenerateable for ImportAssetReference { )))) } - Ok(CodeGeneration { - visitors: vec![], - imports, - } - .into()) + Ok(CodeGeneration { imports }.into()) } } diff --git a/crates/turbopack-css/src/references/mod.rs b/crates/turbopack-css/src/references/mod.rs index 764524e5c5fb0..a8e28218e8c7d 100644 --- a/crates/turbopack-css/src/references/mod.rs +++ b/crates/turbopack-css/src/references/mod.rs @@ -1,19 +1,17 @@ +use std::convert::Infallible; + use anyhow::Result; -use swc_core::{ - common::{ - errors::{Handler, HANDLER}, - source_map::Pos, - Globals, Spanned, GLOBALS, - }, - css::{ - ast::{ImportHref, ImportPrelude, Url, UrlValue}, - visit::{AstNodePath, AstParentKind, VisitAstPath, VisitWithPath}, - }, +use lightningcss::{ + rules::CssRule, + stylesheet::StyleSheet, + traits::IntoOwned, + values::{image::Image, url::Url}, + visitor::{Visit, Visitor}, }; use turbo_tasks::{Value, Vc}; use turbopack_core::{ issue::{IssueSeverity, IssueSource}, - reference::{ModuleReference, ModuleReferences}, + reference::ModuleReference, reference_type::{CssReferenceSubType, ReferenceType}, resolve::{ handle_resolve_error, @@ -22,16 +20,12 @@ use turbopack_core::{ ModuleResolveResult, }, source::Source, + source_pos::SourcePos, }; -use turbopack_swc_utils::emitter::IssueEmitter; -use crate::{ - parse::{parse_css, ParseCssResult}, - references::{ - import::{ImportAssetReference, ImportAttributes}, - url::UrlAssetReference, - }, - CssInputTransforms, CssModuleAssetType, +use crate::references::{ + import::{ImportAssetReference, ImportAttributes}, + url::UrlAssetReference, }; pub(crate) mod compose; @@ -39,49 +33,31 @@ pub(crate) mod import; pub(crate) mod internal; pub(crate) mod url; -#[turbo_tasks::function] -pub async fn analyze_css_stylesheet( +pub type AnalyzedRefs = ( + Vec>>, + Vec<(String, Vc)>, +); + +/// Returns `(all_references, urls)`. +pub fn analyze_references( + stylesheet: &mut StyleSheet<'static, 'static>, source: Vc>, origin: Vc>, - ty: CssModuleAssetType, - transforms: Vc, -) -> Result> { +) -> Result { let mut references = Vec::new(); + let mut urls = Vec::new(); - let parsed = parse_css(source, ty, transforms).await?; - - if let ParseCssResult::Ok { - stylesheet, - source_map, - .. - } = &*parsed - { - let handler = Handler::with_emitter( - true, - false, - Box::new(IssueEmitter { - source, - source_map: source_map.clone(), - title: None, - }), - ); - let globals = Globals::new(); - HANDLER.set(&handler, || { - GLOBALS.set(&globals, || { - // TODO migrate to effects - let mut visitor = ModuleReferencesVisitor::new(source, origin, &mut references); - stylesheet.visit_with_path(&mut visitor, &mut Default::default()); - }) - }); - } - Ok(Vc::cell(references)) + let mut visitor = ModuleReferencesVisitor::new(source, origin, &mut references, &mut urls); + stylesheet.visit(&mut visitor).unwrap(); + + Ok((references, urls)) } struct ModuleReferencesVisitor<'a> { source: Vc>, origin: Vc>, references: &'a mut Vec>>, - is_import: bool, + urls: &'a mut Vec<(String, Vc)>, } impl<'a> ModuleReferencesVisitor<'a> { @@ -89,86 +65,104 @@ impl<'a> ModuleReferencesVisitor<'a> { source: Vc>, origin: Vc>, references: &'a mut Vec>>, + urls: &'a mut Vec<(String, Vc)>, ) -> Self { Self { source, origin, references, - is_import: false, - } - } -} - -fn url_string(u: &Url) -> &str { - match &u.value { - None => { - println!("invalid css url: no value"); - "" + urls, } - Some(box UrlValue::Str(s)) => s.value.as_ref(), - Some(box UrlValue::Raw(r)) => r.value.as_ref(), } } -pub fn as_parent_path(ast_path: &AstNodePath<'_>) -> Vec { - ast_path.iter().map(|n| n.kind()).collect() -} +impl<'a> Visitor<'_> for ModuleReferencesVisitor<'a> { + type Error = Infallible; -impl<'a> VisitAstPath for ModuleReferencesVisitor<'a> { - fn visit_import_prelude<'ast: 'r, 'r>( - &mut self, - i: &'ast ImportPrelude, - ast_path: &mut AstNodePath<'r>, - ) { - let src = match &i.href { - box ImportHref::Str(s) => s.value.as_ref(), - // covered by `visit_url` below - box ImportHref::Url(ref u) => url_string(u), - }; - - let issue_span = i.href.span(); - - self.references.push(Vc::upcast(ImportAssetReference::new( - self.origin, - Request::parse(Value::new(src.to_string().into())), - Vc::cell(as_parent_path(ast_path)), - ImportAttributes::new_from_prelude(i).into(), - IssueSource::from_swc_offsets( - Vc::upcast(self.source), - issue_span.lo.to_usize(), - issue_span.hi.to_usize(), - ), - ))); - - self.is_import = true; - i.visit_children_with_path(self, ast_path); - self.is_import = false; + fn visit_types(&self) -> lightningcss::visitor::VisitTypes { + lightningcss::visitor::VisitTypes::all() } - fn visit_url<'ast: 'r, 'r>(&mut self, u: &'ast Url, ast_path: &mut AstNodePath<'r>) { - if self.is_import { - return u.visit_children_with_path(self, ast_path); + fn visit_rule(&mut self, rule: &mut CssRule) -> std::result::Result<(), Self::Error> { + match rule { + CssRule::Import(i) => { + let src = &*i.url; + + let issue_span = i.loc; + + self.references.push(Vc::upcast(ImportAssetReference::new( + self.origin, + Request::parse(Value::new(src.to_string().into())), + ImportAttributes::new_from_prelude(&i.clone().into_owned()).into(), + IssueSource::from_line_col( + Vc::upcast(self.source), + SourcePos { + line: issue_span.line as _, + column: issue_span.column as _, + }, + SourcePos { + line: issue_span.line as _, + column: issue_span.column as _, + }, + ), + ))); + let vc = UrlAssetReference::new( + self.origin, + Request::parse(Value::new(src.to_string().into())), + IssueSource::from_line_col( + Vc::upcast(self.source), + SourcePos { + line: issue_span.line as _, + column: issue_span.column as _, + }, + SourcePos { + line: issue_span.line as _, + column: issue_span.column as _, + }, + ), + ); + self.urls.push((src.to_string(), vc)); + + // let res = i.visit_children(self); + // res + Ok(()) + } + + _ => rule.visit_children(self), } + } - let src = url_string(u); + fn visit_url(&mut self, u: &mut Url) -> std::result::Result<(), Self::Error> { + let src = &*u.url; // ignore internal urls like `url(#noiseFilter)` // ignore server-relative urls like `url(/foo)` if !matches!(src.bytes().next(), Some(b'#') | Some(b'/')) { - let issue_span = u.span; - self.references.push(Vc::upcast(UrlAssetReference::new( + let issue_span = u.loc; + + let vc = UrlAssetReference::new( self.origin, Request::parse(Value::new(src.to_string().into())), - Vc::cell(as_parent_path(ast_path)), - IssueSource::from_swc_offsets( + IssueSource::from_line_col( Vc::upcast(self.source), - issue_span.lo.to_usize(), - issue_span.hi.to_usize(), + SourcePos { + line: issue_span.line as _, + column: issue_span.column as _, + }, + SourcePos { + line: issue_span.line as _, + column: issue_span.column as _, + }, ), - ))); + ); + + self.references.push(Vc::upcast(vc)); + self.urls.push((u.url.to_string(), vc)); } - u.visit_children_with_path(self, ast_path); + // u.visit_children(self)?; + + Ok(()) } } @@ -194,7 +188,3 @@ pub async fn css_resolve( ) .await } - -// TODO enable serialization -#[turbo_tasks::value(transparent, serialization = "none")] -pub struct AstPath(#[turbo_tasks(trace_ignore)] Vec); diff --git a/crates/turbopack-css/src/references/url.rs b/crates/turbopack-css/src/references/url.rs index 82304e7b14646..92b7f7fe4b0a6 100644 --- a/crates/turbopack-css/src/references/url.rs +++ b/crates/turbopack-css/src/references/url.rs @@ -1,7 +1,11 @@ +use std::{collections::HashMap, convert::Infallible}; + use anyhow::{bail, Result}; -use swc_core::{ - common::DUMMY_SP, - css::ast::{Str, UrlValue}, +use lightningcss::{ + stylesheet::StyleSheet, + values::url::Url, + visit_types, + visitor::{Visit, Visitor}, }; use turbo_tasks::{debug::ValueDebug, Value, ValueToString, Vc}; use turbopack_core::{ @@ -18,12 +22,7 @@ use turbopack_core::{ }; use turbopack_ecmascript::resolve::url_resolve; -use crate::{ - code_gen::{CodeGenerateable, CodeGeneration}, - create_visitor, - embed::CssEmbed, - references::AstPath, -}; +use crate::embed::CssEmbed; #[turbo_tasks::value(into = "new")] pub enum ReferencedAsset { @@ -36,7 +35,6 @@ pub enum ReferencedAsset { pub struct UrlAssetReference { pub origin: Vc>, pub request: Vc, - pub path: Vc, pub issue_source: Vc, } @@ -46,13 +44,11 @@ impl UrlAssetReference { pub fn new( origin: Vc>, request: Vc, - path: Vc, issue_source: Vc, ) -> Vc { Self::cell(UrlAssetReference { origin, request, - path, issue_source, }) } @@ -116,45 +112,60 @@ impl ValueToString for UrlAssetReference { } } -#[turbo_tasks::value_impl] -impl CodeGenerateable for UrlAssetReference { - #[turbo_tasks::function] - async fn code_generation( - self: Vc, - chunking_context: Vc>, - ) -> Result> { - let this = self.await?; - // TODO(WEB-662) This is not the correct way to get the current chunk path. It - // currently works as all chunks are in the same directory. - let chunk_path = chunking_context.chunk_path( - AssetIdent::from_path(this.origin.origin_path()), - ".css".to_string(), - ); - let context_path = chunk_path.parent().await?; - - let mut visitors = Vec::new(); - - if let ReferencedAsset::Some(asset) = &*self.get_referenced_asset(chunking_context).await? { - let path = asset.ident().path().await?; - let relative_path = context_path - .get_relative_path_to(&path) - .unwrap_or_else(|| format!("/{}", path.path)); - - visitors.push( - create_visitor!((&this.path.await?), visit_mut_url(u: &mut Url) { - u.value = Some(Box::new(UrlValue::Str(Str { - span: DUMMY_SP, - value: relative_path.as_str().into(), - raw: None, - }))) - }), - ); - } +#[turbo_tasks::function] +pub async fn resolve_url_reference( + url: Vc, + chunking_context: Vc>, +) -> Result>> { + let this = url.await?; + // TODO(WEB-662) This is not the correct way to get the current chunk path. It + // currently works as all chunks are in the same directory. + let chunk_path = chunking_context.chunk_path( + AssetIdent::from_path(this.origin.origin_path()), + ".css".to_string(), + ); + let context_path = chunk_path.parent().await?; + + if let ReferencedAsset::Some(asset) = &*url.get_referenced_asset(chunking_context).await? { + // TODO(WEB-662) This is not the correct way to get the path of the asset. + // `asset` is on module-level, but we need the output-level asset instead. + let path = asset.ident().path().await?; + let relative_path = context_path + .get_relative_path_to(&path) + .unwrap_or_else(|| format!("/{}", path.path)); - Ok(CodeGeneration { - visitors, - imports: vec![], + return Ok(Vc::cell(Some(relative_path))); + } + + Ok(Vc::cell(None)) +} + +pub fn replace_url_references( + ss: &mut StyleSheet<'static, 'static>, + urls: &HashMap, +) { + let mut replacer = AssetReferenceReplacer { urls }; + ss.visit(&mut replacer).unwrap(); +} + +struct AssetReferenceReplacer<'a> { + urls: &'a HashMap, +} + +impl<'i> Visitor<'i> for AssetReferenceReplacer<'_> { + type Error = Infallible; + + fn visit_types(&self) -> lightningcss::visitor::VisitTypes { + visit_types!(URLS) + } + + fn visit_url(&mut self, u: &mut Url) -> std::result::Result<(), Self::Error> { + u.visit_children(self)?; + + if let Some(new) = self.urls.get(&*u.url) { + u.url = new.clone().into(); } - .into()) + + Ok(()) } } diff --git a/crates/turbopack-css/src/transform/mod.rs b/crates/turbopack-css/src/transform/mod.rs deleted file mode 100644 index 0267bb1bfb5ed..0000000000000 --- a/crates/turbopack-css/src/transform/mod.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::sync::Arc; - -use anyhow::Result; -use swc_core::{ - common::SourceMap, - css::{ast::Stylesheet, visit::VisitMutWith}, -}; - -#[turbo_tasks::value(serialization = "auto_for_input")] -#[derive(PartialOrd, Ord, Hash, Debug, Copy, Clone)] -pub enum CssInputTransform { - Nested, - Custom, -} - -#[turbo_tasks::value(transparent, serialization = "auto_for_input")] -#[derive(Debug, PartialOrd, Ord, Hash, Clone)] -pub struct CssInputTransforms(Vec); - -pub struct TransformContext<'a> { - pub source_map: &'a Arc, -} - -impl CssInputTransform { - pub async fn apply( - &self, - stylesheet: &mut Stylesheet, - &TransformContext { source_map: _ }: &TransformContext<'_>, - ) -> Result<()> { - match *self { - CssInputTransform::Nested => { - stylesheet.visit_mut_with(&mut swc_core::css::compat::compiler::Compiler::new( - swc_core::css::compat::compiler::Config { - process: swc_core::css::compat::feature::Features::NESTING, - }, - )); - } - CssInputTransform::Custom => todo!(), - } - Ok(()) - } -} diff --git a/crates/turbopack-ecmascript-plugins/src/transform/styled_jsx.rs b/crates/turbopack-ecmascript-plugins/src/transform/styled_jsx.rs index 1c4d798e13253..fbedafe8c8d65 100644 --- a/crates/turbopack-ecmascript-plugins/src/transform/styled_jsx.rs +++ b/crates/turbopack-ecmascript-plugins/src/transform/styled_jsx.rs @@ -34,6 +34,7 @@ impl CustomTransformer for StyledJsxTransformer { FileName::Anon, styled_jsx::visitor::Config { use_lightningcss: false, + ..Default::default() }, )); diff --git a/crates/turbopack/src/lib.rs b/crates/turbopack/src/lib.rs index 416635bdb5076..768d72a361000 100644 --- a/crates/turbopack/src/lib.rs +++ b/crates/turbopack/src/lib.rs @@ -171,10 +171,9 @@ async fn apply_module_type( source, Vc::upcast(module_asset_context), )), - ModuleType::Css { ty, transforms } => Vc::upcast(CssModuleAsset::new( + ModuleType::Css { ty } => Vc::upcast(CssModuleAsset::new( source, Vc::upcast(module_asset_context), - *transforms, *ty, )), ModuleType::Static => Vc::upcast(StaticModuleAsset::new( diff --git a/crates/turbopack/src/module_options/mod.rs b/crates/turbopack/src/module_options/mod.rs index 173550f3b49ab..2ab17607f437a 100644 --- a/crates/turbopack/src/module_options/mod.rs +++ b/crates/turbopack/src/module_options/mod.rs @@ -14,7 +14,7 @@ use turbopack_core::{ reference_type::{CssReferenceSubType, ReferenceType, UrlReferenceSubType}, resolve::options::{ImportMap, ImportMapping}, }; -use turbopack_css::{CssInputTransform, CssModuleAssetType}; +use turbopack_css::CssModuleAssetType; use turbopack_ecmascript::{EcmascriptInputTransform, EcmascriptOptions, SpecifiedModuleType}; use turbopack_mdx::MdxTransformOptions; use turbopack_node::transforms::{postcss::PostCssTransform, webpack::WebpackLoaders}; @@ -181,7 +181,6 @@ impl ModuleOptions { Vc::cell(transforms.clone()) }; - let css_transforms = Vc::cell(vec![CssInputTransform::Nested]); let mdx_transforms = Vc::cell( if let Some(transform) = &ts_transform { if let Some(decorators_transform) = &decorators_transform { @@ -381,7 +380,6 @@ impl ModuleOptions { )]), vec![ModuleRuleEffect::ModuleType(ModuleType::Css { ty: CssModuleAssetType::Default, - transforms: css_transforms, })], ), ModuleRule::new( @@ -390,7 +388,6 @@ impl ModuleOptions { )]), vec![ModuleRuleEffect::ModuleType(ModuleType::Css { ty: CssModuleAssetType::Module, - transforms: css_transforms, })], ), ]); @@ -461,7 +458,6 @@ impl ModuleOptions { ]), vec![ModuleRuleEffect::ModuleType(ModuleType::Css { ty: CssModuleAssetType::Default, - transforms: css_transforms, })], ), ModuleRule::new( @@ -474,7 +470,6 @@ impl ModuleOptions { ]), vec![ModuleRuleEffect::ModuleType(ModuleType::Css { ty: CssModuleAssetType::Module, - transforms: css_transforms, })], ), ModuleRule::new_internal( @@ -483,7 +478,6 @@ impl ModuleOptions { )]), vec![ModuleRuleEffect::ModuleType(ModuleType::Css { ty: CssModuleAssetType::Default, - transforms: css_transforms, })], ), ModuleRule::new_internal( @@ -492,7 +486,6 @@ impl ModuleOptions { )]), vec![ModuleRuleEffect::ModuleType(ModuleType::Css { ty: CssModuleAssetType::Module, - transforms: css_transforms, })], ), ]); diff --git a/crates/turbopack/src/module_options/module_rule.rs b/crates/turbopack/src/module_options/module_rule.rs index 6e35a8c6e191b..1cfea45252379 100644 --- a/crates/turbopack/src/module_options/module_rule.rs +++ b/crates/turbopack/src/module_options/module_rule.rs @@ -5,7 +5,7 @@ use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ reference_type::ReferenceType, source::Source, source_transform::SourceTransforms, }; -use turbopack_css::{CssInputTransforms, CssModuleAssetType}; +use turbopack_css::CssModuleAssetType; use turbopack_ecmascript::{EcmascriptInputTransforms, EcmascriptOptions}; use turbopack_mdx::MdxTransformOptions; use turbopack_wasm::source::WebAssemblySourceType; @@ -122,7 +122,6 @@ pub enum ModuleType { CssModule, Css { ty: CssModuleAssetType, - transforms: Vc, }, Static, WebAssembly {