or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-features.mdast-nodes.mdcode-generation.mdformatting-options.mdindex.mdsource-maps.md
tile.json

ast-nodes.mddocs/

AST Node Support

Comprehensive support for all JavaScript, Flow, and JSX AST node types. Babel Generator includes specialized generation methods for every node type in the Babel AST specification.

Capabilities

Base Nodes

Core structural nodes that form the foundation of JavaScript programs.

// Core program structure nodes
interface BaseNodes {
  /** File wrapper containing program and comments */
  File: (node: FileNode) => void;
  
  /** Program root containing body statements */
  Program: (node: ProgramNode) => void;
  
  /** Block statement with curly braces */
  BlockStatement: (node: BlockStatementNode) => void;
  
  /** No-operation placeholder */
  Noop: () => void;
  
  /** Directive like "use strict" */
  Directive: (node: DirectiveNode) => void;
  
  /** Directive literal (alias for StringLiteral) */
  DirectiveLiteral: (node: StringLiteralNode) => void;
}

Expression Nodes

All forms of expressions including operators, function calls, and object access.

interface ExpressionNodes {
  /** Unary operations (!, -, +, typeof, etc.) */
  UnaryExpression: (node: UnaryExpressionNode) => void;
  
  /** Do expressions (do { ... }) */
  DoExpression: (node: DoExpressionNode) => void;
  
  /** Parenthesized expressions */
  ParenthesizedExpression: (node: ParenthesizedExpressionNode) => void;
  
  /** Increment/decrement (++, --) */
  UpdateExpression: (node: UpdateExpressionNode) => void;
  
  /** Ternary conditional operator (? :) */
  ConditionalExpression: (node: ConditionalExpressionNode) => void;
  
  /** New expressions (new Foo()) */
  NewExpression: (node: NewExpressionNode, parent?: Node) => void;
  
  /** Comma operator sequences */
  SequenceExpression: (node: SequenceExpressionNode) => void;
  
  /** 'this' keyword */
  ThisExpression: () => void;
  
  /** 'super' keyword */
  Super: () => void;
  
  /** Decorator syntax (@decorator) */
  Decorator: (node: DecoratorNode) => void;
  
  /** Function calls */
  CallExpression: (node: CallExpressionNode) => void;
  
  /** Dynamic import expressions */
  Import: () => void;
  
  /** Yield expressions in generators */
  YieldExpression: (node: YieldExpressionNode) => void;
  
  /** Await expressions in async functions */
  AwaitExpression: (node: AwaitExpressionNode) => void;
  
  /** Empty statements (standalone semicolons) */
  EmptyStatement: () => void;
  
  /** Expression statements */
  ExpressionStatement: (node: ExpressionStatementNode) => void;
  
  /** Assignment patterns in destructuring */
  AssignmentPattern: (node: AssignmentPatternNode) => void;
  
  /** Assignment expressions (=, +=, etc.) */
  AssignmentExpression: (node: AssignmentExpressionNode, parent?: Node) => void;
  
  /** Binary expressions (+, -, *, etc.) - alias for AssignmentExpression */
  BinaryExpression: (node: BinaryExpressionNode, parent?: Node) => void;
  
  /** Logical expressions (&&, ||) - alias for AssignmentExpression */
  LogicalExpression: (node: LogicalExpressionNode, parent?: Node) => void;
  
  /** Bind expressions (::) */
  BindExpression: (node: BindExpressionNode) => void;
  
  /** Property access (obj.prop, obj[prop]) */
  MemberExpression: (node: MemberExpressionNode) => void;
  
  /** Meta properties (new.target, import.meta) */
  MetaProperty: (node: MetaPropertyNode) => void;
}

Statement Nodes

Control flow and declaration statements.

interface StatementNodes {
  /** With statements (deprecated) */
  WithStatement: (node: WithStatementNode) => void;
  
  /** If statements and if-else */
  IfStatement: (node: IfStatementNode) => void;
  
  /** For loops */
  ForStatement: (node: ForStatementNode) => void;
  
  /** While loops */
  WhileStatement: (node: WhileStatementNode) => void;
  
  /** For-in loops */
  ForInStatement: (node: ForInStatementNode) => void;
  
  /** For-of loops */
  ForOfStatement: (node: ForOfStatementNode) => void;
  
  /** For-await loops */
  ForAwaitStatement: (node: ForAwaitStatementNode) => void;
  
