Source maps
Recover names and original sources from a map, or emit maps for the decompiled output.
Choose the operation that matches what you want to recover or trace:
| I want to… | Use |
|---|---|
| Get the original source files back | Extract the sources with wakaru extract |
| Improve variable names in decompiled code | Provide an input map with --source-map |
| Trace decompiled code back to its input file | Emit an output map with --emit-source-map |
If you have a source map, try extracting the original files first. You may not need to decompile anything. If you only want to trace Wakaru's output, you can emit a map without having an original source map.
Recover the original sources
npx wakaru extract input.js.map -o src/Many production maps embed the original files themselves, in a field called
sourcesContent. wakaru extract writes those files straight to disk. When
this works, you get the original source, not a reconstruction. Try it first
whenever a map is available.
Recover names with an input map
npx wakaru input.js --source-map input.js.map -o output.jsUse an input map when you want to keep decompiling the code and improve its names. Wakaru can recover identifiers from names recorded in the map or from embedded source files.
This works in single-file mode only. --unpack rejects input maps because
the split modules no longer line up with the bundle's coordinates.
Emit a map for the output
npx wakaru input.js --emit-source-map -o output.js
npx wakaru bundle.js --unpack --emit-source-map -o out/--emit-source-map writes a .map next to each output file, mapping the
decompiled code back to the input. Unlike input maps, this works with
--unpack: each module's map points into the bundle.
Code that Wakaru adds, such as recovered import and export statements,
has no position in the input and stays unmapped. Each map refers to its
input by a path relative to the map file. Unpack maps leave the bundle's
text out of the map, so keep the bundle where it was when you open the maps
in a tool.
See the mapping visually
The playground has a Mapping toggle. It colors each line of the output and highlights the input it came from, so you can trace any decompiled line back to the original.
Hover any line below to see its counterpart on the other side. This is the live playground, so the code is editable: