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

compilation.mddocs/

Core Compilation

Primary compilation functions for transforming CoffeeScript source code into JavaScript with full control over compilation options and output formats.

Capabilities

Compile Function

Main compilation function that converts CoffeeScript source code to JavaScript.

/**
 * Compiles CoffeeScript source code to JavaScript
 * @param code - CoffeeScript source code as string
 * @param options - Compilation options object
 * @returns Compiled JavaScript string, or object with js/sourceMap if sourceMap option enabled
 */
function compile(code, options);

Parameters:

  • code (string): CoffeeScript source code to compile
  • options (object, optional): Compilation configuration options

Returns:

  • String: Compiled JavaScript code (default)
  • Object: {js, sourceMap, v3SourceMap} if options.sourceMap is true

Usage Examples:

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

// Basic compilation
const js = CoffeeScript.compile('square = (x) -> x * x');
console.log(js);

// Compilation with options
const result = CoffeeScript.compile(`
  class Animal
    constructor: (@name) ->
    speak: -> "#{@name} makes a sound"
`, {
  bare: true,        // Don't wrap in function
  header: true,      // Add "Generated by CoffeeScript" header
  sourceMap: true    // Generate source map
});

console.log(result.js);
console.log(result.v3SourceMap);

Tokens Function

Lexical tokenization function that converts CoffeeScript source into an array of tokens.

/**
 * Tokenizes CoffeeScript source code into lexical tokens
 * @param code - CoffeeScript source code as string  
 * @param options - Tokenization options object
 * @returns Array of token objects
 */
function tokens(code, options);

Parameters:

  • code (string): CoffeeScript source code to tokenize
  • options (object, optional): Tokenization options

Returns:

  • Array: List of token arrays in format [type, value, locationData]

Usage Examples:

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

// Tokenize simple expression
const tokens = CoffeeScript.tokens('x = 42');
console.log(tokens);
// Output: [['IDENTIFIER', 'x', {...}], ['=', '=', {...}], ['NUMBER', '42', {...}], ...]

// Tokenize with options
const tokens2 = CoffeeScript.tokens('console.log "hello"', {
  rewrite: false,  // Skip token rewriting phase
  literate: false  // Not literate CoffeeScript
});

Nodes Function

Parser function that converts CoffeeScript source or tokens into an Abstract Syntax Tree.

/**
 * Parses CoffeeScript source or tokens into AST nodes
 * @param source - CoffeeScript source string or token array
 * @param options - Parsing options object
 * @returns Root AST node (typically Block)
 */
function nodes(source, options);

Parameters:

  • source (string|array): CoffeeScript source code or pre-tokenized array
  • options (object, optional): Parsing options

Returns:

  • AST Node: Root node of the Abstract Syntax Tree (usually Block)

Usage Examples:

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

// Parse from source string
const ast = CoffeeScript.nodes('x = 42\nconsole.log x');
console.log(ast.constructor.name); // 'Block'
console.log(ast.expressions.length); // 2

// Parse from tokens
const tokens = CoffeeScript.tokens('square = (x) -> x * x');
const ast2 = CoffeeScript.nodes(tokens);
console.log(ast2.expressions[0].constructor.name); // 'Assign'

// Access AST structure
ast.expressions.forEach((expr, i) => {
  console.log(`Expression ${i}: ${expr.constructor.name}`);
});

File Compilation

Internal function for compiling CoffeeScript files from disk with source map support.

/**
 * Compiles a CoffeeScript file from disk
 * @param filename - Path to .coffee file
 * @param sourceMap - Whether to generate source map
 * @param inlineMap - Whether to inline source map in output
 * @returns Compiled JavaScript or object with source map
 */
function _compileFile(filename, sourceMap, inlineMap);

Parameters:

  • filename (string): File path to compile
  • sourceMap (boolean): Generate separate source map
  • inlineMap (boolean): Include inline source map

Returns:

  • String: Compiled JavaScript (if no source maps)
  • Object: {js, sourceMap, v3SourceMap} (if source maps enabled)

Compilation Options

interface CompileOptions {
  /** Compile without top-level function wrapper */
  bare?: boolean;
  
  /** Add "Generated by CoffeeScript" header comment */
  header?: boolean;
  
  /** Generate source map for debugging */
  sourceMap?: boolean;
  
  /** Include source map inline in JavaScript output */
  inlineMap?: boolean;
  
  /** Filename for source map and error reporting */
  filename?: string;
  
  /** Treat input as literate CoffeeScript */
  literate?: boolean;
  
  /** Array of referenced variable names */
  referencedVars?: string[];
  
  /** Source file paths for source map */
  sourceFiles?: string[];
  
  /** Line number offset for source map */
  shiftLine?: number;
}

interface TokenizeOptions {
  /** Skip token rewriting phase */
  rewrite?: boolean;
  
  /** Treat input as literate CoffeeScript */
  literate?: boolean;
}

Package Constants

/** CoffeeScript version string */
const VERSION: string;

/** Supported file extensions for CoffeeScript files */
const FILE_EXTENSIONS: string[]; // ['.coffee', '.litcoffee', '.coffee.md']

/** Reference to helpers utility module */
const helpers: object;