{"id":26141,"library":"ranger-compiler","title":"Ranger Compiler","description":"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.","status":"active","version":"2.1.70","language":"javascript","source_language":"en","source_url":"https://github.com/terotests/Ranger","tags":["javascript","Compiler","typescript"],"install":[{"cmd":"npm install ranger-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add ranger-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add ranger-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required when using TypeScript API to interface with the compiler","package":"typescript","optional":true}],"imports":[{"note":"The package provides a default export. TypeScript types are included.","wrong":"const R = require('ranger-compiler')","symbol":"Ranger (default export)","correct":"import R from 'ranger-compiler'"},{"note":"addFile is a method on the default export, not a named export.","wrong":"import { addFile } from 'ranger-compiler';","symbol":"addFile","correct":"import R from 'ranger-compiler';\nR.addFile('file.clj', source);"},{"note":"compile is a method on the default export. Options object varies by version.","wrong":"import { compile } from 'ranger-compiler';","symbol":"compile (static method)","correct":"import R from 'ranger-compiler';\nR.compile({ files: [], outputDir: 'bin' });"},{"note":"TypeScript users can import the type using 'import type' for type-only usage.","wrong":"import R from 'ranger-compiler'; // if only types needed","symbol":"type exports (TypeScript)","correct":"import type R from 'ranger-compiler';"}],"quickstart":{"code":"// Install: npm install -g ranger-compiler\n// Save this as hello.clj:\n// class Hello {\n//     static fn main () {\n//         print \"Hello World\"\n//     }\n// }\n// Then run: ranger-compiler hello.clj\n// Output: bin/hello.js\n\n// Alternatively, from TypeScript:\nimport * as fs from 'fs';\nimport R from 'ranger-compiler';\n\n// Load standard library files\nR.addFile('Lang.clj', fs.readFileSync('./libs/Lang.clj', 'utf8'));\nR.addFile('stdlib.clj', fs.readFileSync('./libs/stdlib.clj', 'utf8'));\nR.addFile('stdops.clj', fs.readFileSync('./libs/stdops.clj', 'utf8'));\nR.addFile('JSON.clj', fs.readFileSync('./libs/JSON.clj', 'utf8'));\n\n// Add your source files\nconst files = ['hello.clj', 'other.clj'];\nfiles.forEach(f => R.addFile(f, fs.readFileSync(f, 'utf8')));\n\n// Compile to JavaScript\nconst result = R.compile({\n  files: files,\n  outputDir: 'bin',\n  language: 'es6'\n});\nconsole.log('Compilation successful:', result);","lang":"typescript","description":"Shows CLI usage and TypeScript API to compile a Ranger file to JavaScript, including loading standard library files."},"warnings":[{"fix":"Update code to use R.addFile, R.compile etc. instead of calling R as a function.","message":"The 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.","severity":"breaking","affected_versions":"<2.0"},{"fix":"Remove the `-typescript` flag from CLI invocation. The compiler now always generates TypeScript-annotated JavaScript when compiling to ES6.","message":"The `-typescript` flag was removed in v2.1.0. TypeScript annotations are now generated by default for JavaScript output.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Use `-l=scala` and configure Scala output manually if needed.","message":"The `-scalafiddle` flag is deprecated and will be removed in a future version.","severity":"deprecated","affected_versions":">=2.1.0"},{"fix":"For production, use JavaScript target. Test other targets thoroughly before relying on them.","message":"The compiler is experimental; not all target languages produce compilable output. Only JavaScript target is fully self-hosted.","severity":"gotcha","affected_versions":"all"},{"fix":"Locate the libs folder relative to the package (e.g., node_modules/ranger-compiler/libs/) and load the necessary .clj files using addFile.","message":"The package does not include the standard library files; they must be loaded separately from the 'libs' directory in the package installation.","severity":"gotcha","affected_versions":">=2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install -g ranger-compiler` for CLI, or `npm install ranger-compiler --save-dev` for local usage in a project.","cause":"Package not installed or not installed globally when using CLI.","error":"Cannot find module 'ranger-compiler'"},{"fix":"Use `import R from 'ranger-compiler'` and then `R.addFile(...)`.","cause":"Using a named import instead of default import.","error":"addFile is not a function"},{"fix":"For v2.0+, use `import R from 'ranger-compiler';` and call methods on R instead of calling R directly.","cause":"In older versions (<2.0), default export was a function. If using a newer version, this is incorrect.","error":"R is not a function"},{"fix":"Ensure you load required files (Lang.clj, stdlib.clj, stdops.clj, JSON.clj) via `R.addFile()` before calling `R.compile()`.","cause":"Not loading standard library files or missing addFile calls.","error":"TypeError: R.compile is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}