Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Javascript] Arrow function arguments split across lines get wrong scope #2724

Closed
dsl101 opened this issue Feb 19, 2021 · 4 comments
Closed

Comments

@dsl101
Copy link

dsl101 commented Feb 19, 2021

  • Sublime Version: 3.2.2. Build 3211
  • OS Version: Windows 10 64-bit
const oneLine = (p1, p2 = false) => {
  // etc
}

const oneLineDestructured = ({ p1, p2 = false }) => {
  // etc
}

const multiLine = (
  p1,
  p2 = false
) => {
  // etc
}

const multiLineDestructured = ({
  p1,
  p2 = false
}) => {
  // etc
}

image

Scope Hunter reports the function multiLine as source.js meta.binding.name.js variable.other.readwrite.js whereas oneLine is (correctly) source.js meta.function.declaration.js entity.name.function.js variable.other.readwrite.js. There are similar differences for all the other incorrectly highlighted elements. Let me know if it's useful to list them all.

@dsl101 dsl101 changed the title [Javascript] Function arguments split across lines get wrong scope [Javascript] Arrow function arguments split across lines get wrong scope Feb 19, 2021
@dsl101
Copy link
Author

dsl101 commented Feb 19, 2021

Also I found this similar issue in a different repo. I guess it's the same underlying problem (regex engine)? babel/babel-sublime#340

@rchl
Copy link
Contributor

rchl commented Feb 19, 2021

This is how it looks in ST4 build 4098:

Screenshot 2021-02-19 at 14 57 40

Looks like the arguments look good now.
The variables don't get entity.name.function assigned though.

@Thom1729
Copy link
Collaborator

Yep, the current version of the JavaScript syntax fixes multiline arrow function. It relies on a new feature from ST4, so the fix cannot be backported to ST3.

The syntax still uses regexp lookaheads to scope function names in e.g. const f = () => {}, so in that example f won't get entity.name.function. I'd like to fix that, but I haven't worked out the best way to do it without blowing up the syntax definition size. See #2267.

@dsl101
Copy link
Author

dsl101 commented Feb 19, 2021

Fantastic—I will give ST4 a go. Many thanks.

@dsl101 dsl101 closed this as completed Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants