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

ast-nodes.mddocs/

Abstract Syntax Tree

Complete set of AST node classes for representing and manipulating CoffeeScript language constructs programmatically. These nodes form the intermediate representation used during compilation.

Capabilities

Base Node Classes

Foundation classes that all AST nodes inherit from, providing common functionality for code generation and traversal.

/**
 * Base class for all AST nodes
 */
class Base {
  /** Compile node to JavaScript fragments */
  compileToFragments(options);
  
  /** Compile node to JavaScript string */
  compile(options);
  
  /** Add location data to node */
  locationData;
}

/**
 * Container for multiple statements/expressions
 */
class Block extends Base {
  constructor(expressions);
  
  /** Array of child expressions/statements */
  expressions: Base[];
  
  /** Add expression to block */
  push(expression);
  
  /** Remove and return last expression */
  pop();
  
  /** Check if block is empty */
  isEmpty();
}

/**
 * Code fragment with location information
 */
class CodeFragment {
  constructor(parent, code);
  
  /** Generated JavaScript code string */
  code: string;
  
  /** Source location data */
  locationData: object;
}

Literal Node Types

Nodes representing basic literal values in CoffeeScript source code.

/**
 * Base class for literal values
 */
class Literal extends Base {
  constructor(value);
  
  /** The literal value */
  value: string;
}

/** Numeric literal values (42, 3.14, 0x1F) */
class NumberLiteral extends Literal { }

/** Infinity literal */
class InfinityLiteral extends Literal { }

/** NaN literal */  
class NaNLiteral extends Literal { }

/** String literal values ("hello", 'world') */
class StringLiteral extends Literal { }

/** Regular expression literals (/pattern/flags) */
class RegexLiteral extends Literal { }

/** Direct JavaScript code injection (backticks) */
class PassthroughLiteral extends Literal { }

/** Variable and function identifiers */
class IdentifierLiteral extends Literal { }

/** Object property names */
class PropertyName extends Literal { }

/** Statement keywords (break, continue, debugger) */
class StatementLiteral extends Literal { }

/** 'this' keyword reference */
class ThisLiteral extends Literal { }

/** 'undefined' keyword */
class UndefinedLiteral extends Literal { }

/** 'null' keyword */
class NullLiteral extends Literal { }

/** Boolean literals (true, false) */
class BooleanLiteral extends Literal { }

Expression Nodes

Nodes representing expressions and complex value computations.

/**
 * Value expressions with optional property access chain
 */
class Value extends Base {
  constructor(base, properties, tag);
  
  /** Base value (identifier, literal, etc.) */
  base: Base;
  
  /** Property access chain */
  properties: Base[];
  
  /** Check if this is a simple identifier */
  isSimpleNumber();
  
  /** Check if this represents a complex expression */
  isComplex();
}

/**
 * Function and method call expressions
 */
class Call extends Base {
  constructor(variable, args, soak);
  
  /** Function being called */
  variable: Base;
  
  /** Call arguments */
  args: Base[];
  
  /** Whether this is a soak call (?.) */
  soak: boolean;
  
  /** Check if this is a new expression */
  isNew: boolean;
}

/**
 * Super method call expressions
 */
class SuperCall extends Call {
  constructor(args);
}

/**
 * Binary and unary operators
 */
class Op extends Base {
  constructor(op, first, second, flip);
  
  /** Operator symbol (+, -, *, etc.) */
  operator: string;
  
  /** First operand */
  first: Base;
  
  /** Second operand (for binary ops) */
  second?: Base;
  
  /** Whether operands are flipped */
  flip: boolean;
}

/**
 * 'in' operator expressions
 */
class In extends Base {
  constructor(object, array);
  
  /** Object to test */
  object: Base;
  
  /** Array/object to test against */
  array: Base;
}

/**
 * Existence check operator (?.)
 */
class Existence extends Base {
  constructor(expression);
  
  /** Expression to check for existence */
  expression: Base;
}

/**
 * Parentheses grouping
 */
class Parens extends Base {
  constructor(body);
  
  /** Expression inside parentheses */
  body: Base;
}

/**
 * Assignment expressions
 */
class Assign extends Base {
  constructor(variable, value, context, options);
  
