diff --git a/lib/rouge/lexers/javascript.rb b/lib/rouge/lexers/javascript.rb index e5db0eb594..c844c2cf1b 100644 --- a/lib/rouge/lexers/javascript.rb +++ b/lib/rouge/lexers/javascript.rb @@ -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