Skip to content
toolbelt
Back to Guides

Reading Third-Party JavaScript

By ·

Updated

A bundled library is not meant to be read. Formatting gets it close enough that you can answer the one question you have.

What is this tool?

A JavaScript formatter re-prints code with consistent indentation and spacing. It does not undo minification — variable names stay short — but it makes the control flow followable.

How it works

Prettier parses the code into an AST and prints it back. Because it works from the AST, it understands where one statement ends and the next begins, which is why it does not break on semicolons inside strings or regexes.

Example

Before:
function f(a,b){if(!a)return null;const c=b.map(x=>x*2);return{a,c}}

After:
function f(a, b) {
  if (!a) return null;
  const c = b.map((x) => x * 2);
  return { a, c };
}

When to use it

When you need to know whether a library does something before you trust it. When a stack trace points into a vendor bundle. When you are trying to reproduce a bug in third-party code.

Optimization Tips

Do not try to read a formatted bundle top to bottom. Search for the string or the exported function you care about, then read only that function. A formatter helps you follow one function; it does not make 30,000 lines readable.

Frequently Asked Questions

Can it beautify minified code?
It makes the structure readable, but mangled names stay mangled. That is the difference between beautifying and de-minifying.
Why do I get a syntax error?
Either the code is JSX or TypeScript (which use different parsers), or the snippet is only part of a file. Try the full file.
Does it run the code?
Never. It parses and prints. Nothing executes.
Can it fix actual bugs?
No. It only changes layout. If the parser reports an error, the code is genuinely broken.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools