Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Support ES6 ": function"-less notation #16

Closed
gaearon opened this issue Aug 22, 2014 · 17 comments
Closed

Support ES6 ": function"-less notation #16

gaearon opened this issue Aug 22, 2014 · 17 comments

Comments

@gaearon
Copy link

gaearon commented Aug 22, 2014

I'd like to bring yungsters/sublime#5 to your attention in case it doesn't get noticed. There are two stale pull requests in the repo so I'm not sure if it is maintained at all.

The problem arises when using React with harmony transforms: short method notation is unreadable because method names aren't highlighted:

I submitted a pull request to JSX tmLanguage which, albeit hackish, gets the job done and tries very hard to not introduce false positives.

Hope it is helpful to you as it was to me.

@valscion
Copy link

👍 this. I opened the tmLanguage file manually and changed the definitions to incorporate the changes in @gaearon's pull request and I can start using the "function"-less notation with ease! Thanks!

@gaearon
Copy link
Author

gaearon commented Oct 24, 2014

It does have some problems though. (I'm not too irritated so I haven't fixed them myself:)

  • When you open { and later add } on another line, it gets incorrectly indented
  • Selecting lines and pressing Cmd+/ to comment them out no longer works

Please let us know if you find a fix for these!

@dan-dr
Copy link

dan-dr commented Dec 1, 2014

+1 miiiiilion dollars 💰
btw @gaearon your PR isn't working for me for some reason :(

@gaearon
Copy link
Author

gaearon commented Dec 1, 2014

Sorry, don't know why. It works for me..

@dan-dr
Copy link

dan-dr commented Dec 1, 2014

are you using SublimeLinter-jsxhint ?
It seems to have it's own tmLanguage for JSX maybe it's interrupting.
any chance you can upload your ReactJS.sublime-package ?

@gaearon
Copy link
Author

gaearon commented Dec 1, 2014

Here's my setup: http://cl.ly/3T223Z3s2r39/Archive.zip

Not sure which of these are relevant though! And you'll need to manually choose JavaScript (ES6 + JSX) for JSX and JS files separately.

@max-mykhailenko
Copy link

How to add Add function to the sublime functions list?
Used @gaearon setup.

screen shot 2014-12-20 at 6 23 09 pm

@gaearon
Copy link
Author

gaearon commented Dec 20, 2014

I think you don't need : there.

@max-mykhailenko
Copy link

@gaearon How I can pass functions to object without :?

a = {
  b : () => {},
  c : () => {}
}

@gaearon
Copy link
Author

gaearon commented Dec 20, 2014

ES6 concise method notation is

a = {
  b() { },
  c() { }
}

@max-mykhailenko
Copy link

@gaearon, got it. But now I have some indent and no description
screen shot 2014-12-20 at 11 48 07 pm

@gaearon
Copy link
Author

gaearon commented Dec 20, 2014

As I said above, my PR is not entirely correct and is somewhat hackish:

When you open { and later add } on another line, it gets incorrectly indented

this is probably the same problem. I'd love if somebody fixed these! I'm not too keen on language grammar.

@STRML
Copy link

STRML commented Dec 27, 2014

I've been able to make it more accurate with:

    <key>method-concise-es6</key>
    <dict>
      <key>begin</key>
      <string>([a-zA-Z_?.$][\w?.$]*)(?=\(.*\)\ *\{)</string>
      <key>beginCaptures</key>
      <dict>
        <key>0</key>
        <dict>
          <key>name</key>
          <string>meta.function.js</string>
        </dict>
        <key>1</key>
        <dict>
          <key>name</key>
          <string>entity.name.function.js</string>
        </dict>
        <key>2</key>
        <dict>
          <key>name</key>
          <string>storage.type.function.js</string>
        </dict>
      </dict>
      <key>comment</key>
      <string>attempt to match ES6 concise methods: myFunc(arg) { … }</string>
      <key>end</key>
      <string>\}</string>
      <key>endCaptures</key>
      <dict>
        <key>0</key>
        <dict>
          <key>name</key>
          <string>meta.brace.curly.js</string>
        </dict>
      </dict>
      <key>name</key>
      <string>meta.scope.function.js</string>
      <key>patterns</key>
      <array>
        <dict>
          <key>include</key>
          <string>#comment</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#meta-function-parameters</string>
        </dict>
        <dict>
          <key>include</key>
          <string>#meta-function-body</string>
        </dict>
      </array>
    </dict>

The key differences are that it doesn't match the parameters list and opening curly; it rather uses the existing #meta-function-parameters and #meta-function-body. Since it matches far less, I use positive lookahead to ensure it doesn't over-match.

Give it a shot and let me what you think - working great for me so far.

@STRML
Copy link

STRML commented Dec 27, 2014

IMO it's better to just rebase this project on top of JavaScriptNext and work from there so we get all the new stuff.

@gaearon
Copy link
Author

gaearon commented Dec 27, 2014

Wow, great to hear there's been progress. I'll try it out.

@gaearon
Copy link
Author

gaearon commented Jan 19, 2015

IMO it's better to just rebase this project on top of JavaScriptNext and work from there so we get all the new stuff.

Yeah that's what these folks did. It works perfectly:

https://github.com/6to5/6to5-sublime

@jgebhardt
Copy link
Contributor

This package no longer provides syntax highlighting. Please install the "Babel" package for syntax highlighting instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants