β¨ Features
JScriptor is a lightweight, typed superset of JavaScript that catches type errors early and keeps your codebase clean and maintainableβwithout any heavy setup.
Type Inference
Automatic type detection using Hindley-Milner type system with advanced unification algorithms.
Polymorphic Functions
Supports functions that work with multiple types, enabling flexible and reusable code.
Zero Configuration
Works out of the box with sensible defaults. No complex setup required.
Clear Error Reporting
Detailed type error messages with file locations and helpful hints for faster debugging.
Configurable
Customize type checking behavior via
jscriptor.config.js
for your project needs.
Fast & Lightweight
Minimal overhead with optimized performance for large codebases.
Supported JavaScript Features
-
Variable declarations (
const
,let
) - Arrow functions and function calls
-
Binary expressions (
+
,-
,*
,/
,==
,!=
, etc.) - Conditional expressions (ternary operator)
- Array and object literals
- String, number, and boolean literals
- Return statements
- Block statements with scope management
π¦ Installation
Install JScriptor as a development dependency in your project.
npm install --save-dev jscriptor
β‘ Quick Start
1. Initialize Configuration
jscriptor init
This creates a jscriptor.config.js
file with sensible
defaults.
2. Add to package.json
{
"scripts": {
"typecheck": "jscriptor check-all",
"typecheck:file": "jscriptor check"
}
}
3. Run Type Checking
# Check all files based on config
npm run typecheck
# Check a specific file
npm run typecheck:file src/app.js
CLI Commands
jscriptor init
Creates a jscriptor.config.js
file with sensible
defaults
jscriptor check <file>
Type checks a single JavaScript file
jscriptor check-all
Type checks all files matching patterns in your config
jscriptor help
Displays usage information and available commands
π§ͺ Examples
β Valid Code (No Type Errors)
// Function with type inference
const identity = (x) => { return x; };
const result = identity(42); // β
Number type inferred
// Binary operations with matching types
const sum = 5 + 10; // β
Number + Number
const message = "Hello" + " World"; // β
String + String
// Conditional expressions
const max = a > b ? a : b; // β
Boolean condition
β Type Errors
// Type mismatch in binary operation
const badMath = 5 + "hello"; // β Number + String
// Wrong argument type for function
const add = (x, y) => { return x + y; };
const res = add(5, "hello"); // β String passed to function expecting Number
// Non-boolean condition in ternary
const num = 5;
const result = num ? "yes" : "no"; // β Number used as condition
π₯οΈ Example Output
π Checking src/simple-errors.js...
β 1 error(s) found
1. [E_TERNARY_TEST_NOT_BOOL] Type mismatch in ternary: condition must be Boolean, got Number
at src/simple-errors.js:15:20
13 |
14 | // Type error: ternary with non-boolean condition
15 | const badTernary = num ? "yes" : "no";
| ^
16 |
17 | console.log("This file has type errors!");
π‘ Hint: The condition in a ternary operator must evaluate to a boolean
π Summary: Found 1 type error(s) in src/simple-errors.js
βοΈ Configuration
JScriptor uses a jscriptor.config.js
file to configure
type checking behavior. Run jscriptor init
to create a
default configuration file.
Configuration Options
module.exports = {
// Entry points - files or directories to type-check
include: [
"src/**/*.js",
"lib/**/*.js"
],
// Files to exclude from type checking
exclude: [
"node_modules/**/*",
"dist/**/*",
"build/**/*",
"**/*.test.js",
"**/*.spec.js"
],
// Output directory for compiled files (optional)
outDir: null,
// Whether to watch for file changes
watch: false,
// Strict mode settings
strict: {
// Require explicit type annotations
explicitTypes: false,
// Check for unused variables
unusedVars: false,
// Check for unreachable code
unreachableCode: false,
},
// Type checking options
typeCheck: {
// Whether to infer types from usage
inferTypes: true,
// Whether to check function return types
checkReturnTypes: true,
// Whether to check parameter types
checkParameterTypes: true,
},
// Compiler options
compiler: {
// Whether to preserve comments
preserveComments: true,
// Whether to generate source maps
sourceMaps: false,
// Target JavaScript version
target: "es2020",
}
};
include
Glob patterns for files to type check
exclude
Glob patterns for files to skip
strict
Strict mode settings for additional checks
typeCheck
Core type checking behavior
compiler
Compilation and output options
π How It Works

π€ Tokenize
Parses JavaScript into tokens using lexical analysis
π³ Parse
Builds an Abstract Syntax Tree (AST) from tokens
π Type Check
Infers and validates types using Hindley-Milner system
π Report
Generates clear error messages with file locations
π§ Development
Want to contribute or test JScriptor locally? Here's how to set up the development environment.
Local Development Setup
# Clone the repository
git clone https://github.com/Hareesh108/jscriptor.git
cd jscriptor
# Install dependencies
npm install
# Link the CLI locally
npm link
# Test on an example file
echo 'const x = 5; const y = "hi"; const z = x + y;' > test.js
jscriptor test.js
# Unlink when done
npm unlink -g jscriptor
Project Structure
src/
βββ cli.js # Command-line interface
βββ compile.js # Main compilation entry point
βββ config.js # Configuration loading and processing
βββ 01-tokenize/ # Lexical analysis
β βββ tokenize.js # Tokenizer implementation
β βββ utils.js # Token utilities
βββ 02-parse/ # Syntax analysis
β βββ parse.js # Parser implementation
βββ 03-typecheck/ # Type checking and inference
β βββ typecheck.js # Main type checker
β βββ db.js # Type database
β βββ errors.js # Error reporting
β βββ scope.js # Scope management
β βββ unification.js # Type unification
β βββ type-utils.js # Type utilities
β βββ utils.js # General utilities
β βββ visitors/ # AST visitors
β βββ index.js # Visitor dispatcher
β βββ declarations.js # Declaration visitors
β βββ expressions.js # Expression visitors
β βββ functions.js # Function visitors
β βββ identifiers.js # Identifier visitors
β βββ literals.js # Literal visitors
βββ test/ # Test files
βββ check.js # Test runner
βββ test.js # Test utilities
βββ typecheck.spec.js # Type checker tests
π Roadmap
Current Version (v0.0.5)
- Basic type inference and checking
- CLI interface with configuration support
- Error reporting with file locations
- Support for common JavaScript constructs
Upcoming Features
- Enhanced CLI output with syntax highlighting
- Plugin system for custom type rules
- VS Code extension for real-time type checking
- Type annotations support (optional)
- Watch mode for continuous type checking
- Performance optimizations for large codebases