Shopify / javascript

The home for all things JavaScript at Shopify.
MIT License
251 stars 38 forks source link

Move private class vars to outer scope. #157

Closed lemonmade closed 8 years ago

lemonmade commented 8 years ago

Discussed in #155. Currently, decaf with throw an error on this:

class Foo
  bar = -> 'baz'

Because there is no comparable JS thing for private members scoped to a class. I think we should just move the statements to the upper scope, as the linter will catch any duplicate declarations if there are any (which I think is unlikely). So, this:

class Foo
  bar = -> 'baz'
  qux: -> bar()

Becomes:

var bar = function bar() { return 'baz'; }

class Foo {
  qux() { return bar(); }
}

(I am guessing on what exactly the bar = becomes, but whatever happens our transforms should turn it into what we want (a function declaration)).

GoodForOneFare commented 8 years ago

This could be tricky from a technical perspective. Might have to mess with scope as a temporary store again. The point where decaf goes AAAAAAAAAARGH is: https://github.com/Shopify/decaf/blob/master/src/parser.js#L361.