Registry / testing / pretty-format-ast

pretty-format-ast

JSON →
library1.0.1jsnpmunverified

A plugin for pretty-format2 that prints Abstract Syntax Trees (ASTs) in a human-readable, indented format. Version 1.0.1 is the current stable release. It provides a structured view of AST nodes with their properties, types, and positions. Compared to alternatives like util.inspect, it produces a much more concise and visually organized output, specifically designed for AST inspection. The package works with any AST that follows a similar node structure and requires pretty-format2 as a peer dependency.

npm install pretty-format-ast
INSTALL
IMPORT
SIG · PRETTY-FORMAT-AST
P
pretty-format-ast
testingjavascriptv1.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import prettyFormatAST from 'pretty-format-ast'
✗ const prettyFormatAST = require('pretty-format-ast')
CommonJS require works if using CJS, but ESM import is preferred for consistency.
prettyFormat2
✓ import prettyFormat2 from 'pretty-format2'
✗ const { format } = require('pretty-format2')
prettyFormat2 is a default export; named exports like 'format' are not available.
plugins
✓ prettyFormat2(val, { plugins: [prettyFormatAST] })
✗ prettyFormat2(val, { plugin: prettyFormatAST })
The option key is 'plugins' (plural) and must be an array.

Demonstrates basic usage: import pretty-format2 and pretty-format-ast, then format a simple AST object with the plugin.

const prettyFormat2 = require('pretty-format2'); const prettyFormatAST = require('pretty-format-ast'); const ast = { type: 'Program', body: [ { type: 'ExpressionStatement', expression: { type: 'Literal', value: 42 }, }, ], }; console.log(prettyFormat2(ast, { plugins: [prettyFormatAST] })); // Output: // Node "Program" // body: Array [ // Node "ExpressionStatement" // expression: Node "Literal" // value: 42, // ]
Debug
Known issues
gotchaPlugin must be passed as an array to the 'plugins' option. Passing a single plugin object without wrapping in an array will be silently ignored.
fix
Use { plugins: [prettyFormatAST] } instead of { plugins: prettyFormatAST }.
affects: <=1.0.1
deprecatedpretty-format2 v1.x is still used, but there is a newer major version v2.x. The plugin may not be compatible with v2.x without updates.
fix
Check compatibility with pretty-format2 v2.0.0 before upgrading.
affects: >=1.0.0
breakingStarting from pretty-format2 v2.0.0, the plugin API changed. pretty-format-ast v1.0.1 is not updated and may not work with v2.
fix
Wait for an updated version of pretty-format-ast or pin pretty-format2 to v1.x.
affects: >=2.0.0
gotchaThe plugin only works with AST nodes that have a 'type' property. Objects without 'type' will not be formatted specially.
fix
Ensure your AST objects have a 'type' string field for proper formatting.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: prettyFormat2(...) is not a function
CommonJS require of pretty-format2 may return different export depending on version. In v1.x, it is a default export function, but in v2.x, it may be exported differently.
fix
Use import: import prettyFormat2 from 'pretty-format2'; or ensure you have v1.x installed.
Error: Cannot find module 'pretty-format2'
pretty-format2 is a peer dependency and must be installed separately.
fix
Run: npm install pretty-format2
SyntaxError: Unexpected token 'export'
Using ESM imports in a CommonJS script or without proper package.json type: 'module'.
fix
Use require syntax, or set "type": "module" in package.json.
TypeError: plugins is not iterable
Passing a non-array value to the 'plugins' option, such as an object.
fix
Wrap the plugin in an array: plugins: [prettyFormatAST]
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
pretty-format2requiredCore dependency; pretty-format-ast is a plugin for pretty-format2 and cannot work without it.
Agent activity
6 hits · last 30 days
node
6
Resources
pretty-format-ast — npm install pretty-format-ast · libregistry