Registry / serialization / ranger-compiler

ranger-compiler

JSON →
library2.1.70jsnpmunverified

Ranger Compiler (v2.1.70, experimental) is a self-hosting cross-language compiler that translates Ranger source code into JavaScript, Java, Go, Swift, PHP, C++, C#, and Scala. It features type safety, classes, inheritance, operator overloading, lambda functions, generic traits, class extensions, and type inference. Unlike single-target compilers, Ranger allows writing portable algorithms that can run on multiple platforms. The compiler runs on Node.js and can be used from TypeScript. Currently, only JavaScript target is fully self-hosted; other targets are in varying stages of completeness. The package is experimental and released on npm.

npm install ranger-compiler
INSTALL
IMPORT
SIG · RANGER-COMPILER
R
ranger-compiler
serializationjavascriptv2.1.70
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Ranger (default export)
import R from 'ranger-compiler'
const R = require('ranger-compiler')
The package provides a default export. TypeScript types are included.
addFile
import R from 'ranger-compiler'; R.addFile('file.clj', source);
import { addFile } from 'ranger-compiler';
addFile is a method on the default export, not a named export.
compile (static method)
import R from 'ranger-compiler'; R.compile({ files: [], outputDir: 'bin' });
import { compile } from 'ranger-compiler';
compile is a method on the default export. Options object varies by version.
type exports (TypeScript)
import type R from 'ranger-compiler';
import R from 'ranger-compiler'; // if only types needed
TypeScript users can import the type using 'import type' for type-only usage.

Shows CLI usage and TypeScript API to compile a Ranger file to JavaScript, including loading standard library files.

// Install: npm install -g ranger-compiler // Save this as hello.clj: // class Hello { // static fn main () { // print "Hello World" // } // } // Then run: ranger-compiler hello.clj // Output: bin/hello.js // Alternatively, from TypeScript: import * as fs from 'fs'; import R from 'ranger-compiler'; // Load standard library files R.addFile('Lang.clj', fs.readFileSync('./libs/Lang.clj', 'utf8')); R.addFile('stdlib.clj', fs.readFileSync('./libs/stdlib.clj', 'utf8')); R.addFile('stdops.clj', fs.readFileSync('./libs/stdops.clj', 'utf8')); R.addFile('JSON.clj', fs.readFileSync('./libs/JSON.clj', 'utf8')); // Add your source files const files = ['hello.clj', 'other.clj']; files.forEach(f => R.addFile(f, fs.readFileSync(f, 'utf8'))); // Compile to JavaScript const result = R.compile({ files: files, outputDir: 'bin', language: 'es6' }); console.log('Compilation successful:', result);
Debug
Known issues
breakingThe default export changed from a function to an object in v2.0. Old code using `import R from 'ranger-compiler'` as a function call will break.
fix
Update code to use R.addFile, R.compile etc. instead of calling R as a function.
affects: <2.0
breakingThe `-typescript` flag was removed in v2.1.0. TypeScript annotations are now generated by default for JavaScript output.
fix
Remove the `-typescript` flag from CLI invocation. The compiler now always generates TypeScript-annotated JavaScript when compiling to ES6.
affects: >=2.1.0
deprecatedThe `-scalafiddle` flag is deprecated and will be removed in a future version.
fix
Use `-l=scala` and configure Scala output manually if needed.
affects: >=2.1.0
gotchaThe compiler is experimental; not all target languages produce compilable output. Only JavaScript target is fully self-hosted.
fix
For production, use JavaScript target. Test other targets thoroughly before relying on them.
affects: all
gotchaThe package does not include the standard library files; they must be loaded separately from the 'libs' directory in the package installation.
fix
Locate the libs folder relative to the package (e.g., node_modules/ranger-compiler/libs/) and load the necessary .clj files using addFile.
affects: >=2.0
Errors
Common errors & fixes
Cannot find module 'ranger-compiler'
Package not installed or not installed globally when using CLI.
fix
Run `npm install -g ranger-compiler` for CLI, or `npm install ranger-compiler --save-dev` for local usage in a project.
addFile is not a function
Using a named import instead of default import.
fix
Use `import R from 'ranger-compiler'` and then `R.addFile(...)`.
R is not a function
In older versions (<2.0), default export was a function. If using a newer version, this is incorrect.
fix
For v2.0+, use `import R from 'ranger-compiler';` and call methods on R instead of calling R directly.
TypeError: R.compile is not a function
Not loading standard library files or missing addFile calls.
fix
Ensure you load required files (Lang.clj, stdlib.clj, stdops.clj, JSON.clj) via `R.addFile()` before calling `R.compile()`.
Upgrade
Version history
2.1.70latest on npm
Audit
Dependencies
typescriptoptionalRequired when using TypeScript API to interface with the compiler
Agent activity
6 hits · last 30 days
node
6
Resources
ranger-compiler — npm install ranger-compiler · libregistry