This commit is contained in:
velzie 2024-07-14 23:17:57 -04:00 committed by Percs
parent a7cbca42d1
commit 6cc293b453
10 changed files with 1050 additions and 91 deletions

2
.gitignore vendored
View file

@ -7,3 +7,5 @@ static/curl-client.js
static/epoxy-client.js static/epoxy-client.js
static/bare-mux-worker.js static/bare-mux-worker.js
meta.json meta.json
rewriter/target
rewriter/out

754
rewriter/Cargo.lock generated Normal file
View file

@ -0,0 +1,754 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "allocator-api2"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
[[package]]
name = "assert-unchecked"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7330592adf847ee2e3513587b4db2db410a0d751378654e7e993d9adcbe5c795"
[[package]]
name = "autocfg"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
dependencies = [
"serde",
]
[[package]]
name = "bumpalo"
version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
dependencies = [
"allocator-api2",
]
[[package]]
name = "castaway"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5"
dependencies = [
"rustversion",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "compact_str"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f"
dependencies = [
"castaway",
"cfg-if",
"itoa",
"ryu",
"serde",
"static_assertions",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]]
name = "dashmap"
version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804c8821570c3f8b70230c2ba75ffa5c0f9a4189b9a432b6656c536712acae28"
dependencies = [
"cfg-if",
"crossbeam-utils",
"hashbrown",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]]
name = "gloo-utils"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e"
dependencies = [
"js-sys",
"serde",
"serde_json",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "itoa"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "js-sys"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miette"
version = "7.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4edc8853320c2a0dab800fbda86253c8938f6ea88510dc92c5f1ed20e794afc1"
dependencies = [
"cfg-if",
"miette-derive",
"owo-colors",
"textwrap",
"thiserror",
"unicode-width",
]
[[package]]
name = "miette-derive"
version = "7.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "num-bigint"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "owo-colors"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caff54706df99d2a78a5a4e3455ff45448d81ef1bb63c22cd14052ca0e993a3f"
[[package]]
name = "oxc_allocator"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d413f72d3253e9adff573635cfb5aca6f092aaee8b4252ee2d02b36fccc8fd2c"
dependencies = [
"allocator-api2",
"bumpalo",
"serde",
]
[[package]]
name = "oxc_ast"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c90e5316ea1cdc09844cacbd9d11dfdaf80894c84d8917a8021903238dfcb449"
dependencies = [
"bitflags",
"num-bigint",
"oxc_allocator",
"oxc_ast_macros",
"oxc_span",
"oxc_syntax",
"serde",
"serde_json",
"tsify",
"wasm-bindgen",
]
[[package]]
name = "oxc_ast_macros"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e75a62baf313dede70692fe7b0dbb84bfdb8cddb118020067b924ee759b08a4e"
[[package]]
name = "oxc_diagnostics"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2963694eba6acab881fe014b843757b57f8bdb755f6014fb7f92790122bd57d"
dependencies = [
"miette",
"owo-colors",
"textwrap",
"unicode-width",
]
[[package]]
name = "oxc_index"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbd279d0188e75bb7268c3d8f54a2b30837ea03135b739b90fb8360dd9f2add8"
dependencies = [
"serde",
]
[[package]]
name = "oxc_parser"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7683a18fa64b8d7756b8a5630e84f075b4cd1dcf85adb04044055c33120e5f9"
dependencies = [
"assert-unchecked",
"bitflags",
"memchr",
"num-bigint",
"num-traits",
"oxc_allocator",
"oxc_ast",
"oxc_diagnostics",
"oxc_span",
"oxc_syntax",
"rustc-hash",
"seq-macro",
]
[[package]]
name = "oxc_span"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efafab0c8cfb6ac6da1b687fef84424d242437f4cfbed51ddfba8ac046ca4a93"
dependencies = [
"compact_str",
"miette",
"oxc_allocator",
"serde",
"tsify",
"wasm-bindgen",
]
[[package]]
name = "oxc_syntax"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ff2ce5c9adcdaee8dc28834ff7a4d9e33b0ecd9c9ec56a5066703cdd3426bb3"
dependencies = [
"bitflags",
"dashmap",
"oxc_index",
"oxc_span",
"phf",
"rustc-hash",
"ryu-js",
"serde",
"tsify",
"unicode-id-start",
"wasm-bindgen",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
]
[[package]]
name = "phf"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [
"phf_macros",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_macros"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b"
dependencies = [
"phf_generator",
"phf_shared",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "phf_shared"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
dependencies = [
"siphasher",
]
[[package]]
name = "proc-macro2"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "redox_syscall"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd"
dependencies = [
"bitflags",
]
[[package]]
name = "rewriter"
version = "0.1.0"
dependencies = [
"oxc_allocator",
"oxc_ast",
"oxc_parser",
"oxc_span",
"oxc_syntax",
"wasm-bindgen",
]
[[package]]
name = "rustc-hash"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]]
name = "rustversion"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
[[package]]
name = "ryu"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "ryu-js"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad97d4ce1560a5e27cec89519dc8300d1aa6035b099821261c651486a19e44d5"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "seq-macro"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
[[package]]
name = "serde"
version = "1.0.204"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.204"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_derive_internals"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "smawk"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "syn"
version = "2.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "textwrap"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
dependencies = [
"smawk",
"unicode-linebreak",
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tsify"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6b26cf145f2f3b9ff84e182c448eaf05468e247f148cf3d2a7d67d78ff023a0"
dependencies = [
"gloo-utils",
"serde",
"serde_json",
"tsify-macros",
"wasm-bindgen",
]
[[package]]
name = "tsify-macros"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a94b0f0954b3e59bfc2c246b4c8574390d94a4ad4ad246aaf2fb07d7dfd3b47"
dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
"syn",
]
[[package]]
name = "unicode-id-start"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc3882f69607a2ac8cc4de3ee7993d8f68bb06f2974271195065b3bd07f2edea"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-linebreak"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-width"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d"
[[package]]
name = "wasm-bindgen"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "web-sys"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

15
rewriter/Cargo.toml Normal file
View file

@ -0,0 +1,15 @@
[package]
name = "rewriter"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
oxc_allocator = "0.20.0"
oxc_ast = { version = "0.20.0", features = ["serialize"]}
oxc_parser = { version = "0.20.0" }
oxc_span = "0.20.0"
oxc_syntax = "0.20.0"
wasm-bindgen = "0.2.92"

6
rewriter/build.sh Normal file
View file

@ -0,0 +1,6 @@
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+simd128' cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std --release
wasm-bindgen --weak-refs --target web --out-dir out/ target/wasm32-unknown-unknown/release/rewriter.wasm
cd ../
# pnpm build
cp rewriter/out/rewriter_bg.wasm ./static/

17
rewriter/src/lib.rs Normal file
View file

@ -0,0 +1,17 @@
pub mod rewrite;
use rewrite::rewrite;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[wasm_bindgen]
pub fn rewrite_js(js: &str) -> String {
log("hello from rust");
rewrite(js)
}

31
rewriter/src/main_.rs Normal file
View file

@ -0,0 +1,31 @@
#![allow(clippy::print_stdout)]
use std::{env, path::Path};
use oxc_allocator::Allocator;
use oxc_ast::{
ast::{AssignmentTarget, Class, Function, IdentifierReference, MemberExpression, TSImportType},
visit::walk,
Visit,
};
use oxc_parser::Parser;
use oxc_span::{SourceType, Span};
use oxc_syntax::scope::ScopeFlags;
pub mod rewrite;
use rewrite::rewrite;
// Instruction:
// create a `test.js`,
// run `cargo run -p oxc_parser --example visitor`
// or `cargo watch -x "run -p oxc_parser --example visitor"`
fn main() -> std::io::Result<()> {
let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string());
let path = Path::new(&name);
let source_text = std::fs::read_to_string(path)?;
dbg!(rewrite(&source_text));
Ok(())
}

