Smack JS Compiler

raw JSON →
1.1.1 verified Fri May 01 auth: no javascript

A compiler/transpiler for the purely functional language 'Smack', converting Smack source code to JavaScript. The current stable version is 1.1.1, with moderate release cadence. Key differentiator: it compiles a minimal functional language to JavaScript, targeting both Node.js and browser environments. Written in JavaScript, it includes a parser and intermediary representation. Not to be confused with other Smack-related tools.

error SyntaxError: Unexpected token 'export'
cause Using CommonJS require in an ESM-only package.
fix
Switch to ESM imports: import { compile } from 'smack-js-compiler'.
error Cannot find module 'smack-js-compiler'
cause Package not installed or incorrect import path.
fix
Install the package: npm install smack-js-compiler.
error TypeError: compile is not a function
cause Default import used when export is named.
fix
Use named import: import { compile } from 'smack-js-compiler'.
gotcha The package does not provide type definitions; TypeScript users may need to declare module.
fix Add a declaration file or use `// @ts-ignore`.
breaking Version 1.0.0 changed the primary export from default to named (`compile`).
fix Update imports from `import compile from 'smack-js-compiler'` to `import { compile } from 'smack-js-compiler'`.
deprecated The `parse` function was marked deprecated in v1.1.0; use `compile` with parse options instead.
fix Replace `parse(code)` with `compile(code, { parseOnly: true })`.
npm install smack-js-compiler
yarn add smack-js-compiler
pnpm add smack-js-compiler

Compiles a simple Smack function definition to JavaScript using the named compile export.

import { compile } from 'smack-js-compiler';

const smackCode = `
  def main = add(2, 3)
  def add(a, b) = a + b
`;

try {
  const jsCode = compile(smackCode);
  console.log(jsCode);
} catch (err) {
  console.error('Compilation failed:', err.message);
}