or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

ast-nodes.mdcli-tools.mdcompilation.mdexecution.mdindex.mdrepl-interactive.mdutilities.md
tile.json

tessl/npm-coffee-script

A programming language that compiles into JavaScript, providing concise syntax and advanced features like classes, comprehensions, and destructuring.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coffee-script@1.12.x

To install, run

npx @tessl/cli install tessl/npm-coffee-script@1.12.0

index.mddocs/

CoffeeScript

CoffeeScript is a programming language that compiles into JavaScript. It adds syntactic sugar inspired by Ruby, Python, and Haskell to enhance JavaScript's brevity and readability. CoffeeScript provides significant whitespace, arrow functions, destructuring assignment, classes, and other features that make JavaScript more concise and expressive.

Package Information

  • Package Name: coffee-script
  • Package Type: npm
  • Language: JavaScript (compiler for CoffeeScript language)
  • Installation: npm install -g coffee-script or npm install coffee-script

Core Imports

const CoffeeScript = require('coffee-script');

For individual functions:

const { compile, run, nodes, tokens } = require('coffee-script');
const evalFunction = require('coffee-script')["eval"];  // Note: eval requires bracket notation

Browser usage:

<script src="path/to/coffee-script.js"></script>

Basic Usage

const CoffeeScript = require('coffee-script');

// Compile CoffeeScript to JavaScript
const coffeeCode = `
square = (x) -> x * x
list = [1, 2, 3, 4, 5]
squares = (square num for num in list)
`;

const jsCode = CoffeeScript.compile(coffeeCode);
console.log(jsCode);

// Run CoffeeScript directly
CoffeeScript.run('console.log "Hello from CoffeeScript!"');

// Evaluate CoffeeScript in a sandbox
const result = CoffeeScript.eval('6 * 7');
console.log(result); // 42

Architecture

CoffeeScript is structured around several key components:

  • Compiler Core: Main compilation engine that transforms CoffeeScript syntax into JavaScript
  • Lexer: Tokenizes CoffeeScript source code into a stream of tokens
  • Parser: Converts token stream into an Abstract Syntax Tree (AST)
  • AST Node System: Comprehensive set of node classes representing different language constructs
  • Code Generator: Transforms AST into executable JavaScript with optional source maps
  • CLI Tools: Command-line interfaces for compilation, execution, and build automation
  • Runtime Support: File extension registration and REPL functionality

Capabilities

Core Compilation

Primary compilation functions for transforming CoffeeScript source code into JavaScript.

function compile(code, options);
function tokens(code, options);
function nodes(source, options);

Core Compilation

Code Execution

Direct execution of CoffeeScript code in various contexts including Node.js main module and sandboxed environments.

function run(code, options);
function eval(code, options);

Code Execution

Abstract Syntax Tree

Complete set of AST node classes for representing and manipulating CoffeeScript language constructs programmatically.

// Base node classes
class Base { }
class Block extends Base { }
class Literal extends Base { }

// Expression nodes
class Value extends Base { }
class Call extends Base { }
class Op extends Base { }
class Assign extends Base { }

// Control flow nodes  
class If extends Base { }
class While extends Base { }
class For extends Base { }
class Try extends Base { }

Abstract Syntax Tree

Command Line Interface

Command-line tools for compiling, running, and building CoffeeScript projects.

// Command module functions
function run(); // Main coffee command
function cake.run(); // Cake build tool

Command Line Interface

REPL and Interactive Features

Interactive CoffeeScript Read-Eval-Print Loop and runtime registration for requiring .coffee files.

function start(opts); // Start REPL
function register(); // Enable .coffee file requires

REPL and Interactive Features

Utilities and Helpers

Comprehensive utility functions for string manipulation, array processing, error handling, and source location management.

// String utilities
function starts(string, literal, start);
function ends(string, literal, back);
function repeat(str, n);
function count(string, substr);

// Array/Object utilities
function compact(array);
function merge(options, overrides);
function extend(object, properties);
function flatten(array);

Utilities and Helpers

Types

interface CompileOptions {
  bare?: boolean;
  header?: boolean;
  sourceMap?: boolean;
  inlineMap?: boolean;
  filename?: string;
  literate?: boolean;
  referencedVars?: string[];
}

interface RunOptions {
  filename?: string;
}

interface EvalOptions {
  sandbox?: object;
  filename?: string;
  modulename?: string;
}

interface TokenizeOptions {
  rewrite?: boolean;
  literate?: boolean;
}

const VERSION: string;
const FILE_EXTENSIONS: string[];
const helpers: object;