atom / symbols-view

Jump to symbols in Atom
MIT License
164 stars 114 forks source link

Request: Support Javascript arrow functions and classes #160

Open KSXGitHub opened 8 years ago

KSXGitHub commented 8 years ago

Arrow functions (named f, g, h):

var f = (x) => 2 * x
let g = (x) => 3 * x
var h = (x, y, z) => {
    return x + 2 * y + 3 * z
}

Classes:

class A {}
class B extends A {}
var C = class {}
let D = class extends C {}
arrowfunxtion commented 7 years ago

Is this available right now? Symbols-view doesn't recognise class methods declared using arrow function syntax

class Animal {
    constructor(){}

    walk = () => {
      console.log('walking around')
    }

   eat(){
        console.log('eating grass')
   }
}

When I click cmd + r, symbols-view only detect constructor() and eat() , walk() is not detected.

KSXGitHub commented 7 years ago

@arrowfunxtion A member variable inside a class? I don't think ES6 has this kind of thing (at least, not yet).

And BTW, your name @arrowfunxtion fit in this proposal perfectly, I wonder if you named it on purpose.

dklanac commented 7 years ago

I couldn't say for sure where arrow functions fit into the ES6/7 official plans. But Babel support for them is a default for projects like create-react-app. It would be awesome to be able to use my fuzzy symbol finder again while in React like I can for my Rails code.

fl0w commented 7 years ago
class Foo {
  bar = () => {
    ...
  }
}

Isn't valid JS as of writing, but the following is:

class Foo {
  get bar () {
    return () => {
      ...
    }
  }
}
KSXGitHub commented 7 years ago

@fl0w it isn't valid in vanilla es6, but it is valid babeljs

fl0w commented 7 years ago

@KSXGitHub Yea, that's what I ment.

KSXGitHub commented 7 years ago

@fl0w I don't see any problem with supporting extra features (babeljs, reactjs, etc.)

fl0w commented 7 years ago

I couldn't say for sure where arrow functions fit into the ES6/7 official plans

@KSXGitHub I'm not injecting an opinion here, I was just adding clarification to the comment.

magicdawn commented 7 years ago

hello @KSXGitHub

class Animal {
    constructor(){}

    walk = () => {
      console.log('walking around')
    }

   eat(){
        console.log('eating grass')
   }
}

the walk = () => { ... } will auto bind this, and it's show in React's documentation, and used a lot in React community.

see https://facebook.github.io/react/docs/handling-events.html image

KSXGitHub commented 7 years ago

@magicdawn Why are you telling me this?

the walk = () => { ... } will auto bind this

How is this even relevant?

magicdawn commented 7 years ago

I'm just saying it helps React developer a lot on handling events. and used a lot. But this package does not support these class members ...................

KSXGitHub commented 7 years ago

@magicdawn Well, then you just need to say that React devs use it a lot. Irrelevant details might be confusing :smile:

KSXGitHub commented 7 years ago

Oh, I forgot about my second comment. I was not against member arrow function or anything, that was a bit surprise from me (because es6 doesn't have it)