Skip to content

fix(javascript) correctly highlight 'for await' again #4240

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

Merged

Conversation

wolfgang42
Copy link
Contributor

Fixes highlighting for for await (foo) {}, which had regressed.

Closes #4235.

Changes

The FUNCTION_CALL highlighting function has a list of excluded keywords; adding await there fixed the highlighting.

However, I’m not sure this is the correct fix. I notice there is another special case as well:

{
// prevent this from getting swallowed up by function
// since they appear "function like"
beginKeywords: "while if switch catch for"
},

This implies to me that perhaps something in this grammar is in the wrong order, or needs its relevance adjusted, but that seems like a much bigger change and I’m having a hard time figuring out what it would need to look like.

Also, it is technically possible (if very confusing) to have a function called await, and this would be highlighted incorrectly:

async function await() {}
await await()

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

@joshgoebel
Copy link
Member

to have a function called await

That's a terrible idea so I don't mind if that edge case isn't covered.

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

7 files changed

Total change +15 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB +1 B
es/highlight.min.js 8.19 KB 8.19 KB +1 B
es/languages/javascript.min.js 2.74 KB 2.74 KB +2 B
es/languages/typescript.min.js 3.21 KB 3.21 KB +3 B
highlight.min.js 8.23 KB 8.23 KB +2 B
languages/javascript.min.js 2.74 KB 2.75 KB +3 B
languages/typescript.min.js 3.21 KB 3.22 KB +3 B

@joshgoebel joshgoebel force-pushed the wolfgang42/javascript-fix-for-await branch from e0bcc85 to d5788d8 Compare April 23, 2025 02:33
Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

6 files changed

Total change +9 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB -1 B
es/highlight.min.js 8.19 KB 8.19 KB -1 B
es/languages/javascript.min.js 2.74 KB 2.74 KB +2 B
es/languages/typescript.min.js 3.21 KB 3.21 KB +3 B
languages/javascript.min.js 2.74 KB 2.75 KB +3 B
languages/typescript.min.js 3.21 KB 3.22 KB +3 B

@joshgoebel joshgoebel merged commit d21e285 into highlightjs:main Apr 23, 2025
19 checks passed
ewwwin pushed a commit to ewwwin/highlight.js that referenced this pull request Apr 24, 2025
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

Successfully merging this pull request may close these issues.

(javascript) regression: “for await“ highlighted as function instead of keyword
3 participants