Registry / testing / power-assert-context-reducer-ast

power-assert-context-reducer-ast

JSON →
library1.2.0jsnpmunverified

Appends AST, tokens, and visitorKeys to power-assert context at runtime. Version 1.2.0 is the latest stable release. This package is part of the power-assert-runtime monorepo and is intended for use when the transpiler does not add AST metadata during compilation. It parses the assertion expression to generate the missing AST nodes, enabling power-assert's enhanced assertion messages even without a transpiler step. The package is lightweight and focused on a single responsibility within the power-assert ecosystem.

npm install power-assert-context-reducer-ast
INSTALL
IMPORT
SIG · POWER-ASSERT-CONTE
P
power-assert-context-reducer-ast
testingjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

appendAst
✓ var appendAst = require('power-assert-context-reducer-ast');
✗ import { appendAst } from 'power-assert-context-reducer-ast';
This package is CommonJS only. Do not use ES module import syntax.
default
✓ var appendAst = require('power-assert-context-reducer-ast');
✗ var appendAst = require('power-assert-context-reducer-ast').default;
The module exports a single function; .default is not defined.
appendAst
✓ const appendAst = require('power-assert-context-reducer-ast');
✗ const { appendAst } = require('power-assert-context-reducer-ast');
The module exports the function directly, not as a named property.

Demonstrates how to use appendAst to add AST, tokens, and visitorKeys to a power-assert context object.

var appendAst = require('power-assert-context-reducer-ast'); // Given a powerAssertContext object without ast, tokens, visitorKeys var context = { source: { content: 'assert(foo === bar)', filepath: 'test/some_test.js', line: 1 }, args: [ { value: false, events: [ { value: 'FOO', espath: 'arguments/0/left' }, { value: 'BAR', espath: 'arguments/0/right' }, { value: false, espath: 'arguments/0' } ] } ] }; var appendedContext = appendAst(context); console.log(appendedContext.source.ast); // prints JSON representation of AST nodes
Debug
Known issues
breakingRequires acorn as a dependency but does not expose it; version mismatches may cause runtime errors.
fix
Ensure acorn is installed as a transitive dependency; avoid directly requiring acorn from this package.
affects: >=1.0.0
gotchaThe input context must not already have ast, tokens, or visitorKeys; if present, they will be overwritten.
fix
Check if context.source.ast is undefined before calling appendAst, or clone the context.
affects: >=1.0.0
deprecatedThis package is part of the power-assert-runtime monorepo and may receive less frequent updates.
fix
Consider using power-assert directly with a transpiler plugin that embeds AST at compile time.
affects: >=1.2.0
Errors
Common errors & fixes
TypeError: appendAst is not a function
Attempted to use ES module import syntax (import { appendAst } from ...) in a CommonJS-only package.
fix
Use require('power-assert-context-reducer-ast') instead.
Cannot find module 'acorn'
acorn was not installed as a peer or transitive dependency; missing from node_modules.
fix
Run 'npm install acorn' or 'npm install power-assert-context-reducer-ast' to include all dependencies.
TypeError: Cannot read property 'ast' of undefined
The source property is missing or undefined in the context object passed to appendAst.
fix
Ensure the context object has a source property with content, filepath, and line.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
acornrequiredUsed for parsing JavaScript expressions to generate AST
Agent activity
6 hits · last 30 days
node
6
Resources
power-assert-context-reducer-ast — npm install power-assert-context-reducer-ast · libregistry