Commit ac4a210
Code quality, Python 3.11 compat, and perf optimizations (#11)
* Enforce coding standards and add docstrings across entire codebase
- Expand all short variable names (init, expr, stmt, prop, obj, args, etc.)
- Add StrEnum for constant strings (BindingKind, node types, operators)
- Replace if/elif chains with match statements (~20 files)
- Reduce nesting via early exits and extracted helper functions
- Add type hints to all function signatures using '|' union syntax
- Add from __future__ import annotations to all modules
- Add concise docstrings to every function, class, and method
- Enforce single quotes for strings, double quotes for docstrings
- Update tests to match renamed symbols and heuristic outputs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
black && isort
* Fix Python 3.11 compatibility: replace type statement with plain aliases
The `type X = ...` syntax requires Python 3.12+, but CI tests on 3.11.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix review issues: revert over-engineering, remove perf regressions
- Revert IntEnum+match/case in traverser hot path back to plain int
constants with if/elif (avoids enum dispatch overhead)
- Revert sys.modules indirection in _run_pre_passes to direct calls
- Remove BindingKind StrEnum; revert to plain string comparisons
- Revert unnecessary variable renames (parser, __main__, _fast_to_dict)
- Remove duplicate _write_output helpers; inline the I/O
- Remove ~56 trivial docstrings that just restate function names
- Restore sample.deobfuscated.js to match main (revert VariableRenamer
behavioral change that renamed str→string, arr→array, etc.)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Optimize ConstantProp, ExpressionSimplifier, and _count_nodes
Profiled 525 files (25 regression + 500 random from dataset).
Total time improved from 20.6s to 18.4s (11% faster).
ConstantProp (30x faster on large files):
- _find_and_remove_declarator did a full AST traversal per removed
binding (O(n*k)). Batched into single pass with set lookup (O(n)).
- vue.esm.browser.js: 0.561s → 0.012s for this transform alone.
ExpressionSimplifier (2.2x faster):
- Merged 5 separate traverse() calls into 2 (one combined pass for
unary/binary/conditional/await/comma + one for method calls).
_count_nodes:
- Replaced callback-based simple_traverse with direct iterative loop,
eliminating per-node function call overhead.
_fast_to_dict (parser):
- Converted recursive esprima-to-dict conversion to stack-based
iteration to avoid recursion overhead on large ASTs.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* bump version
* Add .gitignore and reference Kaggle dataset in README
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Update snapshot to match new VariableRenamer heuristics
The coding standards commit added response-like, path-like, and other
usage-based rename hints to VariableRenamer. Regenerate the expected
output snapshot to match.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 3190899 commit ac4a210
60 files changed
Lines changed: 5574 additions & 4044 deletions
File tree
- pyjsclear
- transforms
- utils
- tests
- fuzz
- resources
- unit
- transforms
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
| 98 | + | |
98 | 99 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | | - | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
0 commit comments