  /** Variable being assigned to */
  variable: Base;
  
  /** Value being assigned */
  value: Base;
  
  /** Assignment context (e.g., 'object', 'conditional') */
  context: string;
  
  /** Check if this is a conditional assignment */
  isConditional();
}

Control Flow Nodes

Nodes representing control flow statements and conditional logic.

/**
 * Return statements
 */
class Return extends Base {
  constructor(expression);
  
  /** Expression to return */
  expression?: Base;
}

/**
 * Yield return statements (generators)
 */
class YieldReturn extends Base {
  constructor(expression);
  
  /** Expression to yield */
  expression?: Base;
}

/**
 * If/else conditional statements
 */
class If extends Base {
  constructor(condition, body, options);
  
  /** Condition expression */
  condition: Base;
  
  /** If body */
  body: Base;
  
  /** Else body */
  elseBody?: Base;
  
  /** Whether this is a statement or expression */
  isStatement: boolean;
}

/**
 * Switch/case statements
 */
class Switch extends Base {
  constructor(subject, cases, otherwise);
  
  /** Expression being switched on */
  subject?: Base;
  
  /** Array of case clauses */
  cases: Base[];
  
  /** Default case */
  otherwise?: Base;
}

/**
 * While loop statements
 */
class While extends Base {
  constructor(condition, options);
  
  /** Loop condition */
  condition: Base;
  
  /** Loop body */
  body: Base;
  
  /** Whether condition is inverted (until) */
  inverted: boolean;
}

/**
 * For loop statements (including comprehensions)
 */
class For extends Base {
  constructor(body, source);
  
  /** Loop body */
  body: Base;
  
  /** Iteration source */
  source: Base;
  
  /** Loop variable */
  name?: Base;
  
  /** Index variable (for in loops) */
  index?: Base;
  
  /** Loop condition */
  guard?: Base;
  
  /** Step expression */
  step?: Base;
}

/**
 * Try/catch/finally blocks
 */
class Try extends Base {
  constructor(attempt, errorVariable, recovery, ensure);
  
  /** Try block body */
  attempt: Base;
  
  /** Error variable name */
  errorVariable?: Base;
  
  /** Catch block body */
  recovery?: Base;
  
  /** Finally block body */
  ensure?: Base;
}

/**
 * Throw statements
 */
class Throw extends Base {
  constructor(expression);
  
  /** Expression to throw */
  expression: Base;
}

Data Structure Nodes

Nodes representing object literals, arrays, and data access patterns.

/**
 * Object literal expressions
 */
class Obj extends Base {
  constructor(props, generated);
  
  /** Object properties */
  objects: Base[];
  
  /** Whether object was generated by compiler */
  generated: boolean;
}

/**
 * Array literal expressions
 */
class Arr extends Base {
  constructor(objs);
  
  /** Array elements */
  objects: Base[];
}

/**
 * Range expressions (1..10, 1...10)
 */
class Range extends Base {
  constructor(from, to, tag);
  
  /** Range start */
  from: Base;
  
  /** Range end */
  to: Base;
  
  /** Range type ('inclusive' or 'exclusive') */
  exclusive: boolean;
}

/**
 * Array/string slicing expressions
 */
class Slice extends Base {
  constructor(range);
  
  /** Range specification */
  range: Range;
}

/**
 * Property access expressions (.property)
 */
class Access extends Base {
  constructor(name, tag);
  
  /** Property name */
  name: Base;
  
  /** Whether this is a soak access (?.) */
  soak: boolean;
}

/**
 * Array indexing expressions ([index])
 */
class Index extends Base {
  constructor(index);
  
  /** Index expression */
  index: Base;
}

Function and Class Nodes

Nodes representing function definitions, classes, and related constructs.

/**
 * Function definitions
 */
class Code extends Base {
  constructor(params, body, tag);
  
  /** Function parameters */
  params: Param[];
  
  /** Function body */
  body: Block;
  
  /** Whether this is a bound function (=>) */
  bound: boolean;
  
  /** Check if function is a generator */
  isGenerator: boolean;
}

/**
 * Function parameter definitions
 */
class Param extends Base {
  constructor(name, value, splat);
  
  /** Parameter name */
  name: Base;
  