  /** Do-while loops */
  DoWhileStatement: (node: DoWhileStatementNode) => void;
  
  /** Continue statements */
  ContinueStatement: (node: ContinueStatementNode) => void;
  
  /** Return statements */
  ReturnStatement: (node: ReturnStatementNode) => void;
  
  /** Break statements */
  BreakStatement: (node: BreakStatementNode) => void;
  
  /** Throw statements */
  ThrowStatement: (node: ThrowStatementNode) => void;
  
  /** Labeled statements */
  LabeledStatement: (node: LabeledStatementNode) => void;
  
  /** Try-catch-finally blocks */
  TryStatement: (node: TryStatementNode) => void;
  
  /** Catch clauses */
  CatchClause: (node: CatchClauseNode) => void;
  
  /** Switch statements */
  SwitchStatement: (node: SwitchStatementNode) => void;
  
  /** Switch cases */
  SwitchCase: (node: SwitchCaseNode) => void;
  
  /** Debugger statements */
  DebuggerStatement: () => void;
  
  /** Variable declarations (var, let, const) */
  VariableDeclaration: (node: VariableDeclarationNode, parent?: Node) => void;
  
  /** Individual variable declarators */
  VariableDeclarator: (node: VariableDeclaratorNode) => void;
}

Type and Literal Nodes

Literals, identifiers, and structured data types.

interface TypeLiteralNodes {
  /** Variable and function identifiers */
  Identifier: (node: IdentifierNode) => void;
  
  /** Rest/spread elements (...args) */
  RestElement: (node: RestElementNode) => void;
  
  /** Spread elements - alias for RestElement */
  SpreadElement: (node: SpreadElementNode) => void;
  
  /** Spread properties - alias for RestElement */
  SpreadProperty: (node: SpreadPropertyNode) => void;
  
  /** Rest properties - alias for RestElement */
  RestProperty: (node: RestPropertyNode) => void;
  
  /** Object literals and patterns */
  ObjectExpression: (node: ObjectExpressionNode) => void;
  
  /** Object patterns - alias for ObjectExpression */
  ObjectPattern: (node: ObjectPatternNode) => void;
  
  /** Object methods */
  ObjectMethod: (node: ObjectMethodNode) => void;
  
  /** Object properties */
  ObjectProperty: (node: ObjectPropertyNode) => void;
  
  /** Array literals and patterns */
  ArrayExpression: (node: ArrayExpressionNode) => void;
  
  /** Array patterns - alias for ArrayExpression */
  ArrayPattern: (node: ArrayPatternNode) => void;
  
  /** Regular expression literals */
  RegExpLiteral: (node: RegExpLiteralNode) => void;
  
  /** Boolean literals (true, false) */
  BooleanLiteral: (node: BooleanLiteralNode) => void;
  
  /** Null literal */
  NullLiteral: () => void;
  
  /** Numeric literals */
  NumericLiteral: (node: NumericLiteralNode) => void;
  
  /** String literals */
  StringLiteral: (node: StringLiteralNode, parent?: Node) => void;
}

Class Nodes

ES2015+ class syntax support.

interface ClassNodes {
  /** Class declarations */
  ClassDeclaration: (node: ClassDeclarationNode) => void;
  
  /** Class expressions - alias for ClassDeclaration */
  ClassExpression: (node: ClassExpressionNode) => void;
  
  /** Class body containing methods and properties */
  ClassBody: (node: ClassBodyNode) => void;
  
  /** Class properties (field declarations) */
  ClassProperty: (node: ClassPropertyNode) => void;
  
  /** Class methods (including constructor) */
  ClassMethod: (node: ClassMethodNode) => void;
}

Function and Method Nodes

Function declarations, expressions, and arrow functions.

interface FunctionNodes {
  /** Function expressions */
  FunctionExpression: (node: FunctionExpressionNode) => void;
  
  /** Function declarations - alias for FunctionExpression */
  FunctionDeclaration: (node: FunctionDeclarationNode) => void;
  
  /** Arrow function expressions */
  ArrowFunctionExpression: (node: ArrowFunctionExpressionNode) => void;
}

Module Nodes

ES2015+ import/export syntax.

interface ModuleNodes {
  /** Import specifiers (import { x } from 'mod') */
  ImportSpecifier: (node: ImportSpecifierNode) => void;
  
