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

(typescript) $class variable is incorrectly highlighted as a keyword #2516

Closed
1aron opened this issue Apr 28, 2020 · 7 comments · Fixed by #2519
Closed

(typescript) $class variable is incorrectly highlighted as a keyword #2516

1aron opened this issue Apr 28, 2020 · 7 comments · Fixed by #2519
Labels
bug help welcome Could use help from community language

Comments

@1aron
Copy link

1aron commented Apr 28, 2020

Describe the issue

Which language seems to have the issue?

Are you using highlight or highlightAuto? highlight

...

Sample Code to Reproduce

https://jsfiddle.net/fsLxdrpm/1/

const ElementPrototype = Element.prototype;
const isBool = (v: any) => typeof v === 'boolean';
const $class = (v: any) => typeof v === 'boolean';
const whether = isBool(true);
const test = $class(true);

Expected behavior

  1. $class prefix with $ went wrong
  2. method with class name went wrong
  3. method isn't be highlighted
  4. Element isn't be highlighted
  5. isBool isn't be highlighted
@1aron 1aron added bug help welcome Could use help from community language labels Apr 28, 2020
@1aron 1aron changed the title (language name) Short description of issue... (typescript) highlight went wrong Apr 28, 2020
@joshgoebel
Copy link
Member

joshgoebel commented Apr 28, 2020

$class prefix with $ went wrong

This is a limitation of how we process keywords because technically the tiny area between $ and class counts as a word boundary. Is this type of naming common in Typescript?

To fix it we'd have to hardcode a rule to match all $[keyword] instances and ignore them. Or change it to \s vs \b but I bet there are cases that would break such as a keyword following a bracket or something like that, no?

method isn't be highlighted

What method? Also see my comment on isBool.

Element isn't be highlighted

We don't have a completely list of types in our grammar... if you have a suggestion of which ones we should add we could discuss it and see if we can find an agreement - but I'm not sure we should "add them all" because there are a ton of them. For example TypeScript's DOM type definition has 100s of types: https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts

So we'd need some way to decide on the "major" ones...

isBool isn't be highlighted

It wouldn't be, we don't highlight method invocation.

@joshgoebel joshgoebel changed the title (typescript) highlight went wrong (typescript) $class variable is incorrectly highlighted as a keyword Apr 28, 2020
@joshgoebel
Copy link
Member

@egor-rogov Actually I wonder if we just extended lexemes to add $ to it (even though it's not used in any keywords)... so now when looking for keywords it matches WHOLE identifiers (perhaps that's the best behavior anyways)... so it would see $class instead of class and go "nope, not a keyword".

See any downsides?

@joshgoebel
Copy link
Member

@allejo

@egor-rogov
Copy link
Collaborator

egor-rogov commented Apr 29, 2020

@egor-rogov Actually I wonder if we just extended lexemes to add $ to it (even though it's not used in any keywords)... so now when looking for keywords it matches WHOLE identifiers (perhaps that's the best behavior anyways)... so it would see $class instead of class and go "nope, not a keyword".

Yeah, I agree.
My first thought was about Perl (which uses $ for scalars and we have a separate rule for this), but no. In Perl $ has its own meaning, while here it's just a part of identifier (right?).

@joshgoebel
Copy link
Member

Yes, in JS/TS $ and _ are just characters like any other. Hence jQuery $ and _ (underscore) libs.

@allejo
Copy link
Member

allejo commented Apr 30, 2020

@egor-rogov Actually I wonder if we just extended lexemes to add $ to it (even though it's not used in any keywords)... so now when looking for keywords it matches WHOLE identifiers (perhaps that's the best behavior anyways)... so it would see $class instead of class and go "nope, not a keyword".

I don't see any downsides to this since $ isn't reserved. Just conventions in libraries like jQuery and Angular (they use $$).

@joshgoebel
Copy link
Member

Fix will go out in 10.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants