make everything use oxc allocator

This commit is contained in:
Toshit Chawda 2025-03-07 15:18:36 -08:00
parent ea2fe7d926
commit 1d834c49e8
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
8 changed files with 328 additions and 296 deletions

194
rewriter/Cargo.lock generated
View file

@ -55,9 +55,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.8.0" version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]] [[package]]
name = "boa_ast" name = "boa_ast"
@ -209,9 +209,9 @@ dependencies = [
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.21.0" version = "1.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540"
dependencies = [ dependencies = [
"bytemuck_derive", "bytemuck_derive",
] ]
@ -289,18 +289,18 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.29" version = "4.5.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acebd8ad879283633b343856142139f2da2317c96b05b4dd6181c61e2480184" checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
] ]
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.29" version = "4.5.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ba32cbda51c7e1dfd49acc1457ba1a7dec5b64fe360e828acb13ca8dc9c2f9" checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"clap_lex", "clap_lex",
@ -435,9 +435,9 @@ dependencies = [
[[package]] [[package]]
name = "either" name = "either"
version = "1.13.0" version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]] [[package]]
name = "equivalent" name = "equivalent"
@ -506,9 +506,9 @@ dependencies = [
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.4.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" checksum = "fbd780fe5cc30f81464441920d82ac8740e2e46b29a6fad543ddd075229ce37e"
[[package]] [[package]]
name = "icu_collections" name = "icu_collections"
@ -682,9 +682,9 @@ dependencies = [
[[package]] [[package]]
name = "is-terminal" name = "is-terminal"
version = "0.4.15" version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e19b23d53f35ce9f56aebc7d1bb4e6ac1e9c0db7ac85c8d1760c04379edced37" checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
dependencies = [ dependencies = [
"hermit-abi", "hermit-abi",
"libc", "libc",
@ -711,9 +711,9 @@ dependencies = [
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.14" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
@ -727,15 +727,15 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.169" version = "0.2.170"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
[[package]] [[package]]
name = "litemap" name = "litemap"
version = "0.7.4" version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" checksum = "23fb14cb19457329c82206317a5663005a4d404783dc74f4252769b0d5f42856"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
@ -749,9 +749,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.25" version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e"
[[package]] [[package]]
name = "memchr" name = "memchr"
@ -861,21 +861,21 @@ checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e"
[[package]] [[package]]
name = "oorandom" name = "oorandom"
version = "11.1.4" version = "11.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "4.1.0" version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb37767f6569cd834a413442455e0f066d0d522de8630436e2a1761d9726ba56" checksum = "1036865bb9422d3300cf723f657c2851d0e9ab12567854b1f4eba3d77decf564"
[[package]] [[package]]
name = "oxc" name = "oxc"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b4a5aba9c3f445db5401f9975266b23a5c5b49a8b4ccb1efa049132e96069dc" checksum = "cae6276febbc5abc1f1e4cf49167d54ab341818656ae4f622d5992b65fcdd371"
dependencies = [ dependencies = [
"oxc_allocator", "oxc_allocator",
"oxc_ast", "oxc_ast",
@ -898,7 +898,7 @@ dependencies = [
"oxc-miette-derive", "oxc-miette-derive",
"textwrap", "textwrap",
"thiserror 1.0.69", "thiserror 1.0.69",
"unicode-width 0.2.0", "unicode-width",
] ]
[[package]] [[package]]
@ -914,9 +914,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_allocator" name = "oxc_allocator"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7844c292ad3f79021bf3066538129c662a65bb4235a3450d124edd81bc9094df" checksum = "22cc5cd078806a1b7061fa146dc4228a57d0765da6c85e99500d069b86f57e94"
dependencies = [ dependencies = [
"allocator-api2", "allocator-api2",
"bumpalo", "bumpalo",
@ -927,9 +927,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_ast" name = "oxc_ast"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4005b2e219aa87cb0cbde495bcd6543748a4d77c8583ec573c6db2984bb249f" checksum = "e4722414ac21a2e28a16b76de8390672c01a39adcb703d405b848149cfaeeaf7"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cow-utils", "cow-utils",
@ -944,9 +944,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_ast_macros" name = "oxc_ast_macros"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93405fb1ad62247fa9296ad73265671b9c4aaa39dbbe142af00a6de415e61606" checksum = "8f1505d8622b2ea6ed0274f355bd5e4ee3f09df5d9b39c8a3a673f344d87b82a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -955,9 +955,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_ast_visit" name = "oxc_ast_visit"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f333b2ae5cbf1328986ce1eca317bc7f2f2e256c3d4a0f72b0d935a30c86b641" checksum = "cf45370c6da0dd142a70468e5b25127d6a34caa71056105c85087559c8ee9afb"
dependencies = [ dependencies = [
"oxc_allocator", "oxc_allocator",
"oxc_ast", "oxc_ast",
@ -967,9 +967,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_data_structures" name = "oxc_data_structures"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc814bebc24ca429f257fba498dee171a98fa2ef1ea0f9c9eb3d69f0993baa6" checksum = "cb49a2ee880952c2079b61851ecc35d7671d9d3509e306f5e704ccacd2783984"
dependencies = [ dependencies = [
"assert-unchecked", "assert-unchecked",
"ropey", "ropey",
@ -977,9 +977,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_diagnostics" name = "oxc_diagnostics"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fd1f43ffbdabf86a563b48970c2abdbc0ac860e49558c83ab23a010b1a774f8" checksum = "ea83fe2415b0580980ac83364c1ae943f8ee9c00becf5395a89e800a9526a080"
dependencies = [ dependencies = [
"cow-utils", "cow-utils",
"oxc-miette", "oxc-miette",
@ -987,9 +987,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_ecmascript" name = "oxc_ecmascript"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a23d0e112ff9ea0f39dd2c9c921f0938e313e26ee9e4022f60c8d81c561e518" checksum = "6c7e7bcc382cf901e93a16f86e70f2737c507aaa833656b0d8484d64f8ae358a"
dependencies = [ dependencies = [
"cow-utils", "cow-utils",
"num-bigint", "num-bigint",
@ -1001,9 +1001,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_estree" name = "oxc_estree"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd9818707125125e32d25fd18c5331a4418fbde084e33c69dee123df5b2531d2" checksum = "1cb66484735d21f096b07c894badc96d89a0c6d31b4bdd46b33b3e44da9b97ac"
[[package]] [[package]]
name = "oxc_index" name = "oxc_index"
@ -1013,9 +1013,9 @@ checksum = "2fa07b0cfa997730afed43705766ef27792873fdf5215b1391949fec678d2392"
[[package]] [[package]]
name = "oxc_parser" name = "oxc_parser"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cce20364085569f8caebeb879aec455c5c8f6e5dcb5d0ecfb88208ae5e709331" checksum = "7a7414e779b9723b0bd2880fe69b0ee517e583f88c5118a7c9053cf3317b95b1"
dependencies = [ dependencies = [
"assert-unchecked", "assert-unchecked",
"bitflags", "bitflags",
@ -1036,9 +1036,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_regular_expression" name = "oxc_regular_expression"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89e1f1e21ed9b3e4d1c6eb10dffc1c71202e8fe111968cf6636f5484ad443b0b" checksum = "d18196c212eac24a7faf613e373e5f9317d3542578a088d01dc1a548fa1e1cb3"
dependencies = [ dependencies = [
"oxc_allocator", "oxc_allocator",
"oxc_ast_macros", "oxc_ast_macros",
@ -1052,9 +1052,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_span" name = "oxc_span"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e59da8e765f44892357f6b75bdb16f486d61956c5bd92a345429ad704d4853fd" checksum = "318f925e26bd118adc082d290538d07611fe2434987a5c60cf5084381ecb42e6"
dependencies = [ dependencies = [
"compact_str", "compact_str",
"oxc-miette", "oxc-miette",
@ -1065,9 +1065,9 @@ dependencies = [
[[package]] [[package]]
name = "oxc_syntax" name = "oxc_syntax"
version = "0.56.0" version = "0.56.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47b8bd67fdd8df27cfddbec577b282f1a6601509ecd750697f590d7cdc2d88b7" checksum = "8cb68ceb7c6902f3043fe8fe49bb886826b1d7741dc2904337297d53692b1b9c"
dependencies = [ dependencies = [
"assert-unchecked", "assert-unchecked",
"bitflags", "bitflags",
@ -1187,9 +1187,9 @@ checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
[[package]] [[package]]
name = "portable-atomic" name = "portable-atomic"
version = "1.10.0" version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]] [[package]]
name = "powerfmt" name = "powerfmt"
@ -1208,27 +1208,27 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "3.2.0" version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
dependencies = [ dependencies = [
"toml_edit", "toml_edit",
] ]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.93" version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.38" version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1285,9 +1285,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.5.8" version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -1358,15 +1358,15 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.19" version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.19" version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]] [[package]]
name = "ryu-js" name = "ryu-js"
@ -1391,24 +1391,24 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "seq-macro" name = "seq-macro"
version = "0.3.5" version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.217" version = "1.0.218"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.217" version = "1.0.218"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1417,9 +1417,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.138" version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -1477,9 +1477,9 @@ checksum = "d08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.98" version = "2.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1505,13 +1505,13 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.16.1" version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
dependencies = [ dependencies = [
"smawk", "smawk",
"unicode-linebreak", "unicode-linebreak",
"unicode-width 0.1.14", "unicode-width",
] ]
[[package]] [[package]]
@ -1562,9 +1562,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.37" version = "0.3.39"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" checksum = "dad298b01a40a23aac4580b67e3dbedb7cc8402f3592d7f49469de2ea4aecdd8"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
@ -1580,15 +1580,15 @@ dependencies = [
[[package]] [[package]]
name = "time-core" name = "time-core"
version = "0.1.2" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" checksum = "765c97a5b985b7c11d7bc27fa927dc4fe6af3a6dfb021d28deb60d3bf51e76ef"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.19" version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" checksum = "e8093bc3e81c3bc5f7879de09619d06c9a5a5e45ca44dfeeb7225bae38005c5c"
dependencies = [ dependencies = [
"num-conv", "num-conv",
"time-core", "time-core",
@ -1639,9 +1639,9 @@ checksum = "2f322b60f6b9736017344fa0635d64be2f458fbc04eef65f6be22976dd1ffd5b"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.16" version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]] [[package]]
name = "unicode-linebreak" name = "unicode-linebreak"
@ -1649,12 +1649,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.2.0" version = "0.2.0"
@ -1871,9 +1865,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.7.2" version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59690dea168f2198d1a3b0cac23b8063efcd11012f10ae4698f284808c8ef603" checksum = "0e7f4ea97f6f78012141bcdb6a216b2609f0979ada50b20ca5b52dde2eac2bb1"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -1937,18 +1931,18 @@ dependencies = [
[[package]] [[package]]
name = "zerofrom" name = "zerofrom"
version = "0.1.5" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5"
dependencies = [ dependencies = [
"zerofrom-derive", "zerofrom-derive",
] ]
[[package]] [[package]]
name = "zerofrom-derive" name = "zerofrom-derive"
version = "0.1.5" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -17,3 +17,4 @@ pedantic = { level = "warn", priority = -1 }
struct-excessive-bools = "allow" struct-excessive-bools = "allow"
missing-errors-doc = "allow" missing-errors-doc = "allow"
cast-possible-truncation = "allow" cast-possible-truncation = "allow"
must-use-candidate = "allow"

View file

@ -2,39 +2,43 @@ use std::{env, fs, str::FromStr, sync::Arc};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use bytes::{Buf, Bytes, BytesMut}; use bytes::{Buf, Bytes, BytesMut};
use oxc::diagnostics::NamedSource; use oxc::{
allocator::{Allocator, String},
diagnostics::NamedSource,
};
use rewriter::{cfg::Config, rewrite, RewriteResult}; use rewriter::{cfg::Config, rewrite, RewriteResult};
use url::Url; use url::Url;
use urlencoding::encode; use urlencoding::encode;
fn dorewrite(data: &str) -> Result<RewriteResult> { fn dorewrite<'alloc>(alloc: &'alloc Allocator, data: &str) -> Result<RewriteResult<'alloc>> {
let url = Url::from_str("https://google.com/glorngle/si.js").context("failed to make url")?; let url = Url::from_str("https://google.com/glorngle/si.js").context("failed to make url")?;
rewrite( rewrite(
alloc,
data, data,
true,
1024,
Config { Config {
prefix: "/scrammedjet/".to_string(), prefix: "/scrammedjet/",
base: url.to_string(), base: "https://google.com/glorngle/si.js",
urlrewriter: Box::new(move |x: String| { urlrewriter: Box::new(move |x: &str, alloc: &'alloc Allocator| {
encode(url.join(&x).unwrap().as_str()).to_string() String::from_str_in(encode(url.join(&x).unwrap().as_str()).as_ref(), alloc)
}), }),
sourcetag: "glongle1".to_string(), sourcetag: "glongle1",
wrapfn: "$wrap".to_string(), wrapfn: "$wrap",
wrapthisfn: "$gwrap".to_string(), wrapthisfn: "$gwrap",
importfn: "$import".to_string(), importfn: "$import",
rewritefn: "$rewrite".to_string(), rewritefn: "$rewrite",
metafn: "$meta".to_string(), metafn: "$meta",
setrealmfn: "$setrealm".to_string(), setrealmfn: "$setrealm",
pushsourcemapfn: "$pushsourcemap".to_string(), pushsourcemapfn: "$pushsourcemap",
capture_errors: true, capture_errors: true,
do_sourcemaps: true, do_sourcemaps: true,
scramitize: false, scramitize: false,
strict_rewrites: true, strict_rewrites: true,
}, },
true,
1024,
) )
.context("failed to rewrite file") .context("failed to rewrite file")
} }
@ -47,7 +51,7 @@ enum RewriteType {
fn dounrewrite(res: RewriteResult) -> Vec<u8> { fn dounrewrite(res: RewriteResult) -> Vec<u8> {
let js = res.js.as_slice(); let js = res.js.as_slice();
let mut map = Bytes::from(res.sourcemap); let mut map = Bytes::from(res.sourcemap.to_vec());
let rewrite_cnt = map.get_u32_le(); let rewrite_cnt = map.get_u32_le();
let mut rewrites = Vec::with_capacity(rewrite_cnt as usize); let mut rewrites = Vec::with_capacity(rewrite_cnt as usize);
@ -102,10 +106,12 @@ fn main() -> Result<()> {
let data = fs::read_to_string(file).context("failed to read file")?; let data = fs::read_to_string(file).context("failed to read file")?;
let bench = env::args().nth(2).is_some(); let bench = env::args().nth(2).is_some();
let alloc = Allocator::default();
if bench { if bench {
let mut i = 0; let mut i = 0;
loop { loop {
let _ = dorewrite(&data); let _ = dorewrite(&alloc, &data);
i += 1; i += 1;
if i % 100 == 0 { if i % 100 == 0 {
println!("{i}..."); println!("{i}...");
@ -114,7 +120,7 @@ fn main() -> Result<()> {
} else { } else {
println!("orig:\n{data}"); println!("orig:\n{data}");
let res = dorewrite(&data)?; let res = dorewrite(&alloc, &data)?;
let source = Arc::new( let source = Arc::new(
NamedSource::new(data.clone(), "https://google.com/glorngle/si.js") NamedSource::new(data.clone(), "https://google.com/glorngle/si.js")
@ -151,13 +157,16 @@ mod test {
property::{Attribute, PropertyDescriptorBuilder}, property::{Attribute, PropertyDescriptorBuilder},
Context, NativeFunction, Source, Context, NativeFunction, Source,
}; };
use oxc::allocator::Allocator;
use crate::dorewrite; use crate::dorewrite;
#[test] #[test]
fn google() { fn google() {
let alloc = Allocator::default();
let source_text = include_str!("../sample/google.js"); let source_text = include_str!("../sample/google.js");
dorewrite(source_text).unwrap(); dorewrite(&alloc, source_text).unwrap();
} }
#[test] #[test]
@ -240,10 +249,13 @@ function check(val) {
)) ))
.unwrap(); .unwrap();
let rewritten = dorewrite(&content).unwrap(); let alloc = Allocator::default();
let rewritten = dorewrite(&alloc, &content).unwrap();
println!("{}", std::str::from_utf8(&rewritten.js).unwrap()); println!("{}", std::str::from_utf8(&rewritten.js).unwrap());
context.eval(Source::from_bytes(&rewritten.js)).unwrap(); context
.eval(Source::from_bytes(rewritten.js.as_slice()))
.unwrap();
println!("PASS"); println!("PASS");
} }
} }

View file

@ -1,20 +1,20 @@
#[derive(Clone)] use oxc::allocator::{Allocator, String};
pub struct Config<E>
where
E: Fn(String) -> String,
E: Clone,
{
pub prefix: String,
pub sourcetag: String,
pub base: String,
pub wrapfn: String, pub struct Config<'alloc, E>
pub wrapthisfn: String, where
pub importfn: String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
pub rewritefn: String, {
pub setrealmfn: String, pub prefix: &'alloc str,
pub metafn: String, pub sourcetag: &'alloc str,
pub pushsourcemapfn: String, pub base: &'alloc str,
pub wrapfn: &'alloc str,
pub wrapthisfn: &'alloc str,
pub importfn: &'alloc str,
pub rewritefn: &'alloc str,
pub setrealmfn: &'alloc str,
pub metafn: &'alloc str,
pub pushsourcemapfn: &'alloc str,
/// URL REWRITER IS RESPONSIBLE FOR ADDING BASE /// URL REWRITER IS RESPONSIBLE FOR ADDING BASE
pub urlrewriter: E, pub urlrewriter: E,

View file

@ -1,15 +1,16 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use oxc::{ use oxc::{
allocator::{Allocator, String, Vec},
ast::ast::AssignmentOperator, ast::ast::AssignmentOperator,
span::{format_compact_str, CompactStr, Span}, span::{format_compact_str, Atom, Span},
}; };
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use crate::{cfg::Config, RewriterError}; use crate::{cfg::Config, RewriterError};
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq)]
pub(crate) enum Rewrite { pub(crate) enum Rewrite<'data> {
/// `(cfg.wrapfn(ident))` | `cfg.wrapfn(ident)` /// `(cfg.wrapfn(ident))` | `cfg.wrapfn(ident)`
WrapFn { WrapFn {
span: Span, span: Span,
@ -37,7 +38,7 @@ pub(crate) enum Rewrite {
/// `$scramerr(name)` /// `$scramerr(name)`
ScramErr { ScramErr {
span: Span, span: Span,
ident: CompactStr, ident: Atom<'data>,
}, },
/// `$scramitize(span)` /// `$scramitize(span)`
Scramitize { Scramitize {
@ -51,7 +52,7 @@ pub(crate) enum Rewrite {
}, },
/// `((t)=>$scramjet$tryset(name,"op",t)||(name op t))(rhsspan)` /// `((t)=>$scramjet$tryset(name,"op",t)||(name op t))(rhsspan)`
Assignment { Assignment {
name: CompactStr, name: Atom<'data>,
entirespan: Span, entirespan: Span,
rhsspan: Span, rhsspan: Span,
op: AssignmentOperator, op: AssignmentOperator,
@ -59,7 +60,7 @@ pub(crate) enum Rewrite {
/// `ident,` -> `ident: cfg.wrapfn(ident),` /// `ident,` -> `ident: cfg.wrapfn(ident),`
ShorthandObj { ShorthandObj {
span: Span, span: Span,
name: CompactStr, name: Atom<'data>,
}, },
SourceTag { SourceTag {
span: Span, span: Span,
@ -68,15 +69,15 @@ pub(crate) enum Rewrite {
// don't use for anything static, only use for stuff like rewriteurl // don't use for anything static, only use for stuff like rewriteurl
Replace { Replace {
span: Span, span: Span,
text: String, text: String<'data>,
}, },
Delete { Delete {
span: Span, span: Span,
}, },
} }
impl Rewrite { impl<'data> Rewrite<'data> {
fn into_inner(self) -> SmallVec<[JsChange; 4]> { fn into_inner(self) -> SmallVec<[JsChange<'data>; 4]> {
match self { match self {
Self::WrapFn { wrapped, span } => { Self::WrapFn { wrapped, span } => {
let start = Span::new(span.start, span.start); let start = Span::new(span.start, span.start);
@ -180,14 +181,14 @@ impl<'a> From<&'a str> for Change<'a> {
} }
} }
impl<'a> From<&'a CompactStr> for Change<'a> { impl<'a> From<&'a String<'_>> for Change<'a> {
fn from(value: &'a CompactStr) -> Self { fn from(value: &'a String<'_>) -> Self {
Self::Str(value.as_str()) Self::Str(value.as_str())
} }
} }
impl<'a> From<&'a String> for Change<'a> { impl<'a> From<&'a Atom<'_>> for Change<'a> {
fn from(value: &'a String) -> Self { fn from(value: &'a Atom<'_>) -> Self {
Self::Str(value.as_str()) Self::Str(value.as_str())
} }
} }
@ -217,8 +218,8 @@ enum JsChangeInner<'a> {
Replace { str: Changes<'a> }, Replace { str: Changes<'a> },
} }
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq)]
enum JsChange { enum JsChange<'data> {
/// insert `${cfg.wrapfn}(` /// insert `${cfg.wrapfn}(`
WrapFn { span: Span, extra: bool }, WrapFn { span: Span, extra: bool },
/// insert `${cfg.setrealmfn}({}).` /// insert `${cfg.setrealmfn}({}).`
@ -226,13 +227,13 @@ enum JsChange {
/// insert `${cfg.wrapthis}(` /// insert `${cfg.wrapthis}(`
WrapThisFn { span: Span }, WrapThisFn { span: Span },
/// insert `$scramerr(ident);` /// insert `$scramerr(ident);`
ScramErrFn { span: Span, ident: CompactStr }, ScramErrFn { span: Span, ident: Atom<'data> },
/// insert `$scramitize(` /// insert `$scramitize(`
ScramitizeFn { span: Span }, ScramitizeFn { span: Span },
/// insert `eval(${cfg.rewritefn}(` /// insert `eval(${cfg.rewritefn}(`
EvalRewriteFn { span: Span }, EvalRewriteFn { span: Span },
/// insert `: ${cfg.wrapfn}(ident)` /// insert `: ${cfg.wrapfn}(ident)`
ShorthandObj { span: Span, ident: CompactStr }, ShorthandObj { span: Span, ident: Atom<'data> },
/// insert scramtag /// insert scramtag
SourceTag { span: Span }, SourceTag { span: Span },
@ -243,7 +244,7 @@ enum JsChange {
/// replace span with `((t)=>$scramjet$tryset(${name},"${op}",t)||(${name}${op}t))(` /// replace span with `((t)=>$scramjet$tryset(${name},"${op}",t)||(${name}${op}t))(`
AssignmentLeft { AssignmentLeft {
span: Span, span: Span,
name: CompactStr, name: Atom<'data>,
op: AssignmentOperator, op: AssignmentOperator,
}, },
@ -255,12 +256,12 @@ enum JsChange {
DoubleClosingParen { span: Span }, DoubleClosingParen { span: Span },
/// replace span with text /// replace span with text
Replace { span: Span, text: String }, Replace { span: Span, text: String<'data> },
/// replace span with "" /// replace span with ""
Delete { span: Span }, Delete { span: Span },
} }
impl JsChange { impl JsChange<'_> {
fn get_span(&self) -> &Span { fn get_span(&self) -> &Span {
match self { match self {
Self::WrapFn { span, .. } Self::WrapFn { span, .. }
@ -282,32 +283,35 @@ impl JsChange {
} }
} }
fn to_inner<'a, E>(&'a self, cfg: &'a Config<E>, offset: usize) -> JsChangeInner<'a> fn to_inner<'alloc, 'change, E>(
&'change self,
cfg: &'change Config<'alloc, E>,
offset: usize,
) -> JsChangeInner<'change>
where where
E: Fn(String) -> String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
E: Clone,
{ {
match self { match self {
Self::WrapFn { span, extra } => { Self::WrapFn { span, extra } => {
if *extra { if *extra {
JsChangeInner::Insert { JsChangeInner::Insert {
loc: span.start, loc: span.start,
str: changes!["(", &cfg.wrapfn, "("], str: changes!["(", cfg.wrapfn, "("],
} }
} else { } else {
JsChangeInner::Insert { JsChangeInner::Insert {
loc: span.start, loc: span.start,
str: changes![&cfg.wrapfn, "("], str: changes![cfg.wrapfn, "("],
} }
} }
} }
Self::SetRealmFn { span } => JsChangeInner::Insert { Self::SetRealmFn { span } => JsChangeInner::Insert {
loc: span.start, loc: span.start,
str: changes![&cfg.setrealmfn, "({})."], str: changes![cfg.setrealmfn, "({})."],
}, },
Self::WrapThisFn { span } => JsChangeInner::Insert { Self::WrapThisFn { span } => JsChangeInner::Insert {
loc: span.start, loc: span.start,
str: changes![&cfg.wrapthisfn, "("], str: changes![cfg.wrapthisfn, "("],
}, },
Self::ScramErrFn { span, ident } => JsChangeInner::Insert { Self::ScramErrFn { span, ident } => JsChangeInner::Insert {
loc: span.start, loc: span.start,
@ -318,11 +322,11 @@ impl JsChange {
str: changes![" $scramitize("], str: changes![" $scramitize("],
}, },
Self::EvalRewriteFn { .. } => JsChangeInner::Replace { Self::EvalRewriteFn { .. } => JsChangeInner::Replace {
str: changes!["eval(", &cfg.rewritefn, "("], str: changes!["eval(", cfg.rewritefn, "("],
}, },
Self::ShorthandObj { span, ident } => JsChangeInner::Insert { Self::ShorthandObj { span, ident } => JsChangeInner::Insert {
loc: span.start, loc: span.start,
str: changes![":", &cfg.wrapfn, "(", ident, ")"], str: changes![":", cfg.wrapfn, "(", ident, ")"],
}, },
Self::SourceTag { span } => JsChangeInner::Insert { Self::SourceTag { span } => JsChangeInner::Insert {
loc: span.start, loc: span.start,
@ -330,15 +334,15 @@ impl JsChange {
"/*scramtag ", "/*scramtag ",
span.start as usize + offset, span.start as usize + offset,
" ", " ",
&cfg.sourcetag, cfg.sourcetag,
"*/" "*/"
], ],
}, },
Self::ImportFn { .. } => JsChangeInner::Replace { Self::ImportFn { .. } => JsChangeInner::Replace {
str: changes![&cfg.importfn, "(\"", &cfg.base, "\","], str: changes![cfg.importfn, "(\"", cfg.base, "\","],
}, },
Self::MetaFn { .. } => JsChangeInner::Replace { Self::MetaFn { .. } => JsChangeInner::Replace {
str: changes![&cfg.metafn, "(\"", &cfg.base], str: changes![cfg.metafn, "(\"", cfg.base],
}, },
Self::AssignmentLeft { name, op, .. } => JsChangeInner::Replace { Self::AssignmentLeft { name, op, .. } => JsChangeInner::Replace {
str: changes![ str: changes![
@ -369,13 +373,13 @@ impl JsChange {
} }
} }
impl PartialOrd for JsChange { impl PartialOrd for JsChange<'_> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other)) Some(self.cmp(other))
} }
} }
impl Ord for JsChange { impl Ord for JsChange<'_> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering { fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.get_span().start.cmp(&other.get_span().start) { match self.get_span().start.cmp(&other.get_span().start) {
Ordering::Equal => match (self, other) { Ordering::Equal => match (self, other) {
@ -388,36 +392,41 @@ impl Ord for JsChange {
} }
} }
pub(crate) struct JsChangeResult { pub(crate) struct JsChangeResult<'alloc> {
pub js: Vec<u8>, pub js: Vec<'alloc, u8>,
pub sourcemap: Vec<u8>, pub sourcemap: Vec<'alloc, u8>,
} }
pub(crate) struct JsChanges { pub(crate) struct JsChanges<'alloc: 'data, 'data> {
inner: Vec<JsChange>, alloc: &'alloc Allocator,
inner: Vec<'alloc, JsChange<'data>>,
} }
impl JsChanges { impl<'alloc: 'data, 'data> JsChanges<'alloc, 'data> {
pub fn new(capacity: usize) -> Self { pub fn new(alloc: &'alloc Allocator, capacity: usize) -> Self {
Self { Self {
inner: Vec::with_capacity(capacity), inner: Vec::with_capacity_in(capacity, alloc),
alloc,
} }
} }
pub fn add(&mut self, rewrite: Rewrite) { pub fn add(&mut self, rewrite: Rewrite<'data>) {
for change in rewrite.into_inner() { for change in rewrite.into_inner() {
self.inner.push(change); self.inner.push(change);
} }
} }
pub fn perform<E>(&mut self, js: &str, cfg: &Config<E>) -> Result<JsChangeResult, RewriterError> pub fn perform<E>(
&mut self,
js: &str,
cfg: &Config<'alloc, E>,
) -> Result<JsChangeResult<'alloc>, RewriterError>
where where
E: Fn(String) -> String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
E: Clone,
{ {
let mut offset = 0; let mut offset = 0;
let mut added = 0i64; let mut added = 0i64;
let mut buffer = Vec::with_capacity(js.len() * 2); let mut buffer = Vec::with_capacity_in(js.len() * 2, self.alloc);
macro_rules! tryget { macro_rules! tryget {
($range:expr) => { ($range:expr) => {
@ -441,7 +450,7 @@ impl JsChanges {
}; };
} }
let mut map = Vec::with_capacity(js.len() * 2); let mut map = Vec::with_capacity_in(js.len() * 2, self.alloc);
map.extend_from_slice(&(self.inner.len() as u32).to_le_bytes()); map.extend_from_slice(&(self.inner.len() as u32).to_le_bytes());
self.inner.sort(); self.inner.sort();

View file

@ -1,5 +1,5 @@
use oxc::{ use oxc::{
allocator::Allocator, allocator::{Allocator, String, Vec},
ast_visit::Visit, ast_visit::Visit,
diagnostics::OxcDiagnostic, diagnostics::OxcDiagnostic,
parser::{ParseOptions, Parser}, parser::{ParseOptions, Parser},
@ -18,7 +18,7 @@ use visitor::Visitor;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum RewriterError { pub enum RewriterError {
#[error("oxc panicked in parser: {0}")] #[error("oxc panicked in parser: {0}")]
OxcPanicked(String), OxcPanicked(std::string::String),
#[error("out of bounds while applying range: {0}..{1})")] #[error("out of bounds while applying range: {0}..{1})")]
Oob(usize, usize), Oob(usize, usize),
#[error("formatting error: {0}")] #[error("formatting error: {0}")]
@ -26,29 +26,27 @@ pub enum RewriterError {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RewriteResult { pub struct RewriteResult<'alloc> {
pub js: Vec<u8>, pub js: Vec<'alloc, u8>,
pub sourcemap: Vec<u8>, pub sourcemap: Vec<'alloc, u8>,
pub sourcetag: String, pub errors: std::vec::Vec<OxcDiagnostic>,
pub errors: Vec<OxcDiagnostic>,
} }
pub fn rewrite<E>( pub fn rewrite<'alloc, 'data, E>(
js: &str, alloc: &'alloc Allocator,
js: &'data str,
config: Config<'alloc, E>,
module: bool, module: bool,
capacity: usize, capacity: usize,
config: Config<E>, ) -> Result<RewriteResult<'alloc>, RewriterError>
) -> Result<RewriteResult, RewriterError>
where where
E: Fn(String) -> String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
E: Clone,
{ {
let allocator = Allocator::default();
let source_type = SourceType::unambiguous() let source_type = SourceType::unambiguous()
.with_javascript(true) .with_javascript(true)
.with_module(module) .with_module(module)
.with_standard(true); .with_standard(true);
let ret = Parser::new(&allocator, js, source_type) let ret = Parser::new(alloc, js, source_type)
.with_options(ParseOptions { .with_options(ParseOptions {
parse_regular_expression: false, parse_regular_expression: false,
allow_v8_intrinsics: true, allow_v8_intrinsics: true,
@ -60,7 +58,7 @@ where
if ret.panicked { if ret.panicked {
use std::fmt::Write; use std::fmt::Write;
let mut errors = String::new(); let mut errors = std::string::String::new();
for error in ret.errors { for error in ret.errors {
writeln!(errors, "{error}")?; writeln!(errors, "{error}")?;
} }
@ -68,13 +66,15 @@ where
} }
let mut visitor = Visitor { let mut visitor = Visitor {
jschanges: JsChanges::new(capacity), jschanges: JsChanges::new(alloc, capacity),
config, config,
alloc,
}; };
visitor.visit_program(&ret.program); visitor.visit_program(&ret.program);
let Visitor { let Visitor {
mut jschanges, mut jschanges,
config, config,
alloc: _,
} = visitor; } = visitor;
let JsChangeResult { js, sourcemap } = jschanges.perform(js, &config)?; let JsChangeResult { js, sourcemap } = jschanges.perform(js, &config)?;
@ -82,7 +82,6 @@ where
Ok(RewriteResult { Ok(RewriteResult {
js, js,
sourcemap, sourcemap,
sourcetag: config.sourcetag,
errors: ret.errors, errors: ret.errors,
}) })
} }

View file

@ -1,4 +1,5 @@
use oxc::{ use oxc::{
allocator::{Allocator, String},
ast::ast::{ ast::ast::{
AssignmentExpression, AssignmentTarget, CallExpression, DebuggerStatement, AssignmentExpression, AssignmentTarget, CallExpression, DebuggerStatement,
ExportAllDeclaration, ExportNamedDeclaration, Expression, ForInStatement, ForOfStatement, ExportAllDeclaration, ExportNamedDeclaration, Expression, ForInStatement, ForOfStatement,
@ -31,24 +32,23 @@ const UNSAFE_GLOBALS: &[&str] = &[
"frames", "frames",
]; ];
pub struct Visitor<E> pub struct Visitor<'alloc, 'data, E>
where where
E: Fn(String) -> String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
E: Clone,
{ {
pub jschanges: JsChanges, pub jschanges: JsChanges<'alloc, 'data>,
pub config: Config<E>, pub config: Config<'alloc, E>,
pub alloc: &'alloc Allocator,
} }
impl<E> Visitor<E> impl<'alloc, 'data, E> Visitor<'alloc, 'data, E>
where where
E: Fn(String) -> String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
E: Clone,
{ {
fn rewrite_url(&mut self, url: String) -> String { fn rewrite_url(&mut self, url: Atom<'data>) -> oxc::allocator::String<'alloc> {
let urlencoded = (self.config.urlrewriter)(url); let mut urlencoded = (self.config.urlrewriter)(&url, self.alloc);
urlencoded.insert_str(0, self.config.prefix);
format!("\"{}{}\"", self.config.prefix, urlencoded) urlencoded
} }
fn rewrite_ident(&mut self, name: &Atom, span: Span) { fn rewrite_ident(&mut self, name: &Atom, span: Span) {
@ -82,10 +82,9 @@ where
} }
} }
impl<'a, E> Visit<'a> for Visitor<E> impl<'alloc, 'data, E> Visit<'data> for Visitor<'alloc, 'data, E>
where where
E: Fn(String) -> String, E: Fn(&str, &'alloc Allocator) -> String<'alloc>,
E: Clone,
{ {
fn visit_identifier_reference(&mut self, it: &IdentifierReference) { fn visit_identifier_reference(&mut self, it: &IdentifierReference) {
// if self.config.capture_errors { // if self.config.capture_errors {
@ -108,12 +107,12 @@ where
} }
// we need to rewrite `new Something` to `new (wrapfn(Something))` instead of `new wrapfn(Something)`, that's why there's weird extra code here // we need to rewrite `new Something` to `new (wrapfn(Something))` instead of `new wrapfn(Something)`, that's why there's weird extra code here
fn visit_new_expression(&mut self, it: &NewExpression) { fn visit_new_expression(&mut self, it: &NewExpression<'data>) {
self.walk_member_expression(&it.callee); self.walk_member_expression(&it.callee);
walk::walk_arguments(self, &it.arguments); walk::walk_arguments(self, &it.arguments);
} }
fn visit_member_expression(&mut self, it: &MemberExpression) { fn visit_member_expression(&mut self, it: &MemberExpression<'data>) {
// TODO // TODO
// you could break this with ["postMessage"] etc // you could break this with ["postMessage"] etc
// however this code only exists because of recaptcha whatever // however this code only exists because of recaptcha whatever
@ -155,7 +154,7 @@ where
// we can't overwrite window.eval in the normal way because that would make everything an // we can't overwrite window.eval in the normal way because that would make everything an
// indirect eval, which could break things. we handle that edge case here // indirect eval, which could break things. we handle that edge case here
fn visit_call_expression(&mut self, it: &CallExpression<'a>) { fn visit_call_expression(&mut self, it: &CallExpression<'data>) {
if let Expression::Identifier(s) = &it.callee { if let Expression::Identifier(s) = &it.callee {
// if it's optional that actually makes it an indirect eval which is handled separately // if it's optional that actually makes it an indirect eval which is handled separately
if s.name == "eval" && !it.optional { if s.name == "eval" && !it.optional {
@ -176,34 +175,31 @@ where
walk::walk_call_expression(self, it); walk::walk_call_expression(self, it);
} }
fn visit_import_declaration(&mut self, it: &ImportDeclaration<'a>) { fn visit_import_declaration(&mut self, it: &ImportDeclaration<'data>) {
let name = it.source.value.to_string(); let text = self.rewrite_url(it.source.value);
let text = self.rewrite_url(name);
self.jschanges.add(Rewrite::Replace { self.jschanges.add(Rewrite::Replace {
span: it.source.span, span: it.source.span,
text, text,
}); });
walk::walk_import_declaration(self, it); walk::walk_import_declaration(self, it);
} }
fn visit_import_expression(&mut self, it: &ImportExpression<'a>) { fn visit_import_expression(&mut self, it: &ImportExpression<'data>) {
self.jschanges.add(Rewrite::ImportFn { self.jschanges.add(Rewrite::ImportFn {
span: Span::new(it.span.start, it.span.start + 7), span: Span::new(it.span.start, it.span.start + 7),
}); });
walk::walk_import_expression(self, it); walk::walk_import_expression(self, it);
} }
fn visit_export_all_declaration(&mut self, it: &ExportAllDeclaration<'a>) { fn visit_export_all_declaration(&mut self, it: &ExportAllDeclaration<'data>) {
let name = it.source.value.to_string(); let text = self.rewrite_url(it.source.value);
let text = self.rewrite_url(name);
self.jschanges.add(Rewrite::Replace { self.jschanges.add(Rewrite::Replace {
span: it.source.span, span: it.source.span,
text, text,
}); });
} }
fn visit_export_named_declaration(&mut self, it: &ExportNamedDeclaration<'a>) { fn visit_export_named_declaration(&mut self, it: &ExportNamedDeclaration<'data>) {
if let Some(source) = &it.source { if let Some(source) = &it.source {
let name = source.value.to_string(); let text = self.rewrite_url(source.value);
let text = self.rewrite_url(name);
self.jschanges.add(Rewrite::Replace { self.jschanges.add(Rewrite::Replace {
span: source.span, span: source.span,
text, text,
@ -213,7 +209,7 @@ where
} }
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
fn visit_try_statement(&mut self, it: &oxc::ast::ast::TryStatement<'a>) { fn visit_try_statement(&mut self, it: &oxc::ast::ast::TryStatement<'data>) {
// for debugging we need to know what the error was // for debugging we need to know what the error was
if self.config.capture_errors { if self.config.capture_errors {
@ -222,7 +218,7 @@ where
if let Some(ident) = name.pattern.get_identifier_name() { if let Some(ident) = name.pattern.get_identifier_name() {
self.jschanges.add(Rewrite::ScramErr { self.jschanges.add(Rewrite::ScramErr {
span: Span::new(h.body.span.start + 1, h.body.span.start + 1), span: Span::new(h.body.span.start + 1, h.body.span.start + 1),
ident: ident.to_compact_str(), ident,
}); });
} }
} }
@ -231,14 +227,14 @@ where
walk::walk_try_statement(self, it); walk::walk_try_statement(self, it);
} }
fn visit_object_expression(&mut self, it: &ObjectExpression<'a>) { fn visit_object_expression(&mut self, it: &ObjectExpression<'data>) {
for prop in &it.properties { for prop in &it.properties {
if let ObjectPropertyKind::ObjectProperty(p) = prop { if let ObjectPropertyKind::ObjectProperty(p) = prop {
if let Expression::Identifier(s) = &p.value { if let Expression::Identifier(s) = &p.value {
if UNSAFE_GLOBALS.contains(&s.name.to_string().as_str()) && p.shorthand { if UNSAFE_GLOBALS.contains(&s.name.to_string().as_str()) && p.shorthand {
self.jschanges.add(Rewrite::ShorthandObj { self.jschanges.add(Rewrite::ShorthandObj {
span: s.span, span: s.span,
name: s.name.to_compact_str(), name: s.name,
}); });
return; return;
} }
@ -249,7 +245,7 @@ where
walk::walk_object_expression(self, it); walk::walk_object_expression(self, it);
} }
fn visit_function_body(&mut self, it: &FunctionBody<'a>) { fn visit_function_body(&mut self, it: &FunctionBody<'data>) {
// tag function for use in sourcemaps // tag function for use in sourcemaps
if self.config.do_sourcemaps { if self.config.do_sourcemaps {
self.jschanges.add(Rewrite::SourceTag { self.jschanges.add(Rewrite::SourceTag {
@ -259,7 +255,7 @@ where
walk::walk_function_body(self, it); walk::walk_function_body(self, it);
} }
fn visit_return_statement(&mut self, it: &ReturnStatement<'a>) { fn visit_return_statement(&mut self, it: &ReturnStatement<'data>) {
// if let Some(arg) = &it.argument { // if let Some(arg) = &it.argument {
// self.jschanges.insert(JsChange::GenericChange { // self.jschanges.insert(JsChange::GenericChange {
// span: Span::new(it.span.start + 6, it.span.start + 6), // span: Span::new(it.span.start + 6, it.span.start + 6),
@ -273,7 +269,7 @@ where
walk::walk_return_statement(self, it); walk::walk_return_statement(self, it);
} }
fn visit_unary_expression(&mut self, it: &UnaryExpression<'a>) { fn visit_unary_expression(&mut self, it: &UnaryExpression<'data>) {
if matches!(it.operator, UnaryOperator::Typeof) { if matches!(it.operator, UnaryOperator::Typeof) {
// don't walk to identifier rewrites since it won't matter // don't walk to identifier rewrites since it won't matter
return; return;
@ -282,29 +278,29 @@ where
} }
// we don't want to rewrite the identifiers here because of a very specific edge case // we don't want to rewrite the identifiers here because of a very specific edge case
fn visit_for_in_statement(&mut self, it: &ForInStatement<'a>) { fn visit_for_in_statement(&mut self, it: &ForInStatement<'data>) {
walk::walk_statement(self, &it.body); walk::walk_statement(self, &it.body);
} }
fn visit_for_of_statement(&mut self, it: &ForOfStatement<'a>) { fn visit_for_of_statement(&mut self, it: &ForOfStatement<'data>) {
walk::walk_statement(self, &it.body); walk::walk_statement(self, &it.body);
} }
fn visit_update_expression(&mut self, _it: &UpdateExpression<'a>) { fn visit_update_expression(&mut self, _it: &UpdateExpression<'data>) {
// then no, don't walk it, we don't care // then no, don't walk it, we don't care
} }
fn visit_meta_property(&mut self, it: &MetaProperty<'a>) { fn visit_meta_property(&mut self, it: &MetaProperty<'data>) {
if it.meta.name == "import" { if it.meta.name == "import" {
self.jschanges.add(Rewrite::MetaFn { span: it.span }); self.jschanges.add(Rewrite::MetaFn { span: it.span });
} }
} }
fn visit_assignment_expression(&mut self, it: &AssignmentExpression<'a>) { fn visit_assignment_expression(&mut self, it: &AssignmentExpression<'data>) {
match &it.left { match &it.left {
AssignmentTarget::AssignmentTargetIdentifier(s) => { AssignmentTarget::AssignmentTargetIdentifier(s) => {
if ["location"].contains(&s.name.to_string().as_str()) { if ["location"].contains(&s.name.to_string().as_str()) {
self.jschanges.add(Rewrite::Assignment { self.jschanges.add(Rewrite::Assignment {
name: s.name.to_compact_str(), name: s.name,
entirespan: it.span, entirespan: it.span,
rhsspan: it.right.span(), rhsspan: it.right.span(),
op: it.operator, op: it.operator,

View file

@ -4,8 +4,11 @@ use std::{sync::Arc, time::Duration};
use error::{Result, RewriterError}; use error::{Result, RewriterError};
use instant::Instant; use instant::Instant;
use js_sys::{Function, Object, Reflect}; use js_sys::{Function, Object, Reflect, Uint8Array};
use oxc::diagnostics::NamedSource; use oxc::{
allocator::{Allocator, String},
diagnostics::NamedSource,
};
use rewriter::{cfg::Config, rewrite, RewriteResult}; use rewriter::{cfg::Config, rewrite, RewriteResult};
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use web_sys::Url; use web_sys::Url;
@ -30,7 +33,7 @@ export function scramtag() {
} }
"#)] "#)]
extern "C" { extern "C" {
pub fn scramtag() -> String; pub fn scramtag() -> std::string::String;
} }
#[wasm_bindgen] #[wasm_bindgen]
@ -45,31 +48,40 @@ extern "C" {
fn error(s: &str); fn error(s: &str);
} }
fn create_encode_function( type EncodeFn<'alloc, 'data> = Box<dyn Fn(&str, &'alloc Allocator) -> String<'alloc> + 'data>;
fn create_encode_function<'alloc, 'data>(
encode: JsValue, encode: JsValue,
base: String, base: &'data str,
) -> Result<impl Fn(String) -> String + Clone> { _alloc: &'alloc Allocator,
) -> Result<EncodeFn<'alloc, 'data>> {
let encode = encode.dyn_into::<Function>()?; let encode = encode.dyn_into::<Function>()?;
Ok(move |str: String| { let func = move |url: &str, alloc: &'alloc Allocator| {
let url = Url::new_with_base(&str, &base).unwrap().to_string(); let url = Url::new_with_base(url, base).unwrap().to_string();
encode oxc::allocator::String::from_str_in(
.call1(&JsValue::NULL, &url.into()) encode
.unwrap() .call1(&JsValue::NULL, &url.into())
.as_string() .unwrap()
.unwrap() .as_string()
.to_string() .unwrap()
}) .as_str(),
alloc,
)
};
Ok(Box::new(func))
} }
fn get_obj(obj: &JsValue, k: &str) -> Result<JsValue> { fn get_obj(obj: &JsValue, k: &str) -> Result<JsValue> {
Ok(Reflect::get(obj, &k.into())?) Ok(Reflect::get(obj, &k.into())?)
} }
fn get_str(obj: &JsValue, k: &str) -> Result<String> { fn get_str<'alloc>(obj: &JsValue, k: &str, alloc: &'alloc Allocator) -> Result<&'alloc str> {
Reflect::get(obj, &k.into())? Reflect::get(obj, &k.into())?
.as_string() .as_string()
.ok_or_else(|| RewriterError::not_str(k)) .ok_or_else(|| RewriterError::not_str(k))
.map(|x| String::from_str_in(&x, alloc).into_bump_str())
} }
fn set_obj(obj: &Object, k: &str, v: &JsValue) -> Result<()> { fn set_obj(obj: &Object, k: &str, v: &JsValue) -> Result<()> {
@ -90,30 +102,34 @@ fn get_flag(scramjet: &Object, url: &str, flag: &str) -> Result<bool> {
.ok_or_else(|| RewriterError::not_bool("scramjet.flagEnabled return value")) .ok_or_else(|| RewriterError::not_bool("scramjet.flagEnabled return value"))
} }
fn get_config(scramjet: &Object, url: String) -> Result<Config<impl Fn(String) -> String + Clone>> { fn get_config<'alloc, 'data>(
scramjet: &Object,
url: &'data str,
alloc: &'alloc Allocator,
) -> Result<Config<'alloc, EncodeFn<'alloc, 'data>>> {
let codec = &get_obj(scramjet, "codec")?; let codec = &get_obj(scramjet, "codec")?;
let config = &get_obj(scramjet, "config")?; let config = &get_obj(scramjet, "config")?;
let globals = &get_obj(config, "globals")?; let globals = &get_obj(config, "globals")?;
Ok(Config { Ok(Config {
prefix: get_str(config, "prefix")?, do_sourcemaps: get_flag(scramjet, url, "sourcemaps")?,
base: url.clone(), capture_errors: get_flag(scramjet, url, "captureErrors")?,
sourcetag: scramtag(), scramitize: get_flag(scramjet, url, "scramitize")?,
strict_rewrites: get_flag(scramjet, url, "strictRewrites")?,
wrapfn: get_str(globals, "wrapfn")?, urlrewriter: create_encode_function(get_obj(codec, "encode")?, url, alloc)?,
wrapthisfn: get_str(globals, "wrapthisfn")?,
importfn: get_str(globals, "importfn")?,
rewritefn: get_str(globals, "rewritefn")?,
metafn: get_str(globals, "metafn")?,
setrealmfn: get_str(globals, "setrealmfn")?,
pushsourcemapfn: get_str(globals, "pushsourcemapfn")?,
do_sourcemaps: get_flag(scramjet, &url, "sourcemaps")?, prefix: get_str(config, "prefix", alloc)?,
capture_errors: get_flag(scramjet, &url, "captureErrors")?, base: String::from_str_in(url, alloc).into_bump_str(),
scramitize: get_flag(scramjet, &url, "scramitize")?, sourcetag: String::from_str_in(&scramtag(), alloc).into_bump_str(),
strict_rewrites: get_flag(scramjet, &url, "strictRewrites")?,
urlrewriter: create_encode_function(get_obj(codec, "encode")?, url)?, wrapfn: get_str(globals, "wrapfn", alloc)?,
wrapthisfn: get_str(globals, "wrapthisfn", alloc)?,
importfn: get_str(globals, "importfn", alloc)?,
rewritefn: get_str(globals, "rewritefn", alloc)?,
metafn: get_str(globals, "metafn", alloc)?,
setrealmfn: get_str(globals, "setrealmfn", alloc)?,
pushsourcemapfn: get_str(globals, "pushsourcemapfn", alloc)?,
}) })
} }
@ -124,8 +140,9 @@ fn duration_to_millis_f64(duration: Duration) -> f64 {
fn create_rewriter_output( fn create_rewriter_output(
out: RewriteResult, out: RewriteResult,
url: String, url: std::string::String,
src: String, src: std::string::String,
sourcetag: &str,
duration: Duration, duration: Duration,
) -> Result<JsRewriterOutput> { ) -> Result<JsRewriterOutput> {
let src = Arc::new(NamedSource::new(url, src).with_language("javascript")); let src = Arc::new(NamedSource::new(url, src).with_language("javascript"));
@ -137,9 +154,13 @@ fn create_rewriter_output(
.collect(); .collect();
let obj = Object::new(); let obj = Object::new();
set_obj(&obj, "js", &out.js.into())?; set_obj(&obj, "js", &Uint8Array::from(out.js.as_slice()).into())?;
set_obj(&obj, "map", &out.sourcemap.into())?; set_obj(
set_obj(&obj, "scramtag", &out.sourcetag.into())?; &obj,
"map",
&Uint8Array::from(out.sourcemap.as_slice()).into(),
)?;
set_obj(&obj, "scramtag", &sourcetag.into())?;
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
set_obj(&obj, "errors", &errs.into())?; set_obj(&obj, "errors", &errs.into())?;
#[cfg(not(feature = "debug"))] #[cfg(not(feature = "debug"))]
@ -151,33 +172,33 @@ fn create_rewriter_output(
#[wasm_bindgen] #[wasm_bindgen]
pub fn rewrite_js( pub fn rewrite_js(
js: String, js: std::string::String,
url: String, url: &str,
script_url: std::string::String,
module: bool, module: bool,
script_url: String,
scramjet: &Object, scramjet: &Object,
) -> Result<JsRewriterOutput> { ) -> Result<JsRewriterOutput> {
let alloc = Allocator::default();
let cfg = get_config(scramjet, url, &alloc)?;
let sourcetag = cfg.sourcetag;
let before = Instant::now(); let before = Instant::now();
let out = rewrite(&js, module, 1024, get_config(scramjet, url)?)?; let out = rewrite(&alloc, &js, cfg, module, 1024)?;
let after = Instant::now(); let after = Instant::now();
create_rewriter_output(out, script_url, js, after - before) create_rewriter_output(out, script_url, js, sourcetag, after - before)
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn rewrite_js_from_arraybuffer( pub fn rewrite_js_from_arraybuffer(
js: Vec<u8>, js: Vec<u8>,
url: String, url: &str,
script_url: std::string::String,
module: bool, module: bool,
script_url: String,
scramjet: &Object, scramjet: &Object,
) -> Result<JsRewriterOutput> { ) -> Result<JsRewriterOutput> {
// we know that this is a valid utf-8 string // we know the js is a valid utf-8 string
let js = unsafe { String::from_utf8_unchecked(js) }; let js = unsafe { std::string::String::from_utf8_unchecked(js) };
let before = Instant::now(); rewrite_js(js, url, script_url, module, scramjet)
let out = rewrite(&js, module, 1024, get_config(scramjet, url)?)?;
let after = Instant::now();
create_rewriter_output(out, script_url, js, after - before)
} }