[][src]Crate prettify_js

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");

Structs

SourceCoord

Source coordinate, line+column

SourceMapColumn

Zero-based column number, in UTF16 code units

SourceMapLine

Zero-based line number

SourceMapping

Points that correspond in the original/generated source code.

Functions

generate_source_map

Generate a source-map as a string, given the original source file name, file data, and a list of mappings from the original source to the generated source.

maybe_prettyprint

Convenience function to create a sourcemap for the prettyprinted version of the file (if it needs prettyprinting), generate a URL for it and append that URL to the file text so it gets used.

prettyprint

Prettyprint JS source code. Returns the prettyprinted code, plus a list of SourceMappings in source order (both in original and prettyprinted code ... we don't reorder code).

should_prettyprint

Uses a heuristic to decide if the source file needs prettyprinting: whether its average line length is > 100.