question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

entity.name.function.js scope not applied to arrow functions inside class definitions

See original GitHub issue

Env

Running Sublime Text build 3176 on OSX, version v1.0.22 of this package.

Steps to repro

Paste this code into the editor.

import React from 'react'


const Test = ({ a, b }) => {
  f1 = (e) => {
    e.preventDefault()
  }

  return null
}

export default Test


class TestComponent extends React.Component {
  f2 = (e) => {
    e.preventDefault()
  }

  render() {
    return null
  }
}

Set the syntax to JS Custom - React or JS Custom - Default and hit <kbd>cmd+R</kbd>. The function identifier f2 isn’t indexed, because the entity.name.function.js scope isn’t applied to it.

If you set the syntax on the view to JavaScript and hit <kbd>cmd+R</kbd>, f2 is indexed, which is correct, but so are other symbols which are neither function nor class definitions.

Also, if you save the file and hit <kbd>shift+cmd+R</kbd> to see all indexed symbols in the project, f2 is indexed correctly.

Other observations

It seems that the base JavaScript syntax applies the correct scope to arrow functions defined inside class definitions, while the JS Custom syntaxes do not.

@Thom1729 I’m really happy you’re working on this plugin. babel-sublime dev has been inactive for most of the last two years, so I’m hoping this plugin is the way forward for writing JS in Sublime Text. If there’s anything you’d like help with, let me know.

Finally, great decision to piggyback as much as possible on the new JavaScript syntax. Reading about why you decided to do that is what made me switch to this package from Babel Sublime.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Thom1729commented, Sep 4, 2018

I’m seeing the same behavior between the core JavaScript syntax and JS Custom. f2 is not indexed because the class property code doesn’t check for function assignments. This should be addressed in core; I’ll see if I can write a PR in the next couple of days.

You’re seeing that the core syntax is indexing f2?

0reactions
kylebebakcommented, Nov 30, 2018

@Thom1729

Hmmm… I installed ST build 3182, which includes the upstream fixes you mentioned, and am running JS Custom v1.0.23.

class A {
  method = () => {}
}

If I set the syntax to plain JavaScript, method is indexed, which means the upstream fix works.

However, if I set the syntax to JS Custom - Default or JS Custom - React, method is not indexed.

I tried removing the User/JS Custom folder and rebuilding the syntaxes to no avail. I also tried uninstalling JS Custom and reinstalling it.

I am using the default JS Custom.sublime-settings that ships with the plugin.

Maybe I’m doing something stupid, but I’ve looked at the README and I can’t figure out what!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Classes and arrow functions and THIS [closed]
Arrow function gets lexical this from enclosing scope. In case an arrow is defined in global scope, this is window , and undefined...
Read more >
Understanding Arrow Functions in JavaScript
Arrow functions are a new way to write anonymous function expressions in JavaScript, and are similar to lambda functions in some other ...
Read more >
How To Use Javascript Arrow Functions & This Keyword
ES6 introduced a new way of writing JavaScript functions called arrow function that uses a fat arrow ( => ). This guide will...
Read more >
Why arrow function not working in Script Include - Tokyo?
However, I have realised that arrow functions are not working inside a class in Script Include. Is everyone having this issue and reasons...
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
Arrow functions don't have their own bindings to this , arguments , or super , and should not be used as methods. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found