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

Keyword "from" is not a valid keyword in some languages #2968

Closed
mmena1 opened this issue Jun 25, 2021 · 1 comment · Fixed by #2970
Closed

Keyword "from" is not a valid keyword in some languages #2968

mmena1 opened this issue Jun 25, 2021 · 1 comment · Fixed by #2970

Comments

@mmena1
Copy link

mmena1 commented Jun 25, 2021

Information:

  • Prism version: latest from the CDN.
  • Plugins: none
  • Environment: Browser

Description
Prism incorrectly highlights the "from" word as a keyword in some languages which are not supposed to be highlighted. An example of this is Javascript and C#.

Although in C# is kinda tricky since it is a keyword when using a from-in clause:

func(from: "America", to: "Asia"); // Prism incorrectly highlights "from" as a keyword

from element in list; // no issues here

Example
JSFiddle

@RunDevelopment
Copy link
Member

JavaScript:

from is a keyword in JavaScript and Prism highlights it as such.

image
(source)

We use a little trick to only highlight the from in imports as a keyword: from(?=\s*(?:['"]|$)). The from keyword is guaranteed to be preceded by a string literal, so our regex checks for that.

C#:

As you said, this is tricky. Prism's regex-based highlighting approach is not powerful enough to detect whether from is used as a keyword inside a LINQ query or as a regular identifier elsewhere.

However, I think we could use a similar trick as for JS. The from keyword is guaranteed to be preceded by either a type or an identifier. I'll make a PR for this trick.

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

Successfully merging a pull request may close this issue.

2 participants