{"id":26096,"library":"power-assert-context-reducer-ast","title":"power-assert-context-reducer-ast","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/twada/power-assert-runtime","tags":["javascript","power-assert"],"install":[{"cmd":"npm install power-assert-context-reducer-ast","lang":"bash","label":"npm"},{"cmd":"yarn add power-assert-context-reducer-ast","lang":"bash","label":"yarn"},{"cmd":"pnpm add power-assert-context-reducer-ast","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for parsing JavaScript expressions to generate AST","package":"acorn","optional":false}],"imports":[{"note":"This package is CommonJS only. Do not use ES module import syntax.","wrong":"import { appendAst } from 'power-assert-context-reducer-ast';","symbol":"appendAst","correct":"var appendAst = require('power-assert-context-reducer-ast');"},{"note":"The module exports a single function; .default is not defined.","wrong":"var appendAst = require('power-assert-context-reducer-ast').default;","symbol":"default","correct":"var appendAst = require('power-assert-context-reducer-ast');"},{"note":"The module exports the function directly, not as a named property.","wrong":"const { appendAst } = require('power-assert-context-reducer-ast');","symbol":"appendAst","correct":"const appendAst = require('power-assert-context-reducer-ast');"}],"quickstart":{"code":"var appendAst = require('power-assert-context-reducer-ast');\n\n// Given a powerAssertContext object without ast, tokens, visitorKeys\nvar context = {\n  source: {\n    content: 'assert(foo === bar)',\n    filepath: 'test/some_test.js',\n    line: 1\n  },\n  args: [\n    {\n      value: false,\n      events: [\n        { value: 'FOO', espath: 'arguments/0/left' },\n        { value: 'BAR', espath: 'arguments/0/right' },\n        { value: false, espath: 'arguments/0' }\n      ]\n    }\n  ]\n};\n\nvar appendedContext = appendAst(context);\nconsole.log(appendedContext.source.ast);\n// prints JSON representation of AST nodes","lang":"javascript","description":"Demonstrates how to use appendAst to add AST, tokens, and visitorKeys to a power-assert context object."},"warnings":[{"fix":"Ensure acorn is installed as a transitive dependency; avoid directly requiring acorn from this package.","message":"Requires acorn as a dependency but does not expose it; version mismatches may cause runtime errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Check if context.source.ast is undefined before calling appendAst, or clone the context.","message":"The input context must not already have ast, tokens, or visitorKeys; if present, they will be overwritten.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider using power-assert directly with a transpiler plugin that embeds AST at compile time.","message":"This package is part of the power-assert-runtime monorepo and may receive less frequent updates.","severity":"deprecated","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use require('power-assert-context-reducer-ast') instead.","cause":"Attempted to use ES module import syntax (import { appendAst } from ...) in a CommonJS-only package.","error":"TypeError: appendAst is not a function"},{"fix":"Run 'npm install acorn' or 'npm install power-assert-context-reducer-ast' to include all dependencies.","cause":"acorn was not installed as a peer or transitive dependency; missing from node_modules.","error":"Cannot find module 'acorn'"},{"fix":"Ensure the context object has a source property with content, filepath, and line.","cause":"The source property is missing or undefined in the context object passed to appendAst.","error":"TypeError: Cannot read property 'ast' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}