120
rewriter/src/rewrite.rs Normal file
View file

@ -0,0 +1,120 @@
use oxc_allocator::Allocator;
use oxc_ast::{
ast::{AssignmentTarget, Class, Function, IdentifierReference, MemberExpression, TSImportType},
visit::walk,
Visit,
};
use oxc_parser::Parser;
use oxc_span::{SourceType, Span};
use oxc_syntax::scope::ScopeFlags;
#[derive(Debug)]
enum JsChange {
GenericChange {
span: Span,
text: String,
},
Assignment {
name: String,
entirespan: Span,
rhsspan: Span,
},
}
#[derive(Debug, Default)]
struct Rewriter {
jschanges: Vec<JsChange>,
}
impl<'a> Visit<'a> for Rewriter {
// fn visit_assignment_expression(&mut self, expr: &oxc_ast::ast::AssignmentExpression<'a>) {
// if expr.left.is_simple_assignment_target() {
// let name = expr
// .left
// .as_simple_assignment_target()
// .unwrap()
// .get_identifier()
// .unwrap();
// if name == "location" {
// use oxc_ast::ast::Expression as E;
// let span = match &expr.right {
// E::Super(s) => s.span,
// E::ThisExpression(s) => s.span,
// E::Identifier(s) => s.span,
// E::NumericLiteral(s) => s.span,
// E::AssignmentExpression(s) => s.span,
//
// _ => todo!("{:?}", expr.right),
// };
// self.jschanges.push(JsChange::Assignment {
// name: name.to_string(),
// entirespan: expr.span,
// rhsspan: span,
// });
// }
// }
// }
fn visit_member_expression(&mut self, it: &MemberExpression<'a>) {
match it {
MemberExpression::StaticMemberExpression(s) => {
if s.property.name.to_string() == "location" {
self.jschanges.push(JsChange::GenericChange {
span: s.property.span,
text: "_location".to_string(),
});
}
}
_ => {}
}
}
}
pub fn rewrite(js: &str) -> String {
let source_text = js.to_string();
let allocator = Allocator::default();
let source_type = SourceType::default();
let ret = Parser::new(&allocator, &source_text, source_type).parse();
for error in ret.errors {
let error = error.with_source_code(source_text.clone());
println!("{error:?}");
}
let program = ret.program;
let mut ast_pass = Rewriter::default();
ast_pass.visit_program(&program);
let mut rewritten = source_text.clone();
let mut offset = 0;
for change in ast_pass.jschanges {
match &change {
JsChange::GenericChange { span, text } => {
let len = (span.end - span.start) as usize;
let start = span.start as usize + offset;
let end = span.end as usize + offset;
rewritten.replace_range(start..end, &text);
offset = (offset as i64 + (text.len() as i64 - len as i64)) as usize;
}
JsChange::Assignment {
name,
entirespan,
rhsspan,
} => {
let len = (entirespan.end - entirespan.start) as usize;
let start = entirespan.start as usize + offset;
let end = entirespan.end as usize + offset;
let text = format!(
"$set({}, {})",
name,
&source_text[rhsspan.start as usize..rhsspan.end as usize]
);
rewritten.replace_range(start..end, &text);
offset += text.len() - len;
}
}
}
return rewritten;
}

