gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.32k stars 156 forks source link

long long if's (how-to go about it) #1091

Open determin1st opened 4 years ago

determin1st commented 4 years ago

For example, if you have some if:

if (typeof options.data == 'string') or (typeof! options.data == 'URLSearchParams')
  true

It's rather long and with more indenting inside some function function with tabs/spaces... readability (of this line) should be broken, eventually..

On the other hand, having this javascript code:

if (typeof options.data === 'string' ||
    toString$.call(options.data).slice(8, -1) === 'URLSearchParams')
{
  true;
}

looks better, right?

So, the question is how to go about long if's, how to indent them, space them, multiline them (in livescript ofc) or this is not possible/resonable/smart enough etc?

ceremcem commented 4 years ago

How about:

if (true or
    false) and
    false
    #----
    console.log "foo"
else
    console.log "bar"
vendethiel commented 4 years ago

if typeof! options.data in <[String URLSearchParams]>

determin1st commented 4 years ago

Great, will use both!

anko commented 4 years ago

You can use a backslash to ignore a newline:

if something? \
  or something-else?
  do-something!