Skip to content

Commit

Permalink
javascript: Fix an issue where some keywords like "for" and "if" are …
Browse files Browse the repository at this point in the history
…mistakenly recognized as functions (#1938)

fix #1934
  • Loading branch information
nsfisis committed Apr 9, 2023
1 parent be4d825 commit b274a10
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/rouge/lexers/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,14 @@ def self.id_regex

rule %r/function(?=(\(.*\)))/, Keyword::Declaration # For anonymous functions

rule %r/(#{id})[ \t]*(?=(\(.*\)))/m, Name::Function
rule %r/(#{id})[ \t]*(?=(\(.*\)))/m do |m|
if self.class.keywords.include? m[1]
# "if" in "if (...)" or "switch" in "switch (...)" are recognized as keywords.
token Keyword
else
token Name::Function
end
end

rule %r/[{}]/, Punctuation, :statement

Expand Down

0 comments on commit b274a10

Please sign in to comment.