Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 7, 2026·3 min de lecture

CoffeeScript — Clean Syntax That Compiles to JavaScript

A programming language that compiles to JavaScript, offering a concise syntax inspired by Ruby and Python with features like list comprehensions, destructuring, and classes.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
CoffeeScript Overview
Commande d'installation directe
npx -y tokrepo@latest install 43eb8544-7a00-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

CoffeeScript is a programming language that compiles into JavaScript, adding syntactic sugar inspired by Ruby, Python, and Haskell. It played a significant role in the evolution of JavaScript by proving that features like classes, arrow functions, and destructuring were in demand, many of which were later adopted into ES2015+.

What CoffeeScript Does

  • Compiles a concise whitespace-significant syntax into clean JavaScript
  • Provides list comprehensions, pattern matching, and string interpolation
  • Supports class-based inheritance with a simple keyword syntax
  • Generates source maps for debugging CoffeeScript code in the browser
  • Runs as a CLI compiler, a Node.js module, or in-browser via a script tag

Architecture Overview

The CoffeeScript compiler is itself written in CoffeeScript (self-hosting). It parses .coffee files into an AST using a Jison-generated parser, applies transformations, and emits readable JavaScript. The compiler supports source maps and can target various ECMAScript output levels. CoffeeScript 2 outputs modern ES2015+ JavaScript.

Self-Hosting & Configuration

  • Install globally via npm for the coffee CLI command
  • Integrate with build tools using coffeescript/register for on-the-fly compilation
  • Use coffee --watch to auto-recompile on file changes during development
  • Configure output directory with -o and enable source maps with -m
  • Works with Node.js, browsers, and bundlers like webpack via coffee-loader

Key Features

  • Significant whitespace eliminates curly braces and semicolons
  • Arrow functions, destructuring, and splats that predate ES2015
  • List comprehensions for concise array transformations
  • String interpolation with embedded expressions
  • Existential operator (?.) for safe property access, later adopted by JavaScript as optional chaining

Comparison with Similar Tools

  • TypeScript — Adds static types to JavaScript with full IDE support; now the dominant compile-to-JS language
  • Babel — Transpiles modern JavaScript syntax to older versions; works at the syntax level rather than introducing new language semantics
  • Elm — Functional language compiling to JS with strong types and no runtime exceptions
  • ReasonML/ReScript — OCaml-family syntax compiling to JS with sound type inference

FAQ

Q: Is CoffeeScript still used in production? A: Some legacy codebases still use CoffeeScript, but most new projects choose TypeScript or modern JavaScript. Rails shipped with CoffeeScript support through Rails 5.

Q: Did CoffeeScript influence JavaScript? A: Significantly. ES2015 adopted arrow functions, classes, destructuring, template literals, default parameters, and rest/spread operators, all features CoffeeScript popularized.

Q: Can I incrementally migrate from CoffeeScript to JavaScript? A: Yes. CoffeeScript 2 emits clean ES2015+ output that can be committed as .js files. Tools like decaffeinate automate the conversion.

Q: Does CoffeeScript support JSX or React? A: CoffeeScript 2 has experimental JSX support via the -jsx flag, but the ecosystem integration is limited compared to TypeScript or Babel.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires