Firescript Transpiler

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

Transpiler module for Firescript, version 0.10.0. Provides two transpiler classes: JavascriptTranspiler to convert Firescript AST to JavaScript source code, and FirescriptTranspiler to output Firescript source. Low-level tool intended for building compilers or tooling around Firescript. Release cadence is unknown.

error TypeError: transpiler.transpile is not a function
cause The transpiler instance was not created correctly; likely using default import without instantiation.
fix
const transpiler = new JavascriptTranspiler(); then transpiler.transpile(ast);
error SyntaxError: Unexpected token 'export'
cause Using ES module import syntax in a CommonJS environment without transpilation.
fix
Use CommonJS require: const { JavascriptTranspiler } = require('firescript-transpiler');
gotcha Both classes are exported as default exports from the same module, so you cannot import them separately via two default imports.
fix Use a single default import and destructure: import TranspilerModule from 'firescript-transpiler'; const { JavascriptTranspiler, FirescriptTranspiler } = TranspilerModule;
gotcha The transpiler expects an AST object, not source code string. Passing a string will throw an error.
fix First parse the source with a Firescript parser (e.g., firescript-parser) to get an AST, then pass it to transpile().
npm install firescript-transpiler
yarn add firescript-transpiler
pnpm add firescript-transpiler

Shows how to import and use both transpiler classes to convert a Firescript AST to JavaScript and Firescript source.

import { JavascriptTranspiler, FirescriptTranspiler } from 'firescript-transpiler';
import { parse } from 'firescript-parser'; // hypothetical parser

const source = 'let x = 5';
const ast = parse(source);

const jsTranspiler = new JavascriptTranspiler();
const jsCode = jsTranspiler.transpile(ast);
console.log(jsCode);

const fsTranspiler = new FirescriptTranspiler();
const fsCode = fsTranspiler.transpile(ast);
console.log(fsCode);