Code Monkey home page Code Monkey logo

Comments (6)

rstacruz avatar rstacruz commented on June 17, 2024

Just a note to myself or whoever will take on this, this also needs some optimizations for if's (if (cond) { x } else { y } => if cond then x else y) :)

from js2coffee.

michaelficarra avatar michaelficarra commented on June 17, 2024

This compilation has improved since the commit that closed #42, but it still doesn't recurse.

from js2coffee.

rstacruz avatar rstacruz commented on June 17, 2024

Weird, you're right. It will recurse down to switches, but it seems to stop on nested if's.

function a() { switch (a) { case B: switch (x) { case Y: if(b) { return "hello there"; } } } } works:

a = ->
  switch a
    when B
      switch x
        when Y
          if b
            "hello there"

from js2coffee.

rstacruz avatar rstacruz commented on June 17, 2024

By the way, on second thought it's probably better for that snippet (in the original post) to compile to:

a = (b, c) ->
  if b
    2
  else
    if c
      3
    else
      4

While using the ternary operator (if x then y else z) makes the example look pretty, what would be the deciding factor on when to reduce an if/else to a single line? It may look pleasing in this theoretical example, but it can potentially ruin the readability of something else in the real world.

from js2coffee.

michaelficarra avatar michaelficarra commented on June 17, 2024

I've been using single-line conditonals interchangeably with multiline conditonals. I don't think this project is anywhere near the point where we start talking about formatting. If we had to, though, I'd say that condional bodies with a single statement should be pushed up next to the condition. So, by that convention, I'd compile it as

a = (b, c) ->
  if b then 2
  else
    if c then 3 else 4

from js2coffee.

dburt avatar dburt commented on June 17, 2024

The return transformer currently ignores all case statements under a switch except for the last. I have a pending, failing test for it in a commit for a related issue, test/pending/no_return_switch.*: https://github.com/dburt/js2coffee/blob/a06bf2a61e8e686cf9db858065f8a903475a9834/test/pending/no_return_switch.js

I haven't managed to solve it, but it might be a problem with Node#walk

from js2coffee.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.