cfsolve 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/THIRD_PARTY_LICENSES/README.md +71 -254
- data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
- data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
- data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
- data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
- data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
- data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
- data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
- data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
- data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
- data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
- data/UPSTREAM.md +7 -5
- data/ext/cfsolve/Cargo.lock +534 -1727
- data/ext/cfsolve/Cargo.toml +4 -0
- data/ext/cfsolve/src/main.rs +1 -1
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
- data/lib/cfsolve/version.rb +2 -2
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +4 -0
- data/vendor/cfsolve/examples/check_answers.rs +2 -2
- data/vendor/cfsolve/examples/compare_session.rs +1 -2
- data/vendor/cfsolve/examples/solver_profile.rs +84 -0
- data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
- data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
- data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
- data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
- data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/sessions.rs +4 -3
- data/vendor/cfsolve/src/capture/upstream.rs +1 -1
- data/vendor/cfsolve/src/challenge/codec.rs +4 -2
- data/vendor/cfsolve/src/challenge/expression.rs +161 -117
- data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
- data/vendor/cfsolve/src/challenge/installed.rs +13 -6
- data/vendor/cfsolve/src/challenge/merge.rs +120 -80
- data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
- data/vendor/cfsolve/src/challenge/payload.rs +69 -31
- data/vendor/cfsolve/src/challenge/program.rs +197 -178
- data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
- data/vendor/cfsolve/src/challenge/source.rs +151 -96
- data/vendor/cfsolve/src/challenge/state.rs +180 -148
- data/vendor/cfsolve/src/challenge/tally.rs +64 -50
- data/vendor/cfsolve/src/challenge.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
- data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
- data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
- data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
- data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
- data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
- data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
- data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
- data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
- data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
- data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
- data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
- data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
- data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
- data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
- data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
- data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
- data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
- data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
- data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
- data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
- data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
- data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
- data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
- data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
- data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
- data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
- data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
- data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
- data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
- data/vendor/cfsolve/src/deobfuscate.rs +15 -11
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
- data/vendor/cfsolve/src/error.rs +40 -5
- data/vendor/cfsolve/src/fingerprint.rs +8 -2
- data/vendor/cfsolve/src/http/client.rs +7 -10
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -263
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -9
- data/vendor/cfsolve/src/listing/query.rs +1 -47
- data/vendor/cfsolve/src/performance_clock.rs +20 -1
- data/vendor/cfsolve/src/profiling.rs +49 -0
- data/vendor/cfsolve/src/script.rs +35 -24
- data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
- data/vendor/cfsolve/src/session/channel.rs +2 -2
- data/vendor/cfsolve/src/session/initial.rs +5 -5
- data/vendor/cfsolve/src/session/sink.rs +26 -1
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
- data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
- data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
- data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
- data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
- data/vendor/cfsolve/src/stage2.rs +2 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/extract.rs +347 -250
- data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
- data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
- data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
- data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
- data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
- data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
- data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
- data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
- data/vendor/cfsolve/src/vm/interpret.rs +9 -1
- data/vendor/cfsolve/src/vm/machine.rs +56 -49
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/session.rs +185 -120
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +2 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +94 -178
- data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
- data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
- data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
- data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
- data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
- data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
- data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
- data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
- data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
- data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
- /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
|
@@ -5,75 +5,65 @@
|
|
|
5
5
|
//! ```
|
|
6
6
|
//!
|
|
7
7
|
//! Applies only to operators whose `ToInt32` or `ToUint32` conversion discards the fractional
|
|
8
|
-
//! part before evaluation.
|
|
8
|
+
//! part before evaluation. Integer operands are also wrapped to their signed 32-bit
|
|
9
|
+
//! representation; shifts retain the same low bits and shift count after the corresponding
|
|
10
|
+
//! JavaScript conversions.
|
|
9
11
|
|
|
10
|
-
use
|
|
11
|
-
use
|
|
12
|
+
use oxc::ast::ast::{AssignmentExpression, BinaryExpression, Expression, Program, UnaryExpression};
|
|
13
|
+
use oxc::ast_visit::{VisitMut, walk_mut};
|
|
14
|
+
use oxc::span::GetSpan;
|
|
12
15
|
|
|
13
16
|
use super::analysis::Analysis;
|
|
17
|
+
use super::ast;
|
|
18
|
+
use crate::js;
|
|
14
19
|
|
|
15
|
-
pub(super) fn run(program: &mut Program
|
|
16
|
-
let mut truncate =
|
|
17
|
-
|
|
20
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
21
|
+
let mut truncate = Truncate {
|
|
22
|
+
analysis,
|
|
23
|
+
changed: false,
|
|
24
|
+
};
|
|
25
|
+
truncate.visit_program(program);
|
|
18
26
|
truncate.changed
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
struct
|
|
29
|
+
struct Truncate<'b, 'a> {
|
|
30
|
+
analysis: &'b Analysis<'a>,
|
|
22
31
|
changed: bool,
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
impl
|
|
26
|
-
fn
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
impl<'a> Truncate<'_, 'a> {
|
|
35
|
+
fn truncate(&mut self, operand: &mut Expression<'a>) {
|
|
36
|
+
if let Some(number) = ast::number(operand) {
|
|
37
|
+
let truncated = js::int32(number) as f64;
|
|
38
|
+
if number != truncated {
|
|
39
|
+
*operand = ast::number_literal(operand.span(), truncated, &self.analysis.ast);
|
|
40
|
+
self.changed = true;
|
|
41
|
+
}
|
|
32
42
|
}
|
|
33
43
|
}
|
|
44
|
+
}
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if
|
|
39
|
-
self.
|
|
46
|
+
impl<'a> VisitMut<'a> for Truncate<'_, 'a> {
|
|
47
|
+
fn visit_binary_expression(&mut self, binary: &mut BinaryExpression<'a>) {
|
|
48
|
+
walk_mut::walk_binary_expression(self, binary);
|
|
49
|
+
if binary.operator.is_bitwise() {
|
|
50
|
+
self.truncate(&mut binary.left);
|
|
51
|
+
self.truncate(&mut binary.right);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
|
|
43
|
-
fn
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
self.changed |= truncate_operand(&mut unary.arg);
|
|
55
|
+
fn visit_assignment_expression(&mut self, assignment: &mut AssignmentExpression<'a>) {
|
|
56
|
+
walk_mut::walk_assignment_expression(self, assignment);
|
|
57
|
+
if assignment.operator.is_bitwise() {
|
|
58
|
+
self.truncate(&mut assignment.right);
|
|
48
59
|
}
|
|
49
60
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
pub(super) fn is_bitwise(operator: BinaryOp) -> bool {
|
|
53
|
-
matches!(
|
|
54
|
-
operator,
|
|
55
|
-
BinaryOp::BitAnd
|
|
56
|
-
| BinaryOp::BitOr
|
|
57
|
-
| BinaryOp::BitXor
|
|
58
|
-
| BinaryOp::LShift
|
|
59
|
-
| BinaryOp::RShift
|
|
60
|
-
| BinaryOp::ZeroFillRShift
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
number.value = number.value.trunc();
|
|
69
|
-
number.raw = None;
|
|
70
|
-
true
|
|
71
|
-
}
|
|
72
|
-
Expr::Paren(paren) => truncate_operand(&mut paren.expr),
|
|
73
|
-
Expr::Unary(unary) if matches!(unary.op, UnaryOp::Plus | UnaryOp::Minus) => {
|
|
74
|
-
truncate_operand(&mut unary.arg)
|
|
62
|
+
fn visit_unary_expression(&mut self, unary: &mut UnaryExpression<'a>) {
|
|
63
|
+
walk_mut::walk_unary_expression(self, unary);
|
|
64
|
+
if unary.operator.is_bitwise() {
|
|
65
|
+
self.truncate(&mut unary.argument)
|
|
75
66
|
}
|
|
76
|
-
_ => false,
|
|
77
67
|
}
|
|
78
68
|
}
|
|
79
69
|
|
|
@@ -83,23 +73,23 @@ mod tests {
|
|
|
83
73
|
|
|
84
74
|
#[test]
|
|
85
75
|
fn truncates_only_bitwise_operands() {
|
|
86
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
76
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
87
77
|
let output = transform(
|
|
88
78
|
"function f(x) { return (x & 255.51) ^ (x | 8.27) ^ (x ^ 60.71) ^ (x << 16.7) ^ (x >> 12.15) ^ (x >>> 10.46); }",
|
|
89
79
|
);
|
|
90
80
|
let expected = [
|
|
91
81
|
"x & 255", "x | 8", "x ^ 60", "x << 16", "x >> 12", "x >>> 10",
|
|
92
82
|
];
|
|
93
|
-
testing::assert_contains(&output, &expected
|
|
83
|
+
testing::assert_contains(&output, &expected);
|
|
94
84
|
assert!(!output.contains('.'), "{output}");
|
|
95
85
|
assert_eq!(transform(&output), output);
|
|
96
86
|
// Compound assignments, negated operands, and complements.
|
|
97
87
|
let output =
|
|
98
88
|
transform("function f(x) { x &= 63.01; x >>>= 3.94; y = x & -3.7; z = ~9.5; }");
|
|
99
|
-
testing::assert_contains(&output, &["x &= 63", "x >>>= 3", "x & -3", "~9"]
|
|
89
|
+
testing::assert_contains(&output, &["x &= 63", "x >>>= 3", "x & -3", "~9"]);
|
|
100
90
|
let output =
|
|
101
91
|
transform("function f(x) { return [x & 255, x + 255.51, x * 1.5, 0.5, x(23.5)]; }");
|
|
102
|
-
let kept = ["x & 255", "x + 255.51", "x * 1.5", "
|
|
103
|
-
testing::assert_contains(&output, &kept
|
|
92
|
+
let kept = ["x & 255", "x + 255.51", "x * 1.5", ".5", "x(23.5)"];
|
|
93
|
+
testing::assert_contains(&output, &kept);
|
|
104
94
|
}
|
|
105
95
|
}
|
|
@@ -8,32 +8,49 @@
|
|
|
8
8
|
//! blocks containing string statements created by [`super::statements`], since unwrapping them
|
|
9
9
|
//! could introduce directives.
|
|
10
10
|
|
|
11
|
-
use
|
|
12
|
-
|
|
13
|
-
use
|
|
14
|
-
use swc_core::ecma::visit::{VisitMut, VisitMutWith};
|
|
11
|
+
use oxc::allocator::{TakeIn, Vec};
|
|
12
|
+
use oxc::ast::ast::{Expression, Program, Statement, VariableDeclarationKind};
|
|
13
|
+
use oxc::ast_visit::{VisitMut, walk_mut};
|
|
15
14
|
|
|
16
15
|
use super::analysis::Analysis;
|
|
17
16
|
|
|
18
|
-
pub(super) fn run(program: &mut Program
|
|
19
|
-
let mut flatten =
|
|
20
|
-
|
|
17
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
18
|
+
let mut flatten = Flatten {
|
|
19
|
+
analysis,
|
|
20
|
+
changed: false,
|
|
21
|
+
};
|
|
22
|
+
flatten.visit_program(program);
|
|
21
23
|
flatten.changed
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
struct
|
|
26
|
+
struct Flatten<'b, 'a> {
|
|
27
|
+
analysis: &'b Analysis<'a>,
|
|
25
28
|
changed: bool,
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
fn is_unscoped(statement: &Statement<'_>) -> bool {
|
|
32
|
+
match statement {
|
|
33
|
+
Statement::VariableDeclaration(declaration) => {
|
|
34
|
+
declaration.kind == VariableDeclarationKind::Var
|
|
35
|
+
}
|
|
36
|
+
Statement::FunctionDeclaration(_) | Statement::ClassDeclaration(_) => false,
|
|
37
|
+
Statement::ExpressionStatement(statement) => {
|
|
38
|
+
!matches!(statement.expression, Expression::StringLiteral(_))
|
|
39
|
+
}
|
|
40
|
+
_ => true,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl<'a> VisitMut<'a> for Flatten<'_, 'a> {
|
|
45
|
+
fn visit_statements(&mut self, statements: &mut Vec<'a, Statement<'a>>) {
|
|
46
|
+
walk_mut::walk_statements(self, statements);
|
|
47
|
+
let builder = &self.analysis.ast;
|
|
48
|
+
let mut flattened = Vec::with_capacity_in(statements.len(), builder);
|
|
49
|
+
for statement in statements.take_in(builder) {
|
|
33
50
|
match statement {
|
|
34
|
-
|
|
35
|
-
flattened.extend(block.
|
|
36
|
-
self.changed = true
|
|
51
|
+
Statement::BlockStatement(block) if block.body.iter().all(is_unscoped) => {
|
|
52
|
+
flattened.extend(block.unbox().body);
|
|
53
|
+
self.changed = true
|
|
37
54
|
}
|
|
38
55
|
statement => flattened.push(statement),
|
|
39
56
|
}
|
|
@@ -42,28 +59,18 @@ impl VisitMut for FlattenBlocks {
|
|
|
42
59
|
}
|
|
43
60
|
}
|
|
44
61
|
|
|
45
|
-
fn is_transparent(block: &BlockStmt) -> bool {
|
|
46
|
-
block.stmts.iter().all(|statement| match statement {
|
|
47
|
-
// Moving a function-scoped `var` out of this block preserves its scope.
|
|
48
|
-
Stmt::Decl(Decl::Var(declaration)) => declaration.kind == VarDeclKind::Var,
|
|
49
|
-
Stmt::Decl(_) => false,
|
|
50
|
-
Stmt::Expr(statement) => !matches!(&*statement.expr, Expr::Lit(Lit::Str(_))),
|
|
51
|
-
_ => true,
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
62
|
#[cfg(test)]
|
|
56
63
|
mod tests {
|
|
57
64
|
use crate::deobfuscate::testing;
|
|
58
65
|
|
|
59
66
|
#[test]
|
|
60
67
|
fn flattens_only_grouping_blocks_in_statement_lists() {
|
|
61
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
68
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
62
69
|
let output = transform("function f() { { a(); { b(); } } var c; { var d = 1; } }");
|
|
63
|
-
testing::assert_contains(&output, &["var d = 1;"
|
|
70
|
+
testing::assert_contains(&output, &["var d = 1;", "a(); b();"]);
|
|
64
71
|
assert_eq!(output.matches('{').count(), 1, "{output}");
|
|
65
72
|
let output =
|
|
66
73
|
transform("function f() { { let a = 1; use(a); } if (a) { b(); } while (c) { d(); } }");
|
|
67
|
-
testing::assert_contains(&output, &["if (a) {", "while(c){"
|
|
74
|
+
testing::assert_contains(&output, &["if (a) {", "while(c){", "{ let a = 1;"]);
|
|
68
75
|
}
|
|
69
76
|
}
|
|
@@ -8,165 +8,119 @@
|
|
|
8
8
|
//! ```
|
|
9
9
|
//!
|
|
10
10
|
//! The helper must be assigned once and forward parameters in order, except for swapping the
|
|
11
|
-
//! method and receiver. The method must be read from the receiver
|
|
11
|
+
//! method and receiver. The method must be read from the same receiver binding. This keeps
|
|
12
12
|
//! the same `this` value as a regular method call. Calls must supply exactly one argument per
|
|
13
13
|
//! parameter, without spreads, so the method receives the same arguments.
|
|
14
14
|
|
|
15
|
-
use
|
|
16
|
-
use
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
use swc_core::ecma::visit::{Visit, VisitMut, VisitMutWith, VisitWith};
|
|
15
|
+
use oxc::allocator::{CloneIn, GetAllocator, Vec};
|
|
16
|
+
use oxc::ast::ast::{Argument, Expression, Function, Program};
|
|
17
|
+
use oxc::ast_visit::{VisitMut, walk_mut};
|
|
18
|
+
use oxc::span::GetSpan;
|
|
21
19
|
|
|
22
|
-
use super::
|
|
23
|
-
use super::
|
|
24
|
-
use crate::js::ast;
|
|
20
|
+
use super::analysis::{Analysis, Id};
|
|
21
|
+
use super::{HashMap, ast};
|
|
25
22
|
|
|
26
|
-
pub(super) fn run(program: &mut Program
|
|
27
|
-
let
|
|
28
|
-
let bindings = analysis.bindings(program);
|
|
29
|
-
let mut helpers = Helpers::default();
|
|
30
|
-
program.visit_with(&mut helpers);
|
|
31
|
-
helpers.0.retain(|id, _| bindings.is_written_once(id));
|
|
32
|
-
if helpers.0.is_empty() {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
23
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
24
|
+
let helpers = ast::functions(program, analysis, &|function| is_helper(function, analysis));
|
|
35
25
|
let mut restore = Restore {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
globals,
|
|
26
|
+
analysis,
|
|
27
|
+
helpers: &helpers,
|
|
39
28
|
changed: false,
|
|
40
29
|
};
|
|
41
|
-
|
|
30
|
+
restore.visit_program(program);
|
|
42
31
|
restore.changed
|
|
43
32
|
}
|
|
44
33
|
|
|
45
|
-
///
|
|
46
|
-
///
|
|
47
|
-
fn is_helper(function: &Function) -> bool {
|
|
48
|
-
let
|
|
49
|
-
if let Some(parameters) = names::parameter_ids(&function.params)
|
|
34
|
+
/// Matches `function (receiver, method, ...rest) { return f.call.call(method, receiver, ...rest); }`
|
|
35
|
+
/// where `f` is a function literal.
|
|
36
|
+
fn is_helper(function: &Function<'_>, analysis: &Analysis<'_>) -> bool {
|
|
37
|
+
if let Some(parameters) = ast::parameters(function)
|
|
50
38
|
&& parameters.len() >= 2
|
|
51
|
-
&& !function.
|
|
52
|
-
&& !function.
|
|
53
|
-
&& let Some(
|
|
54
|
-
|
|
55
|
-
&& let Some(
|
|
56
|
-
&& let Some(inner) =
|
|
57
|
-
&&
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
&& !function.r#async
|
|
40
|
+
&& !function.generator
|
|
41
|
+
&& let Some(Expression::CallExpression(call)) =
|
|
42
|
+
ast::returned(function).map(Expression::get_inner_expression)
|
|
43
|
+
&& let Some(outer) = call.callee.as_member_expression()
|
|
44
|
+
&& let Some(inner) = outer.object().as_member_expression()
|
|
45
|
+
&& outer
|
|
46
|
+
.static_property_name()
|
|
47
|
+
.is_some_and(|name| name == "call")
|
|
48
|
+
&& inner
|
|
49
|
+
.static_property_name()
|
|
50
|
+
.is_some_and(|name| name == "call")
|
|
51
|
+
&& matches!(
|
|
52
|
+
inner.object().get_inner_expression(),
|
|
53
|
+
Expression::FunctionExpression(_) | Expression::ArrowFunctionExpression(_)
|
|
54
|
+
)
|
|
60
55
|
{
|
|
61
|
-
let
|
|
62
|
-
let id = argument
|
|
63
|
-
|
|
64
|
-
.as_ident()
|
|
65
|
-
.filter(|_| argument.spread.is_none())?
|
|
66
|
-
.to_id();
|
|
67
|
-
parameters.iter().position(|parameter| *parameter == id)
|
|
56
|
+
let forwarded = call.arguments.iter().map(|argument| {
|
|
57
|
+
let id = analysis.expression_id(argument.as_expression()?)?;
|
|
58
|
+
parameters.iter().position(|¶meter| parameter == id)
|
|
68
59
|
});
|
|
69
|
-
|
|
70
|
-
passed.eq(swapped)
|
|
71
|
-
} else {
|
|
72
|
-
false
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/// Helpers by binding, with the number of parameters they forward.
|
|
77
|
-
#[derive(Default)]
|
|
78
|
-
struct Helpers(HashMap<Id, usize>);
|
|
79
|
-
|
|
80
|
-
impl Visit for Helpers {
|
|
81
|
-
fn visit_expr(&mut self, expression: &Expr) {
|
|
82
|
-
if let Some((id, Expr::Fn(function))) = ast::assignment(expression)
|
|
83
|
-
&& is_helper(&function.function)
|
|
84
|
-
{
|
|
85
|
-
self.0.insert(id, function.function.params.len());
|
|
86
|
-
}
|
|
87
|
-
expression.visit_children_with(self);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
fn visit_fn_decl(&mut self, declaration: &FnDecl) {
|
|
91
|
-
if is_helper(&declaration.function) {
|
|
92
|
-
self.0
|
|
93
|
-
.insert(declaration.ident.to_id(), declaration.function.params.len());
|
|
94
|
-
}
|
|
95
|
-
declaration.visit_children_with(self);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
fn visit_var_declarator(&mut self, declarator: &VarDeclarator) {
|
|
99
|
-
if let Pat::Ident(name) = &declarator.name
|
|
100
|
-
&& let Some(Expr::Fn(function)) = declarator.init.as_deref()
|
|
101
|
-
&& is_helper(&function.function)
|
|
102
|
-
{
|
|
103
|
-
self.0.insert(name.to_id(), function.function.params.len());
|
|
104
|
-
}
|
|
105
|
-
declarator.visit_children_with(self);
|
|
60
|
+
return forwarded.eq([1, 0].into_iter().chain(2..parameters.len()).map(Some));
|
|
106
61
|
}
|
|
62
|
+
false
|
|
107
63
|
}
|
|
108
64
|
|
|
109
|
-
struct Restore<'a> {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
globals: Globals,
|
|
65
|
+
struct Restore<'b, 'a> {
|
|
66
|
+
analysis: &'b Analysis<'a>,
|
|
67
|
+
helpers: &'b HashMap<Id, &'a Function<'a>>,
|
|
113
68
|
changed: bool,
|
|
114
69
|
}
|
|
115
70
|
|
|
116
|
-
impl Restore<'_> {
|
|
117
|
-
/// Rewrites `helper(receiver, receiver.method, ...rest)` as
|
|
118
|
-
fn
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if arguments.len() != parameters
|
|
123
|
-
|| arguments.iter().any(|argument| argument.spread.is_some())
|
|
71
|
+
impl<'a> Restore<'_, 'a> {
|
|
72
|
+
/// Rewrites `helper(receiver, receiver.method, ...rest)` as `receiver.method(...rest)`.
|
|
73
|
+
fn restore(&self, expression: &Expression<'a>) -> Option<Expression<'a>> {
|
|
74
|
+
let (callee, arguments) = ast::direct_call(expression)?;
|
|
75
|
+
let helper = self.helpers.get(&self.analysis.id(callee)?)?;
|
|
76
|
+
if arguments.len() != helper.params.items.len() || arguments.iter().any(Argument::is_spread)
|
|
124
77
|
{
|
|
125
78
|
return None;
|
|
126
79
|
}
|
|
127
|
-
let [receiver, method, ..] =
|
|
80
|
+
let [receiver, method, rest @ ..] = arguments else {
|
|
128
81
|
return None;
|
|
129
82
|
};
|
|
130
|
-
let
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
(target, unread)
|
|
83
|
+
let receiver = receiver.as_expression()?;
|
|
84
|
+
let method = method.as_expression()?;
|
|
85
|
+
let object = self
|
|
86
|
+
.analysis
|
|
87
|
+
.expression_id(method.as_member_expression()?.object())?;
|
|
88
|
+
let (target, receiver) = match self.analysis.expression_id(receiver) {
|
|
89
|
+
Some(id) => (id, receiver),
|
|
90
|
+
None => {
|
|
91
|
+
let (id, value) = self.analysis.assignment(receiver)?;
|
|
92
|
+
let bindings = &self.analysis.bindings;
|
|
93
|
+
let unread = bindings.references(&id) == 1 && !bindings.is_mapped_parameter(&id);
|
|
94
|
+
(id, if unread { value } else { receiver })
|
|
143
95
|
}
|
|
144
96
|
};
|
|
145
97
|
if target != object {
|
|
146
98
|
return None;
|
|
147
99
|
}
|
|
148
|
-
let
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
100
|
+
let allocator = self.analysis.allocator();
|
|
101
|
+
let mut method = method.clone_in_with_semantic_ids(allocator);
|
|
102
|
+
let member = method.as_member_expression_mut()?;
|
|
103
|
+
*member.object_mut() = receiver.clone_in_with_semantic_ids(allocator);
|
|
104
|
+
let rest = rest
|
|
105
|
+
.iter()
|
|
106
|
+
.map(|argument| argument.clone_in_with_semantic_ids(allocator));
|
|
107
|
+
let rest = Vec::from_iter_in(rest, self.analysis);
|
|
108
|
+
Some(Expression::new_call_expression(
|
|
109
|
+
expression.span(),
|
|
110
|
+
method,
|
|
111
|
+
None,
|
|
112
|
+
rest,
|
|
113
|
+
false,
|
|
114
|
+
self.analysis,
|
|
115
|
+
))
|
|
158
116
|
}
|
|
159
117
|
}
|
|
160
118
|
|
|
161
|
-
impl VisitMut for Restore<'_> {
|
|
162
|
-
fn
|
|
163
|
-
|
|
164
|
-
if let
|
|
165
|
-
|
|
166
|
-
&& let Some(¶meters) = self.helpers.get(&callee.to_id())
|
|
167
|
-
&& let Some(replacement) = self.method_call(&mut call.args, parameters)
|
|
168
|
-
{
|
|
169
|
-
*expression = replacement;
|
|
119
|
+
impl<'a> VisitMut<'a> for Restore<'_, 'a> {
|
|
120
|
+
fn visit_expression(&mut self, expression: &mut Expression<'a>) {
|
|
121
|
+
walk_mut::walk_expression(self, expression);
|
|
122
|
+
if let Some(restored) = self.restore(expression) {
|
|
123
|
+
*expression = restored;
|
|
170
124
|
self.changed = true;
|
|
171
125
|
}
|
|
172
126
|
}
|
|
@@ -188,11 +142,9 @@ mod tests {
|
|
|
188
142
|
call(x, ...methods, 1);
|
|
189
143
|
call(x, x.send, 1);",
|
|
190
144
|
super::run,
|
|
191
|
-
/* fix= */ true,
|
|
192
145
|
);
|
|
193
146
|
testing::assert_contains(
|
|
194
147
|
&output,
|
|
195
|
-
&[],
|
|
196
148
|
&[
|
|
197
149
|
"call(x, x.send);",
|
|
198
150
|
"call(x, x.send, 1, effect());",
|
|
@@ -218,11 +170,9 @@ mod tests {
|
|
|
218
170
|
call(x, x.y.z, 9, 10);
|
|
219
171
|
}",
|
|
220
172
|
super::run,
|
|
221
|
-
/* fix= */ true,
|
|
222
173
|
);
|
|
223
174
|
testing::assert_contains(
|
|
224
175
|
&output,
|
|
225
|
-
&[],
|
|
226
176
|
&[
|
|
227
177
|
"x.send(1, 2);",
|
|
228
178
|
"g().open(3, 4);",
|
|
@@ -240,7 +190,6 @@ mod tests {
|
|
|
240
190
|
let output = testing::rewrite(
|
|
241
191
|
&format!("var call = {helper}; call(x, x.send, 1);"),
|
|
242
192
|
super::run,
|
|
243
|
-
/* fix= */ true,
|
|
244
193
|
);
|
|
245
194
|
assert!(output.contains("call(x, x.send"), "{output}");
|
|
246
195
|
}
|