cfsolve 0.1.2 → 0.1.4
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 +22 -0
- data/README.md +8 -3
- 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 +14 -6
- 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/chrome-157-macos/answers.json +4777 -0
- data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
- 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/lib/cfsolve.rb +1 -1
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +57 -5
- 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/turnstile_smoke.rs +58 -0
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
- 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 +132 -24
- data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
- 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 +12 -11
- data/vendor/cfsolve/src/session/probes.rs +1 -0
- 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/analyze.rs +33 -4
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -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 +113 -41
- data/vendor/cfsolve/src/stage2/call_stack.rs +1564 -1041
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
- 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/dates.rs +44 -0
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +326 -0
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/probes/stack.rs +117 -4
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +80 -2
- data/vendor/cfsolve/src/stage2/probes.rs +1 -0
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/reference.rs +5 -0
- data/vendor/cfsolve/src/stage2/registry.rs +8 -2
- data/vendor/cfsolve/src/stage2/replay.rs +34 -3
- data/vendor/cfsolve/src/stage2/stylesheets.rs +35 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/value_labels.rs +185 -0
- data/vendor/cfsolve/src/stage2/vocabulary.rs +112 -17
- data/vendor/cfsolve/src/stage2.rs +3 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +75 -7
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
- data/vendor/cfsolve/src/vm/extract.rs +550 -250
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +9 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +7438 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +1 -0
- data/vendor/cfsolve/src/vm/interpret/access.rs +71 -50
- 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 +160 -58
- 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 +1765 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +392 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +120 -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 +116 -51
- data/vendor/cfsolve/src/vm/output.rs +19 -6
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/registers.rs +35 -21
- data/vendor/cfsolve/src/vm/session.rs +189 -121
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +3 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +106 -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
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
//! Preserves binding identity when rewrites move code across scope boundaries.
|
|
2
|
+
//!
|
|
3
|
+
//! ```js
|
|
4
|
+
//! function f(x) { var a; a = x; return function(x) { return a + x; }; }
|
|
5
|
+
//! // After copy propagation, hygiene keeps the captured and parameter bindings distinct:
|
|
6
|
+
//! function f(x) { return function(x_1) { return x + x_1; }; }
|
|
7
|
+
//! ```
|
|
8
|
+
//!
|
|
9
|
+
//! Finds references that another binding with the same spelling now hides, and locals with the
|
|
10
|
+
//! same spelling that arrow inlining moved into one function. Those locals get unused names while
|
|
11
|
+
//! references keep their symbols. Renamed shorthand properties keep their original keys.
|
|
12
|
+
|
|
13
|
+
use std::cell::Cell;
|
|
14
|
+
|
|
15
|
+
use oxc::ast::ast::{BindingIdentifier, IdentifierReference, ObjectProperty, Program};
|
|
16
|
+
use oxc::ast_visit::{Visit, VisitMut, walk_mut};
|
|
17
|
+
use oxc::str::Ident;
|
|
18
|
+
use oxc::syntax::scope::{ScopeFlags, ScopeId};
|
|
19
|
+
|
|
20
|
+
use super::analysis::{Analysis, Id};
|
|
21
|
+
use super::{HashMap, HashSet, ast};
|
|
22
|
+
|
|
23
|
+
/// The bindings declared in each scope, by name.
|
|
24
|
+
type Bindings<'a> = HashMap<ScopeId, HashMap<Ident<'a>, HashSet<Id>>>;
|
|
25
|
+
|
|
26
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) {
|
|
27
|
+
let mut declarations = Declarations {
|
|
28
|
+
analysis,
|
|
29
|
+
stack: vec![],
|
|
30
|
+
bindings: HashMap::default(),
|
|
31
|
+
};
|
|
32
|
+
declarations.visit_program(program);
|
|
33
|
+
let bindings = declarations.bindings;
|
|
34
|
+
// Every binding but the first of each name declared in one scope conflicts.
|
|
35
|
+
let mut conflicts = HashSet::default();
|
|
36
|
+
for names in bindings.values() {
|
|
37
|
+
for ids in names.values() {
|
|
38
|
+
let first = ids.iter().min();
|
|
39
|
+
conflicts.extend(ids.iter().filter(|&id| Some(id) != first));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let mut references = References {
|
|
43
|
+
analysis,
|
|
44
|
+
bindings: &bindings,
|
|
45
|
+
stack: vec![],
|
|
46
|
+
conflicts,
|
|
47
|
+
};
|
|
48
|
+
references.visit_program(program);
|
|
49
|
+
let mut conflicts: Vec<Id> = references.conflicts.into_iter().collect();
|
|
50
|
+
conflicts.sort_unstable();
|
|
51
|
+
let mut renamed = HashMap::default();
|
|
52
|
+
for id in conflicts {
|
|
53
|
+
let name = analysis.suffixed_name(analysis.name(id));
|
|
54
|
+
let name = Ident::from_str_in(&name, &analysis.ast);
|
|
55
|
+
let symbol = id.local().expect("a conflicting binding is declared");
|
|
56
|
+
analysis.scoping.set_symbol_name(symbol, name);
|
|
57
|
+
renamed.insert(id, name);
|
|
58
|
+
}
|
|
59
|
+
Rename {
|
|
60
|
+
analysis,
|
|
61
|
+
renamed: &renamed,
|
|
62
|
+
}
|
|
63
|
+
.visit_program(program);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Collects the bindings declared in each scope of the rewritten tree. A binding moved out of
|
|
67
|
+
/// its original scope belongs to the nearest enclosing function scope.
|
|
68
|
+
struct Declarations<'b, 'a> {
|
|
69
|
+
analysis: &'b Analysis<'a>,
|
|
70
|
+
/// The entered scopes and their flags.
|
|
71
|
+
stack: Vec<(ScopeId, ScopeFlags)>,
|
|
72
|
+
bindings: Bindings<'a>,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
impl<'a> Visit<'a> for Declarations<'_, 'a> {
|
|
76
|
+
fn enter_scope(&mut self, flags: ScopeFlags, scope: &Cell<Option<ScopeId>>) {
|
|
77
|
+
let scope = scope.get().unwrap_or_else(|| {
|
|
78
|
+
let parent = self.stack.last();
|
|
79
|
+
parent.map_or(self.analysis.scoping.root_scope_id(), |&(parent, _)| parent)
|
|
80
|
+
});
|
|
81
|
+
self.stack.push((scope, flags))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fn leave_scope(&mut self) {
|
|
85
|
+
self.stack.pop();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fn visit_binding_identifier(&mut self, binding: &BindingIdentifier<'a>) {
|
|
89
|
+
let Some(symbol) = binding.symbol_id.get() else {
|
|
90
|
+
return;
|
|
91
|
+
};
|
|
92
|
+
let id = Id::Local(symbol);
|
|
93
|
+
let original = self.analysis.scope(id);
|
|
94
|
+
let scope = if self.stack.iter().any(|&(scope, _)| scope == original) {
|
|
95
|
+
original
|
|
96
|
+
} else {
|
|
97
|
+
let mut scopes = self.stack.iter().rev();
|
|
98
|
+
let function = scopes.find(|(_, flags)| flags.contains(ScopeFlags::Function));
|
|
99
|
+
function.map_or(self.analysis.scoping.root_scope_id(), |&(scope, _)| scope)
|
|
100
|
+
};
|
|
101
|
+
let names = self.bindings.entry(scope).or_default();
|
|
102
|
+
names.entry(binding.name).or_default().insert(id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// Collects the bindings that hide a reference's own binding.
|
|
107
|
+
struct References<'b, 'a> {
|
|
108
|
+
analysis: &'b Analysis<'a>,
|
|
109
|
+
bindings: &'b Bindings<'a>,
|
|
110
|
+
stack: Vec<ScopeId>,
|
|
111
|
+
conflicts: HashSet<Id>,
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
impl<'a> Visit<'a> for References<'_, 'a> {
|
|
115
|
+
fn enter_scope(&mut self, _: ScopeFlags, scope: &Cell<Option<ScopeId>>) {
|
|
116
|
+
let scope = scope.get().unwrap_or_else(|| {
|
|
117
|
+
let parent = self.stack.last().copied();
|
|
118
|
+
parent.unwrap_or(self.analysis.scoping.root_scope_id())
|
|
119
|
+
});
|
|
120
|
+
self.stack.push(scope)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fn leave_scope(&mut self) {
|
|
124
|
+
self.stack.pop();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
|
|
128
|
+
let expected = self.analysis.id(reference);
|
|
129
|
+
for scope in self.stack.iter().rev() {
|
|
130
|
+
let names = self.bindings.get(scope);
|
|
131
|
+
if let Some(ids) = names.and_then(|names| names.get(&reference.name)) {
|
|
132
|
+
if expected.is_none_or(|id| !ids.contains(&id)) {
|
|
133
|
+
self.conflicts.extend(ids);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
struct Rename<'b, 'a> {
|
|
142
|
+
analysis: &'b Analysis<'a>,
|
|
143
|
+
renamed: &'b HashMap<Id, Ident<'a>>,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
impl<'a> VisitMut<'a> for Rename<'_, 'a> {
|
|
147
|
+
fn visit_binding_identifier(&mut self, binding: &mut BindingIdentifier<'a>) {
|
|
148
|
+
if let Some(symbol) = binding.symbol_id.get()
|
|
149
|
+
&& let Some(&name) = self.renamed.get(&Id::Local(symbol))
|
|
150
|
+
{
|
|
151
|
+
binding.name = name;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
fn visit_object_property(&mut self, property: &mut ObjectProperty<'a>) {
|
|
156
|
+
walk_mut::walk_object_property(self, property);
|
|
157
|
+
ast::normalize_property(property, &self.analysis.ast)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
fn visit_identifier_reference(&mut self, reference: &mut IdentifierReference<'a>) {
|
|
161
|
+
let id = self.analysis.id(reference);
|
|
162
|
+
if let Some(&name) = id.and_then(|id| self.renamed.get(&id)) {
|
|
163
|
+
reference.name = name;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#[cfg(test)]
|
|
169
|
+
mod tests {
|
|
170
|
+
use crate::deobfuscate::testing;
|
|
171
|
+
|
|
172
|
+
#[test]
|
|
173
|
+
fn preserves_references_moved_under_shadowing_parameters() {
|
|
174
|
+
let output = testing::transform("function f(x){var a;a=x;return function(x){return a+x;}}");
|
|
175
|
+
testing::assert_contains(&output, &["return x + x_1;"]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#[test]
|
|
179
|
+
fn separates_bindings_when_an_arrow_body_moves_into_its_parent() {
|
|
180
|
+
let output = testing::transform(
|
|
181
|
+
"function f(){var x=g(),step;step=()=>{var x=h();use(x)};step();return x;}",
|
|
182
|
+
);
|
|
183
|
+
testing::assert_contains(
|
|
184
|
+
&output,
|
|
185
|
+
&["var x = g()", "var x_1 = h()", "use(x_1)", "return x;"],
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#[test]
|
|
190
|
+
fn preserves_global_undefined_and_shorthand_keys() {
|
|
191
|
+
let output = testing::transform("function f(undefined){return [void 0,{undefined}];}");
|
|
192
|
+
testing::assert_contains(
|
|
193
|
+
&output,
|
|
194
|
+
&["function f(undefined_1)", "undefined: undefined_1"],
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -14,196 +14,162 @@
|
|
|
14
14
|
//! already a 32-bit integer is returned unchanged. Requires a helper declared once. Removes the
|
|
15
15
|
//! helper once no reads remain.
|
|
16
16
|
|
|
17
|
-
use
|
|
18
|
-
BinExpr, BinaryOp, Decl, Expr, FnDecl, Function, Id, Lit, Number, Program, Stmt, UnaryOp,
|
|
19
|
-
UpdateOp, VarDeclarator,
|
|
20
|
-
};
|
|
21
|
-
use swc_core::ecma::visit::{Visit, VisitMut, VisitMutWith, VisitWith};
|
|
17
|
+
use std::slice;
|
|
22
18
|
|
|
23
|
-
use
|
|
24
|
-
use
|
|
25
|
-
use
|
|
19
|
+
use oxc::allocator::{CloneIn, GetAllocator};
|
|
20
|
+
use oxc::ast::ast::{Expression, Function, Program, SimpleAssignmentTarget, Statement};
|
|
21
|
+
use oxc::ast_visit::{VisitMut, walk_mut};
|
|
22
|
+
use oxc::syntax::operator::{BinaryOperator, UpdateOperator};
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
use super::analysis::{Analysis, Id};
|
|
25
|
+
use super::{HashMap, HashSet, ast, removal};
|
|
26
|
+
use crate::js;
|
|
27
|
+
|
|
28
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
29
|
+
let accept = |function: &Function<'_>| is_helper(function, analysis).unwrap_or(false);
|
|
30
|
+
let helpers: HashSet<Id> = ast::functions(program, analysis, &accept)
|
|
31
|
+
.into_keys()
|
|
32
|
+
.collect();
|
|
33
|
+
let mut inline = Inline {
|
|
34
|
+
analysis,
|
|
35
|
+
helpers: &helpers,
|
|
37
36
|
replaced: HashMap::default(),
|
|
38
37
|
};
|
|
39
|
-
|
|
40
|
-
let
|
|
41
|
-
program
|
|
38
|
+
inline.visit_program(program);
|
|
39
|
+
let unread = removal::unread(&inline.replaced, analysis);
|
|
40
|
+
removal::remove_function_declarations(program, &unread);
|
|
42
41
|
!inline.replaced.is_empty()
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
///
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
/// Matches `argument & mask` when the mask is an exactly representable signed 32-bit integer.
|
|
45
|
+
fn masked(expression: &Expression<'_>, argument: Id, analysis: &Analysis<'_>) -> Option<i32> {
|
|
46
|
+
let Expression::BinaryExpression(binary) = expression.get_inner_expression() else {
|
|
47
|
+
return None;
|
|
48
|
+
};
|
|
49
|
+
if binary.operator != BinaryOperator::BitwiseAnd
|
|
50
|
+
|| analysis.expression_id(&binary.left) != Some(argument)
|
|
51
|
+
{
|
|
52
|
+
return None;
|
|
53
|
+
}
|
|
54
|
+
let mask = ast::number(&binary.right)?;
|
|
55
|
+
let exact = mask.fract() == 0.0 && (i32::MIN as f64..=i32::MAX as f64).contains(&mask);
|
|
56
|
+
exact.then_some(mask as i32)
|
|
57
|
+
}
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
fn updated(
|
|
60
|
+
expression: &Expression<'_>,
|
|
61
|
+
operator: UpdateOperator,
|
|
62
|
+
analysis: &Analysis<'_>,
|
|
63
|
+
) -> Option<Id> {
|
|
64
|
+
let Expression::UpdateExpression(update) = expression.get_inner_expression() else {
|
|
65
|
+
return None;
|
|
66
|
+
};
|
|
67
|
+
let SimpleAssignmentTarget::AssignmentTargetIdentifier(target) = &update.argument else {
|
|
68
|
+
return None;
|
|
69
|
+
};
|
|
70
|
+
if update.operator != operator {
|
|
71
|
+
return None;
|
|
55
72
|
}
|
|
73
|
+
analysis.id(target)
|
|
56
74
|
}
|
|
57
75
|
|
|
58
|
-
///
|
|
59
|
-
///
|
|
60
|
-
///
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/// for (; low; low--) count++;
|
|
64
|
-
/// return x & ~mask | count;
|
|
65
|
-
/// }
|
|
66
|
-
/// ```
|
|
67
|
-
fn helper_mask(function: &Function) -> Option<i32> {
|
|
68
|
-
let [parameter] = &function.params[..] else {
|
|
76
|
+
/// Recognizes a single-parameter function that counts the low masked bits, then combines the
|
|
77
|
+
/// count with the complementary high-bit mask. Requires the expected decrement and increment
|
|
78
|
+
/// loop, and no other declarations or statements that could affect the result.
|
|
79
|
+
fn is_helper(function: &Function<'_>, analysis: &Analysis<'_>) -> Option<bool> {
|
|
80
|
+
let [argument] = ast::parameters(function)?[..] else {
|
|
69
81
|
return None;
|
|
70
82
|
};
|
|
71
83
|
let [
|
|
72
84
|
declarations @ ..,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
] =
|
|
85
|
+
Statement::ForStatement(counting),
|
|
86
|
+
Statement::ReturnStatement(returned),
|
|
87
|
+
] = function.body.as_ref()?.statements.as_slice()
|
|
76
88
|
else {
|
|
77
89
|
return None;
|
|
78
90
|
};
|
|
79
|
-
let mut declarators
|
|
91
|
+
let mut declarators = vec![];
|
|
80
92
|
for statement in declarations {
|
|
81
|
-
|
|
93
|
+
let Statement::VariableDeclaration(declaration) = statement else {
|
|
94
|
+
return None;
|
|
95
|
+
};
|
|
96
|
+
declarators.extend(&declaration.declarations)
|
|
82
97
|
}
|
|
83
98
|
let [low, count] = declarators[..] else {
|
|
84
99
|
return None;
|
|
85
100
|
};
|
|
86
|
-
let
|
|
87
|
-
let
|
|
88
|
-
let
|
|
89
|
-
let
|
|
90
|
-
let combined = returned.arg.as_deref()?.unwrap_parens().as_bin()?;
|
|
91
|
-
let increment = match &*counting.body {
|
|
92
|
-
Stmt::Block(block) => match &block.stmts[..] {
|
|
93
|
-
[statement] => statement,
|
|
94
|
-
_ => return None,
|
|
95
|
-
},
|
|
96
|
-
statement => statement,
|
|
97
|
-
};
|
|
98
|
-
let reads = |expression: &Expr, id: &Id| {
|
|
99
|
-
expression
|
|
100
|
-
.as_ident()
|
|
101
|
-
.is_some_and(|name| name.to_id() == *id)
|
|
102
|
-
};
|
|
103
|
-
let updates = |expression: &Expr, id: &Id, op: UpdateOp| {
|
|
104
|
-
expression
|
|
105
|
-
.as_update()
|
|
106
|
-
.is_some_and(|update| update.op == op && reads(&update.arg, id))
|
|
107
|
-
};
|
|
108
|
-
let is_helper = mask >= 0
|
|
109
|
-
&& count.init.as_deref().and_then(ast::number) == Some(0.0)
|
|
110
|
-
&& counting.init.is_none()
|
|
111
|
-
&& counting
|
|
112
|
-
.test
|
|
113
|
-
.as_deref()
|
|
114
|
-
.is_some_and(|test| reads(test, &low_name))
|
|
115
|
-
&& counting
|
|
116
|
-
.update
|
|
117
|
-
.as_deref()
|
|
118
|
-
.is_some_and(|update| updates(update, &low_name, UpdateOp::MinusMinus))
|
|
119
|
-
&& increment
|
|
120
|
-
.as_expr()
|
|
121
|
-
.is_some_and(|statement| updates(&statement.expr, &count_name, UpdateOp::PlusPlus))
|
|
122
|
-
&& combined.op == BinaryOp::BitOr
|
|
123
|
-
&& masked(&combined.left, &argument) == Some(!mask)
|
|
124
|
-
&& reads(&combined.right, &count_name);
|
|
125
|
-
is_helper.then_some(mask)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/// The `mask` of `argument & mask`, if it is a 32-bit integer.
|
|
129
|
-
fn masked(expression: &Expr, argument: &Id) -> Option<i32> {
|
|
130
|
-
let Expr::Bin(BinExpr {
|
|
131
|
-
op: BinaryOp::BitAnd,
|
|
132
|
-
left,
|
|
133
|
-
right,
|
|
134
|
-
..
|
|
135
|
-
}) = expression.unwrap_parens()
|
|
101
|
+
let low_id = ast::pattern_id(&low.id)?;
|
|
102
|
+
let count_id = ast::pattern_id(&count.id)?;
|
|
103
|
+
let mask = masked(low.init.as_ref()?, argument, analysis)?;
|
|
104
|
+
let Expression::BinaryExpression(combined) = returned.argument.as_ref()?.get_inner_expression()
|
|
136
105
|
else {
|
|
137
106
|
return None;
|
|
138
107
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
108
|
+
let body = match &counting.body {
|
|
109
|
+
Statement::BlockStatement(block) => block.body.as_slice(),
|
|
110
|
+
statement => slice::from_ref(statement),
|
|
111
|
+
};
|
|
112
|
+
let [Statement::ExpressionStatement(increment)] = body else {
|
|
144
113
|
return None;
|
|
145
|
-
}
|
|
146
|
-
|
|
114
|
+
};
|
|
115
|
+
let tested = counting.test.as_ref()?;
|
|
116
|
+
let decrement = counting.update.as_ref()?;
|
|
117
|
+
Some(
|
|
118
|
+
mask >= 0
|
|
119
|
+
&& count.init.as_ref().and_then(ast::number) == Some(0.0)
|
|
120
|
+
&& counting.init.is_none()
|
|
121
|
+
&& analysis.expression_id(tested) == Some(low_id)
|
|
122
|
+
&& updated(decrement, UpdateOperator::Decrement, analysis) == Some(low_id)
|
|
123
|
+
&& updated(&increment.expression, UpdateOperator::Increment, analysis)
|
|
124
|
+
== Some(count_id)
|
|
125
|
+
&& combined.operator == BinaryOperator::BitwiseOR
|
|
126
|
+
&& masked(&combined.left, argument, analysis) == Some(!mask)
|
|
127
|
+
&& analysis.expression_id(&combined.right) == Some(count_id),
|
|
128
|
+
)
|
|
147
129
|
}
|
|
148
130
|
|
|
149
|
-
///
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
bitwise::is_bitwise(binary.op) && binary.op != BinaryOp::ZeroFillRShift
|
|
131
|
+
/// Checks whether an expression always evaluates to a signed 32-bit integer.
|
|
132
|
+
fn is_int32(expression: &Expression<'_>) -> bool {
|
|
133
|
+
match expression.get_inner_expression() {
|
|
134
|
+
Expression::BinaryExpression(binary) => {
|
|
135
|
+
binary.operator.is_bitwise() && binary.operator != BinaryOperator::ShiftRightZeroFill
|
|
155
136
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
_ => false,
|
|
137
|
+
Expression::UnaryExpression(unary) => unary.operator.is_bitwise(),
|
|
138
|
+
_ => ast::number(expression).is_some_and(|number| number == js::int32(number) as f64),
|
|
159
139
|
}
|
|
160
140
|
}
|
|
161
141
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
helpers: &'
|
|
142
|
+
struct Inline<'b, 'a> {
|
|
143
|
+
analysis: &'b Analysis<'a>,
|
|
144
|
+
helpers: &'b HashSet<Id>,
|
|
165
145
|
replaced: HashMap<Id, usize>,
|
|
166
146
|
}
|
|
167
147
|
|
|
168
|
-
impl VisitMut for
|
|
169
|
-
fn
|
|
170
|
-
|
|
171
|
-
let Some((callee, [argument])) = ast::direct_call(expression)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
span,
|
|
185
|
-
op: BinaryOp::BitOr,
|
|
186
|
-
left: Box::new(ast::parenthesized(argument)),
|
|
187
|
-
right: Box::new(Expr::Lit(Lit::Num(Number {
|
|
148
|
+
impl<'a> VisitMut<'a> for Inline<'_, 'a> {
|
|
149
|
+
fn visit_expression(&mut self, expression: &mut Expression<'a>) {
|
|
150
|
+
walk_mut::walk_expression(self, expression);
|
|
151
|
+
if let Some((callee, [argument])) = ast::direct_call(expression)
|
|
152
|
+
&& let Some(id) = self.analysis.id(callee)
|
|
153
|
+
&& self.helpers.contains(&id)
|
|
154
|
+
&& let Some(argument) = argument.as_expression()
|
|
155
|
+
{
|
|
156
|
+
let builder = &self.analysis.ast;
|
|
157
|
+
let span = callee.span;
|
|
158
|
+
let value = argument.clone_in_with_semantic_ids(builder.allocator());
|
|
159
|
+
*expression = if is_int32(&value) {
|
|
160
|
+
value
|
|
161
|
+
} else {
|
|
162
|
+
let zero = ast::number_literal(span, 0.0, builder);
|
|
163
|
+
Expression::new_binary_expression(
|
|
188
164
|
span,
|
|
189
|
-
value
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
/// Removes the declarations of helpers nothing calls any longer.
|
|
198
|
-
struct RemoveHelpers(HashSet<Id>);
|
|
199
|
-
|
|
200
|
-
impl VisitMut for RemoveHelpers {
|
|
201
|
-
fn visit_mut_stmts(&mut self, statements: &mut Vec<Stmt>) {
|
|
202
|
-
statements.retain(|statement| {
|
|
203
|
-
!matches!(statement, Stmt::Decl(Decl::Fn(declaration))
|
|
204
|
-
if self.0.contains(&declaration.ident.to_id()))
|
|
205
|
-
});
|
|
206
|
-
statements.visit_mut_children_with(self);
|
|
165
|
+
value,
|
|
166
|
+
BinaryOperator::BitwiseOR,
|
|
167
|
+
zero,
|
|
168
|
+
builder,
|
|
169
|
+
)
|
|
170
|
+
};
|
|
171
|
+
*self.replaced.entry(id).or_default() += 1;
|
|
172
|
+
}
|
|
207
173
|
}
|
|
208
174
|
}
|
|
209
175
|
|
|
@@ -219,11 +185,11 @@ mod tests {
|
|
|
219
185
|
|
|
220
186
|
#[test]
|
|
221
187
|
fn inlines_helpers_whose_masks_complement() {
|
|
222
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
188
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
223
189
|
let output = transform(&format!(
|
|
224
190
|
"{HELPER}\nf(convert(a - b & 255), convert(a), convert(~a));"
|
|
225
191
|
));
|
|
226
|
-
testing::assert_contains(&output, &[
|
|
192
|
+
testing::assert_contains(&output, &["f(a - b & 255, a | 0, ~a)"]);
|
|
227
193
|
assert!(!output.contains("function convert"), "{output}");
|
|
228
194
|
let helper = HELPER.replace("-8", "-16");
|
|
229
195
|
let output = transform(&format!("{helper}\nf(convert(a & 255));"));
|