2

I have this valid CoffeeScript and wish to convert it to LiveScript. Can someone explain why it fails to convert? Also to give a converted one?

TodoCtrl = (scope) ->
  scope.addTodo = ->
    scope.todos.push
      text: scope.todoText
      done: false
    scope.todoText = ''

You can use this to compile CoffeeScript.

http://coffeescript.org/

You can use this to compile LiveScript.

http://gkz.github.com/LiveScript/

Nemo
  • 3,104
  • 2
  • 30
  • 46
Phil
  • 46,436
  • 33
  • 110
  • 175

1 Answers1

5

You are calling the function scope.todos.push against an implicit block starting with an implicit object. You must use do in LiveScript, as it does't do this special case (just think of do as parentheses around the block). See https://github.com/gkz/LiveScript/issues/50 for reasons.

The code you want:

TodoCtrl = (scope) ->
  scope.addTodo = ->
    scope.todos.push do
      text: scope.todoText
      done: false
    scope.todoText = ''

which is equivalent to (ie do is just parentheses)

TodoCtrl = (scope) ->
  scope.addTodo = ->
    scope.todos.push(
      text: scope.todoText
      done: false
    )
    scope.todoText = ''

Glad to see you using LiveScript!

gkz
  • 248
  • 1
  • 7
  • Thanks! for my new project I combine LiveScript/AngularJS/Brunch.io (which uses NodeJS) as these all seem to be the best to my eyes at the moment. – Phil Jul 22 '12 at 03:59