Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Tool:Terser

From ReverseEngineering.wiki
Tool
License BSD-2-Clause
Website https://github.com/terser/terser
On this wiki Facts · Code · Notes · Topics

Terser (BSD-2-Clause) is the JavaScript minifier behind most webpack and Vite production bundles: it parses to an AST, compresses with rewrite rules, renames locals and prints compact output.

What it does to code

Three stages, each with its own option object of minify() (README of terser 5.51.2): compress (AST rewrites, on by default), mangle (rename identifiers, on by default) and format/output (printing). Property mangling (mangle.properties) is a separate opt-in pass.

Options that change how output looks

Defaults as stated in the README option list:

  • sequences (true) joins consecutive simple statements with the comma operator; join_vars (true) merges consecutive var/let/const.
  • negate_iife (true) negates immediately-called function expressions, giving !function(){...}().
  • booleans, conditionals, if_return, dead_code, evaluate (constant folding), reduce_vars, collapse_vars, inline, hoist_props, unused, properties (dot notation) are all on; passes defaults to 1.
  • toplevel (false) also drops and renames top-level names; module (false) enables that for ES modules.
  • drop_console (false), drop_debugger (true), pure_funcs, keep_fnames (false), keep_classnames (false) and the unsafe* family (all false).
  • mangle options: reserved, toplevel, eval, keep_fnames, keep_classnames, safari10, nth_identifier (default: an internal mangler that weights characters by frequency). mangle.properties options: builtins (false), keep_quoted, regex, reserved, debug, undeclared.
  • format: comments (default "some": keeps license-style comments), ascii_only, max_line_len, preamble, quote_style, semicolons.

Spotting Terser output

  • Whole file on one or few lines, statements chained with commas, var a=1,b=2 runs, !function(){...}() wrappers, short names a, b, e, t, n assigned by character frequency.
  • Leading /*! ... */ or @license comments are kept.
  • Terser's source confirms both spellings: def_optimize(AST_Undefined) returns make_void_0 (lib/compress/index.js line 2994) and def_optimize(AST_Boolean) with the booleans option (default true) rewrites true and false outside boolean context to !0 and !1 (lines 3490-3516; commit 707c978227009aa6948f2a1048aa59f5fdd5bc40). Unverified: that esbuild does not produce the same spellings; check against a sample before relying on them to tell it from esbuild.
  • No Terser banner is added by default; the preamble option can add one.

What to do with it

What is renamed and what survives: Technique:JavaScript minifier name mangling. Names come back only with a source map (Format:Source map (v3)). Context: Technique:Reversing bundled JavaScript; the other common minifier is Tool:Esbuild.

Code & repositories

  • https://github.com/terser/terser (BSD-2-Clause)
  • https://github.com/terser/terser @ 707c978227009aa6948f2a1048aa59f5fdd5bc40 · license: BSD-2-Clause (declared by the contributor for the files used; GitHub reports BSD-2-Clause (read from LICENSE; GitHub's API was busy) for the repository)
    Terser source and README (option reference).
    Tested on: source read, not run: source read, not run · checked 2026-10-18