├── .github └── workflows │ └── ci_main.yml ├── .gitignore ├── .taplo.toml ├── Cargo.lock ├── Cargo.toml ├── README.md ├── babel.config.js ├── jest.config.js ├── package-lock.json ├── package.json ├── packages ├── swc-plugin-vanilla-extract │ ├── Cargo.toml │ └── src │ │ └── lib.rs └── swc-vanilla-extract-visitor │ ├── Cargo.toml │ └── src │ ├── constants.rs │ ├── debug_id_find_visitor.rs │ ├── debug_id_inject_visitor.rs │ ├── get_relavant_call.rs │ ├── import_collect_visitor.rs │ └── lib.rs ├── rust-toolchain └── spec ├── index.test.ts └── swc-vanilla-custom-transform ├── Cargo.toml ├── build.rs └── src ├── lib.rs └── util.rs /.github/workflows/ci_main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | types: ['opened', 'reopened', 'synchronize'] 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | name: Run test 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: actions/cache@v2 18 | with: 19 | path: | 20 | ~/.cargo/bin/ 21 | ~/.cargo/registry/index/ 22 | ~/.cargo/registry/cache/ 23 | ~/.cargo/git/db/ 24 | target/ 25 | key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} 26 | - uses: actions/setup-node@v2 27 | with: 28 | node-version: "16" 29 | cache: "npm" 30 | - uses: actions-rs/toolchain@v1 31 | with: 32 | profile: minimal 33 | components: llvm-tools-preview 34 | - name: Install cargo-llvm-cov 35 | uses: taiki-e/install-action@cargo-llvm-cov 36 | - name: install 37 | run: | 38 | npm install -g npm@latest 39 | npm ci 40 | curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 41 | rustup target add wasm32-wasi 42 | - name: test 43 | run: npm test 44 | - name: build 45 | run: | 46 | cargo check 47 | - name: Generate code coverage 48 | run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info 49 | - uses: codecov/codecov-action@v2 50 | with: 51 | token: ${{ secrets.CODECOV_TOKEN }} 52 | files: lcov.info 53 | verbose: true 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock 3 | node_modules/ 4 | .swc/ 5 | *.log 6 | *.node 7 | index.d.ts 8 | index.js 9 | spec/swc-vanilla-custom-transform/target/ 10 | a.js 11 | swc-plugin-vanilla-*.tgz 12 | /tmp 13 | trace-*.json -------------------------------------------------------------------------------- /.taplo.toml: -------------------------------------------------------------------------------- 1 | # https://taplo.tamasfe.dev/configuration/formatter-options.html 2 | [formatting] 3 | align_entries = true 4 | indent_tables = true 5 | reorder_keys = true 6 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "Inflector" 7 | version = "0.11.4" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" 10 | dependencies = [ 11 | "lazy_static", 12 | "regex", 13 | ] 14 | 15 | [[package]] 16 | name = "addr2line" 17 | version = "0.17.0" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" 20 | dependencies = [ 21 | "gimli", 22 | ] 23 | 24 | [[package]] 25 | name = "adler" 26 | version = "1.0.2" 27 | source = "registry+https://github.com/rust-lang/crates.io-index" 28 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 29 | 30 | [[package]] 31 | name = "ahash" 32 | version = "0.7.6" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" 35 | dependencies = [ 36 | "getrandom", 37 | "once_cell", 38 | "version_check", 39 | ] 40 | 41 | [[package]] 42 | name = "aho-corasick" 43 | version = "0.7.19" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" 46 | dependencies = [ 47 | "memchr", 48 | ] 49 | 50 | [[package]] 51 | name = "ansi_term" 52 | version = "0.12.1" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" 55 | dependencies = [ 56 | "winapi", 57 | ] 58 | 59 | [[package]] 60 | name = "anyhow" 61 | version = "1.0.66" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" 64 | 65 | [[package]] 66 | name = "ast_node" 67 | version = "0.8.6" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "cf94863c5fdfee166d0907c44e5fee970123b2b7307046d35d1e671aa93afbba" 70 | dependencies = [ 71 | "darling", 72 | "pmutil", 73 | "proc-macro2", 74 | "quote", 75 | "swc_macros_common", 76 | "syn", 77 | ] 78 | 79 | [[package]] 80 | name = "atty" 81 | version = "0.2.14" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 84 | dependencies = [ 85 | "hermit-abi", 86 | "libc", 87 | "winapi", 88 | ] 89 | 90 | [[package]] 91 | name = "autocfg" 92 | version = "1.1.0" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 95 | 96 | [[package]] 97 | name = "backtrace" 98 | version = "0.3.66" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" 101 | dependencies = [ 102 | "addr2line", 103 | "cc", 104 | "cfg-if", 105 | "libc", 106 | "miniz_oxide", 107 | "object", 108 | "rustc-demangle", 109 | ] 110 | 111 | [[package]] 112 | name = "base64" 113 | version = "0.13.1" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" 116 | 117 | [[package]] 118 | name = "better_scoped_tls" 119 | version = "0.1.0" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "b73e8ecdec39e98aa3b19e8cd0b8ed8f77ccb86a6b0b2dc7cd86d105438a2123" 122 | dependencies = [ 123 | "scoped-tls", 124 | ] 125 | 126 | [[package]] 127 | name = "bitflags" 128 | version = "1.3.2" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 131 | 132 | [[package]] 133 | name = "block-buffer" 134 | version = "0.10.3" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" 137 | dependencies = [ 138 | "generic-array", 139 | ] 140 | 141 | [[package]] 142 | name = "bytecheck" 143 | version = "0.6.9" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "d11cac2c12b5adc6570dad2ee1b87eff4955dac476fe12d81e5fdd352e52406f" 146 | dependencies = [ 147 | "bytecheck_derive", 148 | "ptr_meta", 149 | ] 150 | 151 | [[package]] 152 | name = "bytecheck_derive" 153 | version = "0.6.9" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | checksum = "13e576ebe98e605500b3c8041bb888e966653577172df6dd97398714eb30b9bf" 156 | dependencies = [ 157 | "proc-macro2", 158 | "quote", 159 | "syn", 160 | ] 161 | 162 | [[package]] 163 | name = "cc" 164 | version = "1.0.76" 165 | source = "registry+https://github.com/rust-lang/crates.io-index" 166 | checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" 167 | 168 | [[package]] 169 | name = "cfg-if" 170 | version = "1.0.0" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 173 | 174 | [[package]] 175 | name = "cpufeatures" 176 | version = "0.2.5" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" 179 | dependencies = [ 180 | "libc", 181 | ] 182 | 183 | [[package]] 184 | name = "crypto-common" 185 | version = "0.1.6" 186 | source = "registry+https://github.com/rust-lang/crates.io-index" 187 | checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" 188 | dependencies = [ 189 | "generic-array", 190 | "typenum", 191 | ] 192 | 193 | [[package]] 194 | name = "ctor" 195 | version = "0.1.26" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" 198 | dependencies = [ 199 | "quote", 200 | "syn", 201 | ] 202 | 203 | [[package]] 204 | name = "darling" 205 | version = "0.13.4" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" 208 | dependencies = [ 209 | "darling_core", 210 | "darling_macro", 211 | ] 212 | 213 | [[package]] 214 | name = "darling_core" 215 | version = "0.13.4" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" 218 | dependencies = [ 219 | "fnv", 220 | "ident_case", 221 | "proc-macro2", 222 | "quote", 223 | "strsim", 224 | "syn", 225 | ] 226 | 227 | [[package]] 228 | name = "darling_macro" 229 | version = "0.13.4" 230 | source = "registry+https://github.com/rust-lang/crates.io-index" 231 | checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" 232 | dependencies = [ 233 | "darling_core", 234 | "quote", 235 | "syn", 236 | ] 237 | 238 | [[package]] 239 | name = "diff" 240 | version = "0.1.13" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" 243 | 244 | [[package]] 245 | name = "difference" 246 | version = "2.0.0" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" 249 | 250 | [[package]] 251 | name = "digest" 252 | version = "0.10.5" 253 | source = "registry+https://github.com/rust-lang/crates.io-index" 254 | checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" 255 | dependencies = [ 256 | "block-buffer", 257 | "crypto-common", 258 | ] 259 | 260 | [[package]] 261 | name = "either" 262 | version = "1.8.0" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" 265 | 266 | [[package]] 267 | name = "enum-iterator" 268 | version = "1.1.3" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | checksum = "45a0ac4aeb3a18f92eaf09c6bb9b3ac30ff61ca95514fc58cbead1c9a6bf5401" 271 | dependencies = [ 272 | "enum-iterator-derive", 273 | ] 274 | 275 | [[package]] 276 | name = "enum-iterator-derive" 277 | version = "1.1.0" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "828de45d0ca18782232dfb8f3ea9cc428e8ced380eb26a520baaacfc70de39ce" 280 | dependencies = [ 281 | "proc-macro2", 282 | "quote", 283 | "syn", 284 | ] 285 | 286 | [[package]] 287 | name = "enum_kind" 288 | version = "0.2.1" 289 | source = "registry+https://github.com/rust-lang/crates.io-index" 290 | checksum = "78b940da354ae81ef0926c5eaa428207b8f4f091d3956c891dfbd124162bed99" 291 | dependencies = [ 292 | "pmutil", 293 | "proc-macro2", 294 | "swc_macros_common", 295 | "syn", 296 | ] 297 | 298 | [[package]] 299 | name = "fastrand" 300 | version = "1.8.0" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" 303 | dependencies = [ 304 | "instant", 305 | ] 306 | 307 | [[package]] 308 | name = "fnv" 309 | version = "1.0.7" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 312 | 313 | [[package]] 314 | name = "form_urlencoded" 315 | version = "1.1.0" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" 318 | dependencies = [ 319 | "percent-encoding", 320 | ] 321 | 322 | [[package]] 323 | name = "from_variant" 324 | version = "0.1.4" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "f0981e470d2ab9f643df3921d54f1952ea100c39fdb6a3fdc820e20d2291df6c" 327 | dependencies = [ 328 | "pmutil", 329 | "proc-macro2", 330 | "swc_macros_common", 331 | "syn", 332 | ] 333 | 334 | [[package]] 335 | name = "generic-array" 336 | version = "0.14.6" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" 339 | dependencies = [ 340 | "typenum", 341 | "version_check", 342 | ] 343 | 344 | [[package]] 345 | name = "getrandom" 346 | version = "0.2.8" 347 | source = "registry+https://github.com/rust-lang/crates.io-index" 348 | checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" 349 | dependencies = [ 350 | "cfg-if", 351 | "libc", 352 | "wasi", 353 | ] 354 | 355 | [[package]] 356 | name = "getset" 357 | version = "0.1.2" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" 360 | dependencies = [ 361 | "proc-macro-error", 362 | "proc-macro2", 363 | "quote", 364 | "syn", 365 | ] 366 | 367 | [[package]] 368 | name = "gimli" 369 | version = "0.26.2" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" 372 | 373 | [[package]] 374 | name = "glob" 375 | version = "0.3.0" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 378 | 379 | [[package]] 380 | name = "hashbrown" 381 | version = "0.12.3" 382 | source = "registry+https://github.com/rust-lang/crates.io-index" 383 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 384 | dependencies = [ 385 | "ahash", 386 | ] 387 | 388 | [[package]] 389 | name = "hermit-abi" 390 | version = "0.1.19" 391 | source = "registry+https://github.com/rust-lang/crates.io-index" 392 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 393 | dependencies = [ 394 | "libc", 395 | ] 396 | 397 | [[package]] 398 | name = "hex" 399 | version = "0.4.3" 400 | source = "registry+https://github.com/rust-lang/crates.io-index" 401 | checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" 402 | 403 | [[package]] 404 | name = "ident_case" 405 | version = "1.0.1" 406 | source = "registry+https://github.com/rust-lang/crates.io-index" 407 | checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" 408 | 409 | [[package]] 410 | name = "idna" 411 | version = "0.3.0" 412 | source = "registry+https://github.com/rust-lang/crates.io-index" 413 | checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" 414 | dependencies = [ 415 | "unicode-bidi", 416 | "unicode-normalization", 417 | ] 418 | 419 | [[package]] 420 | name = "if_chain" 421 | version = "1.0.2" 422 | source = "registry+https://github.com/rust-lang/crates.io-index" 423 | checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" 424 | 425 | [[package]] 426 | name = "indexmap" 427 | version = "1.9.1" 428 | source = "registry+https://github.com/rust-lang/crates.io-index" 429 | checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" 430 | dependencies = [ 431 | "autocfg", 432 | "hashbrown", 433 | ] 434 | 435 | [[package]] 436 | name = "instant" 437 | version = "0.1.12" 438 | source = "registry+https://github.com/rust-lang/crates.io-index" 439 | checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" 440 | dependencies = [ 441 | "cfg-if", 442 | ] 443 | 444 | [[package]] 445 | name = "is-macro" 446 | version = "0.2.1" 447 | source = "registry+https://github.com/rust-lang/crates.io-index" 448 | checksum = "1c068d4c6b922cd6284c609cfa6dec0e41615c9c5a1a4ba729a970d8daba05fb" 449 | dependencies = [ 450 | "Inflector", 451 | "pmutil", 452 | "proc-macro2", 453 | "quote", 454 | "syn", 455 | ] 456 | 457 | [[package]] 458 | name = "is_ci" 459 | version = "1.1.1" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" 462 | 463 | [[package]] 464 | name = "itoa" 465 | version = "1.0.4" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" 468 | 469 | [[package]] 470 | name = "lazy_static" 471 | version = "1.4.0" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 474 | 475 | [[package]] 476 | name = "lexical" 477 | version = "6.1.1" 478 | source = "registry+https://github.com/rust-lang/crates.io-index" 479 | checksum = "c7aefb36fd43fef7003334742cbf77b243fcd36418a1d1bdd480d613a67968f6" 480 | dependencies = [ 481 | "lexical-core", 482 | ] 483 | 484 | [[package]] 485 | name = "lexical-core" 486 | version = "0.8.5" 487 | source = "registry+https://github.com/rust-lang/crates.io-index" 488 | checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" 489 | dependencies = [ 490 | "lexical-parse-float", 491 | "lexical-parse-integer", 492 | "lexical-util", 493 | "lexical-write-float", 494 | "lexical-write-integer", 495 | ] 496 | 497 | [[package]] 498 | name = "lexical-parse-float" 499 | version = "0.8.5" 500 | source = "registry+https://github.com/rust-lang/crates.io-index" 501 | checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" 502 | dependencies = [ 503 | "lexical-parse-integer", 504 | "lexical-util", 505 | "static_assertions", 506 | ] 507 | 508 | [[package]] 509 | name = "lexical-parse-integer" 510 | version = "0.8.6" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" 513 | dependencies = [ 514 | "lexical-util", 515 | "static_assertions", 516 | ] 517 | 518 | [[package]] 519 | name = "lexical-util" 520 | version = "0.8.5" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" 523 | dependencies = [ 524 | "static_assertions", 525 | ] 526 | 527 | [[package]] 528 | name = "lexical-write-float" 529 | version = "0.8.5" 530 | source = "registry+https://github.com/rust-lang/crates.io-index" 531 | checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" 532 | dependencies = [ 533 | "lexical-util", 534 | "lexical-write-integer", 535 | "static_assertions", 536 | ] 537 | 538 | [[package]] 539 | name = "lexical-write-integer" 540 | version = "0.8.5" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" 543 | dependencies = [ 544 | "lexical-util", 545 | "static_assertions", 546 | ] 547 | 548 | [[package]] 549 | name = "libc" 550 | version = "0.2.137" 551 | source = "registry+https://github.com/rust-lang/crates.io-index" 552 | checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" 553 | 554 | [[package]] 555 | name = "lock_api" 556 | version = "0.4.9" 557 | source = "registry+https://github.com/rust-lang/crates.io-index" 558 | checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" 559 | dependencies = [ 560 | "autocfg", 561 | "scopeguard", 562 | ] 563 | 564 | [[package]] 565 | name = "log" 566 | version = "0.4.17" 567 | source = "registry+https://github.com/rust-lang/crates.io-index" 568 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 569 | dependencies = [ 570 | "cfg-if", 571 | ] 572 | 573 | [[package]] 574 | name = "matchers" 575 | version = "0.1.0" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" 578 | dependencies = [ 579 | "regex-automata", 580 | ] 581 | 582 | [[package]] 583 | name = "memchr" 584 | version = "2.5.0" 585 | source = "registry+https://github.com/rust-lang/crates.io-index" 586 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 587 | 588 | [[package]] 589 | name = "miette" 590 | version = "4.7.1" 591 | source = "registry+https://github.com/rust-lang/crates.io-index" 592 | checksum = "1c90329e44f9208b55f45711f9558cec15d7ef8295cc65ecd6d4188ae8edc58c" 593 | dependencies = [ 594 | "atty", 595 | "backtrace", 596 | "miette-derive", 597 | "once_cell", 598 | "owo-colors", 599 | "supports-color", 600 | "supports-hyperlinks", 601 | "supports-unicode", 602 | "terminal_size", 603 | "textwrap", 604 | "thiserror", 605 | "unicode-width", 606 | ] 607 | 608 | [[package]] 609 | name = "miette-derive" 610 | version = "4.7.1" 611 | source = "registry+https://github.com/rust-lang/crates.io-index" 612 | checksum = "6b5bc45b761bcf1b5e6e6c4128cd93b84c218721a8d9b894aa0aff4ed180174c" 613 | dependencies = [ 614 | "proc-macro2", 615 | "quote", 616 | "syn", 617 | ] 618 | 619 | [[package]] 620 | name = "miniz_oxide" 621 | version = "0.5.4" 622 | source = "registry+https://github.com/rust-lang/crates.io-index" 623 | checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" 624 | dependencies = [ 625 | "adler", 626 | ] 627 | 628 | [[package]] 629 | name = "new_debug_unreachable" 630 | version = "1.0.4" 631 | source = "registry+https://github.com/rust-lang/crates.io-index" 632 | checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" 633 | 634 | [[package]] 635 | name = "nu-ansi-term" 636 | version = "0.46.0" 637 | source = "registry+https://github.com/rust-lang/crates.io-index" 638 | checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" 639 | dependencies = [ 640 | "overload", 641 | "winapi", 642 | ] 643 | 644 | [[package]] 645 | name = "num-bigint" 646 | version = "0.4.3" 647 | source = "registry+https://github.com/rust-lang/crates.io-index" 648 | checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" 649 | dependencies = [ 650 | "autocfg", 651 | "num-integer", 652 | "num-traits", 653 | "serde", 654 | ] 655 | 656 | [[package]] 657 | name = "num-integer" 658 | version = "0.1.45" 659 | source = "registry+https://github.com/rust-lang/crates.io-index" 660 | checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" 661 | dependencies = [ 662 | "autocfg", 663 | "num-traits", 664 | ] 665 | 666 | [[package]] 667 | name = "num-traits" 668 | version = "0.2.15" 669 | source = "registry+https://github.com/rust-lang/crates.io-index" 670 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 671 | dependencies = [ 672 | "autocfg", 673 | ] 674 | 675 | [[package]] 676 | name = "num_cpus" 677 | version = "1.14.0" 678 | source = "registry+https://github.com/rust-lang/crates.io-index" 679 | checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" 680 | dependencies = [ 681 | "hermit-abi", 682 | "libc", 683 | ] 684 | 685 | [[package]] 686 | name = "object" 687 | version = "0.29.0" 688 | source = "registry+https://github.com/rust-lang/crates.io-index" 689 | checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" 690 | dependencies = [ 691 | "memchr", 692 | ] 693 | 694 | [[package]] 695 | name = "once_cell" 696 | version = "1.16.0" 697 | source = "registry+https://github.com/rust-lang/crates.io-index" 698 | checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" 699 | 700 | [[package]] 701 | name = "output_vt100" 702 | version = "0.1.3" 703 | source = "registry+https://github.com/rust-lang/crates.io-index" 704 | checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" 705 | dependencies = [ 706 | "winapi", 707 | ] 708 | 709 | [[package]] 710 | name = "overload" 711 | version = "0.1.1" 712 | source = "registry+https://github.com/rust-lang/crates.io-index" 713 | checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" 714 | 715 | [[package]] 716 | name = "owo-colors" 717 | version = "3.5.0" 718 | source = "registry+https://github.com/rust-lang/crates.io-index" 719 | checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" 720 | 721 | [[package]] 722 | name = "parking_lot" 723 | version = "0.12.1" 724 | source = "registry+https://github.com/rust-lang/crates.io-index" 725 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" 726 | dependencies = [ 727 | "lock_api", 728 | "parking_lot_core", 729 | ] 730 | 731 | [[package]] 732 | name = "parking_lot_core" 733 | version = "0.9.4" 734 | source = "registry+https://github.com/rust-lang/crates.io-index" 735 | checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" 736 | dependencies = [ 737 | "cfg-if", 738 | "libc", 739 | "redox_syscall", 740 | "smallvec", 741 | "windows-sys", 742 | ] 743 | 744 | [[package]] 745 | name = "path-slash" 746 | version = "0.2.1" 747 | source = "registry+https://github.com/rust-lang/crates.io-index" 748 | checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" 749 | 750 | [[package]] 751 | name = "percent-encoding" 752 | version = "2.2.0" 753 | source = "registry+https://github.com/rust-lang/crates.io-index" 754 | checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" 755 | 756 | [[package]] 757 | name = "phf" 758 | version = "0.10.1" 759 | source = "registry+https://github.com/rust-lang/crates.io-index" 760 | checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" 761 | dependencies = [ 762 | "phf_macros", 763 | "phf_shared", 764 | "proc-macro-hack", 765 | ] 766 | 767 | [[package]] 768 | name = "phf_generator" 769 | version = "0.10.0" 770 | source = "registry+https://github.com/rust-lang/crates.io-index" 771 | checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" 772 | dependencies = [ 773 | "phf_shared", 774 | "rand", 775 | ] 776 | 777 | [[package]] 778 | name = "phf_macros" 779 | version = "0.10.0" 780 | source = "registry+https://github.com/rust-lang/crates.io-index" 781 | checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0" 782 | dependencies = [ 783 | "phf_generator", 784 | "phf_shared", 785 | "proc-macro-hack", 786 | "proc-macro2", 787 | "quote", 788 | "syn", 789 | ] 790 | 791 | [[package]] 792 | name = "phf_shared" 793 | version = "0.10.0" 794 | source = "registry+https://github.com/rust-lang/crates.io-index" 795 | checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" 796 | dependencies = [ 797 | "siphasher", 798 | ] 799 | 800 | [[package]] 801 | name = "pin-project-lite" 802 | version = "0.2.9" 803 | source = "registry+https://github.com/rust-lang/crates.io-index" 804 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" 805 | 806 | [[package]] 807 | name = "pmutil" 808 | version = "0.5.3" 809 | source = "registry+https://github.com/rust-lang/crates.io-index" 810 | checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" 811 | dependencies = [ 812 | "proc-macro2", 813 | "quote", 814 | "syn", 815 | ] 816 | 817 | [[package]] 818 | name = "ppv-lite86" 819 | version = "0.2.17" 820 | source = "registry+https://github.com/rust-lang/crates.io-index" 821 | checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" 822 | 823 | [[package]] 824 | name = "precomputed-hash" 825 | version = "0.1.1" 826 | source = "registry+https://github.com/rust-lang/crates.io-index" 827 | checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" 828 | 829 | [[package]] 830 | name = "pretty_assertions" 831 | version = "1.3.0" 832 | source = "registry+https://github.com/rust-lang/crates.io-index" 833 | checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" 834 | dependencies = [ 835 | "ctor", 836 | "diff", 837 | "output_vt100", 838 | "yansi", 839 | ] 840 | 841 | [[package]] 842 | name = "proc-macro-error" 843 | version = "1.0.4" 844 | source = "registry+https://github.com/rust-lang/crates.io-index" 845 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 846 | dependencies = [ 847 | "proc-macro-error-attr", 848 | "proc-macro2", 849 | "quote", 850 | "syn", 851 | "version_check", 852 | ] 853 | 854 | [[package]] 855 | name = "proc-macro-error-attr" 856 | version = "1.0.4" 857 | source = "registry+https://github.com/rust-lang/crates.io-index" 858 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 859 | dependencies = [ 860 | "proc-macro2", 861 | "quote", 862 | "version_check", 863 | ] 864 | 865 | [[package]] 866 | name = "proc-macro-hack" 867 | version = "0.5.19" 868 | source = "registry+https://github.com/rust-lang/crates.io-index" 869 | checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" 870 | 871 | [[package]] 872 | name = "proc-macro2" 873 | version = "1.0.47" 874 | source = "registry+https://github.com/rust-lang/crates.io-index" 875 | checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" 876 | dependencies = [ 877 | "unicode-ident", 878 | ] 879 | 880 | [[package]] 881 | name = "ptr_meta" 882 | version = "0.1.4" 883 | source = "registry+https://github.com/rust-lang/crates.io-index" 884 | checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" 885 | dependencies = [ 886 | "ptr_meta_derive", 887 | ] 888 | 889 | [[package]] 890 | name = "ptr_meta_derive" 891 | version = "0.1.4" 892 | source = "registry+https://github.com/rust-lang/crates.io-index" 893 | checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" 894 | dependencies = [ 895 | "proc-macro2", 896 | "quote", 897 | "syn", 898 | ] 899 | 900 | [[package]] 901 | name = "quote" 902 | version = "1.0.21" 903 | source = "registry+https://github.com/rust-lang/crates.io-index" 904 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 905 | dependencies = [ 906 | "proc-macro2", 907 | ] 908 | 909 | [[package]] 910 | name = "rand" 911 | version = "0.8.5" 912 | source = "registry+https://github.com/rust-lang/crates.io-index" 913 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 914 | dependencies = [ 915 | "libc", 916 | "rand_chacha", 917 | "rand_core", 918 | ] 919 | 920 | [[package]] 921 | name = "rand_chacha" 922 | version = "0.3.1" 923 | source = "registry+https://github.com/rust-lang/crates.io-index" 924 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" 925 | dependencies = [ 926 | "ppv-lite86", 927 | "rand_core", 928 | ] 929 | 930 | [[package]] 931 | name = "rand_core" 932 | version = "0.6.4" 933 | source = "registry+https://github.com/rust-lang/crates.io-index" 934 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" 935 | dependencies = [ 936 | "getrandom", 937 | ] 938 | 939 | [[package]] 940 | name = "redox_syscall" 941 | version = "0.2.16" 942 | source = "registry+https://github.com/rust-lang/crates.io-index" 943 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 944 | dependencies = [ 945 | "bitflags", 946 | ] 947 | 948 | [[package]] 949 | name = "regex" 950 | version = "1.7.0" 951 | source = "registry+https://github.com/rust-lang/crates.io-index" 952 | checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" 953 | dependencies = [ 954 | "aho-corasick", 955 | "memchr", 956 | "regex-syntax", 957 | ] 958 | 959 | [[package]] 960 | name = "regex-automata" 961 | version = "0.1.10" 962 | source = "registry+https://github.com/rust-lang/crates.io-index" 963 | checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" 964 | dependencies = [ 965 | "regex-syntax", 966 | ] 967 | 968 | [[package]] 969 | name = "regex-syntax" 970 | version = "0.6.28" 971 | source = "registry+https://github.com/rust-lang/crates.io-index" 972 | checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" 973 | 974 | [[package]] 975 | name = "relative-path" 976 | version = "1.7.2" 977 | source = "registry+https://github.com/rust-lang/crates.io-index" 978 | checksum = "0df32d82cedd1499386877b062ebe8721f806de80b08d183c70184ef17dd1d42" 979 | 980 | [[package]] 981 | name = "remove_dir_all" 982 | version = "0.5.3" 983 | source = "registry+https://github.com/rust-lang/crates.io-index" 984 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 985 | dependencies = [ 986 | "winapi", 987 | ] 988 | 989 | [[package]] 990 | name = "rend" 991 | version = "0.3.6" 992 | source = "registry+https://github.com/rust-lang/crates.io-index" 993 | checksum = "79af64b4b6362ffba04eef3a4e10829718a4896dac19daa741851c86781edf95" 994 | dependencies = [ 995 | "bytecheck", 996 | ] 997 | 998 | [[package]] 999 | name = "rkyv" 1000 | version = "0.7.37" 1001 | source = "registry+https://github.com/rust-lang/crates.io-index" 1002 | checksum = "1f08c8062c1fe1253064043b8fc07bfea1b9702b71b4a86c11ea3588183b12e1" 1003 | dependencies = [ 1004 | "bytecheck", 1005 | "hashbrown", 1006 | "ptr_meta", 1007 | "rend", 1008 | "rkyv_derive", 1009 | "seahash", 1010 | ] 1011 | 1012 | [[package]] 1013 | name = "rkyv_derive" 1014 | version = "0.7.37" 1015 | source = "registry+https://github.com/rust-lang/crates.io-index" 1016 | checksum = "e289706df51226e84814bf6ba1a9e1013112ae29bc7a9878f73fce360520c403" 1017 | dependencies = [ 1018 | "proc-macro2", 1019 | "quote", 1020 | "syn", 1021 | ] 1022 | 1023 | [[package]] 1024 | name = "rustc-demangle" 1025 | version = "0.1.21" 1026 | source = "registry+https://github.com/rust-lang/crates.io-index" 1027 | checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" 1028 | 1029 | [[package]] 1030 | name = "rustc-hash" 1031 | version = "1.1.0" 1032 | source = "registry+https://github.com/rust-lang/crates.io-index" 1033 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" 1034 | 1035 | [[package]] 1036 | name = "rustc_version" 1037 | version = "0.2.3" 1038 | source = "registry+https://github.com/rust-lang/crates.io-index" 1039 | checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 1040 | dependencies = [ 1041 | "semver", 1042 | ] 1043 | 1044 | [[package]] 1045 | name = "rustversion" 1046 | version = "1.0.9" 1047 | source = "registry+https://github.com/rust-lang/crates.io-index" 1048 | checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" 1049 | 1050 | [[package]] 1051 | name = "ryu" 1052 | version = "1.0.11" 1053 | source = "registry+https://github.com/rust-lang/crates.io-index" 1054 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 1055 | 1056 | [[package]] 1057 | name = "scoped-tls" 1058 | version = "1.0.1" 1059 | source = "registry+https://github.com/rust-lang/crates.io-index" 1060 | checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" 1061 | 1062 | [[package]] 1063 | name = "scopeguard" 1064 | version = "1.1.0" 1065 | source = "registry+https://github.com/rust-lang/crates.io-index" 1066 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 1067 | 1068 | [[package]] 1069 | name = "seahash" 1070 | version = "4.1.0" 1071 | source = "registry+https://github.com/rust-lang/crates.io-index" 1072 | checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" 1073 | 1074 | [[package]] 1075 | name = "semver" 1076 | version = "0.9.0" 1077 | source = "registry+https://github.com/rust-lang/crates.io-index" 1078 | checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 1079 | dependencies = [ 1080 | "semver-parser", 1081 | ] 1082 | 1083 | [[package]] 1084 | name = "semver-parser" 1085 | version = "0.7.0" 1086 | source = "registry+https://github.com/rust-lang/crates.io-index" 1087 | checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 1088 | 1089 | [[package]] 1090 | name = "serde" 1091 | version = "1.0.147" 1092 | source = "registry+https://github.com/rust-lang/crates.io-index" 1093 | checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" 1094 | dependencies = [ 1095 | "serde_derive", 1096 | ] 1097 | 1098 | [[package]] 1099 | name = "serde_derive" 1100 | version = "1.0.147" 1101 | source = "registry+https://github.com/rust-lang/crates.io-index" 1102 | checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" 1103 | dependencies = [ 1104 | "proc-macro2", 1105 | "quote", 1106 | "syn", 1107 | ] 1108 | 1109 | [[package]] 1110 | name = "serde_json" 1111 | version = "1.0.87" 1112 | source = "registry+https://github.com/rust-lang/crates.io-index" 1113 | checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" 1114 | dependencies = [ 1115 | "itoa", 1116 | "ryu", 1117 | "serde", 1118 | ] 1119 | 1120 | [[package]] 1121 | name = "sha-1" 1122 | version = "0.10.0" 1123 | source = "registry+https://github.com/rust-lang/crates.io-index" 1124 | checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" 1125 | dependencies = [ 1126 | "cfg-if", 1127 | "cpufeatures", 1128 | "digest", 1129 | ] 1130 | 1131 | [[package]] 1132 | name = "sharded-slab" 1133 | version = "0.1.4" 1134 | source = "registry+https://github.com/rust-lang/crates.io-index" 1135 | checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" 1136 | dependencies = [ 1137 | "lazy_static", 1138 | ] 1139 | 1140 | [[package]] 1141 | name = "siphasher" 1142 | version = "0.3.10" 1143 | source = "registry+https://github.com/rust-lang/crates.io-index" 1144 | checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" 1145 | 1146 | [[package]] 1147 | name = "smallvec" 1148 | version = "1.10.0" 1149 | source = "registry+https://github.com/rust-lang/crates.io-index" 1150 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 1151 | 1152 | [[package]] 1153 | name = "smawk" 1154 | version = "0.3.1" 1155 | source = "registry+https://github.com/rust-lang/crates.io-index" 1156 | checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" 1157 | 1158 | [[package]] 1159 | name = "sourcemap" 1160 | version = "6.2.0" 1161 | source = "registry+https://github.com/rust-lang/crates.io-index" 1162 | checksum = "c46fdc1838ff49cf692226f5c2b0f5b7538f556863d0eca602984714667ac6e7" 1163 | dependencies = [ 1164 | "base64", 1165 | "if_chain", 1166 | "lazy_static", 1167 | "regex", 1168 | "rustc_version", 1169 | "serde", 1170 | "serde_json", 1171 | "url", 1172 | ] 1173 | 1174 | [[package]] 1175 | name = "stable_deref_trait" 1176 | version = "1.2.0" 1177 | source = "registry+https://github.com/rust-lang/crates.io-index" 1178 | checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" 1179 | 1180 | [[package]] 1181 | name = "static_assertions" 1182 | version = "1.1.0" 1183 | source = "registry+https://github.com/rust-lang/crates.io-index" 1184 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 1185 | 1186 | [[package]] 1187 | name = "string_cache" 1188 | version = "0.8.4" 1189 | source = "registry+https://github.com/rust-lang/crates.io-index" 1190 | checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08" 1191 | dependencies = [ 1192 | "new_debug_unreachable", 1193 | "once_cell", 1194 | "parking_lot", 1195 | "phf_shared", 1196 | "precomputed-hash", 1197 | "serde", 1198 | ] 1199 | 1200 | [[package]] 1201 | name = "string_cache_codegen" 1202 | version = "0.5.2" 1203 | source = "registry+https://github.com/rust-lang/crates.io-index" 1204 | checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" 1205 | dependencies = [ 1206 | "phf_generator", 1207 | "phf_shared", 1208 | "proc-macro2", 1209 | "quote", 1210 | ] 1211 | 1212 | [[package]] 1213 | name = "string_enum" 1214 | version = "0.3.2" 1215 | source = "registry+https://github.com/rust-lang/crates.io-index" 1216 | checksum = "994453cd270ad0265796eb24abf5540091ed03e681c5f3c12bc33e4db33253e1" 1217 | dependencies = [ 1218 | "pmutil", 1219 | "proc-macro2", 1220 | "quote", 1221 | "swc_macros_common", 1222 | "syn", 1223 | ] 1224 | 1225 | [[package]] 1226 | name = "strsim" 1227 | version = "0.10.0" 1228 | source = "registry+https://github.com/rust-lang/crates.io-index" 1229 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 1230 | 1231 | [[package]] 1232 | name = "supports-color" 1233 | version = "1.3.1" 1234 | source = "registry+https://github.com/rust-lang/crates.io-index" 1235 | checksum = "8ba6faf2ca7ee42fdd458f4347ae0a9bd6bcc445ad7cb57ad82b383f18870d6f" 1236 | dependencies = [ 1237 | "atty", 1238 | "is_ci", 1239 | ] 1240 | 1241 | [[package]] 1242 | name = "supports-hyperlinks" 1243 | version = "1.2.0" 1244 | source = "registry+https://github.com/rust-lang/crates.io-index" 1245 | checksum = "590b34f7c5f01ecc9d78dba4b3f445f31df750a67621cf31626f3b7441ce6406" 1246 | dependencies = [ 1247 | "atty", 1248 | ] 1249 | 1250 | [[package]] 1251 | name = "supports-unicode" 1252 | version = "1.0.2" 1253 | source = "registry+https://github.com/rust-lang/crates.io-index" 1254 | checksum = "a8b945e45b417b125a8ec51f1b7df2f8df7920367700d1f98aedd21e5735f8b2" 1255 | dependencies = [ 1256 | "atty", 1257 | ] 1258 | 1259 | [[package]] 1260 | name = "swc-plugin-vanilla-extract" 1261 | version = "0.0.2" 1262 | dependencies = [ 1263 | "serde", 1264 | "serde_json", 1265 | "swc-vanilla-extract-visitor", 1266 | "swc_core", 1267 | ] 1268 | 1269 | [[package]] 1270 | name = "swc-vanilla-extract-visitor" 1271 | version = "0.0.2" 1272 | dependencies = [ 1273 | "once_cell", 1274 | "path-slash", 1275 | "pretty_assertions", 1276 | "regex", 1277 | "swc_core", 1278 | ] 1279 | 1280 | [[package]] 1281 | name = "swc_atoms" 1282 | version = "0.4.24" 1283 | source = "registry+https://github.com/rust-lang/crates.io-index" 1284 | checksum = "79642938ff437f2217718abf30a3450b014f600847c8f4bd60fa44f88a5210ea" 1285 | dependencies = [ 1286 | "once_cell", 1287 | "rkyv", 1288 | "rustc-hash", 1289 | "serde", 1290 | "string_cache", 1291 | "string_cache_codegen", 1292 | "triomphe", 1293 | ] 1294 | 1295 | [[package]] 1296 | name = "swc_common" 1297 | version = "0.29.14" 1298 | source = "registry+https://github.com/rust-lang/crates.io-index" 1299 | checksum = "4bde01c52376971bc6839c42e1a71dec9526ac7acfbfcf1eb3e606e5aa1b2de0" 1300 | dependencies = [ 1301 | "ahash", 1302 | "anyhow", 1303 | "ast_node", 1304 | "atty", 1305 | "better_scoped_tls", 1306 | "cfg-if", 1307 | "either", 1308 | "from_variant", 1309 | "new_debug_unreachable", 1310 | "num-bigint", 1311 | "once_cell", 1312 | "parking_lot", 1313 | "rkyv", 1314 | "rustc-hash", 1315 | "serde", 1316 | "siphasher", 1317 | "sourcemap", 1318 | "string_cache", 1319 | "swc_atoms", 1320 | "swc_eq_ignore_macros", 1321 | "swc_visit", 1322 | "termcolor", 1323 | "tracing", 1324 | "unicode-width", 1325 | "url", 1326 | ] 1327 | 1328 | [[package]] 1329 | name = "swc_core" 1330 | version = "0.43.2" 1331 | source = "registry+https://github.com/rust-lang/crates.io-index" 1332 | checksum = "731fcaa0e3a40844e7da235330d3a654bb8973f9ca6b46bd743ed4d343b7da5e" 1333 | dependencies = [ 1334 | "once_cell", 1335 | "swc_atoms", 1336 | "swc_common", 1337 | "swc_ecma_ast", 1338 | "swc_ecma_quote_macros", 1339 | "swc_ecma_transforms_base", 1340 | "swc_ecma_transforms_testing", 1341 | "swc_ecma_visit", 1342 | "swc_plugin", 1343 | "swc_plugin_macro", 1344 | "swc_plugin_proxy", 1345 | "vergen", 1346 | ] 1347 | 1348 | [[package]] 1349 | name = "swc_ecma_ast" 1350 | version = "0.94.19" 1351 | source = "registry+https://github.com/rust-lang/crates.io-index" 1352 | checksum = "f54bd55f94f02afe98be444e1808e068fa3dca0a113d0c38748d3fdd7a380c2b" 1353 | dependencies = [ 1354 | "bitflags", 1355 | "is-macro", 1356 | "num-bigint", 1357 | "rkyv", 1358 | "scoped-tls", 1359 | "serde", 1360 | "string_enum", 1361 | "swc_atoms", 1362 | "swc_common", 1363 | "unicode-id", 1364 | ] 1365 | 1366 | [[package]] 1367 | name = "swc_ecma_codegen" 1368 | version = "0.127.31" 1369 | source = "registry+https://github.com/rust-lang/crates.io-index" 1370 | checksum = "e807c7271cc05ce3853ce7937776b89730463a39a98729f83bef76bfb6a99048" 1371 | dependencies = [ 1372 | "memchr", 1373 | "num-bigint", 1374 | "once_cell", 1375 | "rustc-hash", 1376 | "serde", 1377 | "sourcemap", 1378 | "swc_atoms", 1379 | "swc_common", 1380 | "swc_ecma_ast", 1381 | "swc_ecma_codegen_macros", 1382 | "tracing", 1383 | ] 1384 | 1385 | [[package]] 1386 | name = "swc_ecma_codegen_macros" 1387 | version = "0.7.1" 1388 | source = "registry+https://github.com/rust-lang/crates.io-index" 1389 | checksum = "0159c99f81f52e48fe692ef7af1b0990b45d3006b14c6629be0b1ffee1b23aea" 1390 | dependencies = [ 1391 | "pmutil", 1392 | "proc-macro2", 1393 | "quote", 1394 | "swc_macros_common", 1395 | "syn", 1396 | ] 1397 | 1398 | [[package]] 1399 | name = "swc_ecma_parser" 1400 | version = "0.122.26" 1401 | source = "registry+https://github.com/rust-lang/crates.io-index" 1402 | checksum = "0bac20cd9f38112de7572150bc3ef24d99eed7c64d03f73f9c87df3bb497ca94" 1403 | dependencies = [ 1404 | "either", 1405 | "enum_kind", 1406 | "lexical", 1407 | "num-bigint", 1408 | "serde", 1409 | "smallvec", 1410 | "swc_atoms", 1411 | "swc_common", 1412 | "swc_ecma_ast", 1413 | "tracing", 1414 | "typed-arena", 1415 | ] 1416 | 1417 | [[package]] 1418 | name = "swc_ecma_quote_macros" 1419 | version = "0.33.27" 1420 | source = "registry+https://github.com/rust-lang/crates.io-index" 1421 | checksum = "2a25295bdddec3ea909cdb6507374e3c69479f6837bf801a0504a36a2743bbf7" 1422 | dependencies = [ 1423 | "anyhow", 1424 | "pmutil", 1425 | "proc-macro2", 1426 | "quote", 1427 | "swc_atoms", 1428 | "swc_common", 1429 | "swc_ecma_ast", 1430 | "swc_ecma_parser", 1431 | "swc_macros_common", 1432 | "syn", 1433 | ] 1434 | 1435 | [[package]] 1436 | name = "swc_ecma_testing" 1437 | version = "0.20.7" 1438 | source = "registry+https://github.com/rust-lang/crates.io-index" 1439 | checksum = "21ecc467eff7ef4ec0a64919402b94da637003015d019de4d649e8efeceafd3f" 1440 | dependencies = [ 1441 | "anyhow", 1442 | "hex", 1443 | "sha-1", 1444 | "swc_atoms", 1445 | "swc_common", 1446 | "swc_ecma_ast", 1447 | "testing", 1448 | "tracing", 1449 | ] 1450 | 1451 | [[package]] 1452 | name = "swc_ecma_transforms_base" 1453 | version = "0.111.46" 1454 | source = "registry+https://github.com/rust-lang/crates.io-index" 1455 | checksum = "1e98c2f5870b3e2b6d8c57aa5c63b9d3fa8076b3d687b1b9875f0923484fd9a9" 1456 | dependencies = [ 1457 | "better_scoped_tls", 1458 | "bitflags", 1459 | "once_cell", 1460 | "phf", 1461 | "rustc-hash", 1462 | "serde", 1463 | "smallvec", 1464 | "swc_atoms", 1465 | "swc_common", 1466 | "swc_ecma_ast", 1467 | "swc_ecma_parser", 1468 | "swc_ecma_utils", 1469 | "swc_ecma_visit", 1470 | "tracing", 1471 | ] 1472 | 1473 | [[package]] 1474 | name = "swc_ecma_transforms_testing" 1475 | version = "0.114.32" 1476 | source = "registry+https://github.com/rust-lang/crates.io-index" 1477 | checksum = "da9d04354bef2099d3781577ba9ec7389f753b26510163f016e6a6c1c39819f5" 1478 | dependencies = [ 1479 | "ansi_term", 1480 | "anyhow", 1481 | "base64", 1482 | "hex", 1483 | "serde", 1484 | "serde_json", 1485 | "sha-1", 1486 | "sourcemap", 1487 | "swc_common", 1488 | "swc_ecma_ast", 1489 | "swc_ecma_codegen", 1490 | "swc_ecma_parser", 1491 | "swc_ecma_testing", 1492 | "swc_ecma_transforms_base", 1493 | "swc_ecma_utils", 1494 | "swc_ecma_visit", 1495 | "tempfile", 1496 | "testing", 1497 | ] 1498 | 1499 | [[package]] 1500 | name = "swc_ecma_utils" 1501 | version = "0.105.32" 1502 | source = "registry+https://github.com/rust-lang/crates.io-index" 1503 | checksum = "55d2be81d1d6072daaac15fc675295d951b73e62f07e749d4faade086424f131" 1504 | dependencies = [ 1505 | "indexmap", 1506 | "num_cpus", 1507 | "once_cell", 1508 | "swc_atoms", 1509 | "swc_common", 1510 | "swc_ecma_ast", 1511 | "swc_ecma_visit", 1512 | "tracing", 1513 | "unicode-id", 1514 | ] 1515 | 1516 | [[package]] 1517 | name = "swc_ecma_visit" 1518 | version = "0.80.19" 1519 | source = "registry+https://github.com/rust-lang/crates.io-index" 1520 | checksum = "d7b42489b19f3451b65c01ed4a7926e44fab294ed9bfa8489634e58ecc96df88" 1521 | dependencies = [ 1522 | "num-bigint", 1523 | "swc_atoms", 1524 | "swc_common", 1525 | "swc_ecma_ast", 1526 | "swc_visit", 1527 | "tracing", 1528 | ] 1529 | 1530 | [[package]] 1531 | name = "swc_eq_ignore_macros" 1532 | version = "0.1.1" 1533 | source = "registry+https://github.com/rust-lang/crates.io-index" 1534 | checksum = "0c20468634668c2bbab581947bb8c75c97158d5a6959f4ba33df20983b20b4f6" 1535 | dependencies = [ 1536 | "pmutil", 1537 | "proc-macro2", 1538 | "quote", 1539 | "syn", 1540 | ] 1541 | 1542 | [[package]] 1543 | name = "swc_error_reporters" 1544 | version = "0.13.14" 1545 | source = "registry+https://github.com/rust-lang/crates.io-index" 1546 | checksum = "cfdfda46250b8d5ff325c4f9e7e50497125e8f357f3a2daa655ba0b4ad8d964a" 1547 | dependencies = [ 1548 | "anyhow", 1549 | "miette", 1550 | "once_cell", 1551 | "parking_lot", 1552 | "swc_common", 1553 | ] 1554 | 1555 | [[package]] 1556 | name = "swc_macros_common" 1557 | version = "0.3.6" 1558 | source = "registry+https://github.com/rust-lang/crates.io-index" 1559 | checksum = "a4be988307882648d9bc7c71a6a73322b7520ef0211e920489a98f8391d8caa2" 1560 | dependencies = [ 1561 | "pmutil", 1562 | "proc-macro2", 1563 | "quote", 1564 | "syn", 1565 | ] 1566 | 1567 | [[package]] 1568 | name = "swc_plugin" 1569 | version = "0.90.0" 1570 | source = "registry+https://github.com/rust-lang/crates.io-index" 1571 | checksum = "ca5df720531bfbd7ceb1139319c39c20c446abfb8f7e0eb47b104205a71152b4" 1572 | dependencies = [ 1573 | "once_cell", 1574 | ] 1575 | 1576 | [[package]] 1577 | name = "swc_plugin_macro" 1578 | version = "0.9.9" 1579 | source = "registry+https://github.com/rust-lang/crates.io-index" 1580 | checksum = "e97eb168af5f767148cfc1948f7f4e4f36551b6638b7620afaa35099d89d699a" 1581 | dependencies = [ 1582 | "proc-macro2", 1583 | "quote", 1584 | "syn", 1585 | ] 1586 | 1587 | [[package]] 1588 | name = "swc_plugin_proxy" 1589 | version = "0.22.19" 1590 | source = "registry+https://github.com/rust-lang/crates.io-index" 1591 | checksum = "1ac15269c27edd456a5e6a218e917fa2ec009e1ea17ffd94cc2eaa7f96d68805" 1592 | dependencies = [ 1593 | "better_scoped_tls", 1594 | "rkyv", 1595 | "swc_common", 1596 | "swc_ecma_ast", 1597 | "swc_trace_macro", 1598 | "tracing", 1599 | ] 1600 | 1601 | [[package]] 1602 | name = "swc_trace_macro" 1603 | version = "0.1.2" 1604 | source = "registry+https://github.com/rust-lang/crates.io-index" 1605 | checksum = "a4795c8d23e0de62eef9cac0a20ae52429ee2ffc719768e838490f195b7d7267" 1606 | dependencies = [ 1607 | "proc-macro2", 1608 | "quote", 1609 | "syn", 1610 | ] 1611 | 1612 | [[package]] 1613 | name = "swc_visit" 1614 | version = "0.5.3" 1615 | source = "registry+https://github.com/rust-lang/crates.io-index" 1616 | checksum = "82f2bcb7223e185c4c7cbf5e0c1207dec6d2bfd5e72e3fb7b3e8d179747e9130" 1617 | dependencies = [ 1618 | "either", 1619 | "swc_visit_macros", 1620 | ] 1621 | 1622 | [[package]] 1623 | name = "swc_visit_macros" 1624 | version = "0.5.4" 1625 | source = "registry+https://github.com/rust-lang/crates.io-index" 1626 | checksum = "8fb1f3561674d84947694d41fb6d5737d19539222779baeac1b3a071a2b29428" 1627 | dependencies = [ 1628 | "Inflector", 1629 | "pmutil", 1630 | "proc-macro2", 1631 | "quote", 1632 | "swc_macros_common", 1633 | "syn", 1634 | ] 1635 | 1636 | [[package]] 1637 | name = "syn" 1638 | version = "1.0.103" 1639 | source = "registry+https://github.com/rust-lang/crates.io-index" 1640 | checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" 1641 | dependencies = [ 1642 | "proc-macro2", 1643 | "quote", 1644 | "unicode-ident", 1645 | ] 1646 | 1647 | [[package]] 1648 | name = "tempfile" 1649 | version = "3.3.0" 1650 | source = "registry+https://github.com/rust-lang/crates.io-index" 1651 | checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" 1652 | dependencies = [ 1653 | "cfg-if", 1654 | "fastrand", 1655 | "libc", 1656 | "redox_syscall", 1657 | "remove_dir_all", 1658 | "winapi", 1659 | ] 1660 | 1661 | [[package]] 1662 | name = "termcolor" 1663 | version = "1.1.3" 1664 | source = "registry+https://github.com/rust-lang/crates.io-index" 1665 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 1666 | dependencies = [ 1667 | "winapi-util", 1668 | ] 1669 | 1670 | [[package]] 1671 | name = "terminal_size" 1672 | version = "0.1.17" 1673 | source = "registry+https://github.com/rust-lang/crates.io-index" 1674 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" 1675 | dependencies = [ 1676 | "libc", 1677 | "winapi", 1678 | ] 1679 | 1680 | [[package]] 1681 | name = "testing" 1682 | version = "0.31.14" 1683 | source = "registry+https://github.com/rust-lang/crates.io-index" 1684 | checksum = "8a6ad9c35c9b4e4834c16b7cbce4209ee0cb6b8af7264d2a8f37f1834340d901" 1685 | dependencies = [ 1686 | "ansi_term", 1687 | "difference", 1688 | "once_cell", 1689 | "pretty_assertions", 1690 | "regex", 1691 | "serde_json", 1692 | "swc_common", 1693 | "swc_error_reporters", 1694 | "testing_macros", 1695 | "tracing", 1696 | "tracing-subscriber", 1697 | ] 1698 | 1699 | [[package]] 1700 | name = "testing_macros" 1701 | version = "0.2.7" 1702 | source = "registry+https://github.com/rust-lang/crates.io-index" 1703 | checksum = "e74ff09d2d4d4b7ea140ff67eb7ed8fd35a708e2c327bcde5a25707d66840099" 1704 | dependencies = [ 1705 | "anyhow", 1706 | "glob", 1707 | "once_cell", 1708 | "pmutil", 1709 | "proc-macro2", 1710 | "quote", 1711 | "regex", 1712 | "relative-path", 1713 | "syn", 1714 | ] 1715 | 1716 | [[package]] 1717 | name = "textwrap" 1718 | version = "0.15.2" 1719 | source = "registry+https://github.com/rust-lang/crates.io-index" 1720 | checksum = "b7b3e525a49ec206798b40326a44121291b530c963cfb01018f63e135bac543d" 1721 | dependencies = [ 1722 | "smawk", 1723 | "unicode-linebreak", 1724 | "unicode-width", 1725 | ] 1726 | 1727 | [[package]] 1728 | name = "thiserror" 1729 | version = "1.0.37" 1730 | source = "registry+https://github.com/rust-lang/crates.io-index" 1731 | checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" 1732 | dependencies = [ 1733 | "thiserror-impl", 1734 | ] 1735 | 1736 | [[package]] 1737 | name = "thiserror-impl" 1738 | version = "1.0.37" 1739 | source = "registry+https://github.com/rust-lang/crates.io-index" 1740 | checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" 1741 | dependencies = [ 1742 | "proc-macro2", 1743 | "quote", 1744 | "syn", 1745 | ] 1746 | 1747 | [[package]] 1748 | name = "thread_local" 1749 | version = "1.1.4" 1750 | source = "registry+https://github.com/rust-lang/crates.io-index" 1751 | checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" 1752 | dependencies = [ 1753 | "once_cell", 1754 | ] 1755 | 1756 | [[package]] 1757 | name = "time" 1758 | version = "0.3.17" 1759 | source = "registry+https://github.com/rust-lang/crates.io-index" 1760 | checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" 1761 | dependencies = [ 1762 | "itoa", 1763 | "serde", 1764 | "time-core", 1765 | "time-macros", 1766 | ] 1767 | 1768 | [[package]] 1769 | name = "time-core" 1770 | version = "0.1.0" 1771 | source = "registry+https://github.com/rust-lang/crates.io-index" 1772 | checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" 1773 | 1774 | [[package]] 1775 | name = "time-macros" 1776 | version = "0.2.6" 1777 | source = "registry+https://github.com/rust-lang/crates.io-index" 1778 | checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2" 1779 | dependencies = [ 1780 | "time-core", 1781 | ] 1782 | 1783 | [[package]] 1784 | name = "tinyvec" 1785 | version = "1.6.0" 1786 | source = "registry+https://github.com/rust-lang/crates.io-index" 1787 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 1788 | dependencies = [ 1789 | "tinyvec_macros", 1790 | ] 1791 | 1792 | [[package]] 1793 | name = "tinyvec_macros" 1794 | version = "0.1.0" 1795 | source = "registry+https://github.com/rust-lang/crates.io-index" 1796 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 1797 | 1798 | [[package]] 1799 | name = "tracing" 1800 | version = "0.1.37" 1801 | source = "registry+https://github.com/rust-lang/crates.io-index" 1802 | checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" 1803 | dependencies = [ 1804 | "cfg-if", 1805 | "pin-project-lite", 1806 | "tracing-attributes", 1807 | "tracing-core", 1808 | ] 1809 | 1810 | [[package]] 1811 | name = "tracing-attributes" 1812 | version = "0.1.23" 1813 | source = "registry+https://github.com/rust-lang/crates.io-index" 1814 | checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" 1815 | dependencies = [ 1816 | "proc-macro2", 1817 | "quote", 1818 | "syn", 1819 | ] 1820 | 1821 | [[package]] 1822 | name = "tracing-core" 1823 | version = "0.1.30" 1824 | source = "registry+https://github.com/rust-lang/crates.io-index" 1825 | checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" 1826 | dependencies = [ 1827 | "once_cell", 1828 | "valuable", 1829 | ] 1830 | 1831 | [[package]] 1832 | name = "tracing-log" 1833 | version = "0.1.3" 1834 | source = "registry+https://github.com/rust-lang/crates.io-index" 1835 | checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" 1836 | dependencies = [ 1837 | "lazy_static", 1838 | "log", 1839 | "tracing-core", 1840 | ] 1841 | 1842 | [[package]] 1843 | name = "tracing-subscriber" 1844 | version = "0.3.16" 1845 | source = "registry+https://github.com/rust-lang/crates.io-index" 1846 | checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" 1847 | dependencies = [ 1848 | "matchers", 1849 | "nu-ansi-term", 1850 | "once_cell", 1851 | "regex", 1852 | "sharded-slab", 1853 | "smallvec", 1854 | "thread_local", 1855 | "tracing", 1856 | "tracing-core", 1857 | "tracing-log", 1858 | ] 1859 | 1860 | [[package]] 1861 | name = "triomphe" 1862 | version = "0.1.8" 1863 | source = "registry+https://github.com/rust-lang/crates.io-index" 1864 | checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db" 1865 | dependencies = [ 1866 | "serde", 1867 | "stable_deref_trait", 1868 | ] 1869 | 1870 | [[package]] 1871 | name = "typed-arena" 1872 | version = "2.0.1" 1873 | source = "registry+https://github.com/rust-lang/crates.io-index" 1874 | checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" 1875 | 1876 | [[package]] 1877 | name = "typenum" 1878 | version = "1.15.0" 1879 | source = "registry+https://github.com/rust-lang/crates.io-index" 1880 | checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" 1881 | 1882 | [[package]] 1883 | name = "unicode-bidi" 1884 | version = "0.3.8" 1885 | source = "registry+https://github.com/rust-lang/crates.io-index" 1886 | checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" 1887 | 1888 | [[package]] 1889 | name = "unicode-id" 1890 | version = "0.3.3" 1891 | source = "registry+https://github.com/rust-lang/crates.io-index" 1892 | checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" 1893 | 1894 | [[package]] 1895 | name = "unicode-ident" 1896 | version = "1.0.5" 1897 | source = "registry+https://github.com/rust-lang/crates.io-index" 1898 | checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" 1899 | 1900 | [[package]] 1901 | name = "unicode-linebreak" 1902 | version = "0.1.4" 1903 | source = "registry+https://github.com/rust-lang/crates.io-index" 1904 | checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137" 1905 | dependencies = [ 1906 | "hashbrown", 1907 | "regex", 1908 | ] 1909 | 1910 | [[package]] 1911 | name = "unicode-normalization" 1912 | version = "0.1.22" 1913 | source = "registry+https://github.com/rust-lang/crates.io-index" 1914 | checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" 1915 | dependencies = [ 1916 | "tinyvec", 1917 | ] 1918 | 1919 | [[package]] 1920 | name = "unicode-width" 1921 | version = "0.1.10" 1922 | source = "registry+https://github.com/rust-lang/crates.io-index" 1923 | checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" 1924 | 1925 | [[package]] 1926 | name = "url" 1927 | version = "2.3.1" 1928 | source = "registry+https://github.com/rust-lang/crates.io-index" 1929 | checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" 1930 | dependencies = [ 1931 | "form_urlencoded", 1932 | "idna", 1933 | "percent-encoding", 1934 | ] 1935 | 1936 | [[package]] 1937 | name = "valuable" 1938 | version = "0.1.0" 1939 | source = "registry+https://github.com/rust-lang/crates.io-index" 1940 | checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" 1941 | 1942 | [[package]] 1943 | name = "vergen" 1944 | version = "7.4.2" 1945 | source = "registry+https://github.com/rust-lang/crates.io-index" 1946 | checksum = "73ba753d713ec3844652ad2cb7eb56bc71e34213a14faddac7852a10ba88f61e" 1947 | dependencies = [ 1948 | "anyhow", 1949 | "cfg-if", 1950 | "enum-iterator", 1951 | "getset", 1952 | "rustversion", 1953 | "thiserror", 1954 | "time", 1955 | ] 1956 | 1957 | [[package]] 1958 | name = "version_check" 1959 | version = "0.9.4" 1960 | source = "registry+https://github.com/rust-lang/crates.io-index" 1961 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 1962 | 1963 | [[package]] 1964 | name = "wasi" 1965 | version = "0.11.0+wasi-snapshot-preview1" 1966 | source = "registry+https://github.com/rust-lang/crates.io-index" 1967 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 1968 | 1969 | [[package]] 1970 | name = "winapi" 1971 | version = "0.3.9" 1972 | source = "registry+https://github.com/rust-lang/crates.io-index" 1973 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1974 | dependencies = [ 1975 | "winapi-i686-pc-windows-gnu", 1976 | "winapi-x86_64-pc-windows-gnu", 1977 | ] 1978 | 1979 | [[package]] 1980 | name = "winapi-i686-pc-windows-gnu" 1981 | version = "0.4.0" 1982 | source = "registry+https://github.com/rust-lang/crates.io-index" 1983 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1984 | 1985 | [[package]] 1986 | name = "winapi-util" 1987 | version = "0.1.5" 1988 | source = "registry+https://github.com/rust-lang/crates.io-index" 1989 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 1990 | dependencies = [ 1991 | "winapi", 1992 | ] 1993 | 1994 | [[package]] 1995 | name = "winapi-x86_64-pc-windows-gnu" 1996 | version = "0.4.0" 1997 | source = "registry+https://github.com/rust-lang/crates.io-index" 1998 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1999 | 2000 | [[package]] 2001 | name = "windows-sys" 2002 | version = "0.42.0" 2003 | source = "registry+https://github.com/rust-lang/crates.io-index" 2004 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 2005 | dependencies = [ 2006 | "windows_aarch64_gnullvm", 2007 | "windows_aarch64_msvc", 2008 | "windows_i686_gnu", 2009 | "windows_i686_msvc", 2010 | "windows_x86_64_gnu", 2011 | "windows_x86_64_gnullvm", 2012 | "windows_x86_64_msvc", 2013 | ] 2014 | 2015 | [[package]] 2016 | name = "windows_aarch64_gnullvm" 2017 | version = "0.42.0" 2018 | source = "registry+https://github.com/rust-lang/crates.io-index" 2019 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 2020 | 2021 | [[package]] 2022 | name = "windows_aarch64_msvc" 2023 | version = "0.42.0" 2024 | source = "registry+https://github.com/rust-lang/crates.io-index" 2025 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 2026 | 2027 | [[package]] 2028 | name = "windows_i686_gnu" 2029 | version = "0.42.0" 2030 | source = "registry+https://github.com/rust-lang/crates.io-index" 2031 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 2032 | 2033 | [[package]] 2034 | name = "windows_i686_msvc" 2035 | version = "0.42.0" 2036 | source = "registry+https://github.com/rust-lang/crates.io-index" 2037 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 2038 | 2039 | [[package]] 2040 | name = "windows_x86_64_gnu" 2041 | version = "0.42.0" 2042 | source = "registry+https://github.com/rust-lang/crates.io-index" 2043 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 2044 | 2045 | [[package]] 2046 | name = "windows_x86_64_gnullvm" 2047 | version = "0.42.0" 2048 | source = "registry+https://github.com/rust-lang/crates.io-index" 2049 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 2050 | 2051 | [[package]] 2052 | name = "windows_x86_64_msvc" 2053 | version = "0.42.0" 2054 | source = "registry+https://github.com/rust-lang/crates.io-index" 2055 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 2056 | 2057 | [[package]] 2058 | name = "yansi" 2059 | version = "0.5.1" 2060 | source = "registry+https://github.com/rust-lang/crates.io-index" 2061 | checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" 2062 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | exclude = ["spec/swc-vanilla-custom-transform"] 3 | members = [ 4 | "packages/swc-plugin-vanilla-extract", 5 | "packages/swc-vanilla-extract-visitor" 6 | ] 7 | 8 | [profile.release] 9 | lto = true 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SWC-plugin-vanilla-extract 2 | 3 | `SWC-plugin-vanilla-extract` 4 | 5 | `swc-plugin-vanilla-extract` is a port of `@vanilla-extract/babel-plugin` for the SWC. Transform can be performed either via SWC's wasm-based plugin, or using custom passes in rust side transform chains. 6 | 7 | ## What does compatible exactly means? 8 | 9 | This plugin attempts to mimic most of defined behavior of original plugin's test fixture. However, due to differences of plugin envioronment it does not support few things like reading package.json's dir, or packagename. Instead it uses current working directory with configurable package name. See the test cases how does it actually works. 10 | 11 | **NOTE: Package can have breaking changes without major semver bump** 12 | 13 | Given SWC's plugin interface itself is under experimental stage does not gaurantee semver-based major bump yet, this package also does not gaurantee semver compliant breaking changes yet. Please refer changelogs if you're encountering unexpected breaking behavior across versions. 14 | 15 | # Usage 16 | 17 | ## Using SWC's wasm-based experimental plugin 18 | 19 | First, install package via npm: 20 | 21 | ``` 22 | npm install --save-dev swc-plugin-vanilla-extract 23 | ``` 24 | 25 | Then add plugin into swc's configuration: 26 | 27 | ``` 28 | const pluginOptions = { packageName?: string } 29 | 30 | jsc: { 31 | ... 32 | experimental: { 33 | plugins: [ 34 | ["swc-plugin-vanilla-extract", pluginOptions] 35 | ] 36 | } 37 | } 38 | ``` 39 | 40 | ## Using custom transform pass in rust 41 | 42 | There is a single interface exposed to create a visitor for the transform, which you can pass into `before_custom_pass`. 43 | 44 | ``` 45 | create_extract_visitor( 46 | _source_map: std::sync::Arc, 47 | _comments: C, 48 | filename: &str, 49 | package_name: &str, 50 | package_dir: &str, 51 | ) -> VanillaExtractVisitor 52 | ``` 53 | 54 | # Building / Testing 55 | 56 | This package runs original plugin's fixture tests against SWC with its wasm plugin & custom transform both. `spec` contains set of the fixtures & unit test to run it, as well as supplimental packages to interop between instrumentation visitor to node.js runtime. 57 | 58 | Few npm scripts are supported for wrapping those setups. 59 | 60 | - `build:all`: Build all relative packages as debug build. 61 | - `test`: Runs unit test for wasm plugin & custom transform. 62 | - `test:debug`: Runs unit test, but only for `debug-test.yaml` fixture. This is mainly for local dev debugging for individual test fixture behavior. 63 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | ['@babel/preset-env', {targets: {node: 'current'}}], 4 | '@babel/preset-typescript', 5 | ], 6 | }; -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | //transform: { 3 | //'\\.tsx?$': ['babel-jest', { configFile: './babel-jest.config.js' }], 4 | //}, 5 | testMatch: ['**/?(*.)+(test).[jt]s?(x)'], 6 | testTimeout: 10000, 7 | }; 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swc-plugin-vanilla-extract", 3 | "version": "0.0.2", 4 | "description": "", 5 | "main": "./target/wasm32-wasi/release/swc_plugin_vanilla_extract.wasm", 6 | "napi": { 7 | "name": "swc", 8 | "triples": { 9 | "defaults": true, 10 | "additional": [ 11 | "x86_64-unknown-linux-musl", 12 | "x86_64-unknown-freebsd", 13 | "i686-pc-windows-msvc", 14 | "aarch64-unknown-linux-gnu", 15 | "armv7-unknown-linux-gnueabihf", 16 | "aarch64-apple-darwin", 17 | "aarch64-linux-android", 18 | "aarch64-unknown-linux-musl", 19 | "aarch64-pc-windows-msvc", 20 | "armv7-linux-androideabi" 21 | ] 22 | } 23 | }, 24 | "files": [ 25 | "package.json", 26 | "README.md", 27 | "LICENSE", 28 | "target/wasm32-wasi/release/swc_plugin_vanilla_extract.wasm" 29 | ], 30 | "scripts": { 31 | "prepublishOnly": "npm-run-all test && npm run build:plugin -- --release", 32 | "build:all": "npm-run-all build:customtransform build:plugin", 33 | "build:customtransform": "napi build --platform --cargo-cwd ./spec/swc-vanilla-custom-transform", 34 | "build:plugin": "cargo build -p swc-plugin-vanilla-extract --target wasm32-wasi", 35 | "test:plugin": "npm-run-all build:all && jest", 36 | "test:customtransform": "npm-run-all build:all && cross-env SWC_TRANSFORM_CUSTOM=1 jest", 37 | "test": "npm-run-all test:plugin test:customtransform", 38 | "prepare": "husky install" 39 | }, 40 | "repository": { 41 | "type": "git", 42 | "url": "git+https://github.com/kwonoj/swc-plugin-vanilla-extract" 43 | }, 44 | "keywords": [ 45 | "SWC", 46 | "plugin", 47 | "vanilla-extract" 48 | ], 49 | "author": "OJ Kwon ", 50 | "license": "MIT", 51 | "bugs": { 52 | "url": "https://github.com/kwonoj/swc-plugin-vanilla-extract/issues" 53 | }, 54 | "homepage": "https://github.com/kwonoj/swc-plugin-vanilla-extract#readme", 55 | "devDependencies": { 56 | "@babel/core": "^7.19.0", 57 | "@babel/preset-env": "^7.19.0", 58 | "@babel/preset-typescript": "^7.18.6", 59 | "@napi-rs/cli": "^2.11.0", 60 | "@swc-node/register": "^1.5.4", 61 | "@swc/core": "^1.3.15", 62 | "@taplo/cli": "^0.4.2", 63 | "@types/jest": "^29.0.0", 64 | "@types/node": "^18.6.5", 65 | "babel-jest": "^29.0.2", 66 | "cross-env": "^7.0.3", 67 | "husky": "^8.0.1", 68 | "jest": "^29.0.2", 69 | "lint-staged": "^13.0.3", 70 | "npm-run-all": "^4.1.5", 71 | "prettier": "^2.6.0", 72 | "typescript": "^4.6.2" 73 | }, 74 | "lint-staged": { 75 | "*.{js,ts,css,md}": "prettier --write", 76 | "*.toml": [ 77 | "taplo format" 78 | ], 79 | "*.rs": [ 80 | "cargo fmt --" 81 | ] 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /packages/swc-plugin-vanilla-extract/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["OJ Kwon "] 3 | description = "Vanilla-extract plugin for SWC" 4 | edition = "2021" 5 | license = "MIT" 6 | name = "swc-plugin-vanilla-extract" 7 | repository = "https://github.com/kwonoj/swc-plugin-vanilla-extract" 8 | version = "0.0.2" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | serde = "1.0.147" 15 | serde_json = "1.0.87" 16 | swc-vanilla-extract-visitor = { path = "../swc-vanilla-extract-visitor", version = "0.0.2" } 17 | swc_core = { version = "0.43.2", features = ["plugin_transform", "ecma_visit_path"] } 18 | -------------------------------------------------------------------------------- /packages/swc-plugin-vanilla-extract/src/lib.rs: -------------------------------------------------------------------------------- 1 | use serde_json::Value; 2 | use swc_core::{ 3 | ecma::{ast::Program, visit::*}, 4 | plugin::{ 5 | metadata::TransformPluginMetadataContextKind, plugin_transform, 6 | proxies::TransformPluginProgramMetadata, 7 | }, 8 | }; 9 | 10 | use swc_vanilla_extract_visitor::create_extract_visitor; 11 | 12 | #[plugin_transform] 13 | pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Program { 14 | let filename = metadata.get_context(&TransformPluginMetadataContextKind::Filename); 15 | let filename = if let Some(filename) = filename.as_deref() { 16 | filename 17 | } else { 18 | "unknown.js" 19 | }; 20 | 21 | let cwd = metadata.get_context(&TransformPluginMetadataContextKind::Cwd); 22 | let cwd = if let Some(cwd) = cwd.as_deref() { 23 | cwd 24 | } else { 25 | "." 26 | }; 27 | 28 | let config = metadata.get_transform_plugin_config(); 29 | let package_name = if let Some(config) = config { 30 | let config: Value = serde_json::from_str(&config).expect("Config should be serializable"); 31 | 32 | let pkg_name = config["packageName"].as_str(); 33 | if let Some(pkg_name) = pkg_name { 34 | pkg_name.to_string() 35 | } else { 36 | "swc-plugin-vanilla-extract".to_string() 37 | } 38 | } else { 39 | "swc-plugin-vanilla-extract".to_string() 40 | }; 41 | 42 | let visitor = create_extract_visitor( 43 | std::sync::Arc::new(metadata.source_map), 44 | metadata.comments.as_ref(), 45 | filename, 46 | &package_name, 47 | cwd, 48 | ); 49 | 50 | program.fold_with(&mut as_folder(visitor)) 51 | } 52 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["OJ Kwon "] 3 | description = "Vanilla-extract custom transform visitor for SWC" 4 | edition = "2021" 5 | license = "MIT" 6 | name = "swc-vanilla-extract-visitor" 7 | repository = "https://github.com/kwonoj/swc-plugin-vanilla-extract" 8 | version = "0.0.2" 9 | 10 | [dependencies] 11 | once_cell = "1.16.0" 12 | regex = "1.7.0" 13 | path-slash = "0.2.1" 14 | swc_core = { version = "0.43.2", features = ["common", "ecma_quote", "ecma_ast", "ecma_visit", "ecma_visit_path"] } 15 | 16 | [dev-dependencies] 17 | pretty_assertions = "1.3.0" 18 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/src/constants.rs: -------------------------------------------------------------------------------- 1 | use std::collections::{HashMap, HashSet}; 2 | 3 | use once_cell::sync::Lazy; 4 | use regex::Regex as Regexp; 5 | use swc_core::{common::DUMMY_SP, ecma::ast::Ident}; 6 | 7 | pub static FILE_SCOPE_IMPORT_NAME: Lazy = 8 | Lazy::new(|| Ident::new("__vanilla_filescope__".into(), DUMMY_SP)); 9 | pub static FILE_SCOPE_PACKAGE_IDENTIFIER: &str = "@vanilla-extract/css/fileScope"; 10 | 11 | pub static PACKAGE_IDENTIFIERS: Lazy> = Lazy::new(|| { 12 | let mut set = HashSet::new(); 13 | set.insert("@vanilla-extract/css".to_string()); 14 | set.insert("@vanilla-extract/recipes".to_string()); 15 | set 16 | }); 17 | 18 | pub static STYLE_FUNCTIONS: [&str; 14] = [ 19 | "style", 20 | "createTheme", 21 | "styleVariants", 22 | "fontFace", 23 | "keyframes", 24 | "createVar", 25 | "recipe", 26 | "createContainer", 27 | "globalStyle", 28 | "createGlobalTheme", 29 | "createThemeContract", 30 | "globalFontFace", 31 | "globalKeyframes", 32 | "recipe", 33 | ]; 34 | 35 | pub static CSS_FILE_FILTER_REGEX: Lazy = 36 | Lazy::new(|| Regexp::new(r"\.css\.(js|mjs|jsx|ts|tsx)(\?used)?$").unwrap()); 37 | 38 | pub static DEBUGGABLE_FUNCTION_CONFIG: Lazy> = Lazy::new(|| { 39 | let mut map = HashMap::default(); 40 | map.insert("style".to_string(), 2); 41 | map.insert("createTheme".to_string(), 3); 42 | map.insert("styleVariants".to_string(), 3); 43 | map.insert("fontFace".to_string(), 2); 44 | map.insert("keyframes".to_string(), 2); 45 | map.insert("createVar".to_string(), 1); 46 | map.insert("recipe".to_string(), 2); 47 | map.insert("createContainer".to_string(), 1); 48 | map 49 | }); 50 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/src/debug_id_find_visitor.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use swc_core::{ 4 | common::pass::AstNodePath, 5 | ecma::{ 6 | ast::{ 7 | CallExpr, Callee, Expr, Ident, Lit, ObjectPatProp, Pat, Prop, PropName, PropOrSpread, 8 | }, 9 | visit::{AstParentNodeRef, VisitAstPath, VisitWithPath}, 10 | }, 11 | }; 12 | 13 | use crate::{ 14 | constants::{DEBUGGABLE_FUNCTION_CONFIG, FILE_SCOPE_PACKAGE_IDENTIFIER}, 15 | get_relavant_call::get_relavant_call, 16 | }; 17 | 18 | /// A visitor to find corresponding debug id for the given callexpr, if it's a vanilla-extract style function. 19 | pub struct DebugIdFindVisitor { 20 | pub is_compiled: bool, 21 | pub debug_id: Option, 22 | 23 | namespace_import: Option, 24 | import_identifiers: HashMap, 25 | } 26 | 27 | impl DebugIdFindVisitor { 28 | pub fn new( 29 | namespace_import: Option, 30 | import_identifiers: HashMap, 31 | ) -> Self { 32 | Self { 33 | debug_id: None, 34 | is_compiled: false, 35 | 36 | namespace_import, 37 | import_identifiers, 38 | } 39 | } 40 | } 41 | 42 | fn extract_name<'r>(node: AstParentNodeRef<'r>) -> Option { 43 | match node { 44 | AstParentNodeRef::PropOrSpread(prop, _) => { 45 | if let PropOrSpread::Prop(prop) = prop { 46 | if let Prop::KeyValue(key_value) = &**prop { 47 | if let PropName::Ident(ident) = &key_value.key { 48 | return Some(ident.sym.to_string()); 49 | } 50 | } 51 | } 52 | } 53 | AstParentNodeRef::ObjectPatProp(pat_prop, _) => { 54 | if let ObjectPatProp::KeyValue(key_value) = pat_prop { 55 | if let PropName::Ident(ident) = &key_value.key { 56 | return Some(ident.sym.to_string()); 57 | } 58 | } 59 | } 60 | AstParentNodeRef::VarDeclarator(declarator, _) => { 61 | match &declarator.name { 62 | Pat::Ident(ident) => { 63 | return Some(ident.sym.to_string()); 64 | } 65 | Pat::Array(array) => { 66 | if let Some(elem) = &array.elems[0] { 67 | if let Pat::Ident(ident) = &*elem { 68 | return Some(ident.sym.to_string()); 69 | } 70 | } 71 | } 72 | _ => return None, 73 | }; 74 | } 75 | AstParentNodeRef::FnDecl(fn_decl, _) => { 76 | return Some(fn_decl.ident.sym.to_string()); 77 | } 78 | AstParentNodeRef::ModuleDecl(module_decl, _) => { 79 | if module_decl.is_export_default_expr() || module_decl.is_export_default_decl() { 80 | return Some("default".to_string()); 81 | } 82 | } 83 | _ => {} 84 | }; 85 | 86 | None 87 | } 88 | 89 | fn get_debug_id<'r>(ast_path: &mut AstNodePath>) -> Option { 90 | // When we arrived here, we no longer cares about keeping ast_path in sync, will just mutate it. 91 | 92 | let first_relevant_parent = ast_path.last().clone(); 93 | 94 | if let Some(first_relevant_parent) = first_relevant_parent { 95 | // Special case: Handle `export const [themeClass, vars] = createTheme({});` 96 | // when it's already been compiled into this: 97 | // 98 | // var _createTheme = createTheme({}), 99 | // _createTheme2 = _slicedToArray(_createTheme, 2), 100 | // themeClass = _createTheme2[0], 101 | // vars = _createTheme2[1]; 102 | let parent = ast_path.last().clone(); //do not take, if this condition doesn't match we'll need to reuse last marker 103 | if let Some(parent) = parent { 104 | if let AstParentNodeRef::VarDecl(decl, _) = parent { 105 | if decl.decls.len() == 4 { 106 | let theme_declarator = decl.decls.get(0).expect("Should exists"); 107 | let class_name_declarator = decl.decls.get(2).expect("Should exists"); 108 | 109 | let valid_theme_decl = 110 | if let Some(theme_declarator_init) = theme_declarator.init.as_ref() { 111 | if let Expr::Call(call) = &**theme_declarator_init { 112 | if let Callee::Expr(callee) = &call.callee { 113 | if let Expr::Ident(callee_ident) = &**callee { 114 | "createTheme" == &*callee_ident.sym 115 | } else { 116 | false 117 | } 118 | } else { 119 | false 120 | } 121 | } else { 122 | false 123 | } 124 | } else { 125 | false 126 | }; 127 | 128 | if valid_theme_decl { 129 | if let Pat::Ident(class_name_decl_ident) = &class_name_declarator.name { 130 | return Some(class_name_decl_ident.sym.to_string()); 131 | } 132 | } 133 | } 134 | } 135 | } 136 | 137 | return match first_relevant_parent { 138 | AstParentNodeRef::ObjectPatProp(..) 139 | | AstParentNodeRef::Stmt(..) 140 | | AstParentNodeRef::Expr(..) 141 | | AstParentNodeRef::SpreadElement(..) => { 142 | let mut names = vec![]; 143 | 144 | for path in ast_path.iter().rev() { 145 | let name = extract_name(*path); 146 | if let Some(name) = name { 147 | names.insert(0, name); 148 | } 149 | } 150 | 151 | if names.len() > 0 { 152 | Some(names.join("_").to_string()) 153 | } else { 154 | None 155 | } 156 | } 157 | _ => extract_name(*first_relevant_parent), 158 | }; 159 | } 160 | 161 | None 162 | } 163 | 164 | impl VisitAstPath for DebugIdFindVisitor { 165 | fn visit_call_expr<'ast: 'r, 'r>( 166 | &mut self, 167 | call_expr: &'r CallExpr, 168 | ast_path: &mut AstNodePath>, 169 | ) { 170 | if self.is_compiled { 171 | return; 172 | } 173 | 174 | if let Callee::Expr(expr) = &call_expr.callee { 175 | if let Expr::Ident(ident) = &**expr { 176 | if &*ident.sym == "require" { 177 | if let Some(arg) = call_expr.args.get(0) { 178 | if let Expr::Lit(expr) = &*arg.expr { 179 | if let Lit::Str(expr) = expr { 180 | if &*expr.value == FILE_SCOPE_PACKAGE_IDENTIFIER { 181 | // If file scope import is found it means the file has already been compiled 182 | self.is_compiled = true; 183 | } 184 | } 185 | } 186 | } 187 | } 188 | } 189 | } 190 | 191 | let used_export = 192 | get_relavant_call(call_expr, &self.namespace_import, &self.import_identifiers); 193 | 194 | if let Some(used_export) = used_export { 195 | if let Some(max_params) = DEBUGGABLE_FUNCTION_CONFIG.get(&used_export) { 196 | if call_expr.args.len() < *max_params { 197 | self.debug_id = get_debug_id(ast_path); 198 | } 199 | } 200 | } 201 | 202 | call_expr.visit_children_with_path(self, ast_path); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/src/debug_id_inject_visitor.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use swc_core::ecma::{ 4 | ast::{CallExpr, Expr, ExprOrSpread, Ident, Lit, Str}, 5 | visit::{VisitMut, VisitMutWith}, 6 | }; 7 | 8 | use crate::{constants::DEBUGGABLE_FUNCTION_CONFIG, get_relavant_call::get_relavant_call}; 9 | 10 | /// A visitor actually injects debugid into given callexpr, if given call expr is a vanilla-extract style function. 11 | pub struct DebugIdInjectVisitor { 12 | pub debug_id: Option, 13 | namespace_import: Option, 14 | import_identifiers: HashMap, 15 | } 16 | 17 | impl DebugIdInjectVisitor { 18 | pub fn new( 19 | namespace_import: Option, 20 | import_identifiers: HashMap, 21 | ) -> Self { 22 | DebugIdInjectVisitor { 23 | debug_id: None, 24 | namespace_import, 25 | import_identifiers, 26 | } 27 | } 28 | } 29 | 30 | impl VisitMut for DebugIdInjectVisitor { 31 | fn visit_mut_call_expr(&mut self, call_expr: &mut CallExpr) { 32 | let used_export = 33 | get_relavant_call(call_expr, &self.namespace_import, &self.import_identifiers); 34 | 35 | if let Some(used_export) = used_export { 36 | if let Some(max_params) = DEBUGGABLE_FUNCTION_CONFIG.get(&used_export) { 37 | if call_expr.args.len() < *max_params { 38 | if let Some(debug_id) = self.debug_id.take() { 39 | call_expr.args.push(ExprOrSpread { 40 | spread: None, 41 | expr: Box::new(Expr::Lit(Lit::Str(Str::from(debug_id)))), 42 | }) 43 | } 44 | } 45 | } 46 | } 47 | 48 | call_expr.visit_mut_children_with(self); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/src/get_relavant_call.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use swc_core::ecma::ast::{CallExpr, Callee, Expr, Ident, MemberProp}; 4 | 5 | use crate::constants::STYLE_FUNCTIONS; 6 | 7 | pub fn get_relavant_call( 8 | call_expr: &CallExpr, 9 | namespace_import: &Option, 10 | import_identifiers: &HashMap, 11 | ) -> Option { 12 | let callee = &call_expr.callee; 13 | 14 | if let Some(namespace_import) = namespace_import { 15 | if let Callee::Expr(expr) = callee { 16 | if !expr.is_member() { 17 | return None; 18 | } 19 | 20 | if let Expr::Member(member_expr) = &**expr { 21 | if let Expr::Ident(ident) = &*member_expr.obj { 22 | if ident.sym == namespace_import.sym { 23 | return STYLE_FUNCTIONS 24 | .iter() 25 | .find(|export_name| { 26 | if let MemberProp::Ident(ident) = &member_expr.prop { 27 | &*ident.sym == **export_name 28 | } else { 29 | false 30 | } 31 | }) 32 | .map(|v| v.to_string()); 33 | } 34 | } 35 | } 36 | } 37 | return None; 38 | } else { 39 | let import_info = import_identifiers.keys().find(|ident| { 40 | if let Callee::Expr(expr) = callee { 41 | if let Expr::Ident(expr_ident) = &**expr { 42 | expr_ident.sym == ident.sym 43 | } else { 44 | false 45 | } 46 | } else { 47 | false 48 | } 49 | }); 50 | 51 | return import_info 52 | .map(|key| import_identifiers.get(key)) 53 | .flatten() 54 | .cloned(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/src/import_collect_visitor.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use swc_core::ecma::{ 4 | ast::{ExportDecl, Ident, ImportDecl, ImportSpecifier, ModuleExportName}, 5 | visit::Visit, 6 | }; 7 | 8 | use crate::constants::{FILE_SCOPE_PACKAGE_IDENTIFIER, PACKAGE_IDENTIFIERS, STYLE_FUNCTIONS}; 9 | 10 | /// A visitor to collect imports from vanilla-extract packages 11 | pub struct ImportCollectVisitor { 12 | pub is_esm: bool, 13 | pub is_compiled: bool, 14 | 15 | pub namespace_import: Option, 16 | pub import_identifiers: HashMap, 17 | } 18 | 19 | impl ImportCollectVisitor { 20 | pub fn new() -> Self { 21 | Self { 22 | is_esm: false, 23 | is_compiled: false, 24 | 25 | namespace_import: None, 26 | import_identifiers: Default::default(), 27 | } 28 | } 29 | } 30 | 31 | impl Visit for ImportCollectVisitor { 32 | fn visit_import_decl(&mut self, import_decl: &ImportDecl) { 33 | self.is_esm = true; 34 | 35 | if self.is_compiled { 36 | // Bail early if file isn't a .css.ts file or the file has already been compiled 37 | return; 38 | } 39 | 40 | let src = &*import_decl.src.value; 41 | if src == FILE_SCOPE_PACKAGE_IDENTIFIER { 42 | // If file scope import is found it means the file has already been compiled 43 | self.is_compiled = true; 44 | return; 45 | } else if PACKAGE_IDENTIFIERS.contains(src) { 46 | for specifier in &import_decl.specifiers { 47 | match specifier { 48 | ImportSpecifier::Named(named_specifier) => { 49 | let imported = &named_specifier.imported; 50 | let local = &named_specifier.local; 51 | 52 | if let Some(imported) = imported { 53 | let import_name = match imported { 54 | ModuleExportName::Ident(ident) => &*ident.sym, 55 | ModuleExportName::Str(str) => &*str.value, 56 | }; 57 | 58 | if STYLE_FUNCTIONS.contains(&import_name) { 59 | self.import_identifiers 60 | .insert(local.clone(), import_name.to_string()); 61 | } 62 | } else if STYLE_FUNCTIONS.contains(&&*local.sym) { 63 | self.import_identifiers 64 | .insert(local.clone(), local.sym.to_string()); 65 | } 66 | } 67 | ImportSpecifier::Default(_default_specifier) => { 68 | //noop 69 | } 70 | ImportSpecifier::Namespace(namespace_specifier) => { 71 | self.namespace_import = Some(namespace_specifier.local.clone()); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | fn visit_export_decl(&mut self, _: &ExportDecl) { 79 | self.is_esm = true; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /packages/swc-vanilla-extract-visitor/src/lib.rs: -------------------------------------------------------------------------------- 1 | use constants::{CSS_FILE_FILTER_REGEX, FILE_SCOPE_IMPORT_NAME, FILE_SCOPE_PACKAGE_IDENTIFIER}; 2 | use debug_id_find_visitor::DebugIdFindVisitor; 3 | use debug_id_inject_visitor::DebugIdInjectVisitor; 4 | use import_collect_visitor::ImportCollectVisitor; 5 | use path_slash::PathBufExt as _; 6 | use std::path::PathBuf; 7 | 8 | use swc_core::{ 9 | common::{comments::Comments, SourceMapper, DUMMY_SP}, 10 | ecma::{ 11 | ast::{ 12 | CallExpr, Callee, Expr, ExprOrSpread, ExprStmt, Ident, ImportDecl, ImportSpecifier, 13 | ImportStarAsSpecifier, Lit, MemberExpr, MemberProp, ModuleDecl, ModuleItem, Stmt, Str, 14 | }, 15 | atoms::JsWord, 16 | visit::{VisitMut, VisitMutWith, VisitWith, VisitWithPath}, 17 | }, 18 | quote, 19 | }; 20 | 21 | mod constants; 22 | mod debug_id_find_visitor; 23 | mod debug_id_inject_visitor; 24 | mod get_relavant_call; 25 | mod import_collect_visitor; 26 | 27 | /// Top level visitor for vanilla-extract plugin. 28 | pub struct VanillaExtractVisitor { 29 | file_path: String, 30 | package_name: String, 31 | 32 | is_css_file: bool, 33 | } 34 | 35 | impl VanillaExtractVisitor { 36 | pub fn new(filename: &str, package_name: &str, package_dir: &str) -> Self { 37 | VanillaExtractVisitor { 38 | file_path: PathBuf::from(package_dir) 39 | .join(filename) 40 | .to_slash_lossy() 41 | .to_string(), 42 | package_name: package_name.to_string(), 43 | 44 | is_css_file: CSS_FILE_FILTER_REGEX.is_match(filename), 45 | } 46 | } 47 | } 48 | 49 | impl VisitMut for VanillaExtractVisitor { 50 | fn visit_mut_module_items( 51 | &mut self, 52 | items: &mut Vec, 53 | //ast_path: &mut AstNodePath>, 54 | ) { 55 | // Bail early if file isn't a .css.ts file 56 | if !self.is_css_file { 57 | return; 58 | } 59 | 60 | let mut new_items = vec![]; 61 | let mut import_collect_visitor = ImportCollectVisitor::new(); 62 | 63 | // Runs all childrens with import collect visitor to collect related imports first 64 | for item in items.iter() { 65 | item.visit_children_with(&mut import_collect_visitor); 66 | } 67 | 68 | if import_collect_visitor.is_compiled { 69 | return; 70 | } 71 | 72 | let mut debug_id_find_visitor = DebugIdFindVisitor::new( 73 | import_collect_visitor.namespace_import.clone(), 74 | import_collect_visitor.import_identifiers.clone(), 75 | ); 76 | let mut debug_id_inject_visitor = DebugIdInjectVisitor::new( 77 | import_collect_visitor.namespace_import, 78 | import_collect_visitor.import_identifiers, 79 | ); 80 | 81 | for mut item in items.drain(..) { 82 | // Bail early if file has already been compiled 83 | if !debug_id_find_visitor.is_compiled { 84 | // First, find debug id with ast_path visitor 85 | item.visit_children_with_path(&mut debug_id_find_visitor, &mut Default::default()); 86 | // Inject debug id with mutable visitor. This make each node traverses twice, but 87 | // mutable visitor does not get the ast_path with node to read its debug id. 88 | debug_id_inject_visitor.debug_id = debug_id_find_visitor.debug_id.take(); 89 | //We'll keep single inject visitor as stateful, visitor will consume debug_id if exists 90 | item.visit_mut_children_with(&mut debug_id_inject_visitor); 91 | } 92 | new_items.push(item); 93 | } 94 | *items = new_items; 95 | 96 | if !debug_id_find_visitor.is_compiled { 97 | // Wrap module with file scope calls 98 | 99 | // Plugin does not determine type of import to be CJS or ESM - SWC core should transpile 100 | // accordingly depends on the config. 101 | let import_scope = ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { 102 | span: DUMMY_SP, 103 | specifiers: vec![ImportSpecifier::Namespace(ImportStarAsSpecifier { 104 | span: DUMMY_SP, 105 | local: FILE_SCOPE_IMPORT_NAME.clone(), 106 | })], 107 | src: Box::new(Str::from(FILE_SCOPE_PACKAGE_IDENTIFIER)), 108 | type_only: false, 109 | asserts: None, 110 | })); 111 | let set_file_scope = ModuleItem::Stmt(Stmt::Expr(ExprStmt { 112 | span: DUMMY_SP, 113 | expr: Box::new(Expr::Call(CallExpr { 114 | span: DUMMY_SP, 115 | callee: Callee::Expr(Box::new(Expr::Member(MemberExpr { 116 | span: DUMMY_SP, 117 | obj: Box::new(Expr::Ident(FILE_SCOPE_IMPORT_NAME.clone())), 118 | prop: MemberProp::Ident(Ident::new("setFileScope".into(), DUMMY_SP)), 119 | }))), 120 | args: vec![ 121 | ExprOrSpread { 122 | spread: None, 123 | expr: Box::new(Expr::Lit(Lit::Str(Str::from(JsWord::from( 124 | self.file_path.clone(), 125 | ))))), 126 | }, 127 | ExprOrSpread { 128 | spread: None, 129 | expr: Box::new(Expr::Lit(Lit::Str(Str::from(JsWord::from( 130 | self.package_name.clone(), 131 | ))))), 132 | }, 133 | ], 134 | type_args: None, 135 | })), 136 | })); 137 | 138 | items.insert(0, import_scope); 139 | items.insert(1, set_file_scope); 140 | 141 | items.push(quote!( 142 | "$file_scope_import_name.endFileScope()" as ModuleItem, 143 | file_scope_import_name = FILE_SCOPE_IMPORT_NAME.clone() 144 | )); 145 | } 146 | } 147 | } 148 | 149 | pub fn create_extract_visitor( 150 | _source_map: std::sync::Arc, 151 | _comments: C, 152 | filename: &str, 153 | package_name: &str, 154 | package_dir: &str, 155 | ) -> VanillaExtractVisitor { 156 | VanillaExtractVisitor::new(filename, package_name, package_dir) 157 | } 158 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | stable -------------------------------------------------------------------------------- /spec/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { Options, transformSync } from "@swc/core"; 3 | 4 | const pluginBinary = path.resolve( 5 | __dirname, 6 | "../target/wasm32-wasi/debug/swc_plugin_vanilla_extract.wasm" 7 | ); 8 | 9 | const transform = ( 10 | code: string, 11 | module?: "commonjs" | "es6", 12 | transformOptions?: Options, 13 | filename?: string 14 | ) => { 15 | const pluginOptions = {}; 16 | 17 | const options: Options = { 18 | filename: filename ?? "dir/mockFilename.css.ts", 19 | jsc: { 20 | parser: { 21 | syntax: "ecmascript", 22 | jsx: true, 23 | }, 24 | target: "es2022", 25 | preserveAllComments: true, 26 | }, 27 | isModule: transformOptions?.isModule ?? true, 28 | module: { 29 | type: module || "es6", 30 | strict: !!transformOptions?.isModule ?? false, 31 | }, 32 | }; 33 | 34 | if (process.env.SWC_TRANSFORM_CUSTOM === "1") { 35 | const { transformSync } = require("../index"); 36 | return transformSync( 37 | code, 38 | true, 39 | Buffer.from(JSON.stringify(options)), 40 | Buffer.from( 41 | JSON.stringify({ 42 | ...pluginOptions, 43 | debugInitialCoverageComment: true, 44 | }) 45 | ) 46 | ).code; 47 | } 48 | 49 | options.jsc!.experimental = { 50 | plugins: [ 51 | [ 52 | pluginBinary, 53 | { 54 | ...pluginOptions, 55 | }, 56 | ], 57 | ], 58 | }; 59 | 60 | return transformSync(code, options).code; 61 | }; 62 | 63 | const cwd = path.resolve(__dirname, ".."); 64 | 65 | describe("babel plugin", () => { 66 | it("should handle style assigned to const", () => { 67 | const source = ` 68 | import { style } from '@vanilla-extract/css'; 69 | 70 | const one = style({ 71 | zIndex: 2, 72 | }); 73 | `; 74 | 75 | expect(transform(source)).toMatchInlineSnapshot(` 76 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 77 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 78 | import { style } from '@vanilla-extract/css'; 79 | const one = style({ 80 | zIndex: 2 81 | }, "one"); 82 | __vanilla_filescope__.endFileScope(); 83 | " 84 | `); 85 | }); 86 | 87 | it("should handle styleVariants assigned to const", () => { 88 | const source = ` 89 | import { styleVariants } from '@vanilla-extract/css'; 90 | 91 | const colors = styleVariants({ 92 | red: { color: 'red' } 93 | }); 94 | `; 95 | 96 | expect(transform(source)).toMatchInlineSnapshot(` 97 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 98 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 99 | import { styleVariants } from '@vanilla-extract/css'; 100 | const colors = styleVariants({ 101 | red: { 102 | color: 'red' 103 | } 104 | }, "colors"); 105 | __vanilla_filescope__.endFileScope(); 106 | " 107 | `); 108 | }); 109 | 110 | it("should handle styleVariants with mapper assigned to const", () => { 111 | const source = ` 112 | import { styleVariants } from '@vanilla-extract/css'; 113 | 114 | const colors = styleVariants({ 115 | red: 'red' 116 | }, (color) => ({ color })); 117 | `; 118 | 119 | expect(transform(source)).toMatchInlineSnapshot(` 120 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 121 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 122 | import { styleVariants } from '@vanilla-extract/css'; 123 | const colors = styleVariants({ 124 | red: 'red' 125 | }, (color)=>({ 126 | color 127 | }), "colors"); 128 | __vanilla_filescope__.endFileScope(); 129 | " 130 | `); 131 | }); 132 | 133 | it("should handle style assigned to default export", () => { 134 | const source = ` 135 | import { style } from '@vanilla-extract/css'; 136 | 137 | export default style({ 138 | zIndex: 2, 139 | }); 140 | `; 141 | 142 | expect(transform(source)).toMatchInlineSnapshot(` 143 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 144 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 145 | import { style } from '@vanilla-extract/css'; 146 | export default style({ 147 | zIndex: 2 148 | }, "default"); 149 | __vanilla_filescope__.endFileScope(); 150 | " 151 | `); 152 | }); 153 | 154 | it("should handle style assigned to object property", () => { 155 | const source = ` 156 | import { style } from '@vanilla-extract/css'; 157 | 158 | const test = { 159 | one: { 160 | two: style({ 161 | zIndex: 2, 162 | }) 163 | } 164 | }; 165 | `; 166 | 167 | expect(transform(source)).toMatchInlineSnapshot(` 168 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 169 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 170 | import { style } from '@vanilla-extract/css'; 171 | const test = { 172 | one: { 173 | two: style({ 174 | zIndex: 2 175 | }, "test_one_two") 176 | } 177 | }; 178 | __vanilla_filescope__.endFileScope(); 179 | " 180 | `); 181 | }); 182 | 183 | it("should handle style returned from an arrow function", () => { 184 | const source = ` 185 | import { style } from '@vanilla-extract/css'; 186 | 187 | const test = () => { 188 | return style({ 189 | color: 'red' 190 | }); 191 | }; 192 | `; 193 | 194 | expect(transform(source)).toMatchInlineSnapshot(` 195 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 196 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 197 | import { style } from '@vanilla-extract/css'; 198 | const test = ()=>{ 199 | return style({ 200 | color: 'red' 201 | }, "test"); 202 | }; 203 | __vanilla_filescope__.endFileScope(); 204 | " 205 | `); 206 | }); 207 | 208 | it("should handle style returned implicitly from an arrow function", () => { 209 | const source = ` 210 | import { style } from '@vanilla-extract/css'; 211 | 212 | const test = () => style({ 213 | color: 'red' 214 | }); 215 | `; 216 | 217 | expect(transform(source)).toMatchInlineSnapshot(` 218 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 219 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 220 | import { style } from '@vanilla-extract/css'; 221 | const test = ()=>style({ 222 | color: 'red' 223 | }, "test"); 224 | __vanilla_filescope__.endFileScope(); 225 | " 226 | `); 227 | }); 228 | 229 | it("should handle style returned from a function", () => { 230 | const source = ` 231 | import { style } from '@vanilla-extract/css'; 232 | 233 | function test() { 234 | return style({ 235 | color: 'red' 236 | }); 237 | } 238 | `; 239 | 240 | expect(transform(source)).toMatchInlineSnapshot(` 241 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 242 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 243 | import { style } from '@vanilla-extract/css'; 244 | function test() { 245 | return style({ 246 | color: 'red' 247 | }, "test"); 248 | } 249 | __vanilla_filescope__.endFileScope(); 250 | " 251 | `); 252 | }); 253 | 254 | it("should handle globalStyle", () => { 255 | const source = ` 256 | import { globalStyle } from '@vanilla-extract/css'; 257 | 258 | globalStyle('html, body', { margin: 0 }); 259 | `; 260 | 261 | expect(transform(source)).toMatchInlineSnapshot(` 262 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 263 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 264 | import { globalStyle } from '@vanilla-extract/css'; 265 | globalStyle('html, body', { 266 | margin: 0 267 | }); 268 | __vanilla_filescope__.endFileScope(); 269 | " 270 | `); 271 | }); 272 | 273 | it("should handle createVar assigned to const", () => { 274 | const source = ` 275 | import { createVar } from '@vanilla-extract/css'; 276 | 277 | const myVar = createVar(); 278 | `; 279 | 280 | expect(transform(source)).toMatchInlineSnapshot(` 281 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 282 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 283 | import { createVar } from '@vanilla-extract/css'; 284 | const myVar = createVar("myVar"); 285 | __vanilla_filescope__.endFileScope(); 286 | " 287 | `); 288 | }); 289 | 290 | it("should handle createContainer assigned to const", () => { 291 | const source = ` 292 | import { createContainer } from '@vanilla-extract/css'; 293 | 294 | const myContainer = createContainer(); 295 | `; 296 | 297 | expect(transform(source)).toMatchInlineSnapshot(` 298 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 299 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 300 | import { createContainer } from '@vanilla-extract/css'; 301 | const myContainer = createContainer("myContainer"); 302 | __vanilla_filescope__.endFileScope(); 303 | " 304 | `); 305 | }); 306 | 307 | it("should handle fontFace assigned to const", () => { 308 | const source = ` 309 | import { fontFace } from '@vanilla-extract/css'; 310 | 311 | const myFont = fontFace({ 312 | src: 'local("Comic Sans MS")', 313 | }); 314 | `; 315 | 316 | expect(transform(source)).toMatchInlineSnapshot(` 317 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 318 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 319 | import { fontFace } from '@vanilla-extract/css'; 320 | const myFont = fontFace({ 321 | src: 'local("Comic Sans MS")' 322 | }, "myFont"); 323 | __vanilla_filescope__.endFileScope(); 324 | " 325 | `); 326 | }); 327 | 328 | it("should handle globalFontFace", () => { 329 | const source = ` 330 | import { globalFontFace } from '@vanilla-extract/css'; 331 | 332 | globalFontFace('myFont', { 333 | src: 'local("Comic Sans MS")', 334 | }); 335 | `; 336 | 337 | expect(transform(source)).toMatchInlineSnapshot(` 338 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 339 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 340 | import { globalFontFace } from '@vanilla-extract/css'; 341 | globalFontFace('myFont', { 342 | src: 'local("Comic Sans MS")' 343 | }); 344 | __vanilla_filescope__.endFileScope(); 345 | " 346 | `); 347 | }); 348 | 349 | it("should handle keyframes assigned to const", () => { 350 | const source = ` 351 | import { keyframes } from '@vanilla-extract/css'; 352 | 353 | const myAnimation = keyframes({ 354 | from: { transform: 'rotate(0deg)' }, 355 | to: { transform: 'rotate(360deg)' } 356 | }); 357 | `; 358 | 359 | expect(transform(source)).toMatchInlineSnapshot(` 360 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 361 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 362 | import { keyframes } from '@vanilla-extract/css'; 363 | const myAnimation = keyframes({ 364 | from: { 365 | transform: 'rotate(0deg)' 366 | }, 367 | to: { 368 | transform: 'rotate(360deg)' 369 | } 370 | }, "myAnimation"); 371 | __vanilla_filescope__.endFileScope(); 372 | " 373 | `); 374 | }); 375 | 376 | it("should handle global keyframes", () => { 377 | const source = ` 378 | import { globalKeyframes } from '@vanilla-extract/css'; 379 | 380 | globalKeyframes('myKeyframes', { 381 | from: { transform: 'rotate(0deg)' }, 382 | to: { transform: 'rotate(360deg)' } 383 | }); 384 | `; 385 | 386 | expect(transform(source)).toMatchInlineSnapshot(` 387 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 388 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 389 | import { globalKeyframes } from '@vanilla-extract/css'; 390 | globalKeyframes('myKeyframes', { 391 | from: { 392 | transform: 'rotate(0deg)' 393 | }, 394 | to: { 395 | transform: 'rotate(360deg)' 396 | } 397 | }); 398 | __vanilla_filescope__.endFileScope(); 399 | " 400 | `); 401 | }); 402 | 403 | it("should handle createTheme assigned to const", () => { 404 | const source = ` 405 | import { createTheme } from '@vanilla-extract/css'; 406 | 407 | const darkTheme = createTheme({}, {}); 408 | `; 409 | 410 | expect(transform(source)).toMatchInlineSnapshot(` 411 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 412 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 413 | import { createTheme } from '@vanilla-extract/css'; 414 | const darkTheme = createTheme({}, {}, "darkTheme"); 415 | __vanilla_filescope__.endFileScope(); 416 | " 417 | `); 418 | }); 419 | 420 | it("should handle createTheme using destructuring", () => { 421 | const source = ` 422 | import { createTheme } from '@vanilla-extract/css'; 423 | 424 | const [theme, vars] = createTheme({}, {}); 425 | `; 426 | 427 | expect(transform(source)).toMatchInlineSnapshot(` 428 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 429 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 430 | import { createTheme } from '@vanilla-extract/css'; 431 | const [theme, vars] = createTheme({}, {}, "theme"); 432 | __vanilla_filescope__.endFileScope(); 433 | " 434 | `); 435 | }); 436 | 437 | it("should handle createTheme using destructuring when already compiled", () => { 438 | const source = ` 439 | import { createTheme } from '@vanilla-extract/css'; 440 | 441 | var _createTheme = createTheme({}), 442 | _createTheme2 = _slicedToArray(_createTheme, 2), 443 | myThemeClass = _createTheme2[0], 444 | vars = _createTheme2[1]; 445 | `; 446 | 447 | expect(transform(source)).toMatchInlineSnapshot(` 448 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 449 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 450 | import { createTheme } from '@vanilla-extract/css'; 451 | var _createTheme = createTheme({}, "_createTheme"), _createTheme2 = _slicedToArray(_createTheme, 2), myThemeClass = _createTheme2[0], vars = _createTheme2[1]; 452 | __vanilla_filescope__.endFileScope(); 453 | " 454 | `); 455 | }); 456 | 457 | it("should handle createGlobalTheme", () => { 458 | const source = ` 459 | import { createGlobalTheme } from '@vanilla-extract/css'; 460 | 461 | const vars = createGlobalTheme(':root', { foo: 'bar' }); 462 | `; 463 | 464 | expect(transform(source)).toMatchInlineSnapshot(` 465 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 466 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 467 | import { createGlobalTheme } from '@vanilla-extract/css'; 468 | const vars = createGlobalTheme(':root', { 469 | foo: 'bar' 470 | }); 471 | __vanilla_filescope__.endFileScope(); 472 | " 473 | `); 474 | }); 475 | 476 | it("should handle createThemeContract", () => { 477 | const source = ` 478 | import { createThemeContract } from '@vanilla-extract/css'; 479 | 480 | const vars = createThemeContract({ 481 | foo: 'bar' 482 | }); 483 | `; 484 | 485 | expect(transform(source)).toMatchInlineSnapshot(` 486 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 487 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 488 | import { createThemeContract } from '@vanilla-extract/css'; 489 | const vars = createThemeContract({ 490 | foo: 'bar' 491 | }); 492 | __vanilla_filescope__.endFileScope(); 493 | " 494 | `); 495 | }); 496 | 497 | it("should handle recipe assigned to const", () => { 498 | const source = ` 499 | import { recipe } from '@vanilla-extract/recipes'; 500 | 501 | const button = recipe({}); 502 | `; 503 | 504 | expect(transform(source)).toMatchInlineSnapshot(` 505 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 506 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 507 | import { recipe } from '@vanilla-extract/recipes'; 508 | const button = recipe({}, "button"); 509 | __vanilla_filescope__.endFileScope(); 510 | " 511 | `); 512 | }); 513 | 514 | it("should ignore functions that already supply a debug name", () => { 515 | const source = ` 516 | import { style, styleVariants } from '@vanilla-extract/css'; 517 | 518 | const three = style({ 519 | testStyle: { 520 | zIndex: 2, 521 | } 522 | }, 'myDebugValue'); 523 | 524 | const four = styleVariants({ 525 | red: { color: 'red' } 526 | }, 'myDebugValue'); 527 | `; 528 | 529 | expect(transform(source)).toMatchInlineSnapshot(` 530 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 531 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 532 | import { style, styleVariants } from '@vanilla-extract/css'; 533 | const three = style({ 534 | testStyle: { 535 | zIndex: 2 536 | } 537 | }, 'myDebugValue'); 538 | const four = styleVariants({ 539 | red: { 540 | color: 'red' 541 | } 542 | }, 'myDebugValue', "four"); 543 | __vanilla_filescope__.endFileScope(); 544 | " 545 | `); 546 | }); 547 | 548 | it("should only apply debug ids to functions imported from the relevant package", () => { 549 | const source = ` 550 | import { style } from 'some-other-package'; 551 | 552 | const three = style({ 553 | zIndex: 2, 554 | }); 555 | `; 556 | 557 | expect(transform(source)).toMatchInlineSnapshot(` 558 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 559 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 560 | import { style } from 'some-other-package'; 561 | const three = style({ 562 | zIndex: 2 563 | }); 564 | __vanilla_filescope__.endFileScope(); 565 | " 566 | `); 567 | }); 568 | 569 | it("should only apply to .css.ts files", () => { 570 | const source = ` 571 | import { style } from '@vanilla-extract/css'; 572 | 573 | const three = style({ 574 | zIndex: 2, 575 | }); 576 | `; 577 | 578 | expect(transform(source, "es6", {}, "dir/mockFilename.ts")) 579 | .toMatchInlineSnapshot(` 580 | "import { style } from '@vanilla-extract/css'; 581 | const three = style({ 582 | zIndex: 2 583 | }); 584 | " 585 | `); 586 | }); 587 | 588 | it("should ignore files that already have filescope information", () => { 589 | const source = ` 590 | import { setFileScope, endFileScope } from '@vanilla-extract/css/fileScope'; 591 | setFileScope('src/dir/someFileName.css.ts', 'some-package'); 592 | import { style } from '@vanilla-extract/css'; 593 | 594 | const three = style({ 595 | zIndex: 2, 596 | }); 597 | endFileScope(); 598 | `; 599 | 600 | expect(transform(source)).toMatchInlineSnapshot(` 601 | "import { setFileScope, endFileScope } from '@vanilla-extract/css/fileScope'; 602 | setFileScope('src/dir/someFileName.css.ts', 'some-package'); 603 | import { style } from '@vanilla-extract/css'; 604 | const three = style({ 605 | zIndex: 2 606 | }); 607 | endFileScope(); 608 | " 609 | `); 610 | }); 611 | 612 | it("should use CJS when it is detected", () => { 613 | const source = ` 614 | const { style } = require('@vanilla-extract/css'); 615 | 616 | const three = style({ 617 | zIndex: 2, 618 | }); 619 | `; 620 | 621 | expect(transform(source)).toMatchInlineSnapshot(` 622 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 623 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 624 | const { style } = require('@vanilla-extract/css'); 625 | const three = style({ 626 | zIndex: 2 627 | }); 628 | __vanilla_filescope__.endFileScope(); 629 | " 630 | `); 631 | }); 632 | 633 | it("should ignore CJS files that already have filescope information", () => { 634 | const source = ` 635 | const { setFileScope, endFileScope } = require('@vanilla-extract/css/fileScope'); 636 | setFileScope('src/dir/someFileName.css.ts', 'some-package'); 637 | const { style } = require('@vanilla-extract/css'); 638 | 639 | const three = style({ 640 | zIndex: 2, 641 | }); 642 | endFileScope(); 643 | `; 644 | 645 | expect(transform(source)).toMatchInlineSnapshot(` 646 | "const { setFileScope , endFileScope } = require('@vanilla-extract/css/fileScope'); 647 | setFileScope('src/dir/someFileName.css.ts', 'some-package'); 648 | const { style } = require('@vanilla-extract/css'); 649 | const three = style({ 650 | zIndex: 2 651 | }); 652 | endFileScope(); 653 | " 654 | `); 655 | }); 656 | 657 | it("should handle renaming imports", () => { 658 | const source = ` 659 | import { style as specialStyle } from '@vanilla-extract/css'; 660 | 661 | const four = specialStyle({ 662 | zIndex: 2, 663 | }); 664 | `; 665 | 666 | expect(transform(source)).toMatchInlineSnapshot(` 667 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 668 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 669 | import { style as specialStyle } from '@vanilla-extract/css'; 670 | const four = specialStyle({ 671 | zIndex: 2 672 | }, "four"); 673 | __vanilla_filescope__.endFileScope(); 674 | " 675 | `); 676 | }); 677 | 678 | it("should handle anonymous style in arrays", () => { 679 | const source = ` 680 | import { style } from '@vanilla-extract/css'; 681 | 682 | export const height = [ 683 | style({ 684 | zIndex: 2, 685 | }) 686 | ]; 687 | `; 688 | 689 | expect(transform(source)).toMatchInlineSnapshot(` 690 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 691 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 692 | import { style } from '@vanilla-extract/css'; 693 | export const height = [ 694 | style({ 695 | zIndex: 2 696 | }, "height") 697 | ]; 698 | __vanilla_filescope__.endFileScope(); 699 | " 700 | `); 701 | }); 702 | 703 | it("should handle object key with anonymous style in arrays", () => { 704 | const source = ` 705 | import { style } from '@vanilla-extract/css'; 706 | 707 | export const height = { 708 | full: [style({ 709 | zIndex: 2, 710 | })] 711 | }; 712 | `; 713 | 714 | expect(transform(source)).toMatchInlineSnapshot(` 715 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 716 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 717 | import { style } from '@vanilla-extract/css'; 718 | export const height = { 719 | full: [ 720 | style({ 721 | zIndex: 2 722 | }, "height_full") 723 | ] 724 | }; 725 | __vanilla_filescope__.endFileScope(); 726 | " 727 | `); 728 | }); 729 | 730 | it("should handle namespace imports", () => { 731 | const source = ` 732 | import * as css from '@vanilla-extract/css'; 733 | 734 | const one = css.style({ 735 | zIndex: 2, 736 | }); 737 | `; 738 | 739 | expect(transform(source)).toMatchInlineSnapshot(` 740 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 741 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 742 | import * as css from '@vanilla-extract/css'; 743 | const one = css.style({ 744 | zIndex: 2 745 | }, "one"); 746 | __vanilla_filescope__.endFileScope(); 747 | " 748 | `); 749 | }); 750 | 751 | it("should handle nested call expressions", () => { 752 | const source = ` 753 | import { style } from '@vanilla-extract/css'; 754 | 755 | const one = instrument(style({ 756 | zIndex: 1, 757 | })); 758 | 759 | const two = instrument(instrument(style({ 760 | zIndex: 2, 761 | }))); 762 | 763 | const three = instrument(instrument(instrument(style({ 764 | zIndex: 3, 765 | })))); 766 | `; 767 | 768 | expect(transform(source)).toMatchInlineSnapshot(` 769 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 770 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 771 | import { style } from '@vanilla-extract/css'; 772 | const one = instrument(style({ 773 | zIndex: 1 774 | }, "one")); 775 | const two = instrument(instrument(style({ 776 | zIndex: 2 777 | }, "two"))); 778 | const three = instrument(instrument(instrument(style({ 779 | zIndex: 3 780 | }, "three")))); 781 | __vanilla_filescope__.endFileScope(); 782 | " 783 | `); 784 | }); 785 | 786 | it("should handle instrumentation via sequence expresions", () => { 787 | const source = ` 788 | import { style } from '@vanilla-extract/css'; 789 | 790 | const one = (something++, style({ 791 | zIndex: 1, 792 | })); 793 | `; 794 | 795 | expect(transform(source)).toMatchInlineSnapshot(` 796 | "import * as __vanilla_filescope__ from "@vanilla-extract/css/fileScope"; 797 | __vanilla_filescope__.setFileScope("${cwd}/dir/mockFilename.css.ts", "swc-plugin-vanilla-extract"); 798 | import { style } from '@vanilla-extract/css'; 799 | const one = (something++, style({ 800 | zIndex: 1 801 | }, "one")); 802 | __vanilla_filescope__.endFileScope(); 803 | " 804 | `); 805 | }); 806 | }); 807 | -------------------------------------------------------------------------------- /spec/swc-vanilla-custom-transform/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2021" 3 | name = "swc-vanilla-custom-transform" 4 | version = "0.1.0" 5 | 6 | [lib] 7 | crate-type = ["cdylib", "rlib"] 8 | 9 | [build-dependencies] 10 | napi-build = "2.0.1" 11 | 12 | [dependencies] 13 | anyhow = "1.0.66" 14 | backtrace = "0.3.66" 15 | napi = { version = "2.10.1", default-features = false, features = [ 16 | "napi3", 17 | "serde-json", 18 | ] } 19 | napi-derive = { version = "2.9.1", default-features = false, features = [ 20 | "type-def", 21 | ] } 22 | serde = { version = "1.0.147", features = ["derive"] } 23 | serde_json = { version = "1.0.87", features = ["unbounded_depth"] } 24 | 25 | swc-vanilla-extract-visitor = { path = "../../packages/swc-vanilla-extract-visitor" } 26 | swc_core = { version = "0.43.2", features = [ 27 | "common_concurrent", 28 | "ecma_transforms", 29 | "ecma_ast", 30 | "allocator_node", 31 | "ecma_visit", 32 | "base_node", 33 | ] } 34 | -------------------------------------------------------------------------------- /spec/swc-vanilla-custom-transform/build.rs: -------------------------------------------------------------------------------- 1 | extern crate napi_build; 2 | 3 | fn main() { 4 | napi_build::setup(); 5 | } 6 | -------------------------------------------------------------------------------- /spec/swc-vanilla-custom-transform/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "2048"] 2 | #![allow(dead_code)] 3 | 4 | mod util; 5 | 6 | #[macro_use] 7 | extern crate napi_derive; 8 | 9 | //extern crate swc_core; 10 | 11 | use std::{env, panic::set_hook, sync::Arc}; 12 | 13 | use backtrace::Backtrace; 14 | 15 | use swc_core::{ 16 | base::{config::Options, Compiler, TransformOutput}, 17 | common::{ 18 | comments::{Comments, SingleThreadedComments}, 19 | sync::Lazy, 20 | FileName, FilePathMapping, SourceMap, 21 | }, 22 | ecma::{ 23 | transforms::base::pass::noop, 24 | visit::{as_folder, Fold}, 25 | }, 26 | }; 27 | use swc_vanilla_extract_visitor::create_extract_visitor; 28 | 29 | use std::path::Path; 30 | 31 | use napi::bindgen_prelude::Buffer; 32 | 33 | use crate::util::{get_deserialized, try_with, MapErr}; 34 | 35 | static COMPILER: Lazy> = Lazy::new(|| { 36 | let cm = Arc::new(SourceMap::new(FilePathMapping::empty())); 37 | 38 | Arc::new(Compiler::new(cm)) 39 | }); 40 | 41 | #[napi::module_init] 42 | fn init() { 43 | if cfg!(debug_assertions) || env::var("SWC_DEBUG").unwrap_or_default() == "1" { 44 | set_hook(Box::new(|panic_info| { 45 | let backtrace = Backtrace::new(); 46 | println!("Panic: {:?}\nBacktrace: {:?}", panic_info, backtrace); 47 | })); 48 | } 49 | } 50 | 51 | fn get_compiler() -> Arc { 52 | COMPILER.clone() 53 | } 54 | 55 | #[napi(js_name = "Compiler")] 56 | pub struct JsCompiler { 57 | _compiler: Arc, 58 | } 59 | 60 | #[napi] 61 | impl JsCompiler { 62 | #[napi(constructor)] 63 | #[allow(clippy::new_without_default)] 64 | pub fn new() -> Self { 65 | Self { 66 | _compiler: COMPILER.clone(), 67 | } 68 | } 69 | } 70 | 71 | pub type ArcCompiler = Arc; 72 | 73 | #[napi] 74 | pub fn transform_sync( 75 | s: String, 76 | _is_module: bool, 77 | opts: Buffer, 78 | _instrument_opts: Buffer, 79 | ) -> napi::Result { 80 | let c = get_compiler(); 81 | 82 | let mut options: Options = get_deserialized(&opts)?; 83 | let instrument_option = "dummy".to_string(); 84 | 85 | if !options.filename.is_empty() { 86 | options.config.adjust(Path::new(&options.filename)); 87 | } 88 | 89 | try_with( 90 | c.cm.clone(), 91 | !options.config.error.filename.into_bool(), 92 | |handler| { 93 | c.run(|| { 94 | let filename = if options.filename.is_empty() { 95 | FileName::Anon 96 | } else { 97 | FileName::Real(options.filename.clone().into()) 98 | }; 99 | 100 | let fm = c.cm.new_source_file(filename.clone(), s); 101 | c.process_js_with_custom_pass( 102 | fm, 103 | None, 104 | handler, 105 | &options, 106 | Default::default(), 107 | |_program| { 108 | vanilla_extract( 109 | c.cm.clone(), 110 | SingleThreadedComments::default(), 111 | instrument_option, 112 | filename.to_string(), 113 | ) 114 | }, 115 | |_| noop(), 116 | ) 117 | }) 118 | }, 119 | ) 120 | .convert_err() 121 | } 122 | 123 | fn vanilla_extract< 124 | 'a, 125 | C: Comments + 'a + std::clone::Clone, 126 | S: 'a + swc_core::common::errors::SourceMapper, 127 | >( 128 | source_map: Arc, 129 | comments: C, 130 | _instrument_options: String, 131 | filename: String, 132 | ) -> impl Fold + 'a { 133 | let visitor = create_extract_visitor( 134 | source_map, 135 | comments, 136 | &filename, 137 | "swc-plugin-vanilla-extract", 138 | std::env::current_dir() 139 | .expect("Should exist") 140 | .as_os_str() 141 | .to_str() 142 | .expect("Should exist"), 143 | ); 144 | 145 | as_folder(visitor) 146 | } 147 | -------------------------------------------------------------------------------- /spec/swc-vanilla-custom-transform/src/util.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | any::type_name, 3 | panic::{catch_unwind, AssertUnwindSafe}, 4 | }; 5 | 6 | use anyhow::{anyhow, Context, Error}; 7 | use napi::Status; 8 | use serde::de::DeserializeOwned; 9 | use swc_core::{ 10 | base::{try_with_handler, HandlerOpts}, 11 | common::{errors::Handler, sync::Lrc, SourceMap, GLOBALS}, 12 | }; 13 | 14 | pub fn try_with(cm: Lrc, skip_filename: bool, op: F) -> Result 15 | where 16 | F: FnOnce(&Handler) -> Result, 17 | { 18 | GLOBALS.set(&Default::default(), || { 19 | try_with_handler( 20 | cm, 21 | HandlerOpts { 22 | skip_filename, 23 | ..Default::default() 24 | }, 25 | |handler| { 26 | // 27 | let result = catch_unwind(AssertUnwindSafe(|| op(handler))); 28 | 29 | let p = match result { 30 | Ok(v) => return v, 31 | Err(v) => v, 32 | }; 33 | 34 | if let Some(s) = p.downcast_ref::() { 35 | Err(anyhow!("failed to handle: {}", s)) 36 | } else if let Some(s) = p.downcast_ref::<&str>() { 37 | Err(anyhow!("failed to handle: {}", s)) 38 | } else { 39 | Err(anyhow!("failed to handle with unknown panic message")) 40 | } 41 | }, 42 | ) 43 | }) 44 | } 45 | 46 | pub trait MapErr: Into> { 47 | fn convert_err(self) -> napi::Result { 48 | self.into() 49 | .map_err(|err| napi::Error::new(Status::GenericFailure, format!("{:?}", err))) 50 | } 51 | } 52 | 53 | impl MapErr for Result {} 54 | 55 | pub(crate) fn get_deserialized(buffer: B) -> napi::Result 56 | where 57 | T: DeserializeOwned, 58 | B: AsRef<[u8]>, 59 | { 60 | let mut deserializer = serde_json::Deserializer::from_slice(buffer.as_ref()); 61 | deserializer.disable_recursion_limit(); 62 | 63 | let v = T::deserialize(&mut deserializer) 64 | .with_context(|| { 65 | format!( 66 | "Failed to deserialize buffer as {}\nJSON: {}", 67 | type_name::(), 68 | String::from_utf8_lossy(buffer.as_ref()) 69 | ) 70 | }) 71 | .convert_err()?; 72 | 73 | Ok(v) 74 | } 75 | 76 | pub(crate) fn deserialize_json(json: &str) -> Result 77 | where 78 | T: DeserializeOwned, 79 | { 80 | let mut deserializer = serde_json::Deserializer::from_str(json); 81 | deserializer.disable_recursion_limit(); 82 | 83 | T::deserialize(&mut deserializer) 84 | } 85 | --------------------------------------------------------------------------------