#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

#1306 in Development tools

Download history 17/week @ 2023-11-20 60/week @ 2023-11-27 23/week @ 2023-12-04 109/week @ 2023-12-11 64/week @ 2023-12-18 150/week @ 2023-12-25 245/week @ 2024-01-01 85/week @ 2024-01-08 137/week @ 2024-01-15 68/week @ 2024-01-22 132/week @ 2024-01-29 269/week @ 2024-02-05 77/week @ 2024-02-12 89/week @ 2024-02-19 259/week @ 2024-02-26 184/week @ 2024-03-04

614 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.3–2.1MB
~43K SLoC