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.31k stars 156 forks source link

Is it expected a "+" sign in an object's key field to be translated into a function? #1120

Open ceremcem opened 2 years ago

ceremcem commented 2 years ago

Is this behavior expected:

a = 
  +: "x"
  -: "y"
a = [
  +(function(){
    _: return "x";
  }()), -(function(){
    _: return "y";
  }())
];

I would definitely expect the following output:

a = {
  "+": "x",
  "-": "y"
};
fatherofinvention commented 1 year ago

Isn't LiveScript dead now? It hasn't had a release in over 2.5 years at this point.

vendethiel commented 1 year ago

Definitely. For the issue at hand, I don't think you can really expect to be able to use operators as object keys. What you wrote is basically

a = 
  +(: "x")
  -(: "y")
ceremcem commented 1 year ago

Thanks. Shouldn't this behavior changed? Why would somebody use an operator as an operator while defining an object?

vendethiel commented 1 year ago

Why would somebody use an operator as an operator while defining an object?

You're not defining an object, you're defining an array, like this:

a =
  1
  2

The fact that you can treat a label as an expression is definitely a bit weird, but it's not only in this case:

$ lsc -bce '+:1'
+(function(){
  _: return 1;
}());