Decaf JS
raw JSON → 0.4.18 verified Fri May 01 auth: no javascript deprecated
A CoffeeScript to ES.Next transpiler that converts CoffeeScript code to modern JavaScript (ES6+). Current version 0.4.18 is released as a young project with limited feature coverage; uses the CoffeeScript compiler under the hood for parsing. Key differentiators: falls back to CoffeeScript output when ES6 transpilation is not supported, integrates with jscodeshift for code optimization. Alternative to manual refactoring or other transpilers like decaffeinate.
Common errors
error Module not found: Can't resolve 'decafjs' ↓
cause Package not installed; incorrect package name used.
fix
Run
npm install decafjs and import with require('decafjs'). error TypeError: decaf.compile is not a function ↓
cause Importing the default export incorrectly with ESM syntax.
fix
Use
const decaf = require('decafjs') instead of import decaf from 'decafjs'. Warnings
gotcha Decaf may not support all CoffeeScript syntax; unsupported features fall back to original CoffeeScript output. ↓
fix Check the test suite for supported features; manually review transpiled output.
deprecated The project is no longer actively maintained; last release was 2016. ↓
fix Consider using an alternative like decaffeinate or manually rewriting code.
gotcha The npm package name is 'decafjs', not 'decaf' or 'shopify-decaf'. ↓
fix Install using `npm install decafjs`.
gotcha The package is CommonJS-only; ESM imports or TypeScript types are not available. ↓
fix Use `require()` or set up a transpilation step.
gotcha The 'compile' function's second argument is passed to recast; options may affect output formatting. ↓
fix Refer to recast documentation for valid options.
Install
npm install shopify-decaf yarn add shopify-decaf pnpm add shopify-decaf Imports
- decaf wrong
const decaf = require('decafjs')correctimport decaf from 'decafjs' - compile wrong
import { compile } from 'decafjs'correctconst { compile } = require('decafjs') - transform wrong
const compile = require('decafjs').compilecorrectconst decaf = require('decafjs'); decaf.compile(code)
Quickstart
const decaf = require('decafjs');
const coffee = `-> alert "hello world"`;
const js = decaf.compile(coffee);
console.log(js);