tidy v2.1.0

v2.1.0

Markdown

The new tidyrs-wasm package, a WebAssembly fallback for tidyrs, and where each syntax error is.


Features

  • tidyrs-wasm is a new package. It's the same WebAssembly build that runs the playground, now on npm. It works in browsers, Workers, Node, Bun & Deno. It has the same format & check as tidyrs, plus config() to read a tidy.json or tidy.toml, and version(). See WebAssembly. (c4afa35)

    JavaScript
    import init, { format } from "tidyrs-wasm";
    
    await init(); // fetches tidy_bg.wasm; a no-op in Node
    format("let a = {b:1}", { lang: "js" });

    Note: It's ~1.25 MB gzipped & about 2-3x slower than the native addon. Use tidyrs when you can.

  • tidyrs falls back to tidyrs-wasm when no native addon loads. This is opt-in: install tidyrs-wasm next to tidyrs, and tidyrs uses it only on a platform without an addon, such as a WebContainer. Set TIDYRS_WASM=1 to use it everywhere. See Platforms. (c4afa35)

  • loc on a syntax error says where the error is, in the same shape as Prettier's errors. Both line & column start at 1. The message doesn't change. (4ff6ba6)

    JavaScript
    try {
      format("let a = 1;\nlet = ;", { lang: "js" });
    } catch (err) {
      err.loc; //=> { start: { line: 2, column: 7 } }
    }

Chore

  • The bindings share one parser for their options and languages. (a576623)
  • The JavaScript benchmark reads the output of hyperfine 2. (5b20334)
Esc