{"id":26539,"library":"tspoon","title":"Tspoon","description":"Tspoon is a library that provides AST visitors for TypeScript, enabling pluggable modifications to the abstract syntax tree before transpilation. Current stable version is 1.0.460, with active development. It leverages the TypeScript compiler API to allow custom visitors to transform code, perform early optimizations, and bypass diagnostics. Unlike general-purpose AST tools, Tspoon is specifically designed for TypeScript and integrates with its transpilation pipeline. Release cadence is irregular. Key differentiator: deep integration with TypeScript's compiler, supporting visitor composition and custom diagnostics.","status":"active","version":"1.0.460","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/wix/tspoon","tags":["javascript","typescript"],"install":[{"cmd":"npm install tspoon","lang":"bash","label":"npm"},{"cmd":"yarn add tspoon","lang":"bash","label":"yarn"},{"cmd":"pnpm add tspoon","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import recommended. CommonJS require also works but not tree-shakable.","wrong":"const tspoon = require('tspoon'); tspoon.transpile(...)","symbol":"transpile","correct":"import { transpile } from 'tspoon'"},{"note":"validate is still experimental; API may change.","wrong":"const validate = require('tspoon').validate","symbol":"validate","correct":"import { validate } from 'tspoon'"},{"note":"Visitor is an interface, type-only import in TypeScript.","wrong":"const { Visitor } = require('tspoon')","symbol":"Visitor","correct":"import type { Visitor } from 'tspoon'"}],"quickstart":{"code":"import { transpile } from 'tspoon';\nimport * as ts from 'typescript';\n\nconst code = `\nclass Foo {\n    private x: number;\n    constructor() { this.x = 42; }\n}`;\n\nconst config = {\n    sourceFileName: 'input.ts',\n    visitors: [{\n        filter(node) { return node.kind === ts.SyntaxKind.PropertyDeclaration && node.modifiers && node.modifiers.some(m => m.kind === ts.SyntaxKind.PrivateKeyword); },\n        visit(node, context, traverse) { context.replace(node.getStart(), node.getEnd(), ''); context.reportDiag(node, ts.DiagnosticCategory.Message, 'deleted private field', false); }\n    }]\n};\n\nconst result = transpile(code, config);\nconsole.log(result.code);","lang":"typescript","description":"Shows how to define a visitor that removes private properties and run transpile."},"warnings":[{"fix":"Always explicitly return true/false in filter.","message":"visitor filter method must return boolean; if omitted or returns falsy, visitor is skipped incorrectly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure end > start and use node.getStart() and node.getEnd() correctly.","message":"context.replace with negative length can corrupt AST.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pin TypeScript version to one compatible with tspoon (check package peerDependencies).","message":"TypeScript compiler version must match; tspoon uses compiler API symbols that may break across TS versions.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Avoid using validate() in production; use transpile with custom diagnostics instead.","message":"The validate() method is experimental and may have breaking changes or be removed.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install tspoon'","cause":"tspoon not installed or not in node_modules","error":"Cannot find module 'tspoon'"},{"fix":"Check that traverse() is called with valid visitors and nodes; avoid calling filter on undefined nodes.","cause":"Visitor filter called on null/undefined node due to improper traversal","error":"TypeError: node.kind is undefined"},{"fix":"Use TypeScript with ESM import: import type { Visitor } from 'tspoon'","cause":"Attempting to import Visitor in CommonJS without TypeScript type support","error":"The 'Visitor' interface is not exported from 'tspoon'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}