Decaf JS
raw JSON → 0.1.0 verified Fri May 01 auth: no javascript maintenance
Decaf JS is a CoffeeScript-to-ES.next transpiler that leverages the CoffeeScript compiler to build a syntax tree and then outputs modern JavaScript. The current stable version is 0.1.0, with infrequent releases. Its key differentiator is the ability to fall back to the CoffeeScript compiler output for unsupported syntax, aiming to cover the full CoffeeScript language. It can be used as a CLI tool or integrated as a code transform with tools like jscodeshift. It uses ast-types for building an esprima-compatible AST and recast for printing JavaScript.
Common errors
error decaf: command not found ↓
cause Decaf is not installed globally or not in PATH.
fix
Run 'npm install -g decafjs' or use 'npx decafjs'.
error Cannot find module 'decafjs' ↓
cause Package not installed in the current project.
fix
Run 'npm install decafjs' in your project directory.
error TypeError: decaf.compile is not a function ↓
cause Incorrect import pattern or version mismatch.
fix
Ensure you require/import the default export: const decaf = require('decafjs');
Warnings
gotcha Decaf may not support all CoffeeScript syntax and falls back to CoffeeScript compiler output for unsupported patterns, which may produce ES5 instead of ES6. ↓
fix Check the test suite for supported features; contribute or submit issues for unsupported syntax.
deprecated The package has seen infrequent updates and may be considered in maintenance mode. ↓
fix Consider alternatives like CoffeeScript's own --transpile flag with Babel for production use.
gotcha When using the CLI globally, ensure you have installed decaf globally; local installs may not expose the command. ↓
fix Use 'npm install decafjs -g' to install globally, or run via 'npx decafjs'.
Install
npm install bouk-decafjs yarn add bouk-decafjs pnpm add bouk-decafjs Imports
- decaf wrong
var decaf = require('decafjs')correctimport decaf from 'decafjs' - compile
decaf.compile(code, options) - default
const decaf = require('decafjs')
Quickstart
const decaf = require('decafjs');
const coffee = 'square = (x) -> x * x';
const js = decaf.compile(coffee, { tabWidth: 2 });
console.log(js);