or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

browser.mdcli.mdcompilation.mdindex.mdparsing.mdregistration.mdrepl.mdutilities.md
tile.json

tessl/npm-coffeescript

A programming language that compiles into JavaScript, offering more concise and readable syntax while maintaining full JavaScript compatibility.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coffeescript@2.7.x

To install, run

npx @tessl/cli install tessl/npm-coffeescript@2.7.0

index.mddocs/

CoffeeScript

CoffeeScript 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.

Package Information

  • Package Name: coffeescript
  • Package Type: npm
  • Language: JavaScript (compiles CoffeeScript to JavaScript)
  • Installation: npm install coffeescript (local) or npm install -g coffeescript (global)

Core Imports

const CoffeeScript = require('coffeescript');

For ES modules:

import CoffeeScript from 'coffeescript';

Basic Usage

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');

Architecture

CoffeeScript is built around several key components:

  • Compiler Core: Main compilation engine that transforms CoffeeScript syntax into JavaScript
  • Lexer & Parser: Tokenizes and parses CoffeeScript source code into Abstract Syntax Tree (AST)
  • Node.js Integration: Seamless require() support for .coffee files and command-line tools
  • Browser Support: Client-side compilation and script tag support for web environments
  • REPL: Interactive CoffeeScript interpreter with Node.js REPL integration
  • CLI Tools: Command-line compiler (coffee) and build system (cake) for development workflows

Capabilities

Core Compilation

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;
}

Core Compilation

File Registration & Extensions

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']

File Registration

Tokenization & Parsing

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
}

Tokenization & Parsing

Command Line Interface

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 build

Command Line Interface

Browser Support

Client-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;

Browser Support

REPL & Interactive Environment

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

Utility Functions

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;

Utility Functions

Types

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;
}