Skip to content

Commit

Permalink
Support private property identifier in JS lexer (#2076)
Browse files Browse the repository at this point in the history
  • Loading branch information
tancnle authored Sep 26, 2024
1 parent 67f3244 commit aafee29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rouge/lexers/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def self.id_regex

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

rule %r/(#{id})[ \t]*(?=(\(.*\)))/m do |m|
if self.class.keywords.include? m[1]
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
Expand All @@ -201,7 +201,7 @@ def self.id_regex

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

rule id do |m|
rule %r/#?#{id}/ do |m|
if self.class.keywords.include? m[0]
token Keyword
push :expr_start
Expand Down
18 changes: 18 additions & 0 deletions spec/visual/samples/javascript
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,21 @@ ret += "\n";

let baz;
baz ??= 'default';

class ClassWithPrivate {
#privateField;
#privateFieldWithInitializer = 42;

#privateMethod(obj) {
if (#privateField in obj) return obj.#privateField;

return "invalid obj"
}

static #privateStaticField;
static #privateStaticFieldWithInitializer = 42;

static #privateStaticMethod() {
// …
}
}

0 comments on commit aafee29

Please sign in to comment.