  /** Default import specifiers (import x from 'mod') */
  ImportDefaultSpecifier: (node: ImportDefaultSpecifierNode) => void;
  
  /** Default export specifiers */
  ExportDefaultSpecifier: (node: ExportDefaultSpecifierNode) => void;
  
  /** Export specifiers (export { x }) */
  ExportSpecifier: (node: ExportSpecifierNode) => void;
  
  /** Namespace export specifiers (export * as ns) */
  ExportNamespaceSpecifier: (node: ExportNamespaceSpecifierNode) => void;
  
  /** Export all declarations (export * from 'mod') */
  ExportAllDeclaration: (node: ExportAllDeclarationNode) => void;
  
  /** Named export declarations */
  ExportNamedDeclaration: (node: ExportNamedDeclarationNode) => void;
  
  /** Default export declarations */
  ExportDefaultDeclaration: (node: ExportDefaultDeclarationNode) => void;
  
  /** Import declarations */
  ImportDeclaration: (node: ImportDeclarationNode) => void;
  
  /** Namespace import specifiers (import * as ns) */
  ImportNamespaceSpecifier: (node: ImportNamespaceSpecifierNode) => void;
}

Flow Type Nodes

Complete Flow type annotation support.

interface FlowNodes {
  /** Flow any type */
  AnyTypeAnnotation: () => void;
  
  /** Flow array types (Array<T>) */
  ArrayTypeAnnotation: (node: ArrayTypeAnnotationNode) => void;
  
  /** Flow boolean type */
  BooleanTypeAnnotation: () => void;
  
  /** Flow boolean literal types */
  BooleanLiteralTypeAnnotation: (node: BooleanLiteralTypeAnnotationNode) => void;
  
  /** Flow null literal type */
  NullLiteralTypeAnnotation: () => void;
  
  /** Flow declare class */
  DeclareClass: (node: DeclareClassNode, parent?: Node) => void;
  
  /** Flow declare function */
  DeclareFunction: (node: DeclareFunctionNode, parent?: Node) => void;
  
  /** Flow declare interface */
  DeclareInterface: (node: DeclareInterfaceNode) => void;
  
  /** Flow declare module */
  DeclareModule: (node: DeclareModuleNode) => void;
  
  /** Flow declare module exports */
  DeclareModuleExports: (node: DeclareModuleExportsNode) => void;
  
  /** Flow declare type alias */
  DeclareTypeAlias: (node: DeclareTypeAliasNode) => void;
  
  /** Flow declare opaque type */
  DeclareOpaqueType: (node: DeclareOpaqueTypeNode, parent?: Node) => void;
  
  /** Flow declare variable */
  DeclareVariable: (node: DeclareVariableNode, parent?: Node) => void;
  
  /** Flow declare export */
  DeclareExportDeclaration: (node: DeclareExportDeclarationNode) => void;
  
  /** Flow function type annotations */
  FunctionTypeAnnotation: (node: FunctionTypeAnnotationNode, parent?: Node) => void;
  
  /** Flow function parameters */
  FunctionTypeParam: (node: FunctionTypeParamNode) => void;
  
  /** Flow interface extends */
  InterfaceExtends: (node: InterfaceExtendsNode) => void;
  
  /** Flow interface declarations */
  InterfaceDeclaration: (node: InterfaceDeclarationNode) => void;
  
  /** Flow intersection types (A & B) */
  IntersectionTypeAnnotation: (node: IntersectionTypeAnnotationNode) => void;
  
  /** Flow mixed type */
  MixedTypeAnnotation: () => void;
  
  /** Flow empty type */
  EmptyTypeAnnotation: () => void;
  
  /** Flow nullable types (?T) */
  NullableTypeAnnotation: (node: NullableTypeAnnotationNode) => void;
  
  /** Flow number type */
  NumberTypeAnnotation: () => void;
  
  /** Flow string type */
  StringTypeAnnotation: () => void;
  
  /** Flow this type */
  ThisTypeAnnotation: () => void;
  
  /** Flow tuple types ([T, U]) */
  TupleTypeAnnotation: (node: TupleTypeAnnotationNode) => void;
  
  /** Flow typeof types */
  TypeofTypeAnnotation: (node: TypeofTypeAnnotationNode) => void;
  
  /** Flow type aliases */
  TypeAlias: (node: TypeAliasNode) => void;
  
  /** Flow opaque types */
  OpaqueType: (node: OpaqueTypeNode) => void;
  
  /** Flow type annotations */
  TypeAnnotation: (node: TypeAnnotationNode) => void;
  
  /** Flow type parameters */
  TypeParameter: (node: TypeParameterNode) => void;
  
  /** Flow type parameter instantiation */
  TypeParameterInstantiation: (node: TypeParameterInstantiationNode) => void;
  
  /** Flow object types */
  ObjectTypeAnnotation: (node: ObjectTypeAnnotationNode) => void;
  
  /** Flow object call properties */
  ObjectTypeCallProperty: (node: ObjectTypeCallPropertyNode) => void;
  
  /** Flow object indexers */
  ObjectTypeIndexer: (node: ObjectTypeIndexerNode) => void;
  
  /** Flow object properties */
  ObjectTypeProperty: (node: ObjectTypePropertyNode) => void;
  
  /** Flow object spread properties */
  ObjectTypeSpreadProperty: (node: ObjectTypeSpreadPropertyNode) => void;
  
  /** Flow qualified type identifiers */
  QualifiedTypeIdentifier: (node: QualifiedTypeIdentifierNode) => void;
  
  /** Flow union types (A | B) */
  UnionTypeAnnotation: (node: UnionTypeAnnotationNode) => void;
  
  /** Flow type cast expressions */
  TypeCastExpression: (node: TypeCastExpressionNode) => void;
  
  /** Flow void type */
  VoidTypeAnnotation: () => void;
}

JSX Nodes

Complete JSX syntax support for React and similar libraries.

interface JSXNodes {
  /** JSX attributes (prop="value") */
  JSXAttribute: (node: JSXAttributeNode) => void;
  
  /** JSX identifiers */
  JSXIdentifier: (node: JSXIdentifierNode) => void;
  
  /** JSX namespaced names (ns:name) */
  JSXNamespacedName: (node: JSXNamespacedNameNode) => void;
  
  /** JSX member expressions (obj.prop) */
  JSXMemberExpression: (node: JSXMemberExpressionNode) => void;
  
  /** JSX spread attributes ({...props}) */
  JSXSpreadAttribute: (node: JSXSpreadAttributeNode) => void;
  
  /** JSX expression containers ({expression}) */
  JSXExpressionContainer: (node: JSXExpressionContainerNode) => void;
  
  /** JSX spread children ({...children}) */
  JSXSpreadChild: (node: JSXSpreadChildNode) => void;
  
  /** JSX text nodes */
  JSXText: (node: JSXTextNode) => void;
  
  /** JSX elements (<div>content</div>) */
  JSXElement: (node: JSXElementNode) => void;
  
  /** JSX opening elements (<div>) */
  JSXOpeningElement: (node: JSXOpeningElementNode) => void;
  
  /** JSX closing elements (</div>) */
  JSXClosingElement: (node: JSXClosingElementNode) => void;
  
  /** JSX empty expressions ({}) */
  JSXEmptyExpression: () => void;
}

Template Literal Nodes

Template literal and tagged template support.

interface TemplateLiteralNodes {
  /** Tagged template expressions (tag`template`) */
  TaggedTemplateExpression: (node: TaggedTemplateExpressionNode) => void;
  
  /** Template elements (static parts) */
  TemplateElement: (node: TemplateElementNode, parent?: Node) => void;
  
  /** Template literals (`template ${expr}`) */
  TemplateLiteral: (node: TemplateLiteralNode) => void;
}

Usage Examples

Basic AST Node Generation:

import generate from "babel-generator";
import * as t from "babel-types";

// Create AST nodes and generate code
const identifier = t.identifier('myVariable');
const literal = t.stringLiteral('hello world');
const assignment = t.assignmentExpression('=', identifier, literal);

const ast = t.program([t.expressionStatement(assignment)]);
const result = generate(ast);

console.log(result.code); // myVariable = "hello world";

Complex AST Generation:

// Generate a function with multiple node types
const params = [t.identifier('x'), t.identifier('y')];
const body = t.blockStatement([
  t.returnStatement(
    t.binaryExpression('+', t.identifier('x'), t.identifier('y'))
  )
]);

const func = t.functionDeclaration(t.identifier('add'), params, body);
const program = t.program([func]);

const result = generate(program, { compact: false });
console.log(result.code);
// function add(x, y) {
//   return x + y;
// }