I am migrating a small script from coco to LiveScript:
D = (obj, l = 20) ->
if (l > 0)
new
@[k] = (try D(v, l - 1) catch (e) e) for k, v in obj
else
obj
This code, which is valid in coco, does not compile in LiveScript:
Parse error on line 4: Unexpected 'FOR'
I was trying to modify that code the following way (for LiveScript):
D = (obj, l = 20) ->
if (l > 0)
new
for k, v of obj
@[k] = (try D(v, l - 1) catch (e) e)
else
obj
But still it does not compile:
invalid assign on line 5
How to rewrite this coco script into LiveScript? (Not in the plain JavaScript way -- without using a temporary variable.)
Just FYI, LiveScript has object comprehensions
D = (obj, l = 20) ->
if l > 0
{[k, try D(v, l - 1) catch => e] for k, v of obj}
else
obj
so, the answer is that catch (e) e
is not valid in LS because LS allowed expressions as catchee for destructuring (catch {msg}
) which means you must pass it a block catch => e
(the e
is implicit, but you can make it explicit : catch e => e
).