View file

@ -16,92 +16,106 @@ import * as ESTree from "estree";
// top // top
// parent // parent
import init, { rewrite_js } from "../../../rewriter/out/rewriter.js";
init("/rewriter_bg.wasm");
export function rewriteJs(js: string, origin?: URL) { export function rewriteJs(js: string, origin?: URL) {
try { let f = rewrite_js(js);
const ast = parseModule(js, { console.log(f)
module: true, return f
webcompat: true,
});
const identifierList = [
"window",
"self",
"globalThis",
"this",
"parent",
"top",
"location",
];
const customTraveler = makeTraveler({
ImportDeclaration: (node: ESTree.ImportDeclaration) => {
node.source.value = encodeUrl(node.source.value as string, origin);
},
ImportExpression: (node: ESTree.ImportExpression) => {
if (node.source.type === "Literal") {
node.source.value = encodeUrl(node.source.value as string, origin);
} else if (node.source.type === "Identifier") {
// this is for things that import something like
// const moduleName = "name";
// await import(moduleName);
node.source.name = `__wrapImport(${node.source.name})`;
}
},
ExportAllDeclaration: (node: ESTree.ExportAllDeclaration) => {
node.source.value = encodeUrl(node.source.value as string, origin);
},
ExportNamedDeclaration: (node: ESTree.ExportNamedDeclaration) => {
// strings are Literals in ESTree syntax but these will always be strings
if (node.source)
node.source.value = encodeUrl(node.source.value as string, origin);
},
MemberExpression: (node: ESTree.MemberExpression) => {
if (
node.object.type === "Identifier" &&
identifierList.includes(node.object.name)
) {
node.object.name = `globalThis.$s(${node.object.name})`;
}
},
AssignmentExpression: (node: ESTree.AssignmentExpression) => {
if (
node.left.type === "Identifier" &&
identifierList.includes(node.left.name)
) {
node.left.name = `globalThis.$s(${node.left.name})`;
}
if (
node.right.type === "Identifier" &&
identifierList.includes(node.right.name)
) {
node.right.name = `globalThis.$s(${node.right.name})`;
}
},
VariableDeclarator: (node: ESTree.VariableDeclarator) => {
if (
node.init &&
node.init.type === "Identifier" &&
identifierList.includes(node.init.name)
) {
node.init.name = `globalThis.$s(${node.init.name})`;
}
},
});
customTraveler.go(ast);
return generate(ast);
} catch (e) {
console.error(e);
console.log(js);
return js;
}
} }
// try {
// const ast = parseModule(js, {
// module: true,
// webcompat: true,
// });
//
// const identifierList = [
// "window",
// "self",
// "globalThis",
// "this",
// "parent",
// "top",
// "location",
// ];
//
// const customTraveler = makeTraveler({
// ImportDeclaration: (node: ESTree.ImportDeclaration) => {
// node.source.value = encodeUrl(node.source.value as string, origin);
// },
//
// ImportExpression: (node: ESTree.ImportExpression) => {
// if (node.source.type === "Literal") {
// node.source.value = encodeUrl(node.source.value as string, origin);
// } else if (node.source.type === "Identifier") {
// // this is for things that import something like
// // const moduleName = "name";
// // await import(moduleName);
// node.source.name = `__wrapImport(${node.source.name})`;
// }
// },
//
// ExportAllDeclaration: (node: ESTree.ExportAllDeclaration) => {
// node.source.value = encodeUrl(node.source.value as string, origin);
// },
//
// ExportNamedDeclaration: (node: ESTree.ExportNamedDeclaration) => {
// // strings are Literals in ESTree syntax but these will always be strings
// if (node.source)
// node.source.value = encodeUrl(node.source.value as string, origin);
// },
//
// MemberExpression: (node: ESTree.MemberExpression) => {
// if (
// node.object.type === "Identifier" &&
// identifierList.includes(node.object.name)
// ) {
// node.object.name = `globalThis.$s(${node.object.name})`;
// }
// },
//
// AssignmentExpression: (node: ESTree.AssignmentExpression, more) => {
// console.log(node, more);
// if (
// node.left.type === "Identifier" &&
// identifierList.includes(node.left.name)
// ) {
// node.left.name = `globalThis.$s(${node.left.name})`;
// }
//
// if (
// node.right.type === "Identifier" &&
// identifierList.includes(node.right.name)
// ) {
// node.right.name = `globalThis.$s(${node.right.name})`;
// }
// },
// ArrayExpression: (node: ESTree.ArrayExpression) => {
// node.elements.forEach((element) => {
// if (element.type === "Identifier" && identifierList.includes(element.name)) {
// element.name = `globalThis.$s(${element.name})`;
// }
// });
// },
//
// VariableDeclarator: (node: ESTree.VariableDeclarator) => {
// if (
// node.init &&
// node.init.type === "Identifier" &&
// identifierList.includes(node.init.name)
// ) {
// node.init.name = `globalThis.$s(${node.init.name})`;
// }
// },
// });
//
// customTraveler.go(ast);
//
// return generate(ast);
// } catch (e) {
// console.error(e);
// console.log(js);
//
// return js;
// }

BIN
static/rewriter_bg.wasm Normal file

Binary file not shown.

View file

@ -1,7 +1,7 @@
<head></head> <head></head>
<script> <script>
function f() { function f() {
location = "http://www.google.com"; s = [window]
} }
</script> </script>
<button onclick="f()">Google</button> <button onclick="console.log(document.querySelector('script').innerHTML)">Google</button>