Technique:JavaScript minifier name mangling
| On this wiki | Facts · Code · Notes · Topics |
|---|
What Terser and esbuild rename when they minify JavaScript, how their short names are generated, and what always survives, so you know which names to trust in a minified bundle.
Terser (BSD-2)
lib/scope.js: local variables, function parameters and (with toplevel, which module mode turns on) top-level names are renamed. Options seen in the source: keep_fnames, keep_classnames, reserved (names never used or replaced), toplevel. Scopes that contain a direct eval call or a with statement are not mangled (the scope records uses_with and checks name == "eval"). Property names are only touched by the separate property mangler (lib/propmangle.js: builtins false by default so DOM and built-in names are left alone; keep_quoted leaves quoted keys), which is off by default.
Name generator base54: the first character comes from abc...zABC...Z$_ (54 letters), later ones also from digits (64); characters are sorted by how often they occur in the code (consider / sort), so the commonest letters become the shortest names. Names therefore differ between builds and between versions.
Page for the tool and its options: Tool:Terser.
esbuild
See Tool:esbuild: sequential names over a-zA-Z_$, properties kept unless --mangle-props.
What survives (practical)
- Property and method names, object keys, string literals, template text, regexes.
- Exported names of ES modules and webpack export maps (Tool:webpack).
- Names under
keep_fnames/--keep-names(function.nameis observable). - Top-level names in classic scripts (not mangled unless
toplevel). /*! ... */and@licensecomments.- Anything referenced by string (reflection,
window["name"]).
Recovering original local names needs a source map (Format:Source map (v3), names array) or manual renaming; deobfuscation heuristics are Unverified guesses. Do not confuse with intentional obfuscation: Technique:Recognizing code obfuscation/JavaScript obfuscator output.
See Technique:Reversing bundled JavaScript.
Code & repositories
- https://github.com/terser/terser (BSD-2-Clause)
- https://github.com/evanw/esbuild (MIT)
- https://github.com/terser/terser @
707c978227009aa6948f2a1048aa59f5fdd5bc40· license: BSD-2-Clause (read from LICENSE; GitHub's API was busy)
Minifier; mangler in lib/scope.js, property mangler in lib/propmangle.js.
Tested on: source read, not run: read only · checked 2026-10-18