  /** Default value */
  value?: Base;
  
  /** Whether this is a splat parameter */
  splat: boolean;
}

/**
 * Splat/spread operator (...)
 */
class Splat extends Base {
  constructor(name);
  
  /** Variable name */
  name: Base;
}

/**
 * Destructuring expansion
 */
class Expansion extends Base {
  constructor();
}

/**
 * Class definitions
 */
class Class extends Base {
  constructor(variable, superClass, body);
  
  /** Class name */
  variable?: Base;
  
  /** Parent class */
  parent?: Base;
  
  /** Class body */
  body?: Base;
}

/**
 * Class inheritance expressions
 */
class Extends extends Base {
  constructor(child, parent);
  
  /** Child class */
  child: Base;
  
  /** Parent class */
  parent: Base;
}

ES6 Module Nodes

Nodes representing ES6 import and export statements.

/**
 * Base module declaration
 */
class ModuleDeclaration extends Base { }

/**
 * Import statements
 */
class ImportDeclaration extends ModuleDeclaration {
  constructor(clause, source);
  
  /** Import clause */
  clause?: Base;
  
  /** Module source */
  source: Base;
}

/**
 * Import clauses
 */
class ImportClause extends Base {
  constructor(defaultBinding, namedImports);
  
  /** Default import */
  defaultBinding?: Base;
  
  /** Named imports */
  namedImports?: Base;
}

/**
 * Named import specifiers
 */
class ImportSpecifier extends Base {
  constructor(imported, local);
  
  /** Imported name */
  imported: Base;
  
  /** Local name */
  local?: Base;
}

/**
 * Default import specifiers
 */
class ImportDefaultSpecifier extends Base {
  constructor(local);
  
  /** Local name */
  local: Base;
}

/**
 * Namespace import specifiers (import * as name)
 */
class ImportNamespaceSpecifier extends Base {
  constructor(local);
  
  /** Local name */
  local: Base;
}

/**
 * Export statements
 */
class ExportDeclaration extends ModuleDeclaration { }

/**
 * Named export statements
 */
class ExportNamedDeclaration extends ExportDeclaration {
  constructor(clause, source);
  
  /** Export clause */
  clause?: Base;
  
  /** Module source */
  source?: Base;
}

/**
 * Default export statements
 */
class ExportDefaultDeclaration extends ExportDeclaration {
  constructor(clause);
  
  /** Export clause */
  clause: Base;
}

/**
 * Export all statements (export *)
 */
class ExportAllDeclaration extends ExportDeclaration {
  constructor(source);
  
  /** Module source */
  source: Base;
}

String Interpolation and Comments

Nodes for advanced string features and code comments.

/**
 * String literals with #{} interpolations
 */
class StringWithInterpolations extends Base {
  constructor(body);
  
  /** String parts and interpolations */
  body: Base;
}

/**
 * Regular expressions with interpolations
 */
class RegexWithInterpolations extends Base {
  constructor(body, flags);
  
  /** Regex parts and interpolations */
  body: Base;
  
  /** Regex flags */
  flags?: Base;
}

/**
 * ES6 tagged template literal calls
 */
class TaggedTemplateCall extends Call {
  constructor(variable, arg, soak);
}

/**
 * Comment nodes in AST
 */
class Comment extends Base {
  constructor(comment);
  
  /** Comment text */
  comment: string;
}

Usage Examples

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

// Get AST for CoffeeScript code
const ast = CoffeeScript.nodes(`
  class Animal
    constructor: (@name) ->
    speak: -> console.log "#{@name} makes a sound"
  
  dog = new Animal "Rex"
  dog.speak()
`);

// Traverse AST
function traverseAST(node, depth = 0) {
  const indent = '  '.repeat(depth);
  console.log(`${indent}${node.constructor.name}`);
  
  // Handle different node types
  if (node instanceof Block) {
    node.expressions.forEach(expr => traverseAST(expr, depth + 1));
  } else if (node instanceof Class) {
    if (node.variable) traverseAST(node.variable, depth + 1);
    if (node.parent) traverseAST(node.parent, depth + 1);
    if (node.body) traverseAST(node.body, depth + 1);
  }
  // ... handle other node types
}

traverseAST(ast);