spoon

raw JSON →
0.1.10 verified Fri May 01 auth: no javascript abandoned

Spoon is a JavaScript transpiler that converts synchronous code into continuation-passing style (CPS) by identifying specified function calls and rewriting the surrounding code to use callbacks. It parses JavaScript using Esprima, constructs a High-Level Intermediate Representation (HIR) in the form of a Control Flow Graph (CFG), and then renders the transformed code back to JavaScript. Current stable version is 0.1.10, with no recent releases. It is primarily a proof-of-concept for transpilation techniques and is not actively maintained. Differentiators include low-level CFG manipulation and selective transpilation via declaration comments.

error Cannot find module 'spoon'
cause Package not installed or not resolved in node_modules.
fix
Install with: npm install spoon
error spoon is not a function
cause Incorrect import style (e.g., import default from ESM).
fix
Use: const spoon = require('spoon');
error Cannot read property 'construct' of undefined
cause Using CommonJS but not requiring the module correctly.
fix
Ensure you are using: const spoon = require('spoon');
breaking spoon() expects an array of function names as second argument, but many users pass a string or options object first.
fix Always pass an array: spoon(code, ['funcName'], options)
deprecated The package is unmaintained since 2012. No security patches or updates.
fix Consider using modern alternatives like Babel plugins or Sweet.js for code transformation.
gotcha Spoon uses UglifyJS for code generation, which may produce different formatting. The 'uglify' option is passed directly to UglifyJS; incorrect options may cause errors.
fix Limit uglify options to known UglifyJS options from version 1.x.
npm install spoon
yarn add spoon
pnpm add spoon

Transpile code to use callbacks for specified function calls, with minimal configuration.

const spoon = require('spoon');
const code = `var x = 1; var y = hardMath(x) * 2; console.log(y);`;
const transformed = spoon(code, ['hardMath']);
console.log(transformed);
// Output uses callbacks for hardMath calls.