CoffeeScript Compiler

2.7.0 · maintenance · verified Sun Apr 19

CoffeeScript is a 'little language' that transpiles into JavaScript, aiming to provide a more concise and readable syntax inspired by Ruby. Its current stable version is 2.7.0. While once very popular, it has seen reduced adoption since the widespread introduction of ES6+ features, which brought much of CoffeeScript's syntactic sugar directly into JavaScript. The project is primarily in maintenance mode with infrequent but significant updates, targeting modern JavaScript. Key differentiators include its significant whitespace, implicit returns, and a streamlined object/array literal syntax compared to direct JavaScript. CoffeeScript maintains backward compatibility where possible while progressively aligning its output with modern JavaScript standards and targeting ES2015+. It is mainly used as a development dependency for projects that chose CoffeeScript for their source code.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic compilation of a CoffeeScript string into JavaScript using the `compile` function, including a class definition and a loop.

import { compile } from 'coffeescript';

const coffeeCode = `
# A simple CoffeeScript example
square = (x) -> x * x

numbers = [1, 2, 3]

for num in numbers
  console.log "The square of #{num} is #{square num}"

class Animal
  constructor: (@name) ->
  move: (meters) ->
    console.log @name, "moved #{meters}m."

cat = new Animal "Cat"
cat.move 5
`;

try {
  const jsCode = compile(coffeeCode, { bare: true });
  console.log('--- CoffeeScript Input ---');
  console.log(coffeeCode);
  console.log('\n--- Compiled JavaScript Output ---');
  console.log(jsCode);
} catch (error) {
  console.error('Compilation Error:', error.message);
}

view raw JSON →