Reading minified JavaScript
Shipped JavaScript is minified: whitespace removed, local names shortened to one or two letters, and statements folded into expressions to save bytes. The tool parses the code, undoes the folding, lays it out one statement per line and makes it navigable. Everything runs in the browser and nothing is uploaded.
- Web apps and hybrid apps (Cordova, Capacitor, Ionic):
assets/www/ or public/ inside the APK / IPA.
- React Native:
assets/index.android.bundle in the APK, main.jsbundle in the IPA. With Hermes enabled (the default since React Native 0.70) this file is bytecode, which the Hermes tool reads. Without Hermes it is a plain-JavaScript Metro bundle, which this viewer reads. The APK and IPA inspectors offer both viewers, and each one says when a file is the other kind.
- Electron and desktop apps: inside
app.asar.
Contents
- Opening code
- Readability rewrites
- Navigating
- Bundles and modules
- Positions and stack traces
- Renames and comments
- Keyboard shortcuts
- Limits
- The parser library (JavaScriptParser)
- The rewrites library (JavaScriptTransform)
- The printer library (JavaScriptPrinter)
- The source map library (SourceMap)
1Opening code
You can open a file in three ways: drop it on the page, use Open .js…, or paste the code with ⌘V / Ctrl+V (or Paste code…). Files of up to 128 MB are accepted. The parser handles current JavaScript (ES2024 and later), including modules, classes with private fields, optional chaining, using declarations and top-level await.
If the file can't be parsed (JSX, TypeScript, Flow, or a syntax error), the tool falls back to a simpler token-based layout. The error and its position are shown in the Overview, with a button to go to it. Outline, references and the rewrites need a successful parse.
2Readability rewrites
Each rewrite is a checkbox in the Overview panel and is saved for next time. None of them changes what the program does: they only reverse transformations that minifiers make. With all of them off, the output is the original program, re-indented.
| Rewrite | Minified | Shown as |
Split comma sequences into statements: also in return, throw, if / switch conditions, var initialisers, for initialisers and arrow bodies | a(), b(), c(); return x(), y; | a(); b(); c(); x(); return y; |
Short-circuit statements become if | a && b(); a || b(); a ?? b(); | if (a) { b(); } if (!a) { b(); } if (a == null) { b(); } |
Ternary statements become if / else | a ? b() : c(); | if (a) { b(); } else { c(); } |
Nested ternaries in return (or ternaries with comma sequences) become an if / else chain | return a ? b : c ? d : e; | if (a) { return b; } else if (c) { return d; } else { return e; } |
Always use braces on if and loop bodies | if (a) b(); | if (a) { b(); } |
| One variable per declaration | var a = 1, b = 2; | var a = 1; var b = 2; |
| Constants | !0 · !1 · void 0 · 1/0 typeof x > "u" | true · false · undefined · Infinity typeof x == "undefined" |
| Constant on the right in comparisons | "object" == typeof a 0 < n | typeof a == "object" n > 0 |
| Property access with identifiers | a["foo"] · {"foo": 1} | a.foo · {foo: 1} |
| Immediately-invoked functions | !function () { … }(); | (function () { … })(); |
return void | return void a(); | a(); return; |
Some rewrites are only made when they are safe. A comma sequence on the right of an assignment is split only when the target is a plain variable. void 0 is left alone if the file assigns to something named undefined. A labelled loop keeps its label on the loop itself.
3Navigating
- Outline (left): every function, class and method, nested as in the code. Names come from declarations, assignments (
e.prototype.send = function…), object keys, class members and call sites (then(…) callback). Filter it with the search box, and click an entry to jump to it.
- Strings (left): every distinct string literal, and the static parts of template literals, in order of appearance with how often each occurs. This is a quick way to find endpoints, keys, feature flags and error messages. Clicking a string lists every place it is used.
- Click a name to highlight every use of the same variable. Uses are resolved by scope, so two different
es are not confused. Clicking a property highlights the same property name everywhere, and clicking a string highlights that string.
- Definition (
d, or ⌘/Ctrl-click) jumps to where the selected variable or function is declared. Names not declared in the file (globals such as window or fetch) are tinted.
- References (
x) lists every line that uses the selection. Click a row to go there.
- Find (
/ or ⌘F) searches the formatted text, with match-case and regular-expression toggles. Press Enter or Shift+Enter to move between matches. The browser's own find can't see lines that are off screen, so use this one instead.
- Back / Forward (
Alt+← / Alt+→) retraces your jumps.
- The status line shows the function you are in and where the current line came from in the original file.
4Bundles and modules
Metro (React Native) bundles wrap every source file in a factory registered by number:
__d(function (global, require, importDefault, importAll, module, exports, dependencyMap) {
var t = require(dependencyMap[0]) /* → module 412 */;
…
}, 37, [412, 18]);
The tool recognises these, lists them in the outline as module 37 (with the file path when the bundle is a development build), and resolves every require(d[N]) through the dependency list. A clickable /* → module 412 */ link after the call takes you to that module.
webpack-style module tables (objects or arrays of (module, exports, require) factories) are recognised the same way, and calls to the factory's require with a module id get the same links. ES modules (Vite, Rollup, esbuild output) show their import / export counts in the Overview.
5Positions and stack traces
Every formatted line remembers where it started in the original file. The status line shows that position as source line:column. Go to… (g) accepts:
| Input | Goes to |
| 120 | Line 120 of the formatted code |
| 1:48213 | Line 1, column 48213 of the original file. You can paste a whole stack-trace frame such as at n (index.android.bundle:1:48213). |
| @48212 | Character offset 48212 of the original file |
| login | The first function whose name contains “login” |
6Renames and comments
Rename (n) gives the selected variable or function a meaningful name. Every use changes, the outline follows, and shorthand properties are expanded ({a} becomes {a: token}) so the code stays correct. Comment (;) attaches a note to the current line. Both are kept in this browser, keyed by a hash of the file's contents, so they come back when you open the same file again. Download saves the formatted code with your names and comments applied, and Copy puts it on the clipboard.
7Keyboard shortcuts
| Key | Action |
| / · ⌘F · Ctrl+F | Find in code |
| Enter · Shift+Enter · F3 | Next / previous match |
| g | Go to a line, original position or function |
| d · F12 · ⌘/Ctrl-click | Go to definition |
| x | References |
| n | Rename |
| ; | Comment on the current line |
| ↑ ↓ | Move the current line (when the code has focus) |
| Alt+← · Alt+→ | Back / forward |
| Esc | Clear the selection and close References |
8Limits
- Names that a minifier removed can't be recovered. The tool only makes the structure readable, and renames are how you add meaning.
- Scope resolution is static. Code that uses
eval or with can reach variables in ways it can't see.
- A source map is used only when it is inline in the script or opened together with it (pick both files at once). A
sourceMappingURL that points to a separate file isn't fetched. When a map is loaded, the status line shows where the current line came from, and the Sources tab opens the original files the map embeds. The formatted code itself is not rewritten back to the original source.
- JSX, TypeScript and Flow aren't parsed. Shipped bundles are already compiled to plain JavaScript.
- Comments from the original file are kept, but they are placed before the next statement, so a comment in the middle of an expression moves.
9The parser library (JavaScriptParser)
The parser is lib/js-parse.js, a JavaScript module with no dependencies and no user interface. It runs on a page, in a module Web Worker (the tool formats in js/js-worker.js) or in jsc. It reads current JavaScript (ES2024 and later) into an ESTree-shaped syntax tree; JSX, TypeScript and Flow are not supported.
import { JavaScriptParser, JavaScriptSyntaxError } from "../lib/js-parse.js";
JavaScriptParser
| Method | What it does |
| JavaScriptParser.parse(source) | { ast, comments }. Every node has start (its offset in the source); functions and classes also have end. Literal nodes have kind ("string", "number", "boolean", "null", "regex") and raw, and strings also their decoded value. A parenthesized expression is marked _paren. comments is [{ start, end, text, block }] in source order. Throws a JavaScriptSyntaxError on invalid input. |
| JavaScriptParser.tokens(source) | A best-effort token list without parsing, [{ type, value, start }] with type one of name, num, str, tmpl, regex, punc, comment. For laying out a file that doesn't parse. |
| JavaScriptParser.unescapeString(text) | The value of a string literal's inner text, with its escapes decoded. |
| JavaScriptParser.RESERVED | The set of reserved words. |
JavaScriptSyntaxError
| Property | What it is |
| message | The error, ending with (line L, column C). |
| pos, line, col | The offset in the source, and the 1-based line and column. |
import { JavaScriptParser, JavaScriptSyntaxError } from "../lib/js-parse.js";
try {
const { ast, comments } = JavaScriptParser.parse(source);
console.log(ast.body.length, "top-level statements,", comments.length, "comments");
} catch (error) {
if (error instanceof JavaScriptSyntaxError) {
console.log("syntax error at offset", error.pos, error.message);
}
}
11The printer library (JavaScriptPrinter)
Scope analysis, bundle detection, the outline and the pretty-printer are lib/js-print.js, a module that imports lib/js-parse.js and lib/js-transform.js itself. No user interface.
import { JavaScriptPrinter } from "../lib/js-print.js";
JavaScriptPrinter
| Method | What it does |
| JavaScriptPrinter.process(source, options) | The whole pipeline: parse, rewrite (when options is given), analyze, detect bundles, outline, print. Returns { lines, maxLen, strings, bindings, globals, outline, bundle, ast, comments, imports, exports, times, ms }. When the source doesn't parse it returns the fallbackPrint layout with error (the JavaScriptSyntaxError), an empty outline and no bindings. |
| result.lines | The printed lines as tokens, so a viewer can draw only the lines on screen and apply renames as it draws: { d (indent level), t: [kind, text, reference, …], o (source offset of the first token), n (text length), raw }. Kinds: k keyword, i identifier, f declared function or class name, p property, s string, n number, r regex, t template, o punctuation, c comment, l label, m module link, h / H / E shorthand property / import / export. The reference is the binding id for names, "m:id" for a module link, else 0. raw lines are the continuation of a multi-line string, template or comment, printed without indent. |
| result.strings | { values, lines }: every string literal and template chunk, and the line it is printed on. |
| JavaScriptPrinter.analyze(ast) | Resolves every identifier to its binding: { bindings, globals }. bindings[id] is { id, name, kind, decl, line } (index 0 is null); each Identifier node gets b, its binding id. Names not declared in the file share one "global" binding per name; globals maps them by name. |
| JavaScriptPrinter.detectBundle(ast) | Metro __d(…) modules or webpack module tables: { kind ("metro", "webpack" or null), modules: Map(id → { id, fn, deps, name, line }), reqs }. Run analyze first: the require parameters are found by binding. |
| JavaScriptPrinter.outline(ast) | The tree of functions and classes, named from their context: { roots, count }, entries { name, kind, node, b, kids, anon, mod, line, end } (line and end, the first and last printed line, are set by process). |
| JavaScriptPrinter.print(ast, { bindings, comments, bundle }) | { lines, maxLen, strings }. Sets _line / _endLine on function and class nodes and the line of each declared binding. |
| JavaScriptPrinter.fallbackPrint(source) | A layout from the raw tokens for a file that doesn't parse: indented by braces, a line break after ; { }. |
| JavaScriptPrinter.moduleLabel(module) | "module 12 · name". |
| JavaScriptPrinter.CHILD_KEYS | For each node type, the keys holding its child nodes, in source order. |
import { JavaScriptPrinter } from "../lib/js-print.js";
const result = JavaScriptPrinter.process(source, { seq: true, braces: true });
const text = result.lines.map(line => {
let code = "";
for (let index = 1; index < line.t.length; index += 3) {
code += line.t[index];
}
return (line.raw ? "" : " ".repeat(line.d)) + code;
}).join("\n");
console.log(result.outline.count, "functions;", result.bundle.kind || "not a bundle");
12The source map library (SourceMap)
Source maps (version 3) are read by lib/sourcemap.js, a module with no dependencies and no user interface.
import { SourceMap } from "../lib/sourcemap.js";
SourceMap
| Method / property | What it does |
| SourceMap.parse(jsonText) | Reads a map and returns a SourceMap. Index maps (with sections) are supported; their sources are concatenated in section order. Throws on invalid JSON, a version other than 3 or bad mappings. |
| map.sources, map.contents | The original file names (with sourceRoot applied), and contents[i], the embedded text of source i or null. |
| map.names, map.file, map.lineCount | The original identifier names, the file field (or null), and the number of generated lines with mappings (not for index maps). |
| map.lookup(line, column) | Where a position of the generated script (0-based line and column) came from: { source (index into sources), line, col (1-based), name }, or null. |
| SourceMap.fromBundle(scriptText) | The sourceMappingURL comment at the end of a script: { url, data }, with data the decoded map for an inline data: URL (url is then "inline"), else null. Null when there is no comment. |
| SourceMap.decode(mappings) | The raw mappings string decoded: one Int32Array per generated line, 5 numbers per segment (generatedColumn, source, sourceLine, sourceColumn, name, −1 when absent). |
import { SourceMap } from "../lib/sourcemap.js";
const reference = SourceMap.fromBundle(scriptText);
const map = SourceMap.parse(reference.data || mapFileText);
const original = map.lookup(0, 48212); // line 1, column 48213 of the script
if (original) {
console.log(map.sources[original.source] + ":" + original.line + ":" + original.col);
}