faylang / fay

A proper subset of Haskell that compiles to JavaScript
https://github.com/faylang/fay/wiki
BSD 3-Clause "New" or "Revised" License
1.29k stars 86 forks source link

Add support for the use of "debugger;" in FFI #389

Closed bitemyapp closed 9 years ago

bitemyapp commented 10 years ago

Currently get: unexpected reserved word "debugger" for an otherwise valid lambda :(

bergmark commented 10 years ago

Thanks for the reminder! This is a restriction in language-ecmascript, i have been meaning to ask them if it's possible to allow it. I'll open an issue in their repo.

bergmark commented 10 years ago

For now, you can do

function f(%1) { debugger; ... }

foo :: X
foo = ffi "f(%1)"
bitemyapp commented 10 years ago

@bergmark this sounds very helpful but I'm a little confused as to what is meant here. It wasn't clear to me that I could inline JavaScript functions without being inside an ffi string into Fay code. Is that what your example is illustrating?

bergmark commented 10 years ago

Forgot to reply to this, sorry!

No it's not valid to inline JS outside the FFI, I meant that you can have a normal JS function that's included which calls debugger. For instance

Debug.js:

function debug(f) { debugger; return f(); }

FayProgram.hs:

foo :: Int -> Int
foo = ffi "debug(function () { return %1; })"

Usually I just add break points in the browser or modify the produced js instead of doing this.

dead-claudia commented 9 years ago

Would it be possible to do something like this? I don't have a lot of experience with Fay (or Haskell, for that matter).

debugBreak :: a -> a
debugBreak = ffi "(function(a){debugger;return a})(%1)"
bergmark commented 9 years ago

@impinball We parse the ffi string as a javascript expression using the language-ecmascript package and it doesn't allow debugger at all.

IIRC this will be supported in language-ecmascript-1.0 but I'm not sure when that will be released.

dead-claudia commented 9 years ago

Oh. It seems odd that it's not even supported.