A programming language that compiles into JavaScript, offering more concise and readable syntax while maintaining full JavaScript compatibility.
npx @tessl/cli install tessl/npm-coffeescript@2.7.0CoffeeScript is a programming language that compiles into JavaScript, offering more concise and readable syntax while maintaining full JavaScript compatibility. It provides syntactic sugar for many common JavaScript patterns including classes, arrow functions, destructuring, and comprehensions, making code more expressive and less verbose. The compiler translates CoffeeScript source files into clean, readable JavaScript that runs in any JavaScript environment.
npm install coffeescript (local) or npm install -g coffeescript (global)const CoffeeScript = require('coffeescript');For ES modules:
import CoffeeScript from 'coffeescript';const CoffeeScript = require('coffeescript');
// Compile CoffeeScript to JavaScript
const coffeeCode = `
square = (x) -> x * x
numbers = [1, 2, 3, 4, 5]
squares = (square num for num in numbers)
`;
const jsCode = CoffeeScript.compile(coffeeCode);
console.log(jsCode);
// Compile and run CoffeeScript
CoffeeScript.run(coffeeCode);
// Register CoffeeScript extensions
CoffeeScript.register();
// Now you can require .coffee files directly
// const myModule = require('./my-module.coffee');CoffeeScript is built around several key components:
Primary compilation functions for transforming CoffeeScript code into JavaScript with various options and environments.
/**
* Compile CoffeeScript code to JavaScript
*/
function compile(code: string, options?: CompileOptions): string | CompilationResult;
/**
* Compile and execute CoffeeScript code with proper Node.js context
*/
function run(code: string, options?: RunOptions): any;
/**
* Compile and evaluate CoffeeScript in sandboxed environment
*/
function eval(code: string, options?: EvalOptions): any;
interface CompileOptions {
filename?: string;
sourceMap?: boolean;
inlineMap?: boolean;
bare?: boolean;
header?: boolean;
ast?: boolean;
transpile?: TranspileOptions;
}
interface CompilationResult {
js: string;
sourceMap?: SourceMap;
v3SourceMap?: string;
}Registration system for seamless integration with Node.js require() system, enabling direct importing of CoffeeScript files.
/**
* Register CoffeeScript file extensions with Node.js
*/
function register(): void;
/**
* Supported file extensions for CoffeeScript files
*/
const FILE_EXTENSIONS: string[]; // ['.coffee', '.litcoffee', '.coffee.md']Low-level compiler internals for tokenizing and parsing CoffeeScript source code into structured data.
/**
* Tokenize CoffeeScript source code
*/
function tokens(code: string, options?: TokenizeOptions): Token[];
/**
* Parse tokens into Abstract Syntax Tree nodes
*/
function nodes(source: string | Token[], options?: ParseOptions): Block;
interface Token {
0: string; // token type
1: string; // token value
2: LocationData; // location information
}Command-line tools for compiling, running, and building CoffeeScript projects from the terminal.
# Compile files
coffee -c script.coffee
# Run CoffeeScript files
coffee script.coffee
# Watch and compile on changes
coffee -w -c src/
# Interactive REPL
coffee
# Build tasks with Cake
cake buildClient-side CoffeeScript compilation and execution for web browsers with source map support.
/**
* Browser-optimized eval function
*/
function eval(code: string, options?: BrowserEvalOptions): any;
/**
* Browser-optimized run function
*/
function run(code: string, options?: BrowserRunOptions): any;Interactive CoffeeScript interpreter with multiline support, history, and Node.js integration. Note: REPL functionality requires separate import.
// REPL must be imported separately
const repl = require('coffeescript/lib/coffeescript/repl');/**
* Start CoffeeScript REPL (from coffeescript/lib/coffeescript/repl)
*/
function start(options?: REPLOptions): REPLServer;
interface REPLOptions {
prompt?: string;
historyFile?: string;
eval?: Function;
}REPL & Interactive Environment
Helper functions and utilities used throughout the CoffeeScript compiler and available for external use.
/**
* Transpile JavaScript using Babel
*/
function transpile(js: string, options?: TranspileOptions): BabelResult;
/**
* Enable stack trace patching for CoffeeScript files
*/
function patchStackTrace(): void;
/**
* Register compiled source map for stack trace patching
*/
function registerCompiled(filename: string, source: string, sourcemap: SourceMap): void;
/**
* Package version constant
*/
const VERSION: string;
/**
* Collection of utility helper functions
*/
const helpers: HelperFunctions;interface LocationData {
first_line: number;
last_line: number;
first_column: number;
last_column: number;
}
interface TranspileOptions {
presets?: any[];
plugins?: any[];
}
interface BabelResult {
code: string;
map?: any;
}
interface RunOptions {
filename?: string;
}
interface EvalOptions {
filename?: string;
modulename?: string;
sandbox?: any;
}
interface TokenizeOptions {
filename?: string;
rewrite?: boolean;
}
interface ParseOptions {
filename?: string;
}
interface BrowserEvalOptions {
bare?: boolean;
inlineMap?: boolean;
}
interface BrowserRunOptions {
bare?: boolean;
shiftLine?: boolean;
}