typed-coffee-script

Unfancy JavaScript with Types

TypedCoffeeScript

CoffeeScript with Types.

This repository is heavily under development and unstable. See below milestone.

  • Structual Subtyping
  • Superset of CoffeeScript
  • Easy to replace coffee (pass unannotated coffee)
  • Pessimistic type interfaces

To pass dynamic type system, TypedCoffeeScript expects symbol to implicit node by default. If compiler compares implicit node type and implicit node type and fails, it recover to implicit Any automatically.

Install and run!

$ npm install -g typed-coffee-script
$ tcoffee -c foo.typed.coffee # compile
$ tcoffee foo.typed.coffee # execute
$ tcoffee # repl
  • .tcoffee and .typed.coffee are compiled by TypedCoffeeScript compiler.
  • Compiler uses jashkenas/coffeescript in require('./foo.coffee') by default.
  • if you want to compile .coffee with TypedCoffeeScript, add --self option.

Current biggest issues is implementation of typescript d.ts importer.

TypeScript AST parser is ready. mizchi/dts-parser

  • Module system
  • Better namespace resolver
  • Splats argument such as ( args...: T[] ) ->
  • This scope in bound function
  • Primitive type interface
  • Array type interface
  • Polymorphic method type overload
  • Nested array with depth Int[][]
  • Type alias such as typealias Bar = Foo<T>[]
  • TypeScript *.d.ts importer
  • Coverage of types to symbol
  • Be stable(RC for 1.0)
  • (Fix CoffeeScriptRedux bugs if I can)
  • Compiler can't resolve module namespace when namespace has more than three dots, such as A.B.C.d
  • Take over all coffee-script-redux problems
    • super with member access super().member
    • object literal parsing in class field

You can use this compiler without type annotation. All test by CoffeeScriptRedux passed.

If you encounter bugs, such as type interface... parser..., please report as github issues or pull request to me. I also welcome new syntax proposal.

I DON'T reccomend to use in production yet.

  • Generics
  • TypeArgument
  • Fix examples
  • Recognise extensions in require
  • Runnable by tcoffee foo.typed.coffee that has require
  • Class static member type interface
  • Struct with implements
  • Rewrite internal AST and type interfaces
  • Add new command line interface
  • Refactor
  • Nullable
  • MemberAccess in struct definition
  • Infer fuction return type with return in Block
  • Destructive Assignment
  • self hosting
  • Implement basic concepts
:: Int = 3
:: Number
= 3.14
:: Number?
= 3.14
= null
list :: Int[= [1..10]
listWithNull :: Int?[= [1null3]

In v0.10, imperfect to struct.

struct Point
  @name :: String
  x :: Number
  y :: Number
:: Point = {x: 3y: 3}
name :: String = Point.name
 
struct Point3d implements Point
  z :: Number

TypedCoffeeScript has module system like TypeScript

module A.B
    class @C
        a :: Int
abc :: A.B.C = new A.B.C
# pre define 
f1 :: Int -> Int
f1 = (n) -> n
 
# annotation 
f2 :: Number -> Point = (n) -> x: ny: n * 2
 
# multi arguments 
f3 :: (Int, Int) -> Int = (m, n) -> m * n
 
# another form of arguments 
f4 :: Int * Int -> Int = (m, n) -> m * n
 
# partial applying 
fc :: Int -> Int -> Int
fc = (m) -> (n) -> m * n
class X
  # bound to this 
  num :: Number
  f   :: Number -> Number
 
  f: (n) ->
    @num = n
 
:: = new X
:: Number = x.3
class Point
  x :: Int
  y :: Int
 
struct Size
  width  :: Int
  height :: Int
 
class Entity extends Point implements Size
:: {x :: Intwidth :: Int} = new Entity
# struct 
struct Value<TU>
    value :: U
struct Id<AB>
    id :: Value<AB>
obj :: Id<IntString> =
  id:
    value: 'value'
 
# function type arguments 
map<TU> :: T[* (T -> U) -> U[]
map = (list, fn) ->
  for i in list
    fn(i)
list :: String[= map<IntString> [1..10](n) -> 'i'
 
# class type arguments 
class Class<A>
  f :: Int -> Int
  constructor :: A -> ()
  constructor: (a) ->
= new Class<Int>(1)

Forked from CoffeeScript II: The Wrath of Khan

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

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

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.

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

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.