Skip to main content

Crate ecma_syntax_cat

Crate ecma_syntax_cat 

Source
Expand description

§ecma-syntax-cat

ECMAScript abstract syntax tree as comp-cat-rs-idiomatic Rust types. ESTree-shaped, ES2024-complete, no panics, no Rc/Arc/RefCell, no interior mutability, no unsafe.

This crate is the foundation layer of a multi-crate reformulation of a JavaScript engine targeting Tauri integration. It deliberately has no runtime dependencies so that every downstream layer (lexer, parser, interpreter, type checker, source-map generator) can adopt it without inheriting our framework choices.

§Shape

Every AST node is a Spanned<T> value: a kind enum paired with a Span denoting the source range it was parsed from. Recursive positions are Box<T>; collections are Vec<T>. Variant fields are named on the variant rather than in per-variant structs except where the variant has enough non-trivial fields to warrant its own type (Function, ArrowFunction, Class, VariableDeclaration).

§Quick start

use ecma_syntax_cat::expression::{Expression, ExpressionKind};
use ecma_syntax_cat::identifier::Identifier;
use ecma_syntax_cat::literal::Literal;
use ecma_syntax_cat::operator::BinaryOperator;
use ecma_syntax_cat::span::Span;

let span = Span::synthetic();
let x = Expression::new(
    ExpressionKind::Identifier(Identifier::new("x")?),
    span,
);
let one = Expression::new(
    ExpressionKind::Literal(Literal::number(1.0)),
    span,
);
let sum = Expression::new(
    ExpressionKind::Binary {
        operator: BinaryOperator::Add,
        left: Box::new(x),
        right: Box::new(one),
    },
    span,
);
assert_eq!(format!("{sum}"), "(x + 1)");

Modules§

class
Class definitions and member kinds.
declaration
Variable declarations.
error
Construction-time error type.
expression
ECMAScript expressions.
function
Function definitions shared between function declarations, function expressions, and method definitions.
identifier
Identifier newtypes.
literal
Static ECMAScript literals.
module
ECMAScript module-level items: imports and exports.
operator
ECMAScript operator enums, factored out of the expression variants.
pattern
Binding patterns used in destructuring, parameter lists, and variable-declarator targets.
program
The top-level Program node.
span
Source-position newtypes and the Spanned wrapper.
statement
ECMAScript statements.