Metastatic.Adapters.JavaScript.ToMeta (Metastatic v0.26.0)

View Source

Regex-based source-to-MetaAST conversion for JavaScript and TypeScript.

Performs single-pass line-by-line scanning to extract structural information from JS/TS source code, producing a proper MetaAST tree wrapped in a :container node for the file module.

Extraction Strategy

Each line is scanned in priority order:

  1. Import statements (import ... from and require(...))
  2. Class declarations (ES6 class)
  3. Function declarations, arrow functions, and class methods
  4. Function call expressions

TypeScript Handling

TypeScript type annotations are stripped before parameter counting:

  • Generic type parameters: <T, U extends Foo>
  • Parameter type annotations: name: Type, name?: Type

Summary

Functions

Parse JavaScript/TypeScript source into a MetaAST tree.

Functions

parse(source)

@spec parse(String.t()) :: {:ok, tuple()} | {:error, term()}

Parse JavaScript/TypeScript source into a MetaAST tree.

Returns {:ok, meta_ast} where meta_ast is a :container node representing the file module, wrapping all extracted declarations.