#source-map #js #prettify #javscript

prettify-js

A fast, robust but imperfect token-based JS code prettifier, written in Rust, that outputs JS source maps

1 unstable release

0.1.0 Jul 17, 2020

#1425 in Development tools

Download history 19/week @ 2024-07-21 35/week @ 2024-07-28 21/week @ 2024-08-04 2/week @ 2024-08-11 7/week @ 2024-08-18 6/week @ 2024-08-25 1/week @ 2024-09-01 4/week @ 2024-09-08 5/week @ 2024-09-15 25/week @ 2024-09-22 21/week @ 2024-09-29 23/week @ 2024-10-06 60/week @ 2024-10-13 57/week @ 2024-10-20 121/week @ 2024-10-27 41/week @ 2024-11-03

282 downloads per month
Used in 2 crates (via densky-core)

BSD-2-Clause

35KB
817 lines

prettify-js

A fast, robust but imperfect token-based JS code prettifier, written in Rust, that outputs JS source maps.

The code was mostly ported from Mozilla's pretty-fast. Instead of using Acorn to tokenize, we use RESS. Instead of using the source-map package to generate source maps, we use our own very minimal handwritten source-map emitter. The original pretty-fast code tries to avoid emitting more than one source-map record per pretty line; instead we emit one source-map record per token, because we sometimes care about code offsets within a pretty line.


lib.rs:

prettify-js is a tokenizer-based JS prettyprinter that generates source maps.

Example:

let (pretty, _) = prettify_js::prettyprint("function x(a){return a;}");
assert_eq!(pretty, "function x(a) {\n  return a;\n}\n");

Dependencies

~1.4–2.3MB
~45K SLoC