typed-coffee-script

Unfancy JavaScript with Types

npm install typed-coffee-script
12 downloads in the last week
18 downloads in the last month

TypedCoffeeScript

Superset of CoffeeScript with types

Concepts

  • Allow to compile all coffee-script
  • Optional type and restrict member access under definition
  • Easy to add type to symbol from the middle of development
  • Easy to replace coffee-script
  • Check type againt cscodegen AST, not in compiler

Getting started

Install

$ npm install -g typed-coffee-script
$ tcoffee foo.coffee

Compile

$ tcoffee --js  < scratch.coffee > scratch.js

or use it with grunt mizchi/grunt-typed-coffee-script

or minimal project sample

$ git clone https://github.com/mizchi/sample-typed-coffee-project.git
$ cd sample-typed-coffee-project
$ npm install
$ grunt typedcoffee

Examples

Assigment with type

n :: Int = 3

Pre-defined symbol

x :: Number
x = 3.14

Struct

struct Point {
  x :: Number
  y :: Number
}
p :: Point = {x: 3, y: 3}

Typed Array

line :: Point[] = [{x: 3, y: 4}, {x: 8, y: 5}, p]

Typed Function

f :: Int -> Int
f = (n) -> n

# left side type definition
fl :: Number -> Point = (n) ->  {x: n, y: n * 2}
# right side
fr = (n :: Number) :: Number ->  n * n

Generics

struct Hash<K, V> {
  get :: K -> V
  set :: K * V -> ()
}

hash :: Hash<String, Number> = {
  get: (key) -> @[key]
  set: (key, val) -> @[key] = val
}
hash.set "a", 1
num :: Number = hash.get "a"

Class with this scope

class X
  # bound to this
  num :: Number
  f :: Number -> Number
  f: (n) ->
    @num = n

x :: X = new X
x.f 3

Class with implemtns

class Point
  x :: Int
  y :: Int

struct Size {
  width  :: Int
  height :: Int
}

class Entity extends Object implements Point, Size
e :: {x :: Int, width :: Int} = new Entity

Forked by CoffeeScript II: The Wrath of Khan

          {
       }   }   {
      {   {  }  }
       }   }{  {
      {  }{  }  }             _____       __  __
     ( }{ }{  { )            / ____|     / _|/ _|
   .- { { }  { }} -.        | |     ___ | |_| |_ ___  ___
  (  ( } { } { } }  )       | |    / _ \|  _|  _/ _ \/ _ \
  |`-..________ ..-'|       | |___| (_) | | | ||  __/  __/
  |                 |        \_____\___/|_| |_| \___|\___|       .-''-.
  |                 ;--.                                       .' .-.  )
  |                (__  \     _____           _       _       / .'  / /
  |                 | )  )   / ____|         (_)     | |     (_/   / /
  |                 |/  /   | (___   ___ _ __ _ _ __ | |_         / /
  |                 (  /     \___ \ / __| '__| | '_ \| __|       / /
  |                 |/       ____) | (__| |  | | |_) | |_       . '
  |                 |       |_____/ \___|_|  |_| .__/ \__|     / /    _.-')
   `-.._________..-'                           | |           .' '  _.'.-''
                                               |_|          /  /.-'_.'
                                                           /    _.'
                                                          ( _.-'

Status

Complete enough to use for nearly every project. See the roadmap to 2.0.

Getting Started

npm install -g coffee-script-redux
coffee --help
coffee --js <input.coffee >output.js

Before transitioning from Jeremy's compiler, see the intentional deviations from jashkenas/coffee-script wiki page.

Development

git clone git://github.com/michaelficarra/CoffeeScriptRedux.git && cd CoffeeScriptRedux && npm install
make clean && git checkout -- lib && make -j build && make test

Notable Contributors

I'd like to thank the following financial contributors for their large donations to the Kickstarter project that funded the initial work on this compiler. Together, you donated over $10,000. Without you, I wouldn't have been able to do this.

  • Groupon, who is generously allowing me to work in their offices
  • Trevor Burnham
  • Shopify
  • Abakas
  • 37signals
  • Brightcove
  • Gaslight
  • Pantheon
  • Benbria
  • Sam Stephenson
  • Bevan Hunt
  • Meryn Stol
  • Rob Tsuk
  • Dion Almaer
  • Andrew Davey
  • Thomas Burleson
  • Michael Kedzierski
  • Jeremy Kemper
  • Kyle Cordes
  • Jason R. Lauman
  • Martin Drenovac (Envizion Systems - Aust)
  • Julian Bilcke
  • Michael Edmondson

And of course, thank you Jeremy (and all the other contributors) for making the original CoffeeScript compiler.

npm loves you