QuickBEAM.JS (QuickBEAM v0.10.6)

Copy Markdown View Source

JavaScript and TypeScript toolchain powered by OXC.

Provides parsing, transformation, minification, and bundling of JS/TS code via Rust NIFs — no Node.js or Bun required.

These are thin wrappers around the OXC library. See OXC module docs for full option details.

Summary

Functions

Bundle multiple TS/JS modules into a single self-executing script.

Bundle multiple TS/JS modules, raising on error.

Bundle an entry file from disk with all its dependencies.

Collect values from an AST tree by walking and filtering nodes.

Extract import specifiers from JS/TS source.

Like imports/2 but raises on errors.

Minify JavaScript source code.

Minify JavaScript source code, raising on error.

Parse JS/TS source into an AST.

Parse JS/TS source into an AST, raising on error.

Apply position-based patches to a source string.

Depth-first post-order AST traversal. Like Macro.postwalk/2.

Depth-first post-order AST traversal with accumulator. Like Macro.postwalk/3.

Transform TypeScript/JSX to plain JavaScript.

Transform TypeScript/JSX to plain JavaScript, raising on error.

Check if JS/TS source is syntactically valid.

Walk an AST tree, calling fun on every node.

Functions

beam_js()

browser_js()

bundle(files, opts \\ [])

@spec bundle(
  [{String.t(), String.t()}],
  keyword()
) :: {:ok, String.t() | map()} | {:error, String.t()}

Bundle multiple TS/JS modules into a single self-executing script.

Accepts a list of {filename, source} tuples. Resolves imports between them, topologically sorts by dependencies, strips module syntax, and wraps the result in an IIFE.

files = [
  {"utils.ts", "export function add(a: number, b: number) { return a + b }"},
  {"main.ts", "import { add } from './utils'\nconsole.log(add(1, 2))"}
]
{:ok, js} = QuickBEAM.JS.bundle(files)

Options

  • :minify — minify the output (default: false)
  • :banner — string to prepend before the IIFE
  • :footer — string to append after the IIFE
  • :sourcemap — generate source map (returns %{code, sourcemap})
  • :define — compile-time identifier replacements
  • :drop_console — remove console.* calls (default: false)

bundle!(files, opts \\ [])

@spec bundle!(
  [{String.t(), String.t()}],
  keyword()
) :: String.t() | map()

Bundle multiple TS/JS modules, raising on error.

bundle_file(path, opts \\ [])

@spec bundle_file(
  String.t(),
  keyword()
) :: {:ok, String.t() | map()} | {:error, term()}

Bundle an entry file from disk with all its dependencies.

Recursively resolves imports — both relative paths (./utils) and bare specifiers (lodash-es) via node_modules/. Reads all sources, then bundles them with OXC.bundle/2.

{:ok, js} = QuickBEAM.JS.bundle_file("src/main.ts")

The node_modules/ directory is found by walking up from the entry file. Override with the :node_modules option.

Accepts all options from bundle/2 plus:

  • :node_modules — explicit path to node_modules/ directory

collect(node, fun)

@spec collect(map(), (map() -> {:keep, any()} | :skip)) :: [any()]

Collect values from an AST tree by walking and filtering nodes.

See OXC.collect/2 for details.

imports(source, filename)

@spec imports(String.t(), String.t()) :: {:ok, [String.t()]} | {:error, [String.t()]}

Extract import specifiers from JS/TS source.

Faster than parse/2 + collect/2 — skips full AST serialization and returns only the import source strings. Type-only imports (import type { ... }) are excluded.

{:ok, imports} = QuickBEAM.JS.imports("import { ref } from 'vue'", "test.ts")
# => {:ok, ["vue"]}

imports!(source, filename)

@spec imports!(String.t(), String.t()) :: [String.t()]

Like imports/2 but raises on errors.

minify(source, filename, opts \\ [])

@spec minify(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, [String.t()]}

Minify JavaScript source code.

{:ok, min} = QuickBEAM.JS.minify("const x = 1 + 2;", "file.js")

Options

  • :compress — apply compression optimizations (default: true)
  • :mangle — mangle variable names (default: true)

minify!(source, filename, opts \\ [])

@spec minify!(String.t(), String.t(), keyword()) :: String.t()

Minify JavaScript source code, raising on error.

node_js()

parse(source, filename)

@spec parse(String.t(), String.t()) :: {:ok, map()} | {:error, [String.t()]}

Parse JS/TS source into an AST.

{:ok, ast} = QuickBEAM.JS.parse("const x: number = 1", "file.ts")

parse!(source, filename)

@spec parse!(String.t(), String.t()) :: map()

Parse JS/TS source into an AST, raising on error.

patch_string(source, patches)

@spec patch_string(String.t(), [map()]) :: String.t()

Apply position-based patches to a source string.

See OXC.patch_string/2 for details.

postwalk(node, fun)

@spec postwalk(map(), (map() -> map())) :: map()

Depth-first post-order AST traversal. Like Macro.postwalk/2.

See OXC.postwalk/2 for details.

postwalk(node, acc, fun)

@spec postwalk(map(), acc, (map(), acc -> {map(), acc})) :: {map(), acc}
when acc: term()

Depth-first post-order AST traversal with accumulator. Like Macro.postwalk/3.

See OXC.postwalk/3 for details.

transform(source, filename, opts \\ [])

@spec transform(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, [String.t()]}

Transform TypeScript/JSX to plain JavaScript.

{:ok, js} = QuickBEAM.JS.transform("const x: number = 1", "file.ts")
# => {:ok, "const x = 1;\n"}

Options

  • :jsx — enable JSX transformation (default: auto-detected from filename)

transform!(source, filename, opts \\ [])

@spec transform!(String.t(), String.t(), keyword()) :: String.t()

Transform TypeScript/JSX to plain JavaScript, raising on error.

valid?(source, filename)

@spec valid?(String.t(), String.t()) :: boolean()

Check if JS/TS source is syntactically valid.

QuickBEAM.JS.valid?("const x = 1", "file.js")
# => true

walk(node, fun)

@spec walk(map(), (map() -> any())) :: :ok

Walk an AST tree, calling fun on every node.

See OXC.walk/2 for details.