Skip to content

feat(deobfuscate): fold calls to pure helpers with literal arguments - #38

Open
Sorte1 wants to merge 1 commit into
mainfrom
feat/fold-pure-calls
Open

Sorte1 wants to merge 1 commit into
mainfrom
feat/fold-pure-calls

Conversation

@Sorte1

@Sorte1 Sorte1 commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Adds a cleanup pass, fold-pure-calls, that evaluates calls like dec(2) to small pure helpers such as let dec = (a) => ["hello", "log"][a] when every argument is a literal, and removes the helper once nothing uses it. Nothing from the input is run: the body is checked and evaluated over a small pure subset (literals, parameters, operators on primitives, ternaries, templates, and own-element reads of literal arrays, objects, strings and never-written constants).

Calls that could run before a let/const they depend on, helpers that are written, impure or read free names, out-of-range reads and arrays that escape are all left alone, in both lanes. The safe lane also requires the helper to be called only directly; the unsafe lane folds a helper passed around as a value. The rules are written up in docs/known-divergences/deobfuscate.md, and fixtures/pure-calls covers both the folded shapes and the near misses against node.

This also touches web/src/settings/passes.json, since the pass table test keeps it in sync.

A new cleanup pass, fold-pure-calls, statically evaluates a call to a small pure function whose arguments are all literals, replaces the call with the result and drops the helper once nothing references it. The safe lane only folds a helper that is called directly; the unsafe lane also folds one that is passed around as a value.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant