disnet/contracts.coffee — Issue #26: CoffeeScript classes supported?
Author: TobiaszCudnik
Created: 2012-02-24 00:07:44+00:00
State: open

Are CoffeeScript classes supported? I didn't have any luck while trying to put a contract on a class in various ways. Maybe i'm doing something wrong?

#### Contract for a whole class:

```coffeescript
NodeAddr = ? {
port: Num
host: Str
}
Node :: (NodeAddr, Any, Any) -> {
address: (NodeAddr) -> Any
}
Node = class
constructor: (address, services, next) ->
address: (addr) ->
```

Results in
````
TypeError: Object.getOwnPropertyDescriptor called on non-object
at Function.getOwnPropertyDescriptor (native)
at Object.getPropertyDescriptor (...node_modules/contracts.js/lib/contracts.js:410:23)
at Contract.handler (...node_modules/contracts.js/lib/contracts.js:853:25)
at Contract.check (...node_modules/contracts.js/lib/contracts.js:597:21)
at ...node_modules/contracts.js/lib/contracts.js:742:29
at
at
at Object. (...prototypes/contracts/foo.coffee:71:9)
at Object. (...prototypes/contracts/foo.coffee:86:4)
at Object. (...prototypes/contracts/foo.coffee:87:4)
```

#### Contract for a specific method:

```coffeescript
NodeAddr = ? {
port: Num
host: Str
}
class Node
constructor :: (NodeAddr, Any, Any) -> Any
constructor: (address, services, next) -> yes
address: (addr) ->
```

Results in "Error: In foo.coffee, Parse error on line 29: Unexpected 'OUTDENT'".