Registry / serialization / tspoon

tspoon

JSON →
library1.0.460jsnpmunverified

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.

npm install tspoon
INSTALL
IMPORT
SIG · TSPOON
T
tspoon
serializationjavascriptv1.0.460
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.

transpile
import { transpile } from 'tspoon'
const tspoon = require('tspoon'); tspoon.transpile(...)
ESM import recommended. CommonJS require also works but not tree-shakable.
validate
import { validate } from 'tspoon'
const validate = require('tspoon').validate
validate is still experimental; API may change.
Visitor
import type { Visitor } from 'tspoon'
const { Visitor } = require('tspoon')
Visitor is an interface, type-only import in TypeScript.

Shows how to define a visitor that removes private properties and run transpile.

import { transpile } from 'tspoon'; import * as ts from 'typescript'; const code = ` class Foo { private x: number; constructor() { this.x = 42; } }`; const config = { sourceFileName: 'input.ts', visitors: [{ filter(node) { return node.kind === ts.SyntaxKind.PropertyDeclaration && node.modifiers && node.modifiers.some(m => m.kind === ts.SyntaxKind.PrivateKeyword); }, visit(node, context, traverse) { context.replace(node.getStart(), node.getEnd(), ''); context.reportDiag(node, ts.DiagnosticCategory.Message, 'deleted private field', false); } }] }; const result = transpile(code, config); console.log(result.code);
Debug
Known issues
gotchavisitor filter method must return boolean; if omitted or returns falsy, visitor is skipped incorrectly.
fix
Always explicitly return true/false in filter.
affects: >=0.0.0
gotchacontext.replace with negative length can corrupt AST.
fix
Ensure end > start and use node.getStart() and node.getEnd() correctly.
affects: >=0.0.0
gotchaTypeScript compiler version must match; tspoon uses compiler API symbols that may break across TS versions.
fix
Pin TypeScript version to one compatible with tspoon (check package peerDependencies).
affects: >=0.0.0
deprecatedThe validate() method is experimental and may have breaking changes or be removed.
fix
Avoid using validate() in production; use transpile with custom diagnostics instead.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'tspoon'
tspoon not installed or not in node_modules
fix
Run 'npm install tspoon'
TypeError: node.kind is undefined
Visitor filter called on null/undefined node due to improper traversal
fix
Check that traverse() is called with valid visitors and nodes; avoid calling filter on undefined nodes.
The 'Visitor' interface is not exported from 'tspoon'
Attempting to import Visitor in CommonJS without TypeScript type support
fix
Use TypeScript with ESM import: import type { Visitor } from 'tspoon'
Upgrade
Version history
1.0.460latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
tspoon — npm install tspoon